Skip to content

Commit f741054

Browse files
committed
Store the things also for the rooms, fixes NPE on some room updates
1 parent 1c8eadd commit f741054

File tree

3 files changed

+15
-88
lines changed

3 files changed

+15
-88
lines changed

src/toniarts/openkeeper/game/component/RoomComponent.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package toniarts.openkeeper.game.component;
1818

1919
import com.simsilica.es.EntityComponent;
20-
import toniarts.openkeeper.tools.convert.map.Thing;
2120

2221
/**
2322
* A base room component. This entity is a room
@@ -28,7 +27,6 @@ public class RoomComponent implements EntityComponent {
2827

2928
public short roomId;
3029
public boolean destroyed = false;
31-
public Thing.Room.Direction direction;
3230

3331
public RoomComponent() {
3432
// For serialization
@@ -38,10 +36,9 @@ public RoomComponent(short roomId) {
3836
this.roomId = roomId;
3937
}
4038

41-
public RoomComponent(short roomId, boolean destroyed, Thing.Room.Direction direction) {
39+
public RoomComponent(short roomId, boolean destroyed) {
4240
this.roomId = roomId;
4341
this.destroyed = destroyed;
44-
this.direction = direction;
4542
}
4643

4744
}

src/toniarts/openkeeper/game/controller/RoomControllerFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static IRoomController constructRoom(EntityData entityData, KwdFile kwdFi
9595

9696
private static void setRoomComponents(EntityId entity, EntityData entityData, RoomInstance roomInstance) {
9797
entityData.setComponents(entity,
98-
new RoomComponent(roomInstance.getRoom().getRoomId(), roomInstance.isDestroyed(), roomInstance.getDirection()),
98+
new RoomComponent(roomInstance.getRoom().getRoomId(), roomInstance.isDestroyed()),
9999
new Owner(roomInstance.getOwnerId(), roomInstance.getOwnerId()));
100100
}
101101

src/toniarts/openkeeper/view/map/MapViewController.java

+13-83
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
import toniarts.openkeeper.view.map.construction.RoomConstructor;
6363
import toniarts.openkeeper.view.map.construction.SingleQuadConstructor;
6464
import toniarts.openkeeper.view.map.construction.WaterConstructor;
65-
import toniarts.openkeeper.world.room.GenericRoom;
6665

6766
/**
6867
* Loads whole maps, and handles the maps
@@ -85,20 +84,16 @@ public abstract class MapViewController implements ILoader<KwdFile> {
8584
private List<Node> pages;
8685
private final KwdFile kwdFile;
8786
private Node map;
88-
//private final MapData mapData;
8987
private final AssetManager assetManager;
9088
private final IMapInformation mapClientService;
91-
//private final EffectManagerState effectManager;
9289
private Node roomsNode;
9390
private final short playerId;
94-
// private final WorldState worldState;
95-
//private final ObjectLoader objectLoader;
96-
// private final List<RoomInstance> rooms = new ArrayList<>(); // The list of rooms
9791
private final Set<Point> flashedTiles = new HashSet<>();
9892
private final List<EntityInstance<Terrain>> waterBatches = new ArrayList<>(); // Lakes and rivers
9993
private final List<EntityInstance<Terrain>> lavaBatches = new ArrayList<>(); // Lakes and rivers, but hot
10094
private final Map<Point, RoomInstance> roomCoordinates = new HashMap<>(); // A quick glimpse whether room at specific coordinates is already "found"
10195
private final Map<RoomInstance, Spatial> roomNodes = new HashMap<>(); // Room instances by node
96+
private final Map<Point, Thing.Room> roomThings = new HashMap<>();
10297
private final Map<RoomInstance, RoomConstructor> roomActuals = new HashMap<>(); // Rooms by room constructor
10398
private final Map<Point, EntityInstance<Terrain>> terrainBatchCoordinates = new HashMap<>(); // A quick glimpse whether terrain batch at specific coordinates is already "found"
10499

@@ -553,19 +548,10 @@ private RoomInstance handleRoom(Point p, Room room, Thing.Room thing) {
553548
return roomInstance;
554549
}
555550

556-
RoomInstance roomInstance = new RoomInstance(room, thing);
557-
findRoom(p, roomInstance);
551+
RoomInstance roomInstance = new RoomInstance(room, thing != null ? thing : roomThings.get(p));
552+
findRoom(p, roomInstance, thing);
558553
findRoomWallSections(roomInstance);
559-
//rooms.add(roomInstance);
560-
561-
// Put the thing attributes in
562-
// if (thing != null) {
563-
// for (Point roomPoint : roomInstance.getCoordinates()) {
564-
// MapTile tile = mapData.getTile(roomPoint);
565-
// tile.setPlayerId(thing.getPlayerId());
566-
// tile.setHealth((int) (tile.getTerrain().getMaxHealth() * (thing.getInitialHealth() / 100f)));
567-
// }
568-
// }
554+
569555
Spatial roomNode = handleRoom(roomInstance);
570556
if (roomNode != null) {
571557
roomsNode.attachChild(roomNode);
@@ -632,8 +618,6 @@ private void handleTop(IMapTileInformation tile, Terrain terrain, Node pageNode)
632618
topTileNode.attachChild(spatial);
633619
setTileMaterialToGeometries(tile, topTileNode);
634620
AssetUtils.translateToTile(topTileNode, p);
635-
636-
// tile.setTopNode(topTileNode);
637621
}
638622

639623
private void handleSide(IMapTileInformation tile, Node pageNode) {
@@ -650,8 +634,6 @@ private void handleSide(IMapTileInformation tile, Node pageNode) {
650634

651635
setTileMaterialToGeometries(tile, sideTileNode);
652636
AssetUtils.translateToTile(sideTileNode, p);
653-
654-
// tile.setSideNode(sideTileNode);
655637
}
656638

657639
public void flashTile(boolean enabled, List<Point> points) {
@@ -736,8 +718,9 @@ public static boolean hasRoomWalls(Room room) {
736718
*
737719
* @param p starting point
738720
* @param roomInstance the room instance
721+
* @param thing fixed room item
739722
*/
740-
private void findRoom(Point p, RoomInstance roomInstance) {
723+
private void findRoom(Point p, RoomInstance roomInstance, Thing.Room thing) {
741724
IMapTileInformation tile = getMapData().getTile(p);
742725

743726
// Get the terrain
@@ -750,18 +733,21 @@ private void findRoom(Point p, RoomInstance roomInstance) {
750733
// Add the coordinate
751734
roomCoordinates.put(p, roomInstance);
752735
roomInstance.addCoordinate(p);
736+
if (thing != null) {
737+
roomThings.put(p, thing);
738+
}
753739

754740
// Find north
755-
findRoom(new Point(p.x, p.y - 1), roomInstance);
741+
findRoom(new Point(p.x, p.y - 1), roomInstance, thing);
756742

757743
// Find east
758-
findRoom(new Point(p.x + 1, p.y), roomInstance);
744+
findRoom(new Point(p.x + 1, p.y), roomInstance, thing);
759745

760746
// Find south
761-
findRoom(new Point(p.x, p.y + 1), roomInstance);
747+
findRoom(new Point(p.x, p.y + 1), roomInstance, thing);
762748

763749
// Find west
764-
findRoom(new Point(p.x - 1, p.y), roomInstance);
750+
findRoom(new Point(p.x - 1, p.y), roomInstance, thing);
765751
}
766752
}
767753
}
@@ -869,26 +855,6 @@ public static void setTerrainMaterialLighting(Material material, Terrain terrain
869855
material.setBoolean("UseMaterialColors", false); // Hmm...
870856
}
871857

