Map conversion update, still bugs in the entities assignements

This commit is contained in:
Ulysse Cura 2025-08-24 14:18:36 +02:00
parent 4c680feb5e
commit cbe4595fb8
7 changed files with 92 additions and 95 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
build build
2D_Engine_Casio_Tool 2D_Engine_Casio_Tool
GameData.bin GameData.bin
assets/maps/__pycache__ assets/__pycache__

View File

@ -31,7 +31,7 @@ LDFLAGS = -m32 -no-pie
# Converter flags # Converter flags
FXCONV_FLAGS = --cg --toolchain= --arch=i386 --outputtarget=elf32-x86-64 FXCONV_FLAGS = --cg --toolchain= --arch=i386 --outputtarget=elf32-x86-64
FXCONV_CONVERTERS = assets/maps/map_converter.py FXCONV_CONVERTER = assets/converters.py
# Change output location # Change output location
OUTPUT := $(BUILD_DIR)/$(OUTPUT) OUTPUT := $(BUILD_DIR)/$(OUTPUT)
@ -78,7 +78,7 @@ $(BUILD_DIR)/%.o: %
$(eval CURRENT_FILE := $(shell echo $$(($(CURRENT_FILE)+1)))) $(eval CURRENT_FILE := $(shell echo $$(($(CURRENT_FILE)+1))))
$(eval PERCENTAGE := $(shell echo $$(($(CURRENT_FILE)*100/$(TOTAL_FILES))))) $(eval PERCENTAGE := $(shell echo $$(($(CURRENT_FILE)*100/$(TOTAL_FILES)))))
@echo "[$(PERCENTAGE)%] $(GREEN)Building FXCONV object $@$(RESET)" @echo "[$(PERCENTAGE)%] $(GREEN)Building FXCONV object $@$(RESET)"
$(Q)fxconv $(FXCONV_FLAGS) --converter=$(FXCONV_CONVERTERS) $< -o $@ $(Q)fxconv $(FXCONV_FLAGS) --converter=$(FXCONV_CONVERTER) $< -o $@
$(Q)objcopy --add-section .note.GNU-stack=/dev/null $@ $(Q)objcopy --add-section .note.GNU-stack=/dev/null $@
# Source files dependencies # Source files dependencies

75
assets/converters.py Normal file
View File

@ -0,0 +1,75 @@
import fxconv
from fxconv import u8, u16, u32, ref, string
import json
def convert(input, output, params, target):
if params["custom-type"] == "map":
convert_map(input, output, params, target)
return 0
else:
return 1
def convert_map(input, output, params, target):
with open(input, "r") as fp:
map = json.load(fp)
TRANSFORM_COMPONENT = 0
SPRITE_COMPONENT = 1
ANIMATION_SYSTEM = 2
background_layer1 = b"".join(u16(tile) for tile in map["BackgroundLayer1"])
background_layer2 = b"".join(u16(tile) for tile in map["BackgroundLayer2"])
background_layer3 = b"".join(u16(tile) for tile in map["BackgroundLayer3"])
foreground = b"".join(u16(tile) for tile in map["Foreground"])
entities = fxconv.Structure()
for e in map["Entities"]:
entities += u16(e["ID"])
entities += u32(len(e["Components"]))
components = fxconv.Structure()
for c in e["Components"]:
component_data = fxconv.Structure()
match c["Type"]:
case "TransformComponent":
components += u32(TRANSFORM_COMPONENT)
component_data += u32(c["x"])
component_data += u32(c["y"])
component_data += u32(c["w"])
component_data += u32(c["h"])
component_data += u32(c["Speed"])
case "SpriteComponent":
components += u32(SPRITE_COMPONENT)
component_data += string(c["TextureName"])
case "AnimationSystem":
components += u32(ANIMATION_SYSTEM)
component_data += u32(c["NbFrames"])
component_data += u32(c["ActualFrame"])
component_data += u32(c["FrameDelayMs"])
component_data += u8(c["Play"])
component_data += u8(c["Loop"])
component_data += u8(c["Reverse"])
case _:
raise fxconv.FxconvError(f"unknown component type {c['Type']}")
components += ref(component_data)
entities += ref(components)
o = fxconv.ObjectData()
o += string(params["name"])
o += u32(map["MapWidth"]) + u32(map["MapHeight"])
o += ref(background_layer1)
o += ref(background_layer2)
o += ref(background_layer3)
o += ref(foreground)
o += u32(len(map["Entities"]))
o += ref(entities)
fxconv.elf(o, output, params["name"], **target)

View File

