tile-names: rename old tile names to new tile names automatically
when loading a saved city file.
This commit is contained in:
parent
de36ad6590
commit
206c12a0c4
4 changed files with 80 additions and 1 deletions
|
@ -69,6 +69,7 @@
|
|||
<arg file="${builddir}/sm" />
|
||||
</java>
|
||||
<copy todir="${builddir}" file="graphics/tiles.rc" />
|
||||
<copy todir="${builddir}/tiles" file="tiles/aliases.txt" />
|
||||
</target>
|
||||
|
||||
<target name="compile" depends="init-builddir">
|
||||
|
|
|
@ -2145,6 +2145,8 @@ public class Micropolis
|
|||
void loadMap_v2(XMLStreamReader in)
|
||||
throws XMLStreamException
|
||||
{
|
||||
Map<String,String> tileUpgradeMap = Tiles.loadTileUpgradeMap();
|
||||
|
||||
ArrayList< char [] > mapList = new ArrayList< char[] >();
|
||||
while (in.next() != XMLStreamConstants.END_ELEMENT) {
|
||||
if (!in.isStartElement()) {
|
||||
|
@ -2167,8 +2169,13 @@ public class Micropolis
|
|||
char[] row = new char[tmp.size()];
|
||||
for (int i = 0; i < row.length; i++) {
|
||||
String [] s_parts = tmp.get(i).split(":");
|
||||
String tileName = s_parts[0];
|
||||
|
||||
TileSpec t = Tiles.load(s_parts[0]);
|
||||
while (tileUpgradeMap.containsKey(tileName)) {
|
||||
tileName = tileUpgradeMap.get(tileName);
|
||||
}
|
||||
|
||||
TileSpec t = Tiles.load(tileName);
|
||||
if (t == null) {
|
||||
throw new XMLStreamException(
|
||||
"Unrecognized tile '"+s_parts[0]+"' at map coordinates ("+i+","+mapList.size()+")",
|
||||
|
|
|
@ -30,6 +30,32 @@ public class Tiles
|
|||
}
|
||||
}
|
||||
|
||||
static final String TILE_ALIASES = "/tiles/aliases.txt";
|
||||
static Map<String,String> loadTileUpgradeMap()
|
||||
{
|
||||
try {
|
||||
Properties p = new Properties();
|
||||
p.load(
|
||||
new InputStreamReader(
|
||||
Tiles.class.getResourceAsStream(TILE_ALIASES),
|
||||
UTF8
|
||||
)
|
||||
);
|
||||
|
||||
HashMap<String,String> rv = new HashMap<String,String>();
|
||||
for (Map.Entry<Object,Object> e : p.entrySet()) {
|
||||
rv.put((String)e.getKey(), (String)e.getValue());
|
||||
}
|
||||
return rv;
|
||||
|
||||
}
|
||||
catch (IOException e) {
|
||||
// probably means the resource file was not found
|
||||
System.err.println(TILE_ALIASES + ": "+e);
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
}
|
||||
|
||||
static void readTiles()
|
||||
throws IOException
|
||||
{
|
||||
|
|
45
tiles/aliases.txt
Normal file
45
tiles/aliases.txt
Normal file
|
@ -0,0 +1,45 @@
|
|||
# In this file are tiles whose official names have changed.
|
||||
# Each entry consists of <old-name> <new-name>.
|
||||
# Whenever <old-name> is found when loading a Micropolis save-file,
|
||||
# that tile will be mapped to <new-name> automatically.
|
||||
#
|
||||
|
||||
# old fire animation
|
||||
57 56
|
||||
58 56
|
||||
59 56
|
||||
60 56
|
||||
61 56
|
||||
62 56
|
||||
63 56
|
||||
# radar dish animation
|
||||
833 832
|
||||
834 832
|
||||
835 832
|
||||
836 832
|
||||
837 832
|
||||
838 832
|
||||
839 832
|
||||
# fountain animation
|
||||
841 840
|
||||
842 840
|
||||
843 840
|
||||
# stadium animation
|
||||
933 932
|
||||
934 932
|
||||
935 932
|
||||
936 932
|
||||
937 932
|
||||
938 932
|
||||
939 932
|
||||
941 940
|
||||
942 940
|
||||
943 940
|
||||
944 940
|
||||
945 940
|
||||
946 940
|
||||
947 940
|
||||
# nuclear swirl
|
||||
953 952
|
||||
954 952
|
||||
955 952
|
Reference in a new issue