Added importation of ExtraData from ObjectLayer in Tiled TMX files

This commit is contained in:
SlyVTT 2023-08-16 17:34:45 +02:00
parent 6075e47ba8
commit c5975889bc
8 changed files with 84 additions and 62 deletions

View file

@ -14,7 +14,7 @@ find_package(LibProf 2.4 REQUIRED)
#set the color mode either to 1b or 2b
set(COLORMODE_fx 2b)
#set the color mode either to 1b, 2b or EGA64
set(COLORMODE_cg 1b)
set(COLORMODE_cg 2b)
fxconv_declare_converters(assets/converters.py)

View file

@ -27,7 +27,8 @@ def convert_world(input, output, params, target):
print( "So let's go ... ")
structWorld = fxconv.Structure()
#structExtra = fxconv.Structure()
for i in range(nbMaps):
nameMap = data["maps"][i]["fileName"].replace(".tmx","")
nameMapFree = nameMap.split("/")[-1]
@ -61,47 +62,22 @@ def convert_world(input, output, params, target):
print( "Map = ", map )
structWorld += fxconv.ptr( map )
#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 )
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)
#structExtra += fxconv.u32(0)
"""
#and all the extra data (PNJ, SGN, ...)
fxconv.elf(structExtra, output, "_" + params["name"]+"Extra", **target)
"""
fxconv.elf_multi(
[("_" + params["varMapData"], structWorld),
("_" + params["varExtraData"], structExtra)],
output, **target)
"""
#generate !
fxconv.elf(structWorld, output, "_" + params["name"], **target)
def get_tile_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
@ -174,6 +150,18 @@ def get_tile_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
structMap += fxconv.ptr(walk_data)
nbextra = 0
extradata = fxconv.Structure()
nbextra, extradata = get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax)
if (nbextra==0):
structMap += fxconv.u32( 0 )
structMap += fxconv.u32( 0 )
else:
structMap += fxconv.u32( int(nbextra) )
structMap += fxconv.ptr( extradata )
#extraction of the data contained in the layer "Background" and "Foreground" of the map
@ -212,8 +200,6 @@ def get_tile_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
layer_data += fxconv.u16(tile-1)
structMap += fxconv.ptr(layer_data)
#generate !
#fxconv.elf(structMap, output, "_" + params["name"], **target)
return structMap
@ -239,20 +225,29 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
break
elif i==nblayer:
print( "ERROR : No ExtraData layer data !!!" )
return fxconv.u32(0)
return 0, fxconv.u32(0)
#create the structure of the map
structData = fxconv.Structure()
nbExtraData = 0
layer = data["layers"][layer_extradata]
for i in layer["objects"]:
nbExtraData = nbExtraData + 1
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 )
nme = i["name"]
tpe = i["type"]
for j in i["properties"]:
stg = j[ "value" ]
print( "OBJECT X= ", x, " Y= ", y, "STR= ", stg )
print( " Type= ", tpe, " Name= ", nme )
structData += fxconv.u16( int(x) )
structData += fxconv.u16( int(y) )
structData += fxconv.string( nme )
structData += fxconv.string( tpe )
structData += fxconv.string( stg )
return structData
return nbExtraData, structData

View file

@ -3,7 +3,9 @@
# name_regex: (.*)\.json map_\1
*.world:
WorldRPG.world:
custom-type: world
# extra: extraRPG
#name: xxx #unused but mandatory (Do not touch)
#varMapData: worldRPG
#varExtraData: extraRPG
name: worldRPG

1
clean
View file

@ -3,6 +3,7 @@ rm -f *.json
rm -r __pycache__
cd ..
rm -r build-cg
rm -r build-cg-push
rm -r build-fx
rm *.g1a
rm *.g3a

View file

@ -7,8 +7,12 @@
#include <gint/keyboard.h>
#include <gint/cpu.h>
void game_logic(Game *game) {
// to be done
}
void draw(Game *game) {

View file

@ -2,6 +2,7 @@
#define GAME_H
#include <gint/display.h>
#include <stdint.h>
@ -33,17 +34,23 @@ typedef struct {
typedef struct {
uint16_t x, y;
char type[3];
uint16_t x;
uint16_t y;
char *name;
char *type;
char *dialog;
} ExtraData;
typedef struct {
/* width, height and the number of layer of the map */
uint16_t w, h;
uint16_t w;
uint16_t h;
uint16_t nblayers;
uint16_t tileset_size;
/* world coordinates of the upper left and bootom right*/
/* corners of the current map to be multiplied in game by PXSIZE */
uint16_t xmin;
uint16_t ymin;
uint16_t xmax;
@ -57,8 +64,13 @@ typedef struct {
uint8_t *walkable;
uint32_t nbextradata;
ExtraData *extradata;
/* list of all the tiles */
uint16_t *layers[];
} Map;
@ -80,8 +92,9 @@ typedef struct {
long int frame_duration;
/* variables used for debuging */
bool debug_player;
bool debug_map;
bool debug_player;
bool debug_extra;
} Game;
/* (Mibi88) TODO: Describe what this function is doing. */

View file

@ -26,8 +26,8 @@
extern bopti_image_t player_face_img;
extern Map *worldRPG[];
extern Map *worldRPG[];
/* Game data (defined in "game.h")*/
Game game = {
@ -36,7 +36,7 @@ Game game = {
false, false, false, 0
/* debug variables*/
, false, false
, false, false, true
};
/* screen capture management code */
@ -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 */
@ -139,6 +139,13 @@ int main(void) {
drect( 5, 55,390, 75, C_WHITE );
dprint( 10, 60, C_BLUE, "X= %d - Y= %d / Wx= %d - Wy= %d", game.player.x, game.player.y, game.player.wx, game.player.wy );
}
if (game.debug_extra)
{
dfont( NULL );
//drect( 155, 80, 390, 150, C_WHITE );
for (int i=0; i<game.map_level->nbextradata; i++ )
dprint( 10, 90+i*15, C_RED, "X= %d - Y= %d - T: %s", game.map_level->extradata[i].x, game.map_level->extradata[i].y, game.map_level->extradata[i].dialog );
}
#endif
/* start the logic of the game */

View file

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