mirror of
https://git.planet-casio.com/Slyvtt/Collab_RPG.git
synced 2025-04-19 09:27:16 +02:00
try to find the source of the bug (need to get map data correctly filled) in map with converter.py
This commit is contained in:
parent
d84fd7f886
commit
16a198bc64
7 changed files with 238 additions and 37 deletions
|
@ -29,6 +29,7 @@ def convert_world(input, output, params, target):
|
|||
structWorld = fxconv.Structure()
|
||||
|
||||
for i in range(nbMaps):
|
||||
|
||||
nameMap = data["maps"][i]["fileName"].replace(".tmx","")
|
||||
nameMapFree = nameMap.split("/")[-1]
|
||||
#count the number of "back" (cd ..) to locate the map on the computer
|
||||
|
@ -47,27 +48,23 @@ def convert_world(input, output, params, target):
|
|||
mapPath = "/".join(input.split("/")[:-nbRetour]) + "/" + nameMap + ".json"
|
||||
print("Map ", i , " name : ", mapPath )
|
||||
|
||||
|
||||
|
||||
xmin = data["maps"][i]["x"]
|
||||
print( "xmin = ", xmin )
|
||||
structWorld += fxconv.u16( xmin ) #xmin parameter
|
||||
|
||||
ymin = data["maps"][i]["y"]
|
||||
print( "ymin = ", ymin )
|
||||
structWorld += fxconv.u16( ymin ) #ymin parameter
|
||||
|
||||
xmax = data["maps"][i]["x"] + data["maps"][i]["width"]
|
||||
print( "xmax = ", xmax )
|
||||
structWorld += fxconv.u16( xmax ) #xmax parameter
|
||||
|
||||
ymax = data["maps"][i]["y"] + data["maps"][i]["height"]
|
||||
print( "ymax = ", ymax )
|
||||
structWorld += fxconv.u16( ymax ) #ymax parameter
|
||||
|
||||
map = convert_map( mapPath, output, params, target )
|
||||
map = convert_map( mapPath, output, params, target, xmin, ymin, xmax, ymax)
|
||||
print( "Map = ", map )
|
||||
structWorld += map
|
||||
structWorld += fxconv.ptr( map )
|
||||
|
||||
structWorld += fxconv.u32(0)
|
||||
|
||||
#generate !
|
||||
fxconv.elf(structWorld, output, "_" + params["name"], **target)
|
||||
|
@ -75,7 +72,7 @@ def convert_world(input, output, params, target):
|
|||
|
||||
|
||||
|
||||
def convert_map(input, output, params, target):
|
||||
def convert_map(input, output, params, target, xmin, ymin, xmax, ymax):
|
||||
print( "WE ARE COMPUTING THE MAP : ", input )
|
||||
data = json.load(open(input, "r"))
|
||||
|
||||
|
@ -120,6 +117,9 @@ def convert_map(input, output, params, target):
|
|||
|
||||
structMap += fxconv.u16(w) + fxconv.u16(h) + fxconv.u16(nbTilelayer)
|
||||
structMap += fxconv.u16(tileset_size)
|
||||
|
||||
structMap += fxconv.u16(xmin) + fxconv.u16(ymin) + fxconv.u16(xmax) + fxconv.u16(ymax)
|
||||
|
||||
structMap += fxconv.ref(f"img_{nameTilesetFree}")
|
||||
|
||||
|
||||
|
@ -142,6 +142,7 @@ def convert_map(input, output, params, target):
|
|||
structMap += fxconv.ptr(walk_data)
|
||||
|
||||
|
||||
|
||||
#extraction of the data contained in the layer "Background" and "Foreground" of the map
|
||||
|
||||
|
||||
|
@ -162,6 +163,7 @@ def convert_map(input, output, params, target):
|
|||
structMap += fxconv.ptr(layer_data)
|
||||
|
||||
|
||||
|
||||
#import the foreground layer of the map
|
||||
for i in range(nbTilelayer+1):
|
||||
datavalid = data["layers"][i]
|
||||
|
@ -178,7 +180,6 @@ def convert_map(input, output, params, target):
|
|||
layer_data += fxconv.u16(tile-1)
|
||||
structMap += fxconv.ptr(layer_data)
|
||||
|
||||
|
||||
#generate !
|
||||
#fxconv.elf(structMap, output, "_" + params["name"], **target)
|
||||
|
||||
|
|
188
assets/converters.py.backup
Normal file
188
assets/converters.py.backup
Normal file
|
@ -0,0 +1,188 @@
|
|||
from random import randint
|
||||
import fxconv
|
||||
import json
|
||||
import pathlib
|
||||
import csv
|
||||
import os
|
||||
|
||||
def convert(input, output, params, target):
|
||||
if params["custom-type"] == "map":
|
||||
#convert_map(input, output, params, target)
|
||||
#return 0
|
||||
return 1
|
||||
elif params["custom-type"] == "world":
|
||||
convert_world(input, output, params, target)
|
||||
return 0
|
||||
else:
|
||||
return 1
|
||||
|
||||
|
||||
|
||||
def convert_world(input, output, params, target):
|
||||
print( "WE ARE COMPUTING THE WORLD", input )
|
||||
|
||||
data = json.load(open(input, "r"))
|
||||
nbMaps = ["fileName" in i for i in data["maps"]].count(True)
|
||||
print( "We have to treat ", nbMaps, " maps")
|
||||
print( "So let's go ... ")
|
||||
|
||||
structWorld = fxconv.Structure()
|
||||
|
||||
for i in range(nbMaps):
|
||||
|
||||
nameMap = data["maps"][i]["fileName"].replace(".tmx","")
|
||||
nameMapFree = nameMap.split("/")[-1]
|
||||
#count the number of "back" (cd ..) to locate the map on the computer
|
||||
nbRetour = nameMap.count("..")+1
|
||||
#create the map absolute path
|
||||
|
||||
|
||||
nameTMX = "/".join(input.split("/")[:-nbRetour]) + "/" + nameMap + ".tmx"
|
||||
nameJSON = "/".join(input.split("/")[:-nbRetour]) + "/" + nameMap + ".json"
|
||||
|
||||
commandline = 'tiled --export-map json ' + nameTMX + ' ' + nameJSON
|
||||
print( "TILED COMMAND LINE FOR MAPS : ", commandline )
|
||||
os.system( commandline )
|
||||
|
||||
|
||||
mapPath = "/".join(input.split("/")[:-nbRetour]) + "/" + nameMap + ".json"
|
||||
print("Map ", i , " name : ", mapPath )
|
||||
|
||||
|
||||
|
||||
xmin = data["maps"][i]["x"]
|
||||
print( "xmin = ", xmin )
|
||||
structWorld += fxconv.u16( xmin ) #xmin parameter
|
||||
|
||||
ymin = data["maps"][i]["y"]
|
||||
print( "ymin = ", ymin )
|
||||
structWorld += fxconv.u16( ymin ) #ymin parameter
|
||||
|
||||
xmax = data["maps"][i]["x"] + data["maps"][i]["width"]
|
||||
print( "xmax = ", xmax )
|
||||
structWorld += fxconv.u16( xmax ) #xmax parameter
|
||||
|
||||
ymax = data["maps"][i]["y"] + data["maps"][i]["height"]
|
||||
print( "ymax = ", ymax )
|
||||
structWorld += fxconv.u16( ymax ) #ymax parameter
|
||||
|
||||
map = convert_map( mapPath, output, params, target )
|
||||
print( "Map = ", map )
|
||||
structWorld += map
|
||||
|
||||
|
||||
#generate !
|
||||
fxconv.elf(structWorld, output, "_" + params["name"], **target)
|
||||
|
||||
|
||||
|
||||
|
||||
def convert_map(input, output, params, target):
|
||||
print( "WE ARE COMPUTING THE MAP : ", input )
|
||||
data = json.load(open(input, "r"))
|
||||
|
||||
#find the tileset in use. it's a relative path (like ../tileset.tsx)
|
||||
nameTileset = data["tilesets"][0]["source"].replace(".tsx","")
|
||||
print(nameTileset)
|
||||
#the name of the tileset without the .something
|
||||
nameTilesetFree = nameTileset.split("/")[-1]
|
||||
#count the number of "back" (cd ..) to locate the tileset on the computer
|
||||
nbRetour = nameTileset.count("..")+1
|
||||
#create the tileset absolute path
|
||||
tilesetTSX = "/".join(input.split("/")[:-nbRetour]) + "/" + nameTileset + ".tsx"
|
||||
tilesetJSON = "/".join(input.split("/")[:-nbRetour]) + "/" + nameTileset + ".json"
|
||||
|
||||
commandline = 'tiled --export-tileset json ' + tilesetTSX + ' ' + tilesetJSON
|
||||
print( "TILED COMMAND LINE FOR TILESET : ", commandline )
|
||||
os.system( commandline )
|
||||
|
||||
tileset = open(tilesetJSON, "r")
|
||||
data_tileset = json.load(tileset)
|
||||
tileset_size = data_tileset.get("columns")
|
||||
tileset.close()
|
||||
|
||||
#find the ID of the first tile in the walkable tileset ()
|
||||
indexWalkable = data["tilesets"][1]["firstgid"]
|
||||
print(indexWalkable)
|
||||
|
||||
#Extract from the json the width, height
|
||||
w, h = data["width"], data["height"]
|
||||
|
||||
#nbTileLayer is the number of "true" layers (without ObjectsLayer)
|
||||
nbTilelayer = ["data" in i for i in data["layers"]].count(True) - 1
|
||||
print( nbTilelayer)
|
||||
|
||||
#index of the various layers (may change from one map to another)
|
||||
layer_walkable = 0
|
||||
layer_foreground = 0
|
||||
layer_background = 0
|
||||
|
||||
#create the structure of the map
|
||||
structMap = fxconv.Structure()
|
||||
|
||||
structMap += fxconv.u16(w) + fxconv.u16(h) + fxconv.u16(nbTilelayer)
|
||||
structMap += fxconv.u16(tileset_size)
|
||||
structMap += fxconv.ref(f"img_{nameTilesetFree}")
|
||||
|
||||
|
||||
#extraction of the data contained in the layer "Walkable" of the map
|
||||
for i in range(nbTilelayer+1):
|
||||
datavalid = data["layers"][i]
|
||||
if datavalid["name"]=="Walkable":
|
||||
layer_walkable = i
|
||||
print( "Walkable Tile Data in layer : ", layer_walkable)
|
||||
break
|
||||
elif i==nbTilelayer:
|
||||
printf( "ERROR : No Walkable layer data !!!" )
|
||||
|
||||
walk_data = bytes()
|
||||
layer = data["layers"][layer_walkable]
|
||||
for tile in layer["data"]:
|
||||
#print( tile )
|
||||
if tile == 0: walk_data += fxconv.u8(tile) #if walkable_data = 0 then it is a blanck cell so nothing to change
|
||||
else : walk_data += fxconv.u8(tile-indexWalkable) #if !=0 than we need to shift the tile number by considering the first tileID (given by indexwalkable)
|
||||
structMap += fxconv.ptr(walk_data)
|
||||
|
||||
|
||||
#extraction of the data contained in the layer "Background" and "Foreground" of the map
|
||||
|
||||
|
||||
#import the Background layer of the map
|
||||
for i in range(nbTilelayer+1):
|
||||
datavalid = data["layers"][i]
|
||||
if datavalid["name"]=="Background":
|
||||
layer_background = i
|
||||
print( "Background Tile Data in layer : ", layer_background)
|
||||
break
|
||||
elif i==nbTilelayer:
|
||||
printf( "ERROR : No Background layer data !!!" )
|
||||
|
||||
layer_data = bytes()
|
||||
layer = data["layers"][layer_background]
|
||||
for tile in layer["data"]:
|
||||
layer_data += fxconv.u16(tile-1)
|
||||
structMap += fxconv.ptr(layer_data)
|
||||
|
||||
|
||||
#import the foreground layer of the map
|
||||
for i in range(nbTilelayer+1):
|
||||
datavalid = data["layers"][i]
|
||||
if datavalid["name"]=="Foreground":
|
||||
layer_foreground = i
|
||||
print( "Foreground Tile Data in layer : ", layer_foreground)
|
||||
break
|
||||
elif i==nbTilelayer:
|
||||
printf( "ERROR : No Foreground layer data !!!" )
|
||||
|
||||
layer_data = bytes()
|
||||
layer = data["layers"][layer_foreground]
|
||||
for tile in layer["data"]:
|
||||
layer_data += fxconv.u16(tile-1)
|
||||
structMap += fxconv.ptr(layer_data)
|
||||
|
||||
|
||||
#generate !
|
||||
#fxconv.elf(structMap, output, "_" + params["name"], **target)
|
||||
|
||||
return structMap
|
||||
|
|
@ -37,6 +37,8 @@ void get_inputs(Game *game) {
|
|||
if(keydown(KEY_UP)) player_move(game->map_level, &game->player, D_UP);
|
||||
if(keydown(KEY_DOWN)) player_move(game->map_level, &game->player, D_DOWN);
|
||||
if(keydown(KEY_SHIFT)) player_action(&game->player);
|
||||
if(keydown(KEY_F1)) game->debug_map = !game->debug_map;
|
||||
if(keydown(KEY_F2)) game->debug_player = !game->debug_player;
|
||||
|
||||
/* if USB is enabled - keybinding for screencapture */
|
||||
|
||||
|
|
|
@ -19,6 +19,11 @@ typedef struct {
|
|||
bool record;
|
||||
/* How many ms the frame already took. */
|
||||
long int frame_duration;
|
||||
|
||||
|
||||
/* variables used for debuging */
|
||||
bool debug_player;
|
||||
bool debug_map;
|
||||
} Game;
|
||||
|
||||
/* (Mibi88) TODO: Describe what this function is doing. */
|
||||
|
|
33
src/main.c
33
src/main.c
|
@ -27,17 +27,18 @@
|
|||
|
||||
extern bopti_image_t player_face_img;
|
||||
|
||||
extern World worldRPG[];
|
||||
|
||||
|
||||
extern const Map *worldRPG[];
|
||||
|
||||
|
||||
/* Game data (defined in "game.h")*/
|
||||
Game game = {
|
||||
&worldRPG[0].mapdata,
|
||||
NULL,
|
||||
{10*PXSIZE, 48*PXSIZE, 0, 0, 100, SPEED},
|
||||
false, false, false, 0
|
||||
};
|
||||
|
||||
/* debug variables*/
|
||||
, true, true
|
||||
};
|
||||
|
||||
/* screen capture management code */
|
||||
|
||||
|
@ -93,6 +94,9 @@ int main(void) {
|
|||
}
|
||||
timer_start(timer);
|
||||
|
||||
game.map_level = &worldRPG[0];
|
||||
|
||||
|
||||
#if USB_FEATURE
|
||||
usb_interface_t const *interfaces[] = {&usb_ff_bulk, NULL};
|
||||
usb_open(interfaces, GINT_CALL_NULL);
|
||||
|
@ -105,12 +109,13 @@ int main(void) {
|
|||
dgray(DGRAY_ON);
|
||||
#endif
|
||||
|
||||
/*
|
||||
/*
|
||||
showtext_dialog(&game, &player_face_img, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet.", true, true);
|
||||
int in = showtext_dialog_ask(&game, &player_face_img, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet.", true, false, "Lorem\0ipsum", 2, 0);
|
||||
if(in) showtext_dialog(&game, &player_face_img, "You choosed ipsum", false, true);
|
||||
int in = showtext_dialog_ask(&game, &player_face_img, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet.", true, false, "Lorem\0Ipsum\0Dolor", 3, 0);
|
||||
if(in==2) showtext_dialog(&game, &player_face_img, "You choosed Dolor", false, true);
|
||||
else if(in==1) showtext_dialog(&game, &player_face_img, "You choosed Ipsum", false, true);
|
||||
else showtext_dialog(&game, &player_face_img, "You choosed Lorem", false, true);
|
||||
*/
|
||||
*/
|
||||
|
||||
do{
|
||||
/* clear screen */
|
||||
|
@ -119,6 +124,16 @@ int main(void) {
|
|||
/* render the map */
|
||||
draw(&game);
|
||||
|
||||
if (game.debug_map)
|
||||
{
|
||||
dfont( NULL );
|
||||
drect( 5, 5, 200, 50, C_WHITE );
|
||||
dprint( 10, 10, C_RED, "Map[ % d ] : Xmin %d Ymin %d Xmax %d Ymax %d", 0, worldRPG[0]->xmin, worldRPG[0]->ymin, worldRPG[0]->xmax, worldRPG[0]->ymax );
|
||||
dprint( 10, 20, C_RED, "Map[ % d ] : Xmin %d Ymin %d Xmax %d Ymax %d", 1, worldRPG[1]->xmin, worldRPG[1]->ymin, worldRPG[1]->xmax, worldRPG[1]->ymax );
|
||||
dprint( 10, 30, C_RED, "Map[ % d ] : Xmin %d Ymin %d Xmax %d Ymax %d", 2, worldRPG[2]->xmin, worldRPG[2]->ymin, worldRPG[2]->xmax, worldRPG[2]->ymax );
|
||||
dprint( 10, 40, C_RED, "Map[ % d ] : Xmin %d Ymin %d Xmax %d Ymax %d", 3, worldRPG[3]->xmin, worldRPG[3]->ymin, worldRPG[3]->xmax, worldRPG[3]->ymax );
|
||||
}
|
||||
|
||||
/* start the logic of the game */
|
||||
game_logic(&game);
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <stdint.h>
|
||||
#include "mapstruct.h"
|
||||
|
||||
extern World worldRPG[];
|
||||
extern const Map *worldRPG[];
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -13,31 +13,21 @@ typedef struct {
|
|||
uint16_t nblayers;
|
||||
uint16_t tileset_size;
|
||||
|
||||
uint16_t xmin;
|
||||
uint16_t ymin;
|
||||
uint16_t xmax;
|
||||
uint16_t ymax;
|
||||
|
||||
/* the tileset to use */
|
||||
bopti_image_t *tileset;
|
||||
|
||||
/* contain the properties of the tiles */
|
||||
/* this is given by the layer Walkable of the map in Tiled
|
||||
*/
|
||||
/* this is given by the layer Walkable of the map in Tiled */
|
||||
|
||||
uint8_t *walkable;
|
||||
|
||||
/* list of all the tiles */
|
||||
uint16_t *layers[];
|
||||
} Map;
|
||||
|
||||
|
||||
typedef struct {
|
||||
/* table of coordinates for each map, each is a table of nbmaps elements */
|
||||
/* area of map N is given by (xmin[N], ymin[N]) --> (xmax[N], ymax[N]) */
|
||||
uint16_t xmin;
|
||||
uint16_t ymin;
|
||||
uint16_t xmax;
|
||||
uint16_t ymax;
|
||||
|
||||
/* pointer to the currentmap*/
|
||||
Map mapdata;
|
||||
|
||||
} World;
|
||||
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue