aboutsummaryrefslogtreecommitdiff
path: root/tools/compile_assets/tiled.odin
diff options
context:
space:
mode:
Diffstat (limited to 'tools/compile_assets/tiled.odin')
-rw-r--r--tools/compile_assets/tiled.odin90
1 files changed, 75 insertions, 15 deletions
diff --git a/tools/compile_assets/tiled.odin b/tools/compile_assets/tiled.odin
index 7752273..5311fa5 100644
--- a/tools/compile_assets/tiled.odin
+++ b/tools/compile_assets/tiled.odin
@@ -210,7 +210,12 @@ Json_Property :: struct {
name: string,
type: string,
propertytype: string,
- value: any,
+ value: union{
+ bool,
+ int,
+ string,
+ f32,
+ },
}
Json_Point :: struct {
@@ -415,33 +420,88 @@ load_json_room :: proc(path: string, file: ^os.File) {
}
}
+ objects: [dynamic]string
+ defer delete(objects)
+
layers: [dynamic][]u32
defer delete(layers)
for layer in json_dat.layers {
- if strings.compare(layer.type, "tilelayer") != 0 {
- continue
- }
+ switch layer.type {
+ case "tilelayer":
+ json_layer_dat, ok := layer.data.([]i32)
+ if !ok {
+ continue
+ }
- json_layer_dat, ok := layer.data.([]i32)
- if !ok {
- continue
- }
+ data := make(
+ []u32,
+ len(json_layer_dat),
+ allocator = context.temp_allocator,
+ )
+
+ for cell, i in json_layer_dat {
+ data[i] = tiled_to_real_gid[cell]
+ }
+
+ append(&layers, data)
+ case "objectgroup":
+ parallax := [2]f32{f32(layer.parallaxx), f32(layer.parallaxy)}
+
+ for obj in layer.objects {
+ type_name := strings.to_screaming_snake_case(obj.type)
- data := make([]u32, len(json_layer_dat), allocator = context.temp_allocator)
+ // `object_type_names` now owns `type_name`; freed in main
+ object_type_names[type_name] = {}
- for cell, i in json_layer_dat {
- data[i] = tiled_to_real_gid[cell]
+ pos := [2]f32{f32(obj.x), f32(obj.y)}
+
+ properties: map[string]union{
+ bool,
+ int,
+ string,
+ f32,
+ }
+ defer delete(properties)
+
+ for property in obj.properties {
+ fmt.println(property.name, property.value)
+ properties[property.name] = property.value
+ }
+
+ line := fmt.tprintf(
+ "{{type = .%v, pos = %w, parallax = %w, properties = %w}}",
+ type_name,
+ pos,
+ parallax,
+ properties,
+ )
+
+ append(&objects, line)
+ }
+ case:
+ fmt.eprintfln("WARNING: Unsupported tile layer type '%v'", layer.type)
}
+ }
+
+ objects_arr_str := ""
- append(&layers, data)
+ for obj in objects {
+ objects_arr_str = strings.concatenate({
+ objects_arr_str,
+ obj,
+ ", "
+ }, allocator = context.temp_allocator)
}
line := fmt.aprintf(
- "{{width=%v, height=%v, tile_width=%v, tile_height=%v, layers=%w, objects={{}}, background_image=nil}}",
- width, height,
- tile_width, tile_height,
+ "{{width=%v, height=%v, tile_width=%v, tile_height=%v, layers=%w, objects={{%v}}, background_image=nil}}",
+ width,
+ height,
+ tile_width,
+ tile_height,
layers[:],
+ objects_arr_str,
)
rooms[filepath.stem(path)] = line
}