diff --git a/core/assets/prefabs/levels/emptyLevel.prefab b/core/assets/prefabs/levels/emptyLevel.prefab index 4472a80..f9bb5b1 100644 --- a/core/assets/prefabs/levels/emptyLevel.prefab +++ b/core/assets/prefabs/levels/emptyLevel.prefab @@ -2,7 +2,7 @@ "LevelComponent": { "blockCoordinates": { }, - "objectCoordinates": { + "locatedObjects": { }, "additionalObjects": [] } diff --git a/core/assets/prefabs/levels/level-sample10.prefab b/core/assets/prefabs/levels/level-sample10.prefab index 2ad3553..58f596e 100644 --- a/core/assets/prefabs/levels/level-sample10.prefab +++ b/core/assets/prefabs/levels/level-sample10.prefab @@ -16,10 +16,10 @@ "2,-2,0": "stone", "1,-1,0": "exitPortal" }, - "objectCoordinates": { - "-3,-2,0": "stoneFront", - "0,-2,-1": "stoneBack" - }, + "locatedObjects": [ + "-3,-2,0|stoneFront", + "0,-2,-1|stoneBack" + ], "minX": -10, "maxX": 6, "minY": -7 diff --git a/core/assets/prefabs/levels/level-sample2.prefab b/core/assets/prefabs/levels/level-sample2.prefab index 4332d9c..d078c51 100644 --- a/core/assets/prefabs/levels/level-sample2.prefab +++ b/core/assets/prefabs/levels/level-sample2.prefab @@ -12,12 +12,12 @@ "8,0,0": "stone", "7,1,0": "exitPortal" }, - "objectCoordinates": { - "-0.5,3,0.5": "star", - "0.5,3.5,0.5": "star", - "1.5,3,0.5": "star", - "5,2,0": "torch" - }, + "locatedObjects": [ + "-0.5,3,0.5|star", + "0.5,3.5,0.5|star", + "1.5,3,0.5|star", + "5,2,0|torch" + ], "minX": -10, "maxX": 14, "minY": -5 diff --git a/core/assets/prefabs/levels/level-sample3.prefab b/core/assets/prefabs/levels/level-sample3.prefab index 22aaa97..b4739d1 100644 --- a/core/assets/prefabs/levels/level-sample3.prefab +++ b/core/assets/prefabs/levels/level-sample3.prefab @@ -17,8 +17,6 @@ "8,0,0": "stone", "7,1,0": "exitPortal" }, - "objectCoordinates": { - }, "minX": -10, "maxX": 14, "minY": -5 diff --git a/core/assets/prefabs/levels/level-sample4.prefab b/core/assets/prefabs/levels/level-sample4.prefab index 2d94f8b..44fc825 100644 --- a/core/assets/prefabs/levels/level-sample4.prefab +++ b/core/assets/prefabs/levels/level-sample4.prefab @@ -12,9 +12,9 @@ "8,0,0": "stone", "7,0,0": "exitPortal" }, - "objectCoordinates": { - "5,1,0.5": "bug" - }, + "locatedObjects": [ + "5,1,0.5|bug" + ], "additionalObjects": [ "playerFaction", "bugFaction" diff --git a/core/assets/prefabs/levels/level-sample5.prefab b/core/assets/prefabs/levels/level-sample5.prefab index fcb4bef..1ffbe12 100644 --- a/core/assets/prefabs/levels/level-sample5.prefab +++ b/core/assets/prefabs/levels/level-sample5.prefab @@ -18,9 +18,9 @@ "12,0,0": "stone", "11,1,0": "exitPortal" }, - "objectCoordinates": { - "5,2,0.5": "bugWithGun" - }, + "locatedObjects": [ + "5,2,0.5|bugWithGun" + ], "additionalObjects": [ "playerFaction", "bugFaction" diff --git a/core/assets/prefabs/levels/level-sample6.prefab b/core/assets/prefabs/levels/level-sample6.prefab index 4ef6a14..c406bc3 100644 --- a/core/assets/prefabs/levels/level-sample6.prefab +++ b/core/assets/prefabs/levels/level-sample6.prefab @@ -14,10 +14,11 @@ "-3,2,0": "stone", "9,-1,0": "exitPortal" }, - "objectCoordinates": { - "-3,-1,0": "cycleDoor", - "1,-1.5,0": { + "locatedObjects": [ + "-3,-1,0|cycleDoor", + { "prefabName": "stonePlatform", + "location": "1,-1.5,0", "changes": { "RenderedMultiShapeComponent": { "shapeCount": 3 @@ -37,7 +38,7 @@ } } } - }, + ], "minX": -10, "maxX": 15, "minY": -7 diff --git a/core/assets/prefabs/levels/level-sample7.prefab b/core/assets/prefabs/levels/level-sample7.prefab index fe07901..fbf9a94 100644 --- a/core/assets/prefabs/levels/level-sample7.prefab +++ b/core/assets/prefabs/levels/level-sample7.prefab @@ -14,9 +14,10 @@ "-2,1,0": "stone", "-2,2,0": "stone" }, - "objectCoordinates": { - "-8,-2,0": { + "locatedObjects": [ + { "prefabName": "pressurePlate", + "location": "-8,-2,0", "changes": { "SignalProducerComponent": { "channel": "openDoor" @@ -26,8 +27,9 @@ } } }, - "-2,-1,0": { + { "prefabName": "signalDoor", + "location": "-2,-1,0", "changes": { "SignalConsumerComponent": { "channel": "openDoorDelayed" @@ -37,8 +39,9 @@ } } }, - "-2,1,1": { + { "prefabName": "signalIndicator", + "location": "-2,1,1", "changes": { "SignalConsumerComponent": { "channel": "openDoorDelayed" @@ -48,7 +51,7 @@ } } } - }, + ], "additionalObjects": [ { "prefabName": "signalRelay", diff --git a/core/assets/prefabs/levels/level-sample8.prefab b/core/assets/prefabs/levels/level-sample8.prefab index f20a9bd..d0a7f25 100644 --- a/core/assets/prefabs/levels/level-sample8.prefab +++ b/core/assets/prefabs/levels/level-sample8.prefab @@ -23,9 +23,10 @@ "7,6,0": "stone", "7,7,0": "stone" }, - "objectCoordinates": { - "3,0,0": { + "locatedObjects": [ + { "prefabName": "pressurePlate", + "location": "3,0,0", "changes": { "SignalProducerComponent": { "channel": "spawnGhost" @@ -35,16 +36,18 @@ } } }, - "1,6,0": { + { "prefabName": "tombstone", + "location": "1,6,0", "changes": { "SignalConsumerComponent": { "channel": "spawnGhost" } } }, - "1,5,1": { + { "prefabName": "signalIndicator", + "location": "1,5,1", "changes": { "SignalConsumerComponent": { "channel": "spawnGhost" @@ -54,8 +57,9 @@ } } }, - "5,5,0": { + { "prefabName": "pressurePlate", + "location": "5,5,0", "changes": { "SignalProducerComponent": { "channel": "openDoor" @@ -65,16 +69,18 @@ } } }, - "5,1,0": { + { "prefabName": "signalDoor", + "location": "5,1,0", "changes": { "SignalConsumerComponent": { "channel": "openDoor" } } }, - "5,3,1": { + { "prefabName": "signalIndicator", + "location": "5,3,1", "changes": { "SignalConsumerComponent": { "channel": "openDoor" @@ -84,7 +90,7 @@ } } } - }, + ], "minX": -5, "maxX": 14, "minY": -5 diff --git a/core/assets/prefabs/levels/level-sample9.prefab b/core/assets/prefabs/levels/level-sample9.prefab index f1a123d..c360d23 100644 --- a/core/assets/prefabs/levels/level-sample9.prefab +++ b/core/assets/prefabs/levels/level-sample9.prefab @@ -15,9 +15,10 @@ "5,3,0": "stone", "5,4,0": "stone" }, - "objectCoordinates": { - "3,1,0": { + "locatedObjects": [ + { "prefabName": "lever", + "location": "3,1,0", "changes": { "SignalProducerComponent": { "channel": "openDoor" @@ -27,16 +28,18 @@ } } }, - "5,1,0": { + { "prefabName": "signalDoor", + "location": "5,1,0", "changes": { "SignalConsumerComponent": { "channel": "openDoor" } } }, - "5,3,1": { + { "prefabName": "signalIndicator", + "location": "5,3,1", "changes": { "SignalConsumerComponent": { "channel": "openDoor" @@ -46,7 +49,7 @@ } } } - }, + ], "minX": -5, "maxX": 14, "minY": -5 diff --git a/core/src/main/java/jgd/platformer/editor/EditorLogicSystem.java b/core/src/main/java/jgd/platformer/editor/EditorLogicSystem.java index c189df5..4274f3c 100644 --- a/core/src/main/java/jgd/platformer/editor/EditorLogicSystem.java +++ b/core/src/main/java/jgd/platformer/editor/EditorLogicSystem.java @@ -26,6 +26,7 @@ import jgd.platformer.gameplay.rendering.platform.RebuildBlockMesh; import java.util.Collections; +import java.util.List; import java.util.Map; @RegisterSystem( @@ -145,16 +146,16 @@ public void placeObject(PlaceObject placeObject, EntityRef entityRef, LevelCompo entityRef.send(new RebuildBlockMesh()); } if (lastSelectedObjectType != null) { - Map objectCoordinates = levelComponent.getObjectCoordinates(); + List objectCoordinates = levelComponent.getLocatedObjects(); Vector3 placementTranslate = lastSelectedObjectType.getPlacementTranslate(); float x = lastMousePosition.x + placementTranslate.x; float y = lastMousePosition.y + placementTranslate.y; float z = lastMousePosition.z + placementTranslate.z; String position = x + "," + y + "," + z; String prefabName = lastSelectedObjectType.getPrefabName(); - objectCoordinates.put(position, prefabName); + objectCoordinates.add(position + "|" + prefabName); - levelComponent.setObjectCoordinates(objectCoordinates); + levelComponent.setLocatedObjects(objectCoordinates); entityRef.saveChanges(); platformerEntitySpawner.createEntityAt(x, y, z, prefabName, Collections.emptyMap()); diff --git a/core/src/main/java/jgd/platformer/gameplay/level/LevelComponent.java b/core/src/main/java/jgd/platformer/gameplay/level/LevelComponent.java index fbe7ce6..dd9df46 100644 --- a/core/src/main/java/jgd/platformer/gameplay/level/LevelComponent.java +++ b/core/src/main/java/jgd/platformer/gameplay/level/LevelComponent.java @@ -9,9 +9,9 @@ public interface LevelComponent extends Component { Map getBlockCoordinates(); void setBlockCoordinates(Map blockCoordinates); - Map getObjectCoordinates(); + List getLocatedObjects(); - void setObjectCoordinates(Map objectCoordinates); + void setLocatedObjects(List locatedObjects); List getAdditionalObjects(); diff --git a/core/src/main/java/jgd/platformer/gameplay/level/LevelEntitySystem.java b/core/src/main/java/jgd/platformer/gameplay/level/LevelEntitySystem.java index bc05a6c..5557a5c 100644 --- a/core/src/main/java/jgd/platformer/gameplay/level/LevelEntitySystem.java +++ b/core/src/main/java/jgd/platformer/gameplay/level/LevelEntitySystem.java @@ -36,21 +36,31 @@ public void levelLoaded(AfterLevelLoaded event, EntityRef entity, LevelComponent } } - if (level.getObjectCoordinates() != null) { - for (Map.Entry objectCoordinates : level.getObjectCoordinates().entrySet()) { - String locationStr = objectCoordinates.getKey(); - Object value = objectCoordinates.getValue(); + if (level.getLocatedObjects() != null) { + for (Object locatedObject : level.getLocatedObjects()) { + if (locatedObject instanceof String) { + String[] objectSplit = ((String) locatedObject).split("\\|", 2); + String locationStr = objectSplit[0]; + String recipe = objectSplit[1]; - String[] locationSplit = locationStr.split(","); - float x = Float.parseFloat(locationSplit[0]); - float y = Float.parseFloat(locationSplit[1]); - float z = Float.parseFloat(locationSplit[2]); - if (value instanceof String) { - platformerEntitySpawner.createEntityFromRecipeAt(x, y, z, (String) value); + String[] locationSplit = locationStr.split(","); + float x = Float.parseFloat(locationSplit[0]); + float y = Float.parseFloat(locationSplit[1]); + float z = Float.parseFloat(locationSplit[2]); + + platformerEntitySpawner.createEntityFromRecipeAt(x, y, z, recipe); } else { - Map objectMapDef = (Map) value; + Map objectMapDef = (Map) locatedObject; + String locationStr = (String) objectMapDef.get("location"); + String prefabName = (String) objectMapDef.get("prefabName"); + Map changes = (Map) objectMapDef.get("changes"); + + String[] locationSplit = locationStr.split(","); + float x = Float.parseFloat(locationSplit[0]); + float y = Float.parseFloat(locationSplit[1]); + float z = Float.parseFloat(locationSplit[2]); - platformerEntitySpawner.createEntityAt(x, y, z, (String) objectMapDef.get("prefabName"), (Map) objectMapDef.get("changes")); + platformerEntitySpawner.createEntityAt(x, y, z, prefabName, changes); } } }