diff --git a/assets/maps/dungeon_entry.json b/assets/maps/dungeon_entry.json index b4de31d..b9583d9 100644 --- a/assets/maps/dungeon_entry.json +++ b/assets/maps/dungeon_entry.json @@ -106,7 +106,7 @@ 0, 0, 0, 0, 0, 0, 0, 1821, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2323, 2324, 2325, 2326, 2327, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1867, 0, 0, 1870, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2372, 2373, 2374, 2375, 2376, 0, 0, 0, 0, 0 ], - "HitBoxes": [ + "Hitboxes": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -131,5 +131,5 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - ] + ], } \ No newline at end of file diff --git a/assets/maps/dungeon_entry.tmx b/assets/maps/dungeon_entry.tmx index 77744b7..39cecd4 100644 --- a/assets/maps/dungeon_entry.tmx +++ b/assets/maps/dungeon_entry.tmx @@ -1,5 +1,5 @@ - + @@ -25,18 +25,10 @@ eJy9lr1Lw0AYh69JzIeTirZCQXDTxUlBdFKsVRDERfwbXEXQRakfrXbVQXAX7KDS+lHQSdDJQSdRBy212gpOnRQEfyEJvbZJTHK1w0NCkrvnzXt3752PEOKrAbcCIXcCez/9HCE7Dd7ach7bVTLLle5vatSnG3Yp/0+FP8jXN5YeUbtuwhsHAZMx3qpjjiIyIStgFayBdRAFMVl7L+vxNor/40/CkwLH4AScgjOQlkvfDMA9qPszHLvzEn0FFELaQRaeV5ADb+Ad5EFBNs9NUs9PVHbmovtQ2xfxsAj/GNzjirfcGPHFxepxM+ujk9P6MMutHXa5Ud+fw38hlsdmtN3mq/sw2k97GMMliZBlSc+pVP6Ojs14dgX/tcXajrn0H8B3CI4kd+2sSLv0P8P7AjK6P+swji7Ulm4QofKQh7vg0t+EvDaDFjDlcO7MVNS1FK/NU7q2OGUI3w+7aLNhsW/m+Or5z2MNCn+sQ5U5lzGb4RfK149KL9x9YNEiBrp+OPV8WPx/2OY8kaD8X7j/1mOia9AI8hdysF8GLfavBRP/AxyP4Mnk/xMV9Xne4V49YeHfd3GeMotpj+GsYNRKlvlzz3hW+WT0y4zn0Q6G+tmKsWgDfqW0dzuaC5RzksEfgm8UhBX7vfsXuP91rA== - - - - - - - - - - + eJwL52JgCB/Fo3gUj+IhhiOhmB52RWDBxMhRy25S5anpBnL9Rg03kGsGLfw/EHaTmg5oZTeutECrND+KR/Eopj0GAGrPIzU= + diff --git a/assets/maps/dungeon_entry_entities.json b/assets/maps/dungeon_entry_entities.json deleted file mode 100644 index c712587..0000000 --- a/assets/maps/dungeon_entry_entities.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "Entities": [] -} \ No newline at end of file diff --git a/assets/maps/dungeon_room_1.json b/assets/maps/dungeon_room_1.json new file mode 100644 index 0000000..c7d7bef --- /dev/null +++ b/assets/maps/dungeon_room_1.json @@ -0,0 +1,203 @@ +{ + "MapWidth": 14, + "MapHeight": 16, + + "BackgroundLayer1": [ + 13, 157, 157, 157, 157, 157, 245, 247, 157, 157, 157, 157, 157, 14, + 108, 1, 2, 2, 2, 2, 245, 247, 2, 2, 2, 2, 3, 156, + 108, 50, 51, 51, 51, 51, 245, 247, 51, 51, 51, 51, 52, 156, + 108, 196, 197, 197, 197, 197, 151, 150, 197, 197, 197, 197, 198, 156, + 108, 245, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 247, 156, + 108, 245, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 247, 156, + 108, 245, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 247, 156, + 108, 245, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 247, 156, + 108, 245, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 247, 156, + 108, 245, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 247, 156, + 108, 245, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 247, 156, + 108, 245, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 247, 156, + 108, 245, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 247, 156, + 108, 245, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 247, 156, + 108, 294, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 296, 156, + 62, 107, 107, 107, 107, 107, 69, 70, 107, 107, 107, 107, 107, 63 + ], + "BackgroundLayer2": [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 120, 121, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1 + ], + "Entities": [ + { + "ID":1, + "Components": [ + { + "Type": "TRANSFORM_COMPONENT", + "Attributes": [ + 96, + 0, + 32, + 48 + ] + }, + { + "Type": "SPRITE_COMPONENT", + "Attributes": [ + "barred_door_sheet" + ] + }, + { + "Type": "ANIMATION_SYSTEM", + "Attributes": [ + 8, + 0, + 30, + false, + false, + false + ] + }, + { + "Type": "HITBOX_COMPONENT", + "Attributes": [ + 0, + 0.8333333333333334, + 1, + 0.16666666666666666 + ] + }, + { + "Type": "DOOR_COMPONENT", + "Attributes": [ + "0", + false + ] + } + ] + }, + { + "ID":2, + "Components": [ + { + "Type": "TRANSFORM_COMPONENT", + "Attributes": [ + 88, + 112, + 48, + 32 + ] + }, + { + "Type": "SPRITE_COMPONENT", + "Attributes": [ + "lever_sheet" + ] + }, + { + "Type": "ANIMATION_SYSTEM", + "Attributes": [ + 3, + 0, + 100, + false, + false, + false + ] + }, + { + "Type": "HITBOX_COMPONENT", + "Attributes": [ + 0.3333333333333333, + 0.59375, + 0.3333333333333333, + 0.34375 + ] + }, + { + "Type": "INTERACT_COMPONENT", + "Attributes": [ + 0.16666666666666666, + 0.34375, + 0.6666666666666666, + 0.84375, + 0, + 0, + 0 + ] + }, + { + "Type": "LEVER_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 new file mode 100644 index 0000000..d9b0fa0 --- /dev/null +++ b/assets/maps/dungeon_room_1.tmx @@ -0,0 +1,182 @@ + + + + + + + + + +14,158,158,158,158,158,246,248,158,158,158,158,158,15, +109,2,3,3,3,3,246,248,3,3,3,3,4,157, +109,51,52,52,52,52,246,248,52,52,52,52,53,157, +109,197,198,198,198,198,152,151,198,198,198,198,199,157, +109,246,247,247,247,247,247,247,247,247,247,247,248,157, +109,246,247,247,247,247,247,247,247,247,247,247,248,157, +109,246,247,247,247,247,247,247,247,247,247,247,248,157, +109,246,247,247,247,247,247,247,247,247,247,247,248,157, +109,246,247,247,247,247,247,247,247,247,247,247,248,157, +109,246,247,247,247,247,247,247,247,247,247,247,248,157, +109,246,247,247,247,247,247,247,247,247,247,247,248,157, +109,246,247,247,247,247,247,247,247,247,247,247,248,157, +109,246,247,247,247,247,247,247,247,247,247,247,248,157, +109,246,247,247,247,247,247,247,247,247,247,247,248,157, +109,295,296,296,296,296,296,296,296,296,296,296,297,157, +63,108,108,108,108,108,70,71,108,108,108,108,108,64 + + + + +1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,121,122,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,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,1,1,1,1,1, +1,1,1,1,1,1,21,22,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1 + + + + +2647,2647,2647,2647,2647,2648,2650,2650,2648,2647,2647,2647,2647,2647, +2647,2647,2647,2647,2647,2648,2647,2647,2648,2647,2647,2647,2647,2647, +2648,2648,2648,2648,2648,2648,2647,2647,2648,2648,2648,2648,2648,2648, +2648,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2648, +2648,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2648, +2648,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2648, +2648,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2648, +2648,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2648, +2648,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2648, +2648,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2648, +2648,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2648, +2648,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2648, +2648,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2648, +2648,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2648, +2648,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2647,2648, +2648,2648,2648,2648,2648,2648,2649,2649,2648,2648,2648,2648,2648,2648 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/maps/tiled-extensions/json_export_tool.mjs b/assets/maps/tiled-extensions/json_export_tool.mjs index 0095c2a..3203ab1 100644 --- a/assets/maps/tiled-extensions/json_export_tool.mjs +++ b/assets/maps/tiled-extensions/json_export_tool.mjs @@ -1,39 +1,199 @@ +function writeTileLayer(tileLayer, file) +{ + file.writeLine(" \"" + tileLayer.name + "\": ["); + + for(let cell_y = 0; cell_y < tileLayer.height; ++cell_y) + { + file.write(" "); + + for(let cell_x = 0; cell_x < tileLayer.width; ++cell_x) + { + file.write(" " + tileLayer.cellAt(cell_x, cell_y).tileId) + if(cell_x < tileLayer.width - 1 || cell_y < tileLayer.height - 1) + file.write(","); + } + + file.writeLine(""); + } + + file.writeLine(" ],"); +} + +function writeEntities(objectLayer, file) +{ + file.writeLine(" \"Entities\": ["); + + let entities = []; + + for(let i = 0; i < objectLayer.objectCount; i++) + { + let entity = objectLayer.objectAt(i); + + if(entity.name) + { + entities.push(entity); + } + } + + for(let i = 0; i < entities.length; i++) + { + let entity = entities[i]; + + file.writeLine(" {"); + file.writeLine(" \"ID\":" + entity.name + ","); + file.writeLine(" \"Components\": ["); + + let components = entity.properties()["components"]; + let nb_components = Object.keys(components).length; + + for(let j = 0; j < nb_components; j++) + { + let component = components[j]; + let component_type = component[0]; + + file.writeLine(" {"); + + file.write(" \"Type\": \"" + component_type + "\""); + + if(component.length > 1) + { + file.writeLine(","); + file.writeLine(" \"Attributes\": ["); + } + + // Write atributes, speciale cases need speciale treatment. + if(component_type == "TRANSFORM_COMPONENT") + { + file.writeLine(","); + file.writeLine(" \"Attributes\": ["); + file.writeLine(" " + entity.x + ","); + file.writeLine(" " + entity.y + ","); + file.writeLine(" " + entity.width + ","); + file.writeLine(" " + entity.height); + file.writeLine(" ]"); + } + else if(component_type == "HITBOX_COMPONENT") + { + let hitbox; + + for(let k = 0; k < objectLayer.objectCount; k++) + { + hitbox = objectLayer.objectAt(k); + if(hitbox.id === component[1].id) + break; + } + + let x = (hitbox.x - entity.x) / entity.width; + let y = (hitbox.y - entity.y) / entity.height; + let width = hitbox.width / entity.width; + let height = hitbox.height / entity.height; + + file.writeLine(" " + x + ","); + file.writeLine(" " + y + ","); + file.writeLine(" " + width + ","); + file.writeLine(" " + height); + } + else if(component_type == "INTERACT_COMPONENT") + { + let interact_box; + + for(let k = 0; k < objectLayer.objectCount; k++) + { + interact_box = objectLayer.objectAt(k); + if(interact_box.id === component[1].id) + break; + } + + let x = (interact_box.x - entity.x) / entity.width; + let y = (interact_box.y - entity.y) / entity.height; + 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(" " + component[2] + ","); + file.writeLine(" " + component[3] + ","); + file.writeLine(" " + component[4]); + } + 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(""); + } + + if(component.length > 1) + file.writeLine(" ]"); + + if(j == nb_components - 1) + file.writeLine(" }"); + else + file.writeLine(" },"); + } + + file.writeLine(" ]"); + + if(i == entities.length - 1) + file.writeLine(" }"); + else + file.writeLine(" },"); + } + + file.writeLine(" ]"); +} + var customMapFormat = { - name: "Custom map format", - extension: "custom", + name: "Custom JSON map format", + extension: "json", write: function(map, fileName) { - var file = new TextFile(fileName, TextFile.WriteOnly); + let file = new TextFile(fileName, TextFile.WriteOnly); file.writeLine("{"); - file.writeLine(" \"MapWidth\": " + map.width + ","); - file.writeLine(" \"MapHeight\": " + map.height + ","); + file.writeLine(" \"MapWidth\": " + map.width + ","); + file.writeLine(" \"MapHeight\": " + map.height + ","); file.writeLine(""); - for(var i = 0; i < map.layerCount; i++) + for(let i = 0; i < map.layerCount; i++) { - var layer = map.layerAt(i); + let layer = map.layerAt(i); if(layer.isTileLayer) { - file.writeLine(" \"" + layer.name + "\": ["); - - for(var cell_y = 0; cell_y < layer.height; ++cell_y) - { - file.write(" "); - - for (var cell_x = 0; cell_x < layer.width; ++cell_x) - { - file.write(" " + layer.cellAt(cell_x, cell_y).tileId) - if(cell_x < layer.width - 1 || cell_y < layer.height - 1) - file.write(","); - } - - file.writeLine(""); - } - - file.writeLine(" ],"); + writeTileLayer(layer, file); + } + else if(layer.isObjectLayer) + { + writeEntities(layer, file); } }