mirror of
https://git.planet-casio.com/Slyvtt/Collab_RPG.git
synced 2024-12-29 13:03:43 +01:00
converter.py correctly reads and treat maps in world file (importation into data structure in C files not fully working yet
This commit is contained in:
parent
7d04e62848
commit
53b0ddf750
10 changed files with 119 additions and 37 deletions
|
@ -51,10 +51,11 @@ set(SOURCES
|
||||||
)
|
)
|
||||||
# Shared assets, fx-9860G-only assets and fx-CG-50-only assets
|
# Shared assets, fx-9860G-only assets and fx-CG-50-only assets
|
||||||
set(ASSETS
|
set(ASSETS
|
||||||
assets/level0.json
|
#assets/level0.json
|
||||||
assets/level1.json
|
#assets/level1.json
|
||||||
assets/level2.json
|
#assets/level2.json
|
||||||
assets/level3.json
|
#assets/level3.json
|
||||||
|
assets/WorldRPG.world
|
||||||
# ...
|
# ...
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -89,7 +90,7 @@ set(ASSETS_fx_2b
|
||||||
# ...
|
# ...
|
||||||
)
|
)
|
||||||
|
|
||||||
fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} ${ASSETS_fx_1b} ${ASSETS_fx_2b} ${ASSETS_cg_2b} ${ASSETS_cg_EGA64} WITH_METADATA)
|
fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} ${ASSETS_fx_1b} ${ASSETS_fx_2b} ${ASSETS_cg_2b} ${ASSETS_cg_EGA64} WITH_METADATA)
|
||||||
|
|
||||||
if("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G)
|
if("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G)
|
||||||
add_executable(myaddin ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}} ${ASSETS_${FXSDK_PLATFORM}_${COLORMODE_fx}} )
|
add_executable(myaddin ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}} ${ASSETS_${FXSDK_PLATFORM}_${COLORMODE_fx}} )
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 34 KiB |
Binary file not shown.
Before Width: | Height: | Size: 44 KiB |
|
@ -3,15 +3,80 @@ import fxconv
|
||||||
import json
|
import json
|
||||||
import pathlib
|
import pathlib
|
||||||
import csv
|
import csv
|
||||||
|
import os
|
||||||
|
|
||||||
def convert(input, output, params, target):
|
def convert(input, output, params, target):
|
||||||
if params["custom-type"] == "map":
|
if params["custom-type"] == "map":
|
||||||
convert_map(input, output, params, target)
|
#convert_map(input, output, params, target)
|
||||||
|
#return 0
|
||||||
|
return 1
|
||||||
|
elif params["custom-type"] == "world":
|
||||||
|
convert_world(input, output, params, target)
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def convert_world(input, output, params, target):
|
||||||
|
print( "WE ARE COMPUTING THE WORLD", input )
|
||||||
|
|
||||||
|
data = json.load(open(input, "r"))
|
||||||
|
nbMaps = ["fileName" in i for i in data["maps"]].count(True)
|
||||||
|
print( "We have to treat ", nbMaps, " maps")
|
||||||
|
print( "So let's go ... ")
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
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 )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
xmin = data["maps"][i]["x"]
|
||||||
|
print( "xmin = ", xmin )
|
||||||
|
structWorld += fxconv.u16( xmin ) #xmin parameter
|
||||||
|
|
||||||
|
ymin = data["maps"][i]["y"]
|
||||||
|
print( "ymin = ", ymin )
|
||||||
|
structWorld += fxconv.u16( ymin ) #ymin parameter
|
||||||
|
|
||||||
|
xmax = data["maps"][i]["x"] + data["maps"][i]["width"]
|
||||||
|
print( "xmax = ", xmax )
|
||||||
|
structWorld += fxconv.u16( xmax ) #xmax parameter
|
||||||
|
|
||||||
|
ymax = data["maps"][i]["y"] + data["maps"][i]["height"]
|
||||||
|
print( "ymax = ", ymax )
|
||||||
|
structWorld += fxconv.u16( ymax ) #ymax parameter
|
||||||
|
|
||||||
|
map = convert_map( mapPath, output, params, target )
|
||||||
|
print( "Map = ", map )
|
||||||
|
structWorld += map
|
||||||
|
|
||||||
|
#generate !
|
||||||
|
fxconv.elf(structWorld, output, "_" + params["name"], **target)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def convert_map(input, output, params, target):
|
def convert_map(input, output, params, target):
|
||||||
|
print( "WE ARE COMPUTING THE MAP : ", input )
|
||||||
data = json.load(open(input, "r"))
|
data = json.load(open(input, "r"))
|
||||||
|
|
||||||
#find the tileset in use. it's a relative path (like ../tileset.tsx)
|
#find the tileset in use. it's a relative path (like ../tileset.tsx)
|
||||||
|
@ -22,9 +87,14 @@ def convert_map(input, output, params, target):
|
||||||
#count the number of "back" (cd ..) to locate the tileset on the computer
|
#count the number of "back" (cd ..) to locate the tileset on the computer
|
||||||
nbRetour = nameTileset.count("..")+1
|
nbRetour = nameTileset.count("..")+1
|
||||||
#create the tileset absolute path
|
#create the tileset absolute path
|
||||||
tilesetPath = "/".join(input.split("/")[:-nbRetour]) + "/" + nameTileset + ".json"
|
tilesetTSX = "/".join(input.split("/")[:-nbRetour]) + "/" + nameTileset + ".tsx"
|
||||||
|
tilesetJSON = "/".join(input.split("/")[:-nbRetour]) + "/" + nameTileset + ".json"
|
||||||
|
|
||||||
tileset = open(tilesetPath, "r")
|
commandline = 'tiled --export-tileset json ' + tilesetTSX + ' ' + tilesetJSON
|
||||||
|
print( "TILED COMMAND LINE FOR TILESET : ", commandline )
|
||||||
|
os.system( commandline )
|
||||||
|
|
||||||
|
tileset = open(tilesetJSON, "r")
|
||||||
data_tileset = json.load(tileset)
|
data_tileset = json.load(tileset)
|
||||||
tileset_size = data_tileset.get("columns")
|
tileset_size = data_tileset.get("columns")
|
||||||
tileset.close()
|
tileset.close()
|
||||||
|
@ -45,7 +115,6 @@ def convert_map(input, output, params, target):
|
||||||
layer_foreground = 0
|
layer_foreground = 0
|
||||||
layer_background = 0
|
layer_background = 0
|
||||||
|
|
||||||
|
|
||||||
#create the structure of the map
|
#create the structure of the map
|
||||||
structMap = fxconv.Structure()
|
structMap = fxconv.Structure()
|
||||||
|
|
||||||
|
@ -64,7 +133,6 @@ def convert_map(input, output, params, target):
|
||||||
elif i==nbTilelayer:
|
elif i==nbTilelayer:
|
||||||
printf( "ERROR : No Walkable layer data !!!" )
|
printf( "ERROR : No Walkable layer data !!!" )
|
||||||
|
|
||||||
|
|
||||||
walk_data = bytes()
|
walk_data = bytes()
|
||||||
layer = data["layers"][layer_walkable]
|
layer = data["layers"][layer_walkable]
|
||||||
for tile in layer["data"]:
|
for tile in layer["data"]:
|
||||||
|
@ -87,7 +155,6 @@ def convert_map(input, output, params, target):
|
||||||
elif i==nbTilelayer:
|
elif i==nbTilelayer:
|
||||||
printf( "ERROR : No Background layer data !!!" )
|
printf( "ERROR : No Background layer data !!!" )
|
||||||
|
|
||||||
|
|
||||||
layer_data = bytes()
|
layer_data = bytes()
|
||||||
layer = data["layers"][layer_background]
|
layer = data["layers"][layer_background]
|
||||||
for tile in layer["data"]:
|
for tile in layer["data"]:
|
||||||
|
@ -95,7 +162,6 @@ def convert_map(input, output, params, target):
|
||||||
structMap += fxconv.ptr(layer_data)
|
structMap += fxconv.ptr(layer_data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#import the foreground layer of the map
|
#import the foreground layer of the map
|
||||||
for i in range(nbTilelayer+1):
|
for i in range(nbTilelayer+1):
|
||||||
datavalid = data["layers"][i]
|
datavalid = data["layers"][i]
|
||||||
|
@ -106,7 +172,6 @@ def convert_map(input, output, params, target):
|
||||||
elif i==nbTilelayer:
|
elif i==nbTilelayer:
|
||||||
printf( "ERROR : No Foreground layer data !!!" )
|
printf( "ERROR : No Foreground layer data !!!" )
|
||||||
|
|
||||||
|
|
||||||
layer_data = bytes()
|
layer_data = bytes()
|
||||||
layer = data["layers"][layer_foreground]
|
layer = data["layers"][layer_foreground]
|
||||||
for tile in layer["data"]:
|
for tile in layer["data"]:
|
||||||
|
@ -114,9 +179,8 @@ def convert_map(input, output, params, target):
|
||||||
structMap += fxconv.ptr(layer_data)
|
structMap += fxconv.ptr(layer_data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#generate !
|
#generate !
|
||||||
fxconv.elf(structMap, output, "_" + params["name"], **target)
|
#fxconv.elf(structMap, output, "_" + params["name"], **target)
|
||||||
|
|
||||||
|
return structMap
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
*.json:
|
# *.json:
|
||||||
custom-type: map
|
# custom-type: map
|
||||||
name_regex: (.*)\.json map_\1
|
# name_regex: (.*)\.json map_\1
|
||||||
|
|
||||||
|
|
||||||
|
*.world:
|
||||||
|
custom-type: world
|
||||||
|
name: worldRPG
|
||||||
|
|
8
clean
Executable file
8
clean
Executable file
|
@ -0,0 +1,8 @@
|
||||||
|
cd assets
|
||||||
|
rm -f *.json
|
||||||
|
cd ..
|
||||||
|
rm -r build-cg
|
||||||
|
rm -r build-fx
|
||||||
|
rm *.g1a
|
||||||
|
rm *.g3a
|
||||||
|
|
11
src/main.c
11
src/main.c
|
@ -21,14 +21,20 @@
|
||||||
|
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "mapdata.h"
|
#include "mapdata.h"
|
||||||
|
#include "mapstruct.h"
|
||||||
|
|
||||||
#include "dialogs.h"
|
#include "dialogs.h"
|
||||||
|
|
||||||
extern bopti_image_t player_face_img;
|
extern bopti_image_t player_face_img;
|
||||||
|
|
||||||
|
extern World worldRPG[];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Game data (defined in "game.h")*/
|
/* Game data (defined in "game.h")*/
|
||||||
Game game = {
|
Game game = {
|
||||||
&map_level0,
|
&worldRPG[0].mapdata,
|
||||||
{10*PXSIZE, 48*PXSIZE, 0, 0, 100, SPEED},
|
{10*PXSIZE, 48*PXSIZE, 0, 0, 100, SPEED},
|
||||||
false, false, false, 0
|
false, false, false, 0
|
||||||
};
|
};
|
||||||
|
@ -99,10 +105,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", 2, 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", 2, 0);
|
||||||
if(in) showtext_dialog(&game, &player_face_img, "You choosed ipsum", false, true);
|
if(in) 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 */
|
||||||
dclear(C_WHITE);
|
dclear(C_WHITE);
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#ifndef MAPDATA_H
|
#ifndef MAPDATA_H
|
||||||
#define MAPDATA_H
|
#define MAPDATA_H
|
||||||
|
|
||||||
extern Map map_level0;
|
#include <stdint.h>
|
||||||
extern Map map_level1;
|
#include "mapstruct.h"
|
||||||
extern Map map_level2;
|
|
||||||
extern Map map_level3;
|
extern World worldRPG[];
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -26,21 +26,16 @@ typedef struct {
|
||||||
} Map;
|
} Map;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
||||||
/* numberof maps in the world */
|
|
||||||
uint16_t nbmaps;
|
|
||||||
|
|
||||||
/* table of coordinates for each map, each is a table of nbmaps elements */
|
/* table of coordinates for each map, each is a table of nbmaps elements */
|
||||||
/* area of map N is given by (xmin[N], ymin[N]) --> (xmax[N], ymax[N]) */
|
/* area of map N is given by (xmin[N], ymin[N]) --> (xmax[N], ymax[N]) */
|
||||||
uint16_t *xmin;
|
uint16_t xmin;
|
||||||
uint16_t *ymin;
|
uint16_t ymin;
|
||||||
uint16_t *xmax;
|
uint16_t xmax;
|
||||||
uint16_t *ymax;
|
uint16_t ymax;
|
||||||
|
|
||||||
/* pointer to the currentmap*/
|
/* pointer to the currentmap*/
|
||||||
Map *currentmap;
|
Map mapdata;
|
||||||
|
|
||||||
} World;
|
} World;
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ extern bopti_image_t demo_player_img;
|
||||||
|
|
||||||
void player_draw(Player *player) {
|
void player_draw(Player *player) {
|
||||||
dimage(player->px-P_WIDTH/2, player->py-P_HEIGHT/2, &demo_player_img);
|
dimage(player->px-P_WIDTH/2, player->py-P_HEIGHT/2, &demo_player_img);
|
||||||
dprint( 10, 10, C_RED, "X= %d - Y= %d", player->x, player->y );
|
//dprint( 10, 10, C_RED, "X= %d - Y= %d", player->x, player->y );
|
||||||
}
|
}
|
||||||
|
|
||||||
void player_move(Map *map_level, Player *player, Direction direction) {
|
void player_move(Map *map_level, Player *player, Direction direction) {
|
||||||
|
|
Loading…
Reference in a new issue