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 the color mode either to 1b or 2b
set(COLORMODE_fx 2b) set(COLORMODE_fx 2b)
#set the color mode either to 1b, 2b or EGA64 #set the color mode either to 1b, 2b or EGA64
set(COLORMODE_cg 1b) set(COLORMODE_cg 2b)
fxconv_declare_converters(assets/converters.py) fxconv_declare_converters(assets/converters.py)

View file

@ -27,6 +27,7 @@ def convert_world(input, output, params, target):
print( "So let's go ... ") print( "So let's go ... ")
structWorld = fxconv.Structure() structWorld = fxconv.Structure()
#structExtra = fxconv.Structure()
for i in range(nbMaps): for i in range(nbMaps):
nameMap = data["maps"][i]["fileName"].replace(".tmx","") nameMap = data["maps"][i]["fileName"].replace(".tmx","")
@ -61,47 +62,22 @@ def convert_world(input, output, params, target):
print( "Map = ", map ) print( "Map = ", map )
structWorld += fxconv.ptr( 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) structWorld += fxconv.u32(0)
#generate ! #structExtra += fxconv.u32(0)
#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, ...) #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): 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) 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 #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) layer_data += fxconv.u16(tile-1)
structMap += fxconv.ptr(layer_data) structMap += fxconv.ptr(layer_data)
#generate !
#fxconv.elf(structMap, output, "_" + params["name"], **target)
return structMap return structMap
@ -239,20 +225,29 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
break break
elif i==nblayer: elif i==nblayer:
print( "ERROR : No ExtraData layer data !!!" ) print( "ERROR : No ExtraData layer data !!!" )
return fxconv.u32(0) return 0, fxconv.u32(0)
#create the structure of the map #create the structure of the map
structData = fxconv.Structure() structData = fxconv.Structure()
nbExtraData = 0
layer = data["layers"][layer_extradata] layer = data["layers"][layer_extradata]
for i in layer["objects"]: for i in layer["objects"]:
nbExtraData = nbExtraData + 1
x = i["x"] + xmin x = i["x"] + xmin
y = i["y"] + ymin y = i["y"] + ymin
st = i[ "type" ] nme = i["name"]
print( "OBJECT X= ", x, " Y= ", y, "STR= ", st ) tpe = i["type"]
structData += fxconv.u16( x ) for j in i["properties"]:
structData += fxconv.u16( y ) stg = j[ "value" ]
structData += fxconv.string( st ) 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 # name_regex: (.*)\.json map_\1
*.world: WorldRPG.world:
custom-type: world custom-type: world
# extra: extraRPG #name: xxx #unused but mandatory (Do not touch)
#varMapData: worldRPG
#varExtraData: extraRPG
name: worldRPG name: worldRPG

1
clean
View file

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

View file

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

View file

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

View file

@ -26,8 +26,8 @@
extern bopti_image_t player_face_img; extern bopti_image_t player_face_img;
extern Map *worldRPG[];
extern Map *worldRPG[];
/* Game data (defined in "game.h")*/ /* Game data (defined in "game.h")*/
Game game = { Game game = {
@ -36,7 +36,7 @@ Game game = {
false, false, false, 0 false, false, false, 0
/* debug variables*/ /* debug variables*/
, false, false , false, false, true
}; };
/* screen capture management code */ /* screen capture management code */
@ -108,13 +108,13 @@ int main(void) {
dgray(DGRAY_ON); dgray(DGRAY_ON);
#endif #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); 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); 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); 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 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); else showtext_dialog(&game, &player_face_img, "You choosed Lorem", false, true);
*/
do{ do{
/* clear screen */ /* clear screen */
@ -139,6 +139,13 @@ int main(void) {
drect( 5, 55,390, 75, C_WHITE ); 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 ); 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 #endif
/* start the logic of the game */ /* start the logic of the game */

View file

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