872-
/**
873-
* Get coordinate / room instance mapping
874-
*
875-
* @return mapping
876-
*/
877-
public HashMap<Point, RoomInstance> getRoomCoordinates() {
878-
// return roomCoordinates;
879-
return null;
880-
}
881-
882-
/**
883-
* Get list of room instances
884-
*
885-
* @return room instances
886-
*/
887-
protected List<RoomInstance> getRooms() {
888-
// return rooms;
889-
return null;
890-
}
891-
892858
/**
893859
* Remove all the given room instances (and actually removes them from the
894860
* scene)
@@ -899,11 +865,7 @@ protected void removeRoomInstances(RoomInstance... instances) {
899865
for (RoomInstance instance : instances) {
900866
roomsNode.detachChild(roomNodes.get(instance));
901867
roomNodes.remove(instance);
902-
//rooms.remove(instance);
903868

904-
// Signal the room
905-
//GenericRoom room = roomActuals.get(instance);
906-
//room.destroy();
907869
roomActuals.remove(instance);
908870
for (Point p : instance.getCoordinates()) {
909871
roomCoordinates.remove(p);
@@ -1049,38 +1011,6 @@ protected void updateRoom(RoomInstance roomInstance) {
10491011

10501012
// Redraw
10511013
updateRoomWalls(roomInstance);
1052-
// roomActuals.get(roomInstance).construct();
1053-
// roomsNode.attachChild(roomActuals.get(roomInstance).construct());
1054-
}
1055-
1056-
/**
1057-
* Get a rooms by knowing its instance
1058-
*
1059-
* @return room
1060-
*/
1061-
public Map<RoomInstance, GenericRoom> getRoomActuals() {
1062-
// return roomActuals;
1063-
return null;
1064-
}
1065-
1066-
/**
1067-
* Get rooms by function.<br> FIXME: Should the player have ready lists?
1068-
*
1069-
* @param objectType the function
1070-
* @param playerId the player id, can be null
1071-
* @return list of rooms that match the criteria
1072-
*/
1073-
public List<GenericRoom> getRoomsByFunction(GenericRoom.ObjectType objectType, Short playerId) {
1074-
List<GenericRoom> roomsList = new ArrayList<>();
1075-
// for (Entry<RoomInstance, GenericRoom> entry : roomActuals.entrySet()) {
1076-
// if (playerId != null && entry.getKey().getOwnerId() != playerId) {
1077-
// continue;
1078-
// }
1079-
// if (entry.getValue().hasObjectControl(objectType)) {
1080-
// roomsList.add(entry.getValue());
1081-
// }
1082-
// }
1083-
return roomsList;
10841014
}
10851015

10861016
/**

0 commit comments

Comments
 (0)