MCPcopy Create free account
hub / github.com/SimHacker/micropolis / Tiles

Class Tiles

micropolis-java/src/micropolisj/engine/Tiles.java:18–111  ·  view source on GitHub ↗

Provides global methods for loading tile specifications.

Source from the content-addressed store, hash-verified

16 * Provides global methods for loading tile specifications.
17 */
18public class Tiles
19{
20 static final Charset UTF8 = Charset.forName("UTF-8");
21 static TileSpec [] tiles;
22 static Map<String,TileSpec> tilesByName = new HashMap<String,TileSpec>();
23 static {
24 try {
25 readTiles();
26 checkTiles();
27 }
28 catch (IOException e) {
29 throw new RuntimeException(e);
30 }
31 }
32
33 static void readTiles()
34 throws IOException
35 {
36 ArrayList<TileSpec> tilesList = new ArrayList<TileSpec>();
37
38 Properties tilesRc = new Properties();
39 tilesRc.load(
40 new InputStreamReader(
41 Tiles.class.getResourceAsStream("/tiles.rc"),
42 UTF8
43 )
44 );
45
46 String [] tileNames = TileSpec.generateTileNames(tilesRc);
47 tiles = new TileSpec[tileNames.length];
48
49 for (int i = 0; i < tileNames.length; i++) {
50 String tileName = tileNames[i];
51 String rawSpec = tilesRc.getProperty(tileName);
52 if (rawSpec == null) {
53 break;
54 }
55
56 TileSpec ts = TileSpec.parse(i, tileName, rawSpec, tilesRc);
57 tilesByName.put(tileName, ts);
58 tiles[i] = ts;
59 }
60
61 for (int i = 0; i < tiles.length; i++) {
62 tiles[i].resolveReferences(tilesByName);
63
64 TileSpec.BuildingInfo bi = tiles[i].getBuildingInfo();
65 if (bi != null) {
66 for (int j = 0; j < bi.members.length; j++) {
67 int tid = bi.members[j];
68 int offx = (bi.width >= 3 ? -1 : 0) + j % bi.width;
69 int offy = (bi.height >= 3 ? -1 : 0) + j / bi.width;
70
71 if (tiles[tid].owner == null &&
72 (offx != 0 || offy != 0)
73 )
74 {
75 tiles[tid].owner = tiles[i];

Callers

nothing calls this directly

Calls 2

readTilesMethod · 0.95
checkTilesMethod · 0.95

Tested by

no test coverage detected