From 8e350ac509c9e1ff8da9d75ddb416a4da187b6e2 Mon Sep 17 00:00:00 2001 From: Ulysse Cura Date: Sun, 16 Aug 2026 16:03:56 +0200 Subject: [PATCH] Corrected floating point numbers issus because of javascript and entity writing order depending on their IDs. --- SDL3_Core | 2 +- assets/maps/dungeon_room_1.map | 94 +++++++++---------- assets/maps/dungeon_room_1.tmx | 4 +- .../tiled-extensions/json_export_tool.mjs | 91 ++++++++++-------- 4 files changed, 101 insertions(+), 90 deletions(-) diff --git a/SDL3_Core b/SDL3_Core index a9d88e5..152be5f 160000 --- a/SDL3_Core +++ b/SDL3_Core @@ -1 +1 @@ -Subproject commit a9d88e50e71ed30570c72f3587be8f8899ca697f +Subproject commit 152be5f888f7c5c44d0cee77c21d75abf78ec410 diff --git a/assets/maps/dungeon_room_1.map b/assets/maps/dungeon_room_1.map index 81fcca7..556f293 100644 --- a/assets/maps/dungeon_room_1.map +++ b/assets/maps/dungeon_room_1.map @@ -95,53 +95,6 @@ "Entities": [ { "ID":1, - "Components": [ - { - "Type": "TRANSFORM_COMPONENT", - "Attributes": [ - 96.0, - 0.0, - 32.0, - 48.0 - ] - }, - { - "Type": "SPRITE_COMPONENT", - "Attributes": [ - "barred_door_sheet" - ] - }, - { - "Type": "ANIMATION_SYSTEM", - "Attributes": [ - 8, - 0, - 30.0, - false, - false, - false - ] - }, - { - "Type": "HITBOX_COMPONENT", - "Attributes": [ - 0.0, - 0.8333333333333334, - 1.0, - 0.16666666666666666 - ] - }, - { - "Type": "DOOR_COMPONENT", - "Attributes": [ - 0, - false - ] - } - ] - }, - { - "ID":2, "Components": [ { "Type": "TRANSFORM_COMPONENT", @@ -198,6 +151,53 @@ ] } ] + }, + { + "ID":2, + "Components": [ + { + "Type": "TRANSFORM_COMPONENT", + "Attributes": [ + 96.0, + 0.0, + 32.0, + 48.0 + ] + }, + { + "Type": "SPRITE_COMPONENT", + "Attributes": [ + "barred_door_sheet" + ] + }, + { + "Type": "ANIMATION_SYSTEM", + "Attributes": [ + 8, + 0, + 30.0, + false, + false, + false + ] + }, + { + "Type": "HITBOX_COMPONENT", + "Attributes": [ + 0.0, + 0.8333333333333334, + 1.0, + 0.16666666666666666 + ] + }, + { + "Type": "DOOR_COMPONENT", + "Attributes": [ + 0, + false + ] + } + ] } ] } \ No newline at end of file diff --git a/assets/maps/dungeon_room_1.tmx b/assets/maps/dungeon_room_1.tmx index 7cdc359..f9f23d5 100644 --- a/assets/maps/dungeon_room_1.tmx +++ b/assets/maps/dungeon_room_1.tmx @@ -106,7 +106,7 @@ - + @@ -138,7 +138,7 @@ - + diff --git a/assets/maps/tiled-extensions/json_export_tool.mjs b/assets/maps/tiled-extensions/json_export_tool.mjs index c8768f6..8e80d81 100644 --- a/assets/maps/tiled-extensions/json_export_tool.mjs +++ b/assets/maps/tiled-extensions/json_export_tool.mjs @@ -1,3 +1,11 @@ +function stringifyFloat(floatNumber) +{ + if(floatNumber == Math.trunc(floatNumber)) + return String(floatNumber) + ".0" + + return String(floatNumber); +} + function writeTileLayer(tileLayer, file) { file.writeLine(" \"" + tileLayer.name + "\": ["); @@ -35,6 +43,13 @@ function writeEntities(objectLayer, file) } } + entities.sort((a, b) => { + if(Number(a.name) > Number(b.name)) + return 1; + + return -1; + }); + for(let i = 0; i < entities.length; i++) { let entity = entities[i]; @@ -66,10 +81,10 @@ function writeEntities(objectLayer, file) { file.writeLine(","); file.writeLine(" \"Attributes\": ["); - file.writeLine(" " + entity.x + ","); - file.writeLine(" " + entity.y + ","); - file.writeLine(" " + entity.width + ","); - file.writeLine(" " + entity.height); + file.writeLine(" " + stringifyFloat(entity.x) + ","); + file.writeLine(" " + stringifyFloat(entity.y) + ","); + file.writeLine(" " + stringifyFloat(entity.width) + ","); + file.writeLine(" " + stringifyFloat(entity.height)); file.writeLine(" ]"); } else if(component_type == "HITBOX_COMPONENT") @@ -88,10 +103,10 @@ function writeEntities(objectLayer, file) let width = hitbox.width / entity.width; let height = hitbox.height / entity.height; - file.writeLine(" " + x + ","); - file.writeLine(" " + y + ","); - file.writeLine(" " + width + ","); - file.writeLine(" " + height); + file.writeLine(" " + stringifyFloat(x) + ","); + file.writeLine(" " + stringifyFloat(y) + ","); + file.writeLine(" " + stringifyFloat(width) + ","); + file.writeLine(" " + stringifyFloat(height)); } else if(component_type == "INTERACT_COMPONENT") { @@ -109,45 +124,41 @@ function writeEntities(objectLayer, file) let width = interact_box.width / entity.width; let height = interact_box.height / entity.height; - file.writeLine(" " + x + ","); - file.writeLine(" " + y + ","); - file.writeLine(" " + width + ","); - file.writeLine(" " + height + ","); + file.writeLine(" " + stringifyFloat(x) + ","); + file.writeLine(" " + stringifyFloat(y) + ","); + file.writeLine(" " + stringifyFloat(width) + ","); + file.writeLine(" " + stringifyFloat(height) + ","); file.writeLine(" " + component[2] + ","); file.writeLine(" " + component[3] + ","); file.writeLine(" " + component[4]); } + else if(component_type == "SPRITE_COMPONENT") + { + file.writeLine(" \"" + component[1] + "\""); + } + else if(component_type == "ANIMATION_SYSTEM") + { + file.writeLine(" " + component[1] + ","); + file.writeLine(" " + component[2] + ","); + file.writeLine(" " + stringifyFloat(component[3]) + ","); + file.writeLine(" " + component[4] + ","); + file.writeLine(" " + component[5] + ","); + file.writeLine(" " + component[6]); + } + else if(component_type == "LEVER_COMPONENT") + { + file.writeLine(" " + component[1] + ","); + file.writeLine(" " + component[2]); + } + else if(component_type == "DOOR_COMPONENT") + { + file.writeLine(" " + component[1] + ","); + file.writeLine(" " + component[2]); + } else { - if(component.length > 1) - { - for(let k = 1; k < component.length; k++) - { - file.write(" "); - switch(typeof(component[k])) - { - case typeof(Number()): - case typeof(Boolean()): - file.write(component[k]); - break; - - case typeof(String()): - file.write("\"" + component[k] + "\""); - break; - - default: - throw new Error("Attribute \"" + component[k] + "\", type not supported : " + typeof(component[k])); - } - - if(k == component.length - 1) - file.writeLine(""); - else - file.writeLine(","); - } - } - else - file.writeLine(""); + throw new Error("Component type not supported for exporting : " + component_type); } if(component.length > 1)