try to import Extra Data from world and maps

This commit is contained in:
SlyVTT 2023-08-15 16:50:51 +02:00
parent df33d2f090
commit 6075e47ba8
6 changed files with 95 additions and 14 deletions

View file

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

View file

@ -5,4 +5,5 @@
*.world:
custom-type: world
# extra: extraRPG
name: worldRPG

View file

@ -91,21 +91,24 @@
</layer>
<objectgroup id="4" name="ExtraData">
<object id="1" name="PlayerStart" type="PST" x="52" y="44">
<properties>
<property name="dialog" value="Quelqu'un est mort ici ..."/>
</properties>
<point/>
</object>
<object id="2" name="PNJ1" type="NPC" x="236.667" y="165">
<object id="2" name="PNJ1" type="NPC" x="252" y="164">
<properties>
<property name="dialog" value="Salut, je suis un PNJ"/>
</properties>
<point/>
</object>
<object id="4" name="SGN1" type="SGN" x="96.3333" y="136">
<object id="4" name="SGN1" type="SGN" x="96" y="136">
<properties>
<property name="dialog" value="Indication sur le panneau. Bienvenue dans la maison du Tondu ..."/>
</properties>
<point/>
</object>
<object id="5" name="SGN2" type="SGN" x="288" y="127.333">
<object id="5" name="SGN2" type="SGN" x="288" y="128">
<properties>
<property name="dialog" value="Indication sur le panneau. Entree dans le Sanctuaire Maudit ..."/>
</properties>

View file

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

View file

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

View file

@ -5,6 +5,7 @@
#include <gint/display.h>
extern Map *worldRPG[];
//extern ExtraData *extraRPG[];
void render_map(Game *game) {