Wrote tools to ease the process of renaming tilesets.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1421 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-06-04 02:50:02 +00:00
parent c4c8e2297b
commit 1b3b5bb794
3 changed files with 125 additions and 1 deletions
@@ -0,0 +1,38 @@
//
// $Id: DumpTileSetMap.java,v 1.1 2002/06/04 02:50:02 mdb Exp $
package com.threerings.media.tile.tools;
import java.io.File;
import java.util.Iterator;
import com.samskivert.io.PersistenceException;
/**
* Prints out the tileset mappings in a {@link MapFileTileSetIDBroker}.
*/
public class DumpTileSetMap
{
public static void main (String[] args)
{
if (args.length < 1) {
System.err.println("Usage: DumpTileSetMap tileset.map");
System.exit(-1);
}
try {
MapFileTileSetIDBroker broker =
new MapFileTileSetIDBroker(new File(args[0]));
Iterator iter = broker.enumerateMappings();
while (iter.hasNext()) {
String tsname = iter.next().toString();
System.out.println(tsname + " => " +
broker.getTileSetID(tsname));
}
} catch (PersistenceException pe) {
System.err.println("Unable to dump mapping: " + pe);
System.exit(-1);
}
}
}
@@ -1,5 +1,5 @@
//
// $Id: MapFileTileSetIDBroker.java,v 1.4 2002/04/03 22:42:22 mdb Exp $
// $Id: MapFileTileSetIDBroker.java,v 1.5 2002/06/04 02:50:02 mdb Exp $
package com.threerings.media.tile.tools;
@@ -12,6 +12,7 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.Iterator;
import com.samskivert.io.PersistenceException;
@@ -94,6 +95,35 @@ public class MapFileTileSetIDBroker implements TileSetIDBroker
}
}
/**
* Copies the ID from the old tileset to the new tileset which is
* useful when a tileset is renamed. This is called by the {@link
* RenameTileSet} utility.
*/
protected boolean renameTileSet (String oldName, String newName)
{
Integer tsid = (Integer)_map.get(oldName);
if (tsid != null) {
_map.put(newName, tsid);
// fudge our stored tileset ID so that we flush ourselves when
// the rename tool requests that we commit the changes
_storedTileSetID--;
return true;
} else {
return false;
}
}
/**
* Used by {@link DumpTileSetMap} to enumerate our tileset ID
* mappings.
*/
protected Iterator enumerateMappings ()
{
return _map.keySet().iterator();
}
/** Our persistent map file. */
protected File _mapfile;
@@ -0,0 +1,56 @@
//
// $Id: RenameTileSet.java,v 1.1 2002/06/04 02:50:02 mdb Exp $
package com.threerings.media.tile.tools;
import java.io.File;
import com.samskivert.io.PersistenceException;
/**
* Used to map a tileset name to the same ID as a pre-existing tileset.
* This only works for tileset mappings stored using a {@link
* MapFileTileSetIDBroker}. If a tileset is renamed, this utility must be
* used to map the new name to the old ID, otherwise scenes created with
* the renamed tileset will cease to work as the tileset will live under a
* new ID.
*/
public class RenameTileSet
{
/**
* Loads up the tileset map file with the specified path and copies
* the tileset ID from the old tileset name to the new tileset name.
* This is necessary when a tileset is renamed so that the new name
* does not cause the tileset to be assigned a new tileset ID. Bear in
* mind that the old name should never again be used as it will
* conflict with a tileset provided under the new name.
*/
public static void renameTileSet (
String mapPath, String oldName, String newName)
throws PersistenceException
{
MapFileTileSetIDBroker broker =
new MapFileTileSetIDBroker(new File(mapPath));
if (!broker.renameTileSet(oldName, newName)) {
throw new PersistenceException(
"No such old tileset '" + oldName + "'.");
}
broker.commit();
}
public static void main (String[] args)
{
if (args.length < 3) {
System.err.println("Usage: RenameTileSet tileset.map " +
"old_name new_name");
System.exit(-1);
}
try {
renameTileSet(args[0], args[1], args[2]);
} catch (PersistenceException pe) {
System.err.println("Unable to rename tileset: " + pe);
System.exit(-1);
}
}
}