Skip to content

Commit

Permalink
Changed the definition of the level.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinSc committed Sep 19, 2016
1 parent 8387d3a commit 8e16d91
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 58 deletions.
2 changes: 1 addition & 1 deletion core/assets/prefabs/levels/emptyLevel.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"LevelComponent": {
"blockCoordinates": {
},
"objectCoordinates": {
"locatedObjects": {
},
"additionalObjects": []
}
Expand Down
8 changes: 4 additions & 4 deletions core/assets/prefabs/levels/level-sample10.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions core/assets/prefabs/levels/level-sample2.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions core/assets/prefabs/levels/level-sample3.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
"8,0,0": "stone",
"7,1,0": "exitPortal"
},
"objectCoordinates": {
},
"minX": -10,
"maxX": 14,
"minY": -5
Expand Down
6 changes: 3 additions & 3 deletions core/assets/prefabs/levels/level-sample4.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions core/assets/prefabs/levels/level-sample5.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 5 additions & 4 deletions core/assets/prefabs/levels/level-sample6.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,7 +38,7 @@
}
}
}
},
],
"minX": -10,
"maxX": 15,
"minY": -7
Expand Down
13 changes: 8 additions & 5 deletions core/assets/prefabs/levels/level-sample7.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -26,8 +27,9 @@
}
}
},
"-2,-1,0": {
{
"prefabName": "signalDoor",
"location": "-2,-1,0",
"changes": {
"SignalConsumerComponent": {
"channel": "openDoorDelayed"
Expand All @@ -37,8 +39,9 @@
}
}
},
"-2,1,1": {
{
"prefabName": "signalIndicator",
"location": "-2,1,1",
"changes": {
"SignalConsumerComponent": {
"channel": "openDoorDelayed"
Expand All @@ -48,7 +51,7 @@
}
}
}
},
],
"additionalObjects": [
{
"prefabName": "signalRelay",
Expand Down
22 changes: 14 additions & 8 deletions core/assets/prefabs/levels/level-sample8.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -54,8 +57,9 @@
}
}
},
"5,5,0": {
{
"prefabName": "pressurePlate",
"location": "5,5,0",
"changes": {
"SignalProducerComponent": {
"channel": "openDoor"
Expand All @@ -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"
Expand All @@ -84,7 +90,7 @@
}
}
}
},
],
"minX": -5,
"maxX": 14,
"minY": -5
Expand Down
13 changes: 8 additions & 5 deletions core/assets/prefabs/levels/level-sample9.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -46,7 +49,7 @@
}
}
}
},
],
"minX": -5,
"maxX": 14,
"minY": -5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import jgd.platformer.gameplay.rendering.platform.RebuildBlockMesh;

import java.util.Collections;
import java.util.List;
import java.util.Map;

@RegisterSystem(
Expand Down Expand Up @@ -145,16 +146,16 @@ public void placeObject(PlaceObject placeObject, EntityRef entityRef, LevelCompo
entityRef.send(new RebuildBlockMesh());
}
if (lastSelectedObjectType != null) {
Map<String, Object> objectCoordinates = levelComponent.getObjectCoordinates();
List<Object> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public interface LevelComponent extends Component {
Map<String, String> getBlockCoordinates();
void setBlockCoordinates(Map<String, String> blockCoordinates);

Map<String, Object> getObjectCoordinates();
List<Object> getLocatedObjects();

void setObjectCoordinates(Map<String, Object> objectCoordinates);
void setLocatedObjects(List<Object> locatedObjects);

List<Object> getAdditionalObjects();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,31 @@ public void levelLoaded(AfterLevelLoaded event, EntityRef entity, LevelComponent
}
}

if (level.getObjectCoordinates() != null) {
for (Map.Entry<String, Object> 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<String, Object> objectMapDef = (Map<String, Object>) value;
Map<String, Object> objectMapDef = (Map<String, Object>) locatedObject;
String locationStr = (String) objectMapDef.get("location");
String prefabName = (String) objectMapDef.get("prefabName");
Map<String, Object> changes = (Map<String, Object>) 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<String, Object>) objectMapDef.get("changes"));
platformerEntitySpawner.createEntityAt(x, y, z, prefabName, changes);
}
}
}
Expand Down

0 comments on commit 8e16d91

Please sign in to comment.