diff --git a/assets/converters.py b/assets/converters.py index ce4c33d..a7ab5ae 100644 --- a/assets/converters.py +++ b/assets/converters.py @@ -29,13 +29,11 @@ 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 nbRetour = nameMap.count("..")+1 #create the map absolute path - nameTMX = "/".join(input.split("/")[:-nbRetour]) + "/" + nameMap + ".tmx" nameJSON = "/".join(input.split("/")[:-nbRetour]) + "/" + nameMap + ".json" @@ -43,7 +41,6 @@ def convert_world(input, output, params, target): 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 ) @@ -60,19 +57,54 @@ def convert_world(input, output, params, target): ymax = data["maps"][i]["y"] + data["maps"][i]["height"] print( "ymax = ", ymax ) - map = convert_map( mapPath, output, params, target, xmin, ymin, xmax, ymax) + map = get_tile_map_data( mapPath, output, params, target, xmin, ymin, xmax, ymax) print( "Map = ", map ) structWorld += fxconv.ptr( map ) structWorld += fxconv.u32(0) #generate ! + #the map data fxconv.elf(structWorld, output, "_" + params["name"], **target) + + +""" + structExtra = 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 + + mapPath = "/".join(input.split("/")[:-nbRetour]) + "/" + nameMap + ".json" + print("Map ", i , " name : ", mapPath ) + + xmin = data["maps"][i]["x"] + print( "xmin = ", xmin ) + + ymin = data["maps"][i]["y"] + print( "ymin = ", ymin ) + + xmax = data["maps"][i]["x"] + data["maps"][i]["width"] + print( "xmax = ", xmax ) + + ymax = data["maps"][i]["y"] + data["maps"][i]["height"] + print( "ymax = ", ymax ) + + ext = get_extra_map_data( mapPath, output, params, target, xmin, ymin, xmax, ymax ) + print( "Data = ", ext ) + if (ext!=fxconv.u32(0)): structExtra += fxconv.ptr( ext ) + + structExtra += fxconv.u32(0) + #and all the extra data (PNJ, SGN, ...) + fxconv.elf(structExtra, output, "_" + params["name"]+"Extra", **target) +""" - - -def convert_map(input, output, params, target, xmin, ymin, xmax, ymax): +def get_tile_map_data(input, output, params, target, xmin, ymin, xmax, ymax): print( "WE ARE COMPUTING THE MAP : ", input ) data = json.load(open(input, "r")) @@ -131,7 +163,7 @@ def convert_map(input, output, params, target, xmin, ymin, xmax, ymax): print( "Walkable Tile Data in layer : ", layer_walkable) break elif i==nbTilelayer: - printf( "ERROR : No Walkable layer data !!!" ) + print( "ERROR : No Walkable layer data !!!" ) walk_data = bytes() layer = data["layers"][layer_walkable] @@ -154,7 +186,7 @@ def convert_map(input, output, params, target, xmin, ymin, xmax, ymax): print( "Background Tile Data in layer : ", layer_background) break elif i==nbTilelayer: - printf( "ERROR : No Background layer data !!!" ) + print( "ERROR : No Background layer data !!!" ) layer_data = bytes() layer = data["layers"][layer_background] @@ -185,3 +217,42 @@ def convert_map(input, output, params, target, xmin, ymin, xmax, ymax): return structMap + + +def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax): + print( "WE ARE COMPUTING THE EXTRA DATA OF THE MAP : ", input ) + data = json.load(open(input, "r")) + + + nblayer = ["id" in i for i in data["layers"]].count(True) - 1 + print( "I found ", nblayer, " of extradata") + + #index of the various layers (may change from one map to another) + layer_extradata = 0 + + #import the foreground layer of the map + for i in range(nblayer+1): + datavalid = data["layers"][i] + if datavalid["name"]=="ExtraData": + layer_extradata = i + print( "Extra Data in layer : ", layer_extradata) + break + elif i==nblayer: + print( "ERROR : No ExtraData layer data !!!" ) + return fxconv.u32(0) + + #create the structure of the map + structData = fxconv.Structure() + + layer = data["layers"][layer_extradata] + for i in layer["objects"]: + x = i["x"] + xmin + y = i["y"] + ymin + st = i[ "type" ] + print( "OBJECT X= ", x, " Y= ", y, "STR= ", st ) + structData += fxconv.u16( x ) + structData += fxconv.u16( y ) + structData += fxconv.string( st ) + + + return structData diff --git a/assets/fxconv-metadata.txt b/assets/fxconv-metadata.txt index 77b9eb0..0176752 100644 --- a/assets/fxconv-metadata.txt +++ b/assets/fxconv-metadata.txt @@ -5,4 +5,5 @@ *.world: custom-type: world +# extra: extraRPG name: worldRPG diff --git a/assets/level0.tmx b/assets/level0.tmx index 2090f4e..9e150be 100644 --- a/assets/level0.tmx +++ b/assets/level0.tmx @@ -91,21 +91,24 @@ + + + - + - + - + diff --git a/src/game.h b/src/game.h index b8b8615..5dc51c5 100644 --- a/src/game.h +++ b/src/game.h @@ -32,6 +32,11 @@ typedef struct { } Player; +typedef struct { + uint16_t x, y; + char type[3]; +} ExtraData; + typedef struct { /* width, height and the number of layer of the map */ diff --git a/src/main.c b/src/main.c index 7a84413..eef0fec 100644 --- a/src/main.c +++ b/src/main.c @@ -108,13 +108,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\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 */ diff --git a/src/map.c b/src/map.c index df771d0..94b43ff 100644 --- a/src/map.c +++ b/src/map.c @@ -5,6 +5,7 @@ #include extern Map *worldRPG[]; +//extern ExtraData *extraRPG[]; void render_map(Game *game) {