Corrected floating point numbers issus because of javascript and entity writing order depending on their IDs.

This commit is contained in:
Ulysse Cura 2026-08-16 16:03:56 +02:00
parent 67ca898bcd
commit 8e350ac509
4 changed files with 101 additions and 90 deletions

@ -1 +1 @@
Subproject commit a9d88e50e71ed30570c72f3587be8f8899ca697f Subproject commit 152be5f888f7c5c44d0cee77c21d75abf78ec410

View File

@ -95,53 +95,6 @@
"Entities": [ "Entities": [
{ {
"ID":1, "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": [ "Components": [
{ {
"Type": "TRANSFORM_COMPONENT", "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
]
}
]
} }
] ]
} }

View File

@ -106,7 +106,7 @@
</data> </data>
</layer> </layer>
<objectgroup id="8" name="Entities"> <objectgroup id="8" name="Entities">
<object id="4" name="1" x="96" y="0" width="32" height="48"> <object id="4" name="2" x="96" y="0" width="32" height="48">
<properties> <properties>
<property name="components" type="list"> <property name="components" type="list">
<item type="list"> <item type="list">
@ -138,7 +138,7 @@
</properties> </properties>
</object> </object>
<object id="5" x="96" y="40" width="32" height="8"/> <object id="5" x="96" y="40" width="32" height="8"/>
<object id="8" name="2" x="88" y="112" width="48" height="32"> <object id="8" name="1" x="88" y="112" width="48" height="32">
<properties> <properties>
<property name="components" type="list"> <property name="components" type="list">
<item type="list"> <item type="list">

View File

@ -1,3 +1,11 @@
function stringifyFloat(floatNumber)
{
if(floatNumber == Math.trunc(floatNumber))
return String(floatNumber) + ".0"
return String(floatNumber);
}
function writeTileLayer(tileLayer, file) function writeTileLayer(tileLayer, file)
{ {
file.writeLine(" \"" + tileLayer.name + "\": ["); 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++) for(let i = 0; i < entities.length; i++)
{ {
let entity = entities[i]; let entity = entities[i];
@ -66,10 +81,10 @@ function writeEntities(objectLayer, file)
{ {
file.writeLine(","); file.writeLine(",");
file.writeLine(" \"Attributes\": ["); file.writeLine(" \"Attributes\": [");
file.writeLine(" " + entity.x + ","); file.writeLine(" " + stringifyFloat(entity.x) + ",");
file.writeLine(" " + entity.y + ","); file.writeLine(" " + stringifyFloat(entity.y) + ",");
file.writeLine(" " + entity.width + ","); file.writeLine(" " + stringifyFloat(entity.width) + ",");
file.writeLine(" " + entity.height); file.writeLine(" " + stringifyFloat(entity.height));
file.writeLine(" ]"); file.writeLine(" ]");
} }
else if(component_type == "HITBOX_COMPONENT") else if(component_type == "HITBOX_COMPONENT")
@ -88,10 +103,10 @@ function writeEntities(objectLayer, file)
let width = hitbox.width / entity.width; let width = hitbox.width / entity.width;
let height = hitbox.height / entity.height; let height = hitbox.height / entity.height;
file.writeLine(" " + x + ","); file.writeLine(" " + stringifyFloat(x) + ",");
file.writeLine(" " + y + ","); file.writeLine(" " + stringifyFloat(y) + ",");
file.writeLine(" " + width + ","); file.writeLine(" " + stringifyFloat(width) + ",");
file.writeLine(" " + height); file.writeLine(" " + stringifyFloat(height));
} }
else if(component_type == "INTERACT_COMPONENT") else if(component_type == "INTERACT_COMPONENT")
{ {
@ -109,45 +124,41 @@ function writeEntities(objectLayer, file)
let width = interact_box.width / entity.width; let width = interact_box.width / entity.width;
let height = interact_box.height / entity.height; let height = interact_box.height / entity.height;
file.writeLine(" " + x + ","); file.writeLine(" " + stringifyFloat(x) + ",");
file.writeLine(" " + y + ","); file.writeLine(" " + stringifyFloat(y) + ",");
file.writeLine(" " + width + ","); file.writeLine(" " + stringifyFloat(width) + ",");
file.writeLine(" " + height + ","); file.writeLine(" " + stringifyFloat(height) + ",");
file.writeLine(" " + component[2] + ","); file.writeLine(" " + component[2] + ",");
file.writeLine(" " + component[3] + ","); file.writeLine(" " + component[3] + ",");
file.writeLine(" " + component[4]); 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 else
{ {
if(component.length > 1) throw new Error("Component type not supported for exporting : " + component_type);
{
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("");
} }
if(component.length > 1) if(component.length > 1)