From 65a2ceda55198dab3bab75c06c0d50adeb0a1101 Mon Sep 17 00:00:00 2001 From: Xander Swan <[hidden email]> Date: Thu, 1 Jan 2026 18:32:20 -0500 Subject: lots of changes + player dash --- src/tiled/world.odin | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/tiled/world.odin (limited to 'src/tiled/world.odin') diff --git a/src/tiled/world.odin b/src/tiled/world.odin new file mode 100644 index 0000000..c55097a --- /dev/null +++ b/src/tiled/world.odin @@ -0,0 +1,84 @@ +package tiled + +import os "core:os/os2" +import "core:log" +import "core:encoding/json" +import "core:path/filepath" +import "core:strings" + +World_Room :: struct { + file_name: string `json:"fileName"`, + x: i32, + y: i32, + width: i32, + height: i32, +} + +res_dir: string +world: []World_Room +current_room: struct { + tmap: Map, + using room: World_Room, +} + +load_world :: proc(path: string) -> bool { + world_text, read_err := os.read_entire_file(path, context.temp_allocator) + if read_err != nil { + log.errorf("Failed to read file %v (%v)", path, read_err) + return false + } + + jworld: struct { + maps: []World_Room, + } + unmarshal_err := json.unmarshal( + world_text, + &jworld, + ) + if unmarshal_err != nil { + log.errorf("Failed to unmarshal file %v (%v)", path, unmarshal_err) + return false + } + + world = jworld.maps + res_dir = filepath.dir(path) + + return true +} + +delete_world :: proc() { + delete_map(current_room.tmap) + delete(world) + delete(res_dir) +} + +open_new_room_at :: proc(pos: [2]i32) -> bool { + pos := pos + pos += {current_room.room.x, current_room.room.y} + + log.debug("trying to change room...", pos) + for room in world { + if strings.compare(room.file_name, current_room.room.file_name) == 0 { + continue + } + + if pos.x >= room.x && pos.x <= room.x + room.width \ + && pos.y >= room.y && pos.y <= room.y + room.height { + delete_map(current_room.tmap) + + path := strings.concatenate( + {res_dir, "/", room.file_name}, + allocator = context.temp_allocator, + ) + new_map, err := load_map(path) + if err != .NONE { + log.error("could not load new room") + return false + } + current_room.tmap = new_map + current_room.room = room + return true + } + } + return false +} -- cgit v1.3-2-g0d8e