refactor: make TileSpec do its own reference resolving

git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@905 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
jason@long.name 2013-12-14 22:10:21 +00:00
parent 447a78b4d7
commit ae13414b34
2 changed files with 63 additions and 30 deletions

View file

@ -54,22 +54,8 @@ public class Tiles
tiles = tilesList.toArray(new TileSpec[0]);
for (int i = 0; i < tiles.length; i++) {
String tmp = tiles[i].getAttribute("becomes");
if (tmp != null) {
tiles[i].animNext = get(Integer.parseInt(tmp));
}
tmp = tiles[i].getAttribute("onpower");
if (tmp != null) {
tiles[i].onPower = get(Integer.parseInt(tmp));
}
tmp = tiles[i].getAttribute("onshutdown");
if (tmp != null) {
tiles[i].onShutdown = get(Integer.parseInt(tmp));
}
tmp = tiles[i].getAttribute("building-part");
if (tmp != null) {
handleBuildingPart(tiles[i], tmp);
}
tiles[i].resolveReferences(tilesByName);
TileSpec.BuildingInfo bi = tiles[i].getBuildingInfo();
if (bi != null) {
for (int j = 0; j < bi.members.length; j++) {
@ -90,20 +76,6 @@ public class Tiles
}
}
private static void handleBuildingPart(TileSpec partTile, String tmp)
{
String [] parts = tmp.split(",");
if (parts.length != 3) {
throw new Error("Invalid building-part specification");
}
partTile.owner = get(Integer.parseInt(parts[0]));
partTile.ownerOffsetX = Integer.parseInt(parts[1]);
partTile.ownerOffsetY = Integer.parseInt(parts[2]);
assert partTile.ownerOffsetX != 0 || partTile.ownerOffsetY != 0;
}
public static TileSpec get(int tileNumber)
{
if (tileNumber >= 0 && tileNumber < tiles.length) {