Various improvements to the AS tile code to prepare for component tiles.

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@969 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Mike Thomas
2010-08-10 20:27:42 +00:00
parent ba76a845e0
commit 4b09709590
5 changed files with 92 additions and 15 deletions
@@ -19,6 +19,7 @@
package com.threerings.media.tile {
import com.threerings.util.ArrayUtil;
import com.threerings.util.StringUtil;
public class BaseTileSet extends SwissArmyTileSet
@@ -40,18 +41,18 @@ public class BaseTileSet extends SwissArmyTileSet
return _passable;
}
protected override function createTile () :Tile
override protected function createTile () :Tile
{
return new BaseTile();
}
protected override function initTile (tile :Tile, tileIndex :int, zations :Array) :void
override protected function initTile (tile :Tile, tileIndex :int, zations :Array) :void
{
super.initTile(tile, tileIndex, zations);
(BaseTile(tile)).setPassable(_passable[tileIndex]);
}
protected override function toStringBuf (buf :String) :String
override protected function toStringBuf (buf :String) :String
{
buf = super.toStringBuf(buf);
buf = buf.concat(", passable=", StringUtil.toString(_passable));
@@ -65,12 +66,24 @@ public class BaseTileSet extends SwissArmyTileSet
return set;
}
protected override function populateFromXml (xml :XML) :void
override protected function populateFromXml (xml :XML) :void
{
super.populateFromXml(xml);
_passable = toBoolArray(xml.passable);
}
override public function populateClone (clone :TileSet) :void
{
super.populateClone(clone);
var bClone :BaseTileSet = BaseTileSet(clone);
bClone._passable = _passable == null ? null : ArrayUtil.copyOf(_passable);
}
override public function createClone () :TileSet
{
return new BaseTileSet();
}
/** Whether each tile is passable. */
protected var _passable :Array;
}
@@ -25,9 +25,6 @@ import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.events.IOErrorEvent;
import flash.utils.ByteArray;
import com.threerings.io.ObjectInputStream;
@@ -189,7 +189,7 @@ public class ObjectTileSet extends SwissArmyTileSet
return _ozations;
}
protected override function toStringBuf (buf :String) :String
override protected function toStringBuf (buf :String) :String
{
buf = super.toStringBuf(buf);
buf = buf.concat(", owidths=", StringUtil.toString(_owidths));
@@ -205,7 +205,7 @@ public class ObjectTileSet extends SwissArmyTileSet
return buf;
}
protected override function getTileColorizations (tileIndex :int, rizer :Colorizer) :Array
override protected function getTileColorizations (tileIndex :int, rizer :Colorizer) :Array
{
var zations :Array = null;
if (rizer != null && _ozations != null) {
@@ -217,12 +217,12 @@ public class ObjectTileSet extends SwissArmyTileSet
return zations;
}
protected override function createTile () :Tile
override protected function createTile () :Tile
{
return new ObjectTile();
}
protected override function initTile (tile :Tile, tileIndex :int, zations :Array) :void
override protected function initTile (tile :Tile, tileIndex :int, zations :Array) :void
{
super.initTile(tile, tileIndex, zations);
@@ -251,7 +251,7 @@ public class ObjectTileSet extends SwissArmyTileSet
return set;
}
protected override function populateFromXml (xml :XML) :void
override protected function populateFromXml (xml :XML) :void
{
super.populateFromXml(xml);
_owidths = toIntArray(xml.objectWidths);
@@ -272,6 +272,27 @@ public class ObjectTileSet extends SwissArmyTileSet
}
}
override public function populateClone (clone :TileSet) :void
{
super.populateClone(clone);
var oClone :ObjectTileSet = ObjectTileSet(clone);
oClone._owidths = _owidths == null ? null : ArrayUtil.copyOf(_owidths);
oClone._oheights = _oheights == null ? null : ArrayUtil.copyOf(_oheights);
oClone._xorigins = _xorigins == null ? null : ArrayUtil.copyOf(_xorigins);
oClone._yorigins = _yorigins == null ? null : ArrayUtil.copyOf(_yorigins);
oClone._priorities = _priorities == null ? null : ArrayUtil.copyOf(_priorities);
oClone._ozations = _ozations == null ? null : ArrayUtil.copyOf(_ozations);
oClone._xspots = _xspots == null ? null : ArrayUtil.copyOf(_xspots);
oClone._yspots = _yspots == null ? null : ArrayUtil.copyOf(_yspots);
oClone._sorients = _sorients == null ? null : ArrayUtil.copyOf(_sorients);
oClone._constraints = _constraints == null ? null : ArrayUtil.copyOf(_constraints);
}
override public function createClone () :TileSet
{
return new ObjectTileSet();
}
/** The width (in tile units) of our object tiles. */
protected var _owidths :Array;
@@ -24,6 +24,7 @@ package com.threerings.media.tile {
import flash.geom.Point;
import flash.geom.Rectangle;
import com.threerings.util.ArrayUtil;
import com.threerings.util.StringUtil;
/**
@@ -209,7 +210,7 @@ public class SwissArmyTileSet extends TileSet
}
return str.split(",").map(function(element :*, index :int, arr :Array) :Boolean {
return Boolean(element);
return Boolean(StringUtil.trim(element));
});
}
@@ -220,10 +221,27 @@ public class SwissArmyTileSet extends TileSet
}
return str.split(",").map(function(element :*, index :int, arr :Array) :int {
return int(element);
return int(StringUtil.trim(element));
});
}
override public function populateClone (clone :TileSet) :void
{
super.populateClone(clone);
var saClone :SwissArmyTileSet = SwissArmyTileSet(clone);
saClone._tileCounts = _tileCounts == null ? null : ArrayUtil.copyOf(_tileCounts);
saClone._numTiles = _numTiles;
saClone._widths = _widths == null ? null : ArrayUtil.copyOf(_widths);
saClone._heights = _heights == null ? null : ArrayUtil.copyOf(_heights);
saClone._offsetPos = _offsetPos;
saClone._gapSize = _gapSize;
}
override public function createClone () :TileSet
{
return new SwissArmyTileSet();
}
/** The number of tiles in each row. */
protected var _tileCounts :Array;
+29 -1
View File
@@ -28,6 +28,7 @@ import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
import com.threerings.io.Streamable;
import com.threerings.media.image.Colorization;
import com.threerings.util.Cloneable;
import com.threerings.util.Hashable;
import com.threerings.util.Log;
import com.threerings.util.StringUtil;
@@ -36,7 +37,7 @@ import com.threerings.util.maps.HashMap;
import com.threerings.util.maps.WeakValueMap;
public /* abstract */ class TileSet
implements Streamable, Hashable
implements Streamable, Hashable, Cloneable
{
private static var log :Log = Log.getLog(TileSet);
@@ -339,6 +340,33 @@ public /* abstract */ class TileSet
_imagePath = xml.imagePath;
}
public function clone () :Object
{
var newSet :TileSet = createClone();
populateClone(newSet);
return newSet;
}
public function populateClone (clone :TileSet) :void
{
clone._isLoaded = _isLoaded;
clone._imagePath = _imagePath;
clone._name = _name;
clone._improv = _improv;
}
public function createClone () :TileSet
{
return new TileSet();
}
public function cloneWithZations (zations :Array) :TileSet
{
var newSet :TileSet = TileSet(clone());
newSet._zations = zations;
return newSet;
}
/** Whether all the media for this tileset is loaded and ready. */
protected var _isLoaded :Boolean;