tiles: add name property to spec
This commit is contained in:
parent
35acab9d30
commit
7b890e9d89
3 changed files with 26 additions and 11 deletions
|
@ -52,12 +52,13 @@ public class MakeTiles
|
||||||
|
|
||||||
for (int i = 0; i < NTILES; i++) {
|
for (int i = 0; i < NTILES; i++) {
|
||||||
int tileNumber = SKIP_TILES + i;
|
int tileNumber = SKIP_TILES + i;
|
||||||
String rawSpec = recipe.getProperty(Integer.toString(tileNumber));
|
String tileName = Integer.toString(tileNumber);
|
||||||
|
String rawSpec = recipe.getProperty(tileName);
|
||||||
if (rawSpec == null) {
|
if (rawSpec == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
TileSpec tileSpec = TileSpec.parse(tileNumber, rawSpec, recipe);
|
TileSpec tileSpec = TileSpec.parse(tileNumber, tileName, rawSpec, recipe);
|
||||||
FrameSpec ref = parseFrameSpec(tileSpec);
|
FrameSpec ref = parseFrameSpec(tileSpec);
|
||||||
if (ref == null) {
|
if (ref == null) {
|
||||||
// tile is defined, but it has no images
|
// tile is defined, but it has no images
|
||||||
|
|
|
@ -13,6 +13,7 @@ import java.util.*;
|
||||||
public class TileSpec
|
public class TileSpec
|
||||||
{
|
{
|
||||||
int tileNumber;
|
int tileNumber;
|
||||||
|
String name;
|
||||||
TileSpec animNext;
|
TileSpec animNext;
|
||||||
TileSpec onPower;
|
TileSpec onPower;
|
||||||
TileSpec onShutdown;
|
TileSpec onShutdown;
|
||||||
|
@ -29,16 +30,17 @@ public class TileSpec
|
||||||
Map<String,String> attributes;
|
Map<String,String> attributes;
|
||||||
List<String> images;
|
List<String> images;
|
||||||
|
|
||||||
protected TileSpec(int tileNumber)
|
protected TileSpec(int tileNumber, String tileName)
|
||||||
{
|
{
|
||||||
this.tileNumber = tileNumber;
|
this.tileNumber = tileNumber;
|
||||||
|
this.name = tileName;
|
||||||
this.attributes = new HashMap<String,String>();
|
this.attributes = new HashMap<String,String>();
|
||||||
this.images = new ArrayList<String>();
|
this.images = new ArrayList<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TileSpec parse(int tileNumber, String inStr, Properties tilesRc)
|
public static TileSpec parse(int tileNumber, String tileName, String inStr, Properties tilesRc)
|
||||||
{
|
{
|
||||||
TileSpec ts = new TileSpec(tileNumber);
|
TileSpec ts = new TileSpec(tileNumber, tileName);
|
||||||
ts.load(inStr, tilesRc);
|
ts.load(inStr, tilesRc);
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
@ -290,7 +292,12 @@ public class TileSpec
|
||||||
|
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return "{tile#"+tileNumber+"}";
|
return "{tile:"+name+"}";
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isNumberedTile()
|
||||||
|
{
|
||||||
|
return name.matches("^\\d+$");
|
||||||
}
|
}
|
||||||
|
|
||||||
void resolveReferences(Map<String,TileSpec> tileMap)
|
void resolveReferences(Map<String,TileSpec> tileMap)
|
||||||
|
|
|
@ -43,18 +43,20 @@ public class Tiles
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
for (int i = 0; ; i++) {
|
String [] tileNames = TileSpec.generateTileNames(tilesRc);
|
||||||
String tileName = Integer.toString(i);
|
tiles = new TileSpec[tileNames.length];
|
||||||
|
|
||||||
|
for (int i = 0; i < tileNames.length; i++) {
|
||||||
|
String tileName = tileNames[i];
|
||||||
String rawSpec = tilesRc.getProperty(tileName);
|
String rawSpec = tilesRc.getProperty(tileName);
|
||||||
if (rawSpec == null) {
|
if (rawSpec == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
TileSpec ts = TileSpec.parse(i, rawSpec, tilesRc);
|
TileSpec ts = TileSpec.parse(i, tileName, rawSpec, tilesRc);
|
||||||
tilesByName.put(tileName, ts);
|
tilesByName.put(tileName, ts);
|
||||||
tilesList.add(ts);
|
tiles[i] = ts;
|
||||||
}
|
}
|
||||||
tiles = tilesList.toArray(new TileSpec[0]);
|
|
||||||
|
|
||||||
for (int i = 0; i < tiles.length; i++) {
|
for (int i = 0; i < tiles.length; i++) {
|
||||||
tiles[i].resolveReferences(tilesByName);
|
tiles[i].resolveReferences(tilesByName);
|
||||||
|
@ -79,6 +81,11 @@ public class Tiles
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TileSpec load(String tileName)
|
||||||
|
{
|
||||||
|
return tilesByName.get(tileName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access a tile specification by index number.
|
* Access a tile specification by index number.
|
||||||
*
|
*
|
||||||
|
|
Reference in a new issue