Add dialog + update how object's layout are parse

This commit is contained in:
bgiraudr 2022-01-18 18:59:09 +01:00
parent 6949e4b58f
commit a12fb2e47f
9 changed files with 121 additions and 55 deletions

View File

@ -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)
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

View File

@ -1,7 +1,7 @@
tileset.png:
type: bopti-image
name: img_tileset
profile:p4
profile: p4
spritesheet.png:
type: bopti-image

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.5" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="12" height="10" tilewidth="16" tileheight="16" infinite="0" nextlayerid="11" nextobjectid="34">
<map version="1.5" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="12" height="10" tilewidth="16" tileheight="16" infinite="0" nextlayerid="12" nextobjectid="35">
<editorsettings>
<export target="interior_1.json" format="json"/>
</editorsettings>
@ -35,15 +35,18 @@
<objectgroup id="10" name="dialog">
<object id="32" gid="267" x="144" y="128" width="16" height="16">
<properties>
<property name="name" value="Television"/>
<property name="text" value="La tele diffuse une ancienne;emission : Odyssee"/>
<property name="name" value="Télévision"/>
<property name="text" value="La télé diffuse une ancienne chaine à la mode; Odyssée"/>
</properties>
</object>
<object id="33" gid="267" x="160" y="128" width="16" height="16">
<properties>
<property name="name" value="Television"/>
<property name="text" value="La tele diffuse une ancienne;emission : Odyssee"/>
<property name="name" value="Télévision"/>
<property name="text" value="Le personnage semble bien mal au point..."/>
</properties>
</object>
</objectgroup>
<objectgroup id="11" name="test">
<object id="34" gid="267" x="80" y="64" width="16" height="16"/>
</objectgroup>
</map>

View File

@ -46,17 +46,17 @@
0,0,0,0,0,0,707,0,0,707,0,0,0,0,0
</data>
</layer>
<objectgroup id="14" name="Calque d'Objets 1">
<objectgroup id="14" name="dialog">
<object id="32" gid="267" x="16" y="64" width="16" height="16">
<properties>
<property name="name" value="Television"/>
<property name="text" value="La television est eteinte"/>
<property name="name" value="Télévision"/>
<property name="text" value="La télévision est éteinte"/>
</properties>
</object>
<object id="34" gid="267" x="32" y="64" width="16" height="16">
<properties>
<property name="name" value="Television"/>
<property name="text" value="Des traces de doigts sont;presentes sur l'ecran"/>
<property name="name" value="Télévision"/>
<property name="text" value="Des traces de doigts sont;présentes sur l'écran"/>
</properties>
</object>
</objectgroup>

View File

@ -24,8 +24,8 @@
<data encoding="csv">
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
</data>
</layer>
<objectgroup id="4" name="talk">
<objectgroup id="4" name="dialog">
<object id="1" gid="267" x="64" y="64" width="16" height="16">
<properties>
<property name="name" value="Télévision"/>
<property name="text" value="&quot;Bonjour à tous !&quot;"/>
</properties>
</object>
<object id="2" gid="267" x="80" y="64" width="16" height="16"/>
<object id="2" gid="267" x="80" y="64" width="16" height="16">
<properties>
<property name="name" value="Télévision"/>
<property name="text" value="&quot;Et à bientôt sur Planète Casio !&quot;"/>
</properties>
</object>
</objectgroup>
</map>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.5" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="100" height="38" tilewidth="16" tileheight="16" infinite="0" nextlayerid="11" nextobjectid="38">
<map version="1.5" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="100" height="38" tilewidth="16" tileheight="16" infinite="0" nextlayerid="11" nextobjectid="48">
<editorsettings>
<export target="testCarte.json" format="json"/>
</editorsettings>
@ -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
</data>
</layer>
<objectgroup id="10" name="text">
<objectgroup id="10" name="dialog">
<object id="33" gid="267" x="592" y="528" width="16" height="16">
<properties>
<property name="name" value="Tituya"/>
<property name="text" value="J'ai toujours aimé ce pont;Pas toi ?"/>
<property name="text" value="Bonjour !;Je ne pense pas finir ce jeu...;voici donc une sorte de preview de ce qui;ne va pas arriver.;Encore désolé pour ce projet..."/>
</properties>
</object>
<object id="34" gid="267" x="704" y="368" width="16" height="16">
@ -119,5 +119,65 @@
<property name="text" value="Je te rassure, pas de Pokémon !"/>
</properties>
</object>
<object id="38" gid="267" x="32" y="160" width="16" height="16">
<properties>
<property name="name" value="FlamingKite"/>
<property name="text" value="Vous avez vu le dernier Vilebrequin ?"/>
</properties>
</object>
<object id="39" gid="267" x="160" y="336" width="16" height="16">
<properties>
<property name="name" value="Planète Casio"/>
<property name="text" value="La ville déserte la plus active !"/>
</properties>
</object>
<object id="40" gid="267" x="176" y="336" width="16" height="16">
<properties>
<property name="name" value="Planète Casio"/>
<property name="text" value="Bienvenue !"/>
</properties>
</object>
<object id="41" gid="267" x="832" y="48" width="16" height="16">
<properties>
<property name="name" value="Masséna"/>
<property name="text" value="Evocalc ?"/>
</properties>
</object>
<object id="42" gid="267" x="1216" y="304" width="16" height="16">
<properties>
<property name="name" value="Shadow15510"/>
<property name="text" value="C'est Odyssée ici ?"/>
</properties>
</object>
<object id="43" gid="267" x="1440" y="272" width="16" height="16">
<properties>
<property name="name" value="Tituya"/>
<property name="text" value="Tu savais que je suis rédacteur ?"/>
</properties>
</object>
<object id="44" gid="267" x="1312" y="592" width="16" height="16">
<properties>
<property name="name" value="Hackcell"/>
<property name="text" value="Aujourd'hui, j'ai envie de parler;Comment vas-tu ?;Tu sais que j'ai bruteforce le puzzle de Noël !;Bientôt en violet sur la shout !"/>
</properties>
</object>
<object id="45" gid="267" x="1392" y="80" width="16" height="16">
<properties>
<property name="name" value="Inikiwi"/>
<property name="text" value="Bonjour !"/>
</properties>
</object>
<object id="46" gid="267" x="1104" y="32" width="16" height="16">
<properties>
<property name="name" value="Adoranda"/>
<property name="text" value="Ville la plus hype de la région !"/>
</properties>
</object>
<object id="47" gid="267" x="1120" y="32" width="16" height="16">
<properties>
<property name="name" value="Adoranda"/>
<property name="text" value="Parlez à nos habitants !"/>
</properties>
</object>
</objectgroup>
</map>

View File

@ -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