From 22c0edc7c166c047cd5ed5a5ee7ae8ac242169f5 Mon Sep 17 00:00:00 2001 From: "jason@long.name" Date: Sat, 20 Jul 2013 21:29:47 +0000 Subject: [PATCH] tiles.rc syntax: allow inheriting of another tile's images/attributes To inherit, just put the name of tile you want to inherit from in parenthesis at the beginning of the specification. E.g. road-1-1 (road) roads/1-1 (road-north)(road-south) will define a tile named "road-1-1", which first starts with all the images and properties of tile "road" and then layers on top of that the 'road/1-1' image, and then sets the 'road-north' and 'road-south' flags. git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@754 d9718cc8-9f43-0410-858b-315f434eb58c --- src/micropolisj/build_tool/MakeTiles.java | 2 +- src/micropolisj/engine/TileSpec.java | 18 ++++++++++++++---- src/micropolisj/engine/Tiles.java | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/micropolisj/build_tool/MakeTiles.java b/src/micropolisj/build_tool/MakeTiles.java index d94ea94..9fee28f 100644 --- a/src/micropolisj/build_tool/MakeTiles.java +++ b/src/micropolisj/build_tool/MakeTiles.java @@ -47,7 +47,7 @@ public class MakeTiles String rawSpec = recipe.getProperty(Integer.toString(i)); assert rawSpec != null; - TileSpec tileSpec = TileSpec.parse(i, rawSpec); + TileSpec tileSpec = TileSpec.parse(i, rawSpec, recipe); FrameSpec ref = parseFrameSpec(tileSpec); drawTo(ref, gr, 0, TILE_SIZE*i); } diff --git a/src/micropolisj/engine/TileSpec.java b/src/micropolisj/engine/TileSpec.java index df6c1b8..04f071a 100644 --- a/src/micropolisj/engine/TileSpec.java +++ b/src/micropolisj/engine/TileSpec.java @@ -20,10 +20,10 @@ public class TileSpec this.images = new ArrayList(); } - public static TileSpec parse(int tileNumber, String inStr) + public static TileSpec parse(int tileNumber, String inStr, Properties tilesRc) { TileSpec ts = new TileSpec(tileNumber); - ts.load(inStr); + ts.load(inStr, tilesRc); return ts; } @@ -43,7 +43,7 @@ public class TileSpec return images.toArray(new String[0]); } - protected void load(String inStr) + protected void load(String inStr, Properties tilesRc) { Scanner in = new Scanner(inStr); @@ -58,7 +58,17 @@ public class TileSpec v = in.readAttributeValue(); } in.eatChar(')'); - attributes.put(k, v); + + if (!attributes.containsKey(k)) { + attributes.put(k, v); + String sup = tilesRc.getProperty(k); + if (sup != null) { + load(sup, tilesRc); + } + } + else { + attributes.put(k, v); + } } else if (in.peekChar() == '|' || in.peekChar() == ',') { diff --git a/src/micropolisj/engine/Tiles.java b/src/micropolisj/engine/Tiles.java index c7e4aa9..1a69527 100644 --- a/src/micropolisj/engine/Tiles.java +++ b/src/micropolisj/engine/Tiles.java @@ -37,7 +37,7 @@ public class Tiles continue; } - tiles[i] = TileSpec.parse(i, rawSpec); + tiles[i] = TileSpec.parse(i, rawSpec, tilesRc); } for (int i = 0; i < tiles.length; i++) {