graphics: tile recipe now parsed using Java properties format
This replaces the custom parser with the standard Java properties parser, which has more features. git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@720 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
parent
eff811b159
commit
158e85a784
1 changed files with 9 additions and 15 deletions
|
@ -3,6 +3,7 @@ package micropolisj.build_tool;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import javax.imageio.*;
|
import javax.imageio.*;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
|
@ -12,6 +13,7 @@ public class MakeTiles
|
||||||
static HashMap<String,String> tileData = new HashMap<String,String>();
|
static HashMap<String,String> tileData = new HashMap<String,String>();
|
||||||
static HashMap<String,Image> loadedImages = new HashMap<String,Image>();
|
static HashMap<String,Image> loadedImages = new HashMap<String,Image>();
|
||||||
|
|
||||||
|
static final Charset UTF8 = Charset.forName("UTF-8");
|
||||||
static final int NTILES = 960;
|
static final int NTILES = 960;
|
||||||
static final int TILE_SIZE = 16;
|
static final int TILE_SIZE = 16;
|
||||||
|
|
||||||
|
@ -21,27 +23,19 @@ public class MakeTiles
|
||||||
File recipeFile = new File(args[0]);
|
File recipeFile = new File(args[0]);
|
||||||
File outputFile = new File(args[1]);
|
File outputFile = new File(args[1]);
|
||||||
|
|
||||||
BufferedReader in = new BufferedReader(
|
Properties recipe = new Properties();
|
||||||
new FileReader(recipeFile));
|
recipe.load(
|
||||||
String l;
|
new InputStreamReader(
|
||||||
while ( (l=in.readLine()) != null )
|
new FileInputStream(recipeFile),
|
||||||
{
|
UTF8
|
||||||
if (l.startsWith("#")) {
|
));
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String[] parts = l.split("\\s+", 2);
|
|
||||||
String tileName = parts[0];
|
|
||||||
String tileImage = parts[1];
|
|
||||||
tileData.put(tileName, tileImage);
|
|
||||||
}
|
|
||||||
in.close();
|
|
||||||
|
|
||||||
// actually assemble the image
|
// actually assemble the image
|
||||||
BufferedImage buf = new BufferedImage(TILE_SIZE,TILE_SIZE*NTILES,BufferedImage.TYPE_INT_RGB);
|
BufferedImage buf = new BufferedImage(TILE_SIZE,TILE_SIZE*NTILES,BufferedImage.TYPE_INT_RGB);
|
||||||
Graphics2D gr = buf.createGraphics();
|
Graphics2D gr = buf.createGraphics();
|
||||||
|
|
||||||
for (int i = 0; i < NTILES; i++) {
|
for (int i = 0; i < NTILES; i++) {
|
||||||
String tileImage = tileData.get(Integer.toString(i));
|
String tileImage = recipe.getProperty(Integer.toString(i));
|
||||||
assert tileImage != null;
|
assert tileImage != null;
|
||||||
|
|
||||||
ImageSpec ref = parseImageSpec(tileImage);
|
ImageSpec ref = parseImageSpec(tileImage);
|
||||||
|
|
Reference in a new issue