From efde68f9c708d9763463e97d25c25625f823a887 Mon Sep 17 00:00:00 2001
From: mibi88 <76903855+mibi88@users.noreply.github.com>
Date: Tue, 30 Jul 2024 20:15:39 +0200
Subject: [PATCH] Got map rendering back working
---
CMakeLists.txt | 5 ++++-
assets/converters.py | 50 ++++++++++++++++++++++++++++++++++++++++++--
assets/level1.tmx | 2 +-
assets/level4.tmx | 2 +-
src/config.h | 2 +-
src/main.c | 8 +++----
src/map.c | 35 +++++++++++++------------------
src/player.c | 4 +++-
8 files changed, 77 insertions(+), 31 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 31954ba..8e33e0f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -37,8 +37,11 @@ set(SOURCES
)
# Shared assets, fx-9860G-only assets and fx-CG-50-only assets
set(ASSETS
- #assets/WorldRPG.world
assets/level0.tmx
+ assets/level1.tmx
+ assets/level2.tmx
+ assets/level3.tmx
+ assets/level4.tmx
# ...
)
diff --git a/assets/converters.py b/assets/converters.py
index 5373dd4..db9f90a 100644
--- a/assets/converters.py
+++ b/assets/converters.py
@@ -2,6 +2,7 @@ import xml.etree.ElementTree as ET
import json
import os
import sys
+import fxconv
VERBOSE = 1
SIGN_TYPES = ["INFO", "SGN"]
@@ -24,6 +25,9 @@ class Tileset:
tilecount_str = self.root.get("tilecount")
if tilecount_str == None: raise Exception("tilecount not found!")
self.tilecount = int(tilecount_str)
+ columns_str = self.root.get("columns")
+ if columns_str == None: raise Exception("columns not found!")
+ self.columns = int(columns_str)
def is_raw_in_tileset(self, raw: int) -> bool:
if raw >= self.firstgid and raw < self.firstgid+self.tilecount:
@@ -84,7 +88,9 @@ class Object:
self.name = element.get("name")
if self.name == None: raise Exception("Name attribute missing!")
self.type = element.get("type")
- if self.type == None: raise Exception("Type attribute missing!")
+ if self.type == None:
+ self.type = ""
+ if VERBOSE: print("WARNING: Type attribute missing!")
x_str = element.get("x")
if x_str == None: raise Exception("X attribute missing!")
self.x = int(float(x_str))
@@ -254,6 +260,8 @@ def convert_map(input, output, params, target):
npcs = {}
signs = {}
+ map_struct = fxconv.Structure()
+
# Get the dialog file
try:
if VERBOSE: print("INFO: Getting the dialog file")
@@ -369,7 +377,45 @@ def convert_map(input, output, params, target):
+ f" Error message: {e}\n")
sys.exit(1)
# Generate the structs
- #
+ map_struct += fxconv.u32(width)
+ map_struct += fxconv.u32(height)
+ map_struct += fxconv.u32(3)
+ map_struct += fxconv.u32(outdoor_tileset.columns)
+ map_struct += fxconv.u32(0)
+ map_struct += fxconv.u32(0)
+ map_struct += fxconv.u32(0)
+ map_struct += fxconv.u32(0)
+ tileset_name = os.path.splitext(os.path.basename(outdoor_tileset.source))[0]
+ map_struct += fxconv.ref(f"img_{tileset_name}")
+
+ walkable_data = bytes()
+ for i in walkable_layer:
+ if i < 0: i = 0
+ walkable_data += fxconv.u8(i)
+ map_struct += fxconv.ptr(walkable_data)
+
+ map_struct += fxconv.u32(0) # TODO: NPC support in-game
+ map_struct += fxconv.ptr(bytes())
+ map_struct += fxconv.u32(0) # TODO: Sign support in-game
+ map_struct += fxconv.ptr(bytes())
+ map_struct += fxconv.u32(0) # TODO: Portal support in-game
+ map_struct += fxconv.ptr(bytes())
+ map_struct += fxconv.u32(0) # TODO: Dialog support
+ map_struct += fxconv.ptr(bytes())
+
+ background_data = bytes()
+ for i in background_layer:
+ background_data += fxconv.u16(i)
+ map_struct += fxconv.ptr(background_data)
+
+ foreground_data = bytes()
+ for i in foreground_layer:
+ foreground_data += fxconv.u16(i)
+ map_struct += fxconv.ptr(foreground_data)
+
+ # Create the fxconv object
+ name = os.path.splitext(os.path.basename(input))[0]
+ fxconv.elf(map_struct, output, f"_{name}", **target)
def convert_dialog(input, output, params, target):
if VERBOSE: print(f"INFO: Converting dialog file {input} -> {output}")
diff --git a/assets/level1.tmx b/assets/level1.tmx
index b635cb5..689f530 100644
--- a/assets/level1.tmx
+++ b/assets/level1.tmx
@@ -107,7 +107,7 @@
-