@ -47,7 +47,7 @@
] ]
}, },
{ {
"ID": 2034, "ID": 345,
"Components": [ "Components": [
{ {
"Type": "TransformComponent", "Type": "TransformComponent",

View File

@ -1,79 +0,0 @@
import fxconv
from fxconv import u16, u32, ref, chars, string
import json
def convert(input, output, params, target):
if params["custom-type"] == "map":
convert_map(input, output, params, target)
return 0
else:
return 1
def convert_map(input, output, params, target):
with open(input, "r") as fp:
map = json.load(fp)
TRANSFORM_COMPONENT = 0
SPRITE_COMPONENT = 1
ANIMATION_SYSTEM = 2
background_layer1 = b''.join(u16(tile) for tile in map["BackgroundLayer1"])
background_layer2 = b''.join(u16(tile) for tile in map["BackgroundLayer2"])
background_layer3 = b''.join(u16(tile) for tile in map["BackgroundLayer3"])
foreground = b''.join(u16(tile) for tile in map["Foreground"])
entities = fxconv.Structure()
for entity in map["Entities"]:
e = fxconv.Structure()
e += u16(entity["ID"])
e += u32(len(entity["Components"]))
components = fxconv.Structure()
for component in entity["Components"]:
c = fxconv.Structure()
c_data = fxconv.Structure()
match component["Type"]:
case "TransformComponent":
c += u32(TRANSFORM_COMPONENT)
c_data += u32(component["x"])
c_data += u32(component["y"])
c_data += u32(component["w"])
c_data += u32(component["h"])
c_data += u32(component["Speed"])
case "SpriteComponent":
c += u32(SPRITE_COMPONENT)
c_data += string(component["TextureName"])
case "AnimationSystem":
c += u32(SPRITE_COMPONENT)
c_data += u32(component["NbFrames"])
c_data += u32(component["ActualFrame"])
c_data += u32(component["FrameDelayMs"])
c_data += u32(component["Play"])
c_data += u32(component["Loop"])
c_data += u32(component["Reverse"])
case _:
raise fxconv.FxconvError(f"unknown component type {component['Type']}")
c += ref(c_data)
components += c
e += ref(components)
entities += e
o = fxconv.ObjectData()
o += string(params["name"])
o += u32(map["MapWidth"]) + u32(map["MapHeight"])
o += ref(background_layer1)
o += ref(background_layer2)
o += ref(background_layer3)
o += ref(foreground)
o += u32(len(map["Entities"]))
o += ref(entities)
fxconv.elf(o, output, params["name"], **target)

View File

@ -4,13 +4,13 @@
#include <stdint.h> #include <stdint.h>
typedef struct animation_system_data_t { typedef struct animation_system_data_t {
bool play :1;
bool loop :1;
bool reverse :1;
float frame_delay_ms;
uint32_t actual_frame_nb;
uint32_t nb_frames; uint32_t nb_frames;
uint32_t actual_frame_nb;
uint32_t frame_delay_ms;
bool play;
bool loop;
bool reverse;
} animation_system_data_t; } animation_system_data_t;
#endif // SPRITE_COMPONENT_H #endif // SPRITE_COMPONENT_H

View File

@ -69,6 +69,7 @@ void verify_maps_integrity(void)
{ {
const uint32_t NB_COMPONENTS = ENTITIES[entity_index].nb_component; const uint32_t NB_COMPONENTS = ENTITIES[entity_index].nb_component;
const component_t *COMPONENTS = ENTITIES[entity_index].components; const component_t *COMPONENTS = ENTITIES[entity_index].components;
std::cout << " Entity " << entity_index + 1 << std::endl; std::cout << " Entity " << entity_index + 1 << std::endl;
std::cout << " - ID : " << ENTITIES[entity_index].id << std::endl; std::cout << " - ID : " << ENTITIES[entity_index].id << std::endl;
std::cout << " - Nb Components : " << NB_COMPONENTS << std::endl; std::cout << " - Nb Components : " << NB_COMPONENTS << std::endl;
@ -105,12 +106,12 @@ void verify_maps_integrity(void)
{ {
const animation_system_data_t *system_data = COMPONENT->component_data.animation_system_data; const animation_system_data_t *system_data = COMPONENT->component_data.animation_system_data;
std::cout << " - AnimationSystem :" << std::endl; std::cout << " - AnimationSystem :" << std::endl;
std::cout << " - NbFrames : " << system_data->nb_frames; std::cout << " - NbFrames : " << system_data->nb_frames << std::endl;
std::cout << " - FrameNb : " << system_data->actual_frame_nb; std::cout << " - FrameNb : " << system_data->actual_frame_nb << std::endl;
std::cout << " - FrameDelay : " << system_data->frame_delay_ms; std::cout << " - FrameDelay : " << system_data->frame_delay_ms << std::endl;
std::cout << " - Play : " << system_data->play; std::cout << " - Play : " << system_data->play << std::endl;
std::cout << " - Loop : " << system_data->loop; std::cout << " - Loop : " << system_data->loop << std::endl;
std::cout << " - Reverse : " << system_data->reverse; std::cout << " - Reverse : " << system_data->reverse << std::endl;
break; break;
} }
} }