More faces :) + reduced map converter logs.

This commit is contained in:
mibi88 2024-07-25 19:08:23 +02:00
parent f91fd572ac
commit 3b2fc58c57
8 changed files with 36 additions and 34 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 107 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 555 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 105 B

After

Width:  |  Height:  |  Size: 107 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 354 B

View file

@ -6,6 +6,7 @@ import pathlib
import csv
import os
DEBUG = 0
def convert(input, output, params, target):
if params["custom-type"] == "map":
@ -34,8 +35,8 @@ def convert_world(input, output, params, target):
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 ... ")
if DEBUG: print( "We have to treat ", nbMaps, " maps")
if DEBUG: print( "So let's go ... ")
structWorld = fxconv.Structure()
#structExtra = fxconv.Structure()
@ -51,26 +52,26 @@ def convert_world(input, output, params, target):
nameJSON = "/".join(input.split("/")[:-nbRetour]) + "/" + nameMap + ".json"
commandline = 'tiled --export-map json ' + nameTMX + ' ' + nameJSON
print( "TILED COMMAND LINE FOR MAPS : ", commandline )
if DEBUG: print( "TILED COMMAND LINE FOR MAPS : ", commandline )
os.system( commandline )
mapPath = "/".join(input.split("/")[:-nbRetour]) + "/" + nameMap + ".json"
print("Map ", i , " name : ", mapPath )
if DEBUG: print("Map ", i , " name : ", mapPath )
xmin = data["maps"][i]["x"]
print( "xmin = ", xmin )
if DEBUG: print( "xmin = ", xmin )
ymin = data["maps"][i]["y"]
print( "ymin = ", ymin )
if DEBUG: print( "ymin = ", ymin )
xmax = data["maps"][i]["x"] + data["maps"][i]["width"]
print( "xmax = ", xmax )
if DEBUG: print( "xmax = ", xmax )
ymax = data["maps"][i]["y"] + data["maps"][i]["height"]
print( "ymax = ", ymax )
if DEBUG: print( "ymax = ", ymax )
map = get_tile_map_data( mapPath, output, params, target, xmin, ymin, xmax, ymax)
print( "Map = ", map )
if DEBUG: print( "Map = ", map )
structWorld += fxconv.ptr( map )
structWorld += fxconv.u32(0)
@ -85,7 +86,7 @@ def get_tile_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
#find the tileset in use. it's a relative path (like ../tileset.tsx)
nameTileset = data["tilesets"][0]["source"].replace(".tsx","")
print(nameTileset)
if DEBUG: print(nameTileset)
#the name of the tileset without the .something
nameTilesetFree = nameTileset.split("/")[-1]
#count the number of "back" (cd ..) to locate the tileset on the computer
@ -95,7 +96,7 @@ def get_tile_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
tilesetJSON = "/".join(input.split("/")[:-nbRetour]) + "/" + nameTileset + ".json"
commandline = 'tiled --export-tileset json ' + tilesetTSX + ' ' + tilesetJSON
print( "TILED COMMAND LINE FOR TILESET : ", commandline )
if DEBUG: print( "TILED COMMAND LINE FOR TILESET : ", commandline )
os.system( commandline )
tileset = open(tilesetJSON, "r")
@ -105,14 +106,14 @@ def get_tile_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
#find the ID of the first tile in the walkable tileset ()
indexWalkable = data["tilesets"][1]["firstgid"]
print(indexWalkable)
if DEBUG: print(indexWalkable)
#Extract from the json the width, height
w, h = data["width"], data["height"]
#nbTileLayer is the number of "true" layers (without ObjectsLayer)
nbTilelayer = ["data" in i for i in data["layers"]].count(True) - 1
print( nbTilelayer)
if DEBUG: print( nbTilelayer)
#index of the various layers (may change from one map to another)
layer_walkable = 0
@ -135,7 +136,7 @@ def get_tile_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
datavalid = data["layers"][i]
if datavalid["name"]=="Walkable":
layer_walkable = i
print( "Walkable Tile Data in layer : ", layer_walkable)
if DEBUG: print( "Walkable Tile Data in layer : ", layer_walkable)
break
elif i==nbTilelayer:
print( "ERROR : No Walkable layer data !!!" )
@ -168,7 +169,7 @@ def get_tile_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
nameDialog = data["properties"][0]["value"]
dialogfile = "/".join(input.split("/")[:-nbRetour]) + "/" + nameDialog
print( "THE DIALOGS ARE CONTAINED IN THE FILE : ", dialogfile )
if DEBUG: print( "THE DIALOGS ARE CONTAINED IN THE FILE : ", dialogfile )
nbdiag = 0
diagdata = fxconv.Structure()
@ -192,7 +193,7 @@ def get_tile_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
datavalid = data["layers"][i]
if datavalid["name"]=="Background":
layer_background = i
print( "Background Tile Data in layer : ", layer_background)
if DEBUG: print( "Background Tile Data in layer : ", layer_background)
break
elif i==nbTilelayer:
print( "ERROR : No Background layer data !!!" )
@ -210,10 +211,10 @@ def get_tile_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
datavalid = data["layers"][i]
if datavalid["name"]=="Foreground":
layer_foreground = i
print( "Foreground Tile Data in layer : ", layer_foreground)
if DEBUG: print( "Foreground Tile Data in layer : ", layer_foreground)
break
elif i==nbTilelayer:
printf( "ERROR : No Foreground layer data !!!" )
print( "ERROR : No Foreground layer data !!!" )
layer_data = bytes()
layer = data["layers"][layer_foreground]
@ -227,11 +228,11 @@ def get_tile_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
print( "WE ARE COMPUTING THE EXTRA DATA OF THE MAP : ", input )
if DEBUG: 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")
if DEBUG: print( "I found ", nblayer, " of extradata")
#index of the various layers (may change from one map to another)
layer_extradata = 0
@ -241,7 +242,7 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
datavalid = data["layers"][i]
if datavalid["name"]=="ExtraData":
layer_extradata = i
print( "Extra Data in layer : ", layer_extradata)
if DEBUG: print( "Extra Data in layer : ", layer_extradata)
break
elif i==nblayer:
print( "ERROR : No ExtraData layer data !!!" )
@ -287,36 +288,37 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
pathID = None
path = j[ "value" ]
if path==1:
print( "PNJ has path - NOW LOOKING FOR RELEVANT DATA" )
if DEBUG: print( "PNJ has path - NOW LOOKING FOR RELEVANT DATA" )
# we start looking for path data with first the ID of the path Object
for u in i["properties"]:
if u["name"]=="path":
pathID = u[ "value" ]
print( "path ID is identified : ID= ", pathID )
if DEBUG: print( "path ID is identified : ID= ", pathID )
for v in layer["objects"]:
if v[ "id" ] == pathID:
print( "path data found : " )
if DEBUG: print( "path data found : " )
xdata = bytes()
ydata = bytes()
for w in v[ "polyline" ]:
path_length = path_length + 1
print( "X= ", w[ "x" ], " Y= ", w[ "y" ] )
if DEBUG: print( "X= ", w[ "x" ], " Y= ", w[ "y" ] )
xdata += fxconv.u16( int( w[ "x" ] ) )
ydata += fxconv.u16( int( w[ "y" ] ) )
else:
print( "PNJ has no Path" )
if DEBUG: print( "PNJ has no Path" )
else:
print( "UNIDENTIFIED PROPERTY : ", j["name"])
print( "OBJECT X= ", x, " Y= ", y, "STR= ", dialogID )
print( " Type= ", tpe, " Name= ", nme )
print( " Action?= ", needAction )
if DEBUG:
print( "OBJECT X= ", x, " Y= ", y, "STR= ", dialogID )
print( " Type= ", tpe, " Name= ", nme )
print( " Action?= ", needAction )
@ -345,7 +347,7 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
#else we do nothing (yet)
else:
print( "Skip this object" )
if DEBUG: print( "Skip this object" )
return nbExtraData, structData
@ -372,16 +374,16 @@ def convert_font(input, output, params, target):
def convert_dialogs(input, output, params, target):
print( "WE ARE COMPUTING THE DIALOGS FROM : ", input )
if DEBUG: print( "WE ARE COMPUTING THE DIALOGS FROM : ", input )
data = json.load(open(input, "r"))
structDialogs = fxconv.Structure()
nbdialogs = 0
for d in data["dialogs"]:
print( int(d[ "ID" ]))
if DEBUG: print( int(d[ "ID" ]))
# print( d[ "dialog" ] )
print( int(d[ "isQuestion" ]) )
if DEBUG: print( int(d[ "isQuestion" ]) )
# print( d[ "choice" ].replace('$', chr(0)) )
# print( d[ "conclusion1" ] )
# print( int(d[ "next1" ] ) )
@ -402,4 +404,4 @@ def convert_dialogs(input, output, params, target):
return nbdialogs, structDialogs
#fxconv.elf(structDialogs, output, "_" + params["name"], **target)
#fxconv.elf(structDialogs, output, "_" + params["name"], **target)