diff --git a/.zed/tasks.json b/.zed/tasks.json index 5140ff1..cdc695b 100644 --- a/.zed/tasks.json +++ b/.zed/tasks.json @@ -11,4 +11,8 @@ "label": "Test run (gojo)", "command": "odin run . -- ../Satoru-Gojo-Needle/Satoru-Gojo-Needle.yyp ../Satoru-Gojo-Needle/rooms/rSatoru/rSatoru.yy jmap.jmap jmap_config.json5 -x:1600 -y:608 -clear_area" }, + { + "label": "Diff (gojo)", + "command": "diff rSatoru-original.yy ../Satoru-Gojo-Needle/rooms/rSatoru/rSatoru.yy" + } ] diff --git a/debug.raddbg b/debug.raddbg index 45a79c0..6f8d11b 100755 --- a/debug.raddbg +++ b/debug.raddbg @@ -4,6 +4,15 @@ target: { executable: gamemaker_jmap_import working_directory: "" - enabled: 1 - arguments: "../Satoru-Gojo-Needle/Satoru-Gojo-Needle.yyp jmap.jmap jmap_config.json5" + arguments: "../Satoru-Gojo-Needle/Satoru-Gojo-Needle.yyp ../Satoru-Gojo-Needle/rooms/rSatoru/rSatoru.yy jmap.jmap jmap_config.json5 -x:1600 -y:608 -clear_area" + enabled: 0 + label: "Test gojo" +} +target: +{ + executable: gamemaker_jmap_import + working_directory: "" + arguments: "project.yyp rSatoru.yy jmap.jmap jmap_config.json5 -x:1600 -y:608 -clear_area" + label: Test + enabled: 1 } diff --git a/gamemaker_jmap_import.rdi b/gamemaker_jmap_import.rdi index a09d108..9582d41 100755 Binary files a/gamemaker_jmap_import.rdi and b/gamemaker_jmap_import.rdi differ diff --git a/jmap_config.json5 b/jmap_config.json5 index 119ef5a..76c4ee5 100644 --- a/jmap_config.json5 +++ b/jmap_config.json5 @@ -1,9 +1,10 @@ { instance_layer: "Instances" + tile_layer: "Tiles" mappings: { "block": { - object_name: "objBlock", - type: "tile", + object_name: "objBlock" + type: "tile" }, } } diff --git a/main.odin b/main.odin index 739b0de..d6b8767 100644 --- a/main.odin +++ b/main.odin @@ -306,7 +306,11 @@ GamemakerTilemap :: struct { } /* + NOTE (synthas): GameMaker compresses their tile data stored in the room resource + -2147483648 is a null-tile, 0 is a nothing tile. + But when erased 0 is used instead. + Imagine the following data: -4,-2147483648,1,6,-4,-2147483648,4,6,-2147483648,-2147483648,6,-3,-2147483648,1,6, It represents tile data for the following tilemap: @@ -325,28 +329,27 @@ resource_room_tile_layer_decompress :: proc(layer: json.Object, allocator := con tilemap_grid_x := int(layer["gridX"].(json.Integer)) tilemap_grid_y := int(layer["gridY"].(json.Integer)) tilemap_data := layer["tiles"].(json.Object) - tilemap_width := int(layer["SerializeWidth"].(json.Integer)) - tilemap_height := int(layer["SerializeHeight"].(json.Integer)) - tilemap_compressed := layer["TileCompressedData"].(json.Array) + tilemap_width := int(tilemap_data["SerialiseWidth"].(json.Integer)) + tilemap_height := int(tilemap_data["SerialiseHeight"].(json.Integer)) + tilemap_compressed := tilemap_data["TileCompressedData"].(json.Array) tilemap.data = make([dynamic]i64, tilemap_width * tilemap_height, allocator = allocator) tilemap_tile_index := 0 for i := 0; i < len(tilemap_compressed); { value := int(tilemap_compressed[i].(json.Integer)) + i += 1 switch math.sign(value) { case 1: tile_count := value - i += 1 for j in 0.. json.Array { + tilemap_compressed := make(json.Array, allocator) + for i := 0; i < len(tilemap.data);{ + remaining := len(tilemap.data) - i + if remaining < 3 { + append(&tilemap_compressed, i64(remaining)) + for value in tilemap.data[i:] { + append(&tilemap_compressed, value) + } + break + } + + tile := tilemap.data[i] + if tilemap.data[i + 1] == tile && tilemap.data[i + 2] == tile { + tilemap_index := i + 3 + for ; tilemap_index < len(tilemap.data); tilemap_index += 1 { + if tilemap.data[tilemap_index] != tile { + break + } + } + append_elems(&tilemap_compressed, i64((tilemap_index - i) * -1), tile) + i = tilemap_index + } else { + combo := 0 + combo_tile_current_index := i + combo_tile_current := tilemap.data[i] + tilemap_index := i + 1 + for ; i < len(tilemap.data); tilemap_index += 1 { + if tilemap.data[tilemap_index] == combo_tile_current { + combo += 1 + if combo > 2 { + break + } + } else { + combo_tile_current = tilemap.data[tilemap_index] + combo_tile_current_index = tilemap_index + } + } + append(&tilemap_compressed, i64(combo_tile_current_index - i)) + for value in tilemap.data[i:combo_tile_current_index] { + append(&tilemap_compressed, value) + } + i = tilemap_index + } + } + + return tilemap_compressed +} + +resource_room_tile_layer_set_tiles :: proc(room_layer: ^json.Object, tilemap: ^GamemakerTilemap, allocator := context.allocator) { + tile_data := &(&room_layer["tiles"]).(json.Object) + tile_data["TileCompressedData"] = resource_room_tile_layer_compress(tilemap) +} + resource_room_layer_tile_is_empty :: proc(mask: GamemakerTile) -> bool { return mask == min(GamemakerTile) } @@ -370,9 +428,9 @@ resource_room_tile_layer_insert_tile :: proc(tilemap: json.Array, tilemap_width, tilemap[index] = i64(tile) } -resource_room_tile_layer_clear_area :: proc(tilemap: json.Array, tilemap_width, x, y, width, height, tile_width, tile_height: int) { - assert(len(tilemap) % tilemap_width == 0, "Wrong tilemap width") - tilemap_height := len(tilemap) / tilemap_width +resource_room_tile_layer_clear_area :: proc(tilemap: ^GamemakerTilemap, tilemap_width, x, y, width, height, tile_width, tile_height: int) { + assert(len(tilemap.data) % tilemap_width == 0, "Wrong tilemap width") + tilemap_height := len(tilemap.data) / tilemap_width tilemap_area_x := x / tile_width tilemap_area_y := y / tile_height tilemap_area_width := width / tile_width @@ -386,7 +444,7 @@ resource_room_tile_layer_clear_area :: proc(tilemap: json.Array, tilemap_width, for x in tilemap_area_x..