Allow an orient to be specified to locationForObject
git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@569 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -27,7 +27,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
import com.samskivert.util.SortableArrayList;
|
import com.samskivert.util.SortableArrayList;
|
||||||
import com.samskivert.util.StringUtil;
|
|
||||||
import com.threerings.util.DirectionCodes;
|
import com.threerings.util.DirectionCodes;
|
||||||
import com.threerings.util.DirectionUtil;
|
import com.threerings.util.DirectionUtil;
|
||||||
|
|
||||||
@@ -45,7 +44,6 @@ import com.threerings.miso.util.MisoUtil;
|
|||||||
import com.threerings.miso.util.ObjectSet;
|
import com.threerings.miso.util.ObjectSet;
|
||||||
|
|
||||||
import com.threerings.whirled.spot.data.Cluster;
|
import com.threerings.whirled.spot.data.Cluster;
|
||||||
import com.threerings.whirled.spot.data.Location;
|
|
||||||
import com.threerings.whirled.spot.data.SceneLocation;
|
import com.threerings.whirled.spot.data.SceneLocation;
|
||||||
|
|
||||||
import com.threerings.stage.Log;
|
import com.threerings.stage.Log;
|
||||||
@@ -58,6 +56,13 @@ import com.threerings.stage.data.StageSceneModel;
|
|||||||
*/
|
*/
|
||||||
public class StageSceneUtil
|
public class StageSceneUtil
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Value to pass to {@link #locationForObject(TileManager, ObjectInfo, int)} and
|
||||||
|
* {@link #locationForObject(TileManager, int, int, int, int)}for orientation to indicate it
|
||||||
|
* should use the object's orientation.
|
||||||
|
*/
|
||||||
|
public static final int OBJECT_ORIENTATION = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the scene metrics we use to do our calculations.
|
* Returns the scene metrics we use to do our calculations.
|
||||||
*/
|
*/
|
||||||
@@ -67,40 +72,68 @@ public class StageSceneUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does the necessary jiggery pokery to figure out where the specified
|
* Does the necessary jiggery pokery to figure out where the specified object's associated
|
||||||
* object's associated location is.
|
* location is.
|
||||||
*/
|
*/
|
||||||
public static StageLocation locationForObject (
|
public static StageLocation locationForObject (TileManager tilemgr, ObjectInfo info)
|
||||||
TileManager tilemgr, ObjectInfo info)
|
|
||||||
{
|
{
|
||||||
return locationForObject(tilemgr, info.tileId, info.x, info.y);
|
return locationForObject(tilemgr, info, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does the necessary jiggery pokery to figure out where the specified
|
* Does the necessary jiggery pokery to figure out where the specified object's associated
|
||||||
* object's associated location is.
|
* location is.
|
||||||
*
|
*
|
||||||
* @param tilemgr a tile manager that can be used to look up the tile
|
* @param orient - the orientation to use in the returned location, or
|
||||||
* information.
|
* {@link #OBJECT_ORIENTATION} if the object's orientation should be used
|
||||||
|
*/
|
||||||
|
public static StageLocation locationForObject (TileManager tilemgr, ObjectInfo info,
|
||||||
|
int orient)
|
||||||
|
{
|
||||||
|
return locationForObject(tilemgr, info.tileId, info.x, info.y, orient);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does the necessary jiggery pokery to figure out where the specified object's associated
|
||||||
|
* location is.
|
||||||
|
*
|
||||||
|
* @param tilemgr a tile manager that can be used to look up the tile information.
|
||||||
* @param tileId the fully qualified tile id of the object tile.
|
* @param tileId the fully qualified tile id of the object tile.
|
||||||
* @param tx the object's x tile coordinate.
|
* @param tx the object's x tile coordinate.
|
||||||
* @param ty the object's y tile coordinate.
|
* @param ty the object's y tile coordinate.
|
||||||
*/
|
*/
|
||||||
public static StageLocation locationForObject (
|
public static StageLocation locationForObject (TileManager tilemgr, int tileId, int tx, int ty)
|
||||||
TileManager tilemgr, int tileId, int tx, int ty)
|
{
|
||||||
|
return locationForObject(tilemgr, tileId, tx, ty, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does the necessary jiggery pokery to figure out where the specified object's associated
|
||||||
|
* location is.
|
||||||
|
*
|
||||||
|
* @param tilemgr a tile manager that can be used to look up the tile information.
|
||||||
|
* @param tileId the fully qualified tile id of the object tile.
|
||||||
|
* @param tx the object's x tile coordinate.
|
||||||
|
* @param ty the object's y tile coordinate.
|
||||||
|
* @param orient - the orientation to use in the returned location, or
|
||||||
|
* {@link #OBJECT_ORIENTATION} if the tile's orientation should be used
|
||||||
|
*/
|
||||||
|
public static StageLocation locationForObject (TileManager tilemgr, int tileId, int tx,
|
||||||
|
int ty, int orient)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
int tsid = TileUtil.getTileSetId(tileId);
|
int tsid = TileUtil.getTileSetId(tileId);
|
||||||
int tidx = TileUtil.getTileIndex(tileId);
|
int tidx = TileUtil.getTileIndex(tileId);
|
||||||
TrimmedObjectTileSet tset = (TrimmedObjectTileSet)
|
TrimmedObjectTileSet tset = (TrimmedObjectTileSet)tilemgr.getTileSet(tsid);
|
||||||
tilemgr.getTileSet(tsid);
|
if (tset == null || (orient == OBJECT_ORIENTATION && tset.getSpotOrient(tidx) < 0)) {
|
||||||
if (tset == null || tset.getSpotOrient(tidx) < 0) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (orient == OBJECT_ORIENTATION) {
|
||||||
|
orient = tset.getSpotOrient(tidx);
|
||||||
|
}
|
||||||
|
|
||||||
Point opos = MisoUtil.tilePlusFineToFull(
|
Point opos = MisoUtil.tilePlusFineToFull(_metrics, tx, ty, tset.getXSpot(tidx),
|
||||||
_metrics, tx, ty, tset.getXSpot(tidx), tset.getYSpot(tidx),
|
tset.getYSpot(tidx), new Point());
|
||||||
new Point());
|
|
||||||
|
|
||||||
// Log.info("Computed location [set=" + tset.getName() +
|
// Log.info("Computed location [set=" + tset.getName() +
|
||||||
// ", tidx=" + tidx + ", tx=" + tx + ", ty=" + ty +
|
// ", tidx=" + tidx + ", tx=" + tx + ", ty=" + ty +
|
||||||
@@ -108,8 +141,7 @@ public class StageSceneUtil
|
|||||||
// ", sy=" + tset.getYSpot(tidx) +
|
// ", sy=" + tset.getYSpot(tidx) +
|
||||||
// ", lx=" + opos.x + ", ly=" + opos.y +
|
// ", lx=" + opos.x + ", ly=" + opos.y +
|
||||||
// ", fg=" + _metrics.finegran + "].");
|
// ", fg=" + _metrics.finegran + "].");
|
||||||
return new StageLocation(opos.x, opos.y,
|
return new StageLocation(opos.x, opos.y, (byte)orient);
|
||||||
(byte)tset.getSpotOrient(tidx));
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.warning("Unable to look up object tile for scene object " +
|
Log.warning("Unable to look up object tile for scene object " +
|
||||||
|
|||||||
Reference in New Issue
Block a user