diff --git a/assets-cg/converters.py b/assets-cg/converters.py index 6aeeafd..0a785d3 100644 --- a/assets-cg/converters.py +++ b/assets-cg/converters.py @@ -16,8 +16,9 @@ def convert_map(input, output, params, target): TILE_DOOR_OUT = 3 TILE_TALKABLE = 4 - with open(input, "r") as jsonData: - data = json.load(jsonData) + DIALOG_LAYOUT = "dialog" + + 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","") @@ -57,45 +58,24 @@ def convert_map(input, output, params, target): #Extract from the json the width, height w, h = data["width"], data["height"] - indexObjectlayer = None #nbTileLayer is the number of "true" layers (without ObjectsLayer) - nbTilelayer = len(data["layers"]) - for i in range(nbTilelayer): - try: - data["layers"][i]["data"] - nbTilelayer = i+1 - except KeyError: - indexObjectlayer = i - break - - if indexObjectlayer != None: - nbDialog = len(data["layers"][indexObjectlayer]["objects"]) - else: - nbDialog = 0 + nbTilelayer = ["data" in i for i in data["layers"]].count(True) + objectLayers = data["layers"][nbTilelayer:len(data["layers"])] + nbDialog = 0 structMap = fxconv.Structure() + dialogs = fxconv.Structure() + + for layer in objectLayers: + if layer.get("name") == DIALOG_LAYOUT: + nbDialog = len(layer["objects"]) + dialogs = parseDialog(layer) + else: + print("UNKNOWN LAYOUT FOUND : " + layer.get("name")) + structMap += fxconv.u32(w) + fxconv.u32(h) + fxconv.u32(nbTilelayer) + fxconv.u32(nbDialog) structMap += fxconv.ref(f"img_{nameTilesetFree}") - - dialogs = fxconv.Structure() - # print(indexObjectlayer) - if indexObjectlayer != None: - #generate all of the dialog - for i in data["layers"][indexObjectlayer]["objects"]: - dialogs += fxconv.u32(int(i["x"]/i["width"])) - #Tiled seem to start at the bottom y of the object - #So if tile is 16 px wide, you would start at line y = 1 - dialogs += fxconv.u32(int(i["y"]/i["width"])-1) - - try: - for j in i["properties"]: - if(j["value"] == ""): j["value"] = " " - dialogs += fxconv.string(j["value"]) - except KeyError: - dialogs += fxconv.string("default name") - dialogs += fxconv.string("default text") - structMap += fxconv.ptr(dialogs) #generation of the collision map (take the maximum of the layer except for bridges) @@ -130,4 +110,20 @@ def convert_map(input, output, params, target): structMap += fxconv.ptr(layer_data) #generate ! - fxconv.elf(structMap, output, "_" + params["name"], **target) \ No newline at end of file + fxconv.elf(structMap, output, "_" + params["name"], **target) + +def parseDialog(layer): + dialogs = fxconv.Structure() + for i in layer["objects"]: + dialogs += fxconv.u32(int(i["x"]/i["width"])) + #Tiled seem to start at the bottom y of the object + dialogs += fxconv.u32(int(i["y"]/i["width"])-1) + + try: + for j in i["properties"]: + if(j["value"] == ""): j["value"] = " " + dialogs += fxconv.string(j["value"]) + except KeyError: + dialogs += fxconv.string("default name") + dialogs += fxconv.string("default text") + return dialogs \ No newline at end of file diff --git a/assets-cg/fxconv-metadata.txt b/assets-cg/fxconv-metadata.txt index c5f692f..845e22f 100644 --- a/assets-cg/fxconv-metadata.txt +++ b/assets-cg/fxconv-metadata.txt @@ -1,7 +1,7 @@ tileset.png: type: bopti-image name: img_tileset - profile:p4 + profile: p4 spritesheet.png: type: bopti-image diff --git a/assets-cg/icon-sel.png b/assets-cg/icon-sel.png index 7137b50..c6151c5 100644 Binary files a/assets-cg/icon-sel.png and b/assets-cg/icon-sel.png differ diff --git a/assets-cg/icon-uns.png b/assets-cg/icon-uns.png index 3c99f62..e16a6c5 100644 Binary files a/assets-cg/icon-uns.png and b/assets-cg/icon-uns.png differ diff --git a/assets-cg/maps/inside/1.tmx b/assets-cg/maps/inside/1.tmx index 991f10e..034794d 100644 --- a/assets-cg/maps/inside/1.tmx +++ b/assets-cg/maps/inside/1.tmx @@ -1,5 +1,5 @@ - + @@ -35,15 +35,18 @@ - - + + - - + + + + + diff --git a/assets-cg/maps/inside/2.tmx b/assets-cg/maps/inside/2.tmx index 913f180..3121d4e 100644 --- a/assets-cg/maps/inside/2.tmx +++ b/assets-cg/maps/inside/2.tmx @@ -46,17 +46,17 @@ 0,0,0,0,0,0,707,0,0,707,0,0,0,0,0 - + - - + + - - + + diff --git a/assets-cg/maps/inside/3.tmx b/assets-cg/maps/inside/3.tmx index 96c8bf9..a069a31 100644 --- a/assets-cg/maps/inside/3.tmx +++ b/assets-cg/maps/inside/3.tmx @@ -24,8 +24,8 @@ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,710,710,0,0,0,0,679,0,0,0,0,710,710,0,0,710,710,0,0, -0,739,739,0,704,705,0,20,21,0,0,0,739,739,0,0,739,739,0,0, -0,0,0,0,733,734,0,49,50,654,655,0,0,0,0,0,0,0,0,0, +0,739,739,0,704,705,0,0,0,0,0,0,739,739,0,0,739,739,0,0, +0,0,0,0,733,734,0,0,0,654,655,0,0,0,0,0,0,0,0,0, 0,0,0,0,706,706,0,0,0,654,655,591,0,0,0,0,0,0,0,0, 0,0,591,614,615,615,616,0,0,711,713,620,0,0,0,0,0,0,0,0, 0,0,620,0,0,0,0,0,0,740,742,649,0,0,0,0,0,0,0,0, @@ -58,13 +58,18 @@ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - + - + + + + + + diff --git a/assets-cg/maps/testCarte.tmx b/assets-cg/maps/testCarte.tmx index c29477e..ecbcc70 100644 --- a/assets-cg/maps/testCarte.tmx +++ b/assets-cg/maps/testCarte.tmx @@ -1,5 +1,5 @@ - + @@ -88,11 +88,11 @@ 294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,381,382,383,381,382,383,381,382,383,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - + - + @@ -119,5 +119,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/engine.c b/src/engine.c index fc57ace..f944215 100644 --- a/src/engine.c +++ b/src/engine.c @@ -18,6 +18,8 @@ void engine_draw(struct Game const *game) { engine_draw_player(game); drect(0,0,DWIDTH,20,C_BLACK); drect(0,DHEIGHT-20,DWIDTH,DHEIGHT,C_BLACK); + drect(0,0,20,DHEIGHT,C_BLACK); + drect(DWIDTH-20,0,DWIDTH,DHEIGHT,C_BLACK); dprint(1,1,C_WHITE,"%d:%d",game->player->pos.x, game->player->pos.y); dprint(1,20,C_WHITE,"%d",game->player->sprint); @@ -28,7 +30,7 @@ void engine_draw_map(struct Game const *game) { const int y_offset = (game->camera.offset.y - DHEIGHT/2); for (int y = 1 ; y <= DHEIGHT / TILE_SIZE-1; y++) { - for (int x = 0 ; x <= DWIDTH / TILE_SIZE+1; x++) { + for (int x = 1 ; x <= DWIDTH / TILE_SIZE; x++) { for (int layer = 0 ; layer < game->map->nb_layers; layer++) { unsigned int tile_id = 0; //detect if the map is oob