Make the placement constraints a bit more flexible to other wall types than "normal" or "low"
Note: This does potentially break some backwards compatibility, but I don't believe anyone's actually using PlacementConstraints other than Puzzle Pirates. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@851 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -191,7 +191,7 @@ public class PlacementConstraints
|
|||||||
protected String allowModifyObjects (ObjectData[] added,
|
protected String allowModifyObjects (ObjectData[] added,
|
||||||
ObjectData[] removed)
|
ObjectData[] removed)
|
||||||
{
|
{
|
||||||
DirectionHeight dirheight = new DirectionHeight();
|
DirectionType dirtype = new DirectionType();
|
||||||
|
|
||||||
for (int i = 0; i < added.length; i++) {
|
for (int i = 0; i < added.length; i++) {
|
||||||
if (added[i].tile.hasConstraint(ObjectTileSet.ON_SURFACE) &&
|
if (added[i].tile.hasConstraint(ObjectTileSet.ON_SURFACE) &&
|
||||||
@@ -200,20 +200,20 @@ public class PlacementConstraints
|
|||||||
"m.not_on_surface");
|
"m.not_on_surface");
|
||||||
}
|
}
|
||||||
|
|
||||||
int dir = getConstraintDirection(added[i], ObjectTileSet.ON_WALL);
|
if (getConstraintDirectionType(added[i], ObjectTileSet.ON_WALL,
|
||||||
if (dir != NONE && !isOnWall(added[i], added, removed, dir)) {
|
dirtype) && !isOnWall(added[i], added, removed, dirtype.dir, dirtype.type)) {
|
||||||
return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE,
|
return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE,
|
||||||
"m.not_on_wall");
|
"m.not_on_wall");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getConstraintDirectionHeight(added[i], ObjectTileSet.ATTACH,
|
if (getConstraintDirectionType(added[i], ObjectTileSet.ATTACH,
|
||||||
dirheight) && !isAttached(added[i], added, removed,
|
dirtype) && !isAttached(added[i], added, removed,
|
||||||
dirheight.dir, dirheight.low)) {
|
dirtype.dir, dirtype.type)) {
|
||||||
return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE,
|
return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE,
|
||||||
"m.not_attached");
|
"m.not_attached");
|
||||||
}
|
}
|
||||||
|
|
||||||
dir = getConstraintDirection(added[i], ObjectTileSet.SPACE);
|
int dir = getConstraintDirection(added[i], ObjectTileSet.SPACE);
|
||||||
if (dir != NONE && !hasSpace(added[i], added, removed, dir)) {
|
if (dir != NONE && !hasSpace(added[i], added, removed, dir)) {
|
||||||
return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE,
|
return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE,
|
||||||
"m.no_space");
|
"m.no_space");
|
||||||
@@ -273,11 +273,14 @@ public class PlacementConstraints
|
|||||||
protected boolean hasOnWall (ObjectData data, ObjectData[] added,
|
protected boolean hasOnWall (ObjectData data, ObjectData[] added,
|
||||||
ObjectData[] removed, int dir)
|
ObjectData[] removed, int dir)
|
||||||
{
|
{
|
||||||
|
DirectionType dirtype = new DirectionType();
|
||||||
|
|
||||||
List<ObjectData> objects = getObjectData(data.bounds, added, removed);
|
List<ObjectData> objects = getObjectData(data.bounds, added, removed);
|
||||||
for (int i = 0, size = objects.size(); i < size; i++) {
|
for (int i = 0, size = objects.size(); i < size; i++) {
|
||||||
ObjectData odata = objects.get(i);
|
ObjectData odata = objects.get(i);
|
||||||
if (getConstraintDirection(odata, ObjectTileSet.ON_WALL) == dir &&
|
if (getConstraintDirectionType(odata, ObjectTileSet.ON_WALL,
|
||||||
!isOnWall(odata, added, removed, dir)) {
|
dirtype) && !isAttached(odata, added, removed,
|
||||||
|
dirtype.dir, dirtype.type)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -291,15 +294,15 @@ public class PlacementConstraints
|
|||||||
protected boolean hasAttached (ObjectData data, ObjectData[] added,
|
protected boolean hasAttached (ObjectData data, ObjectData[] added,
|
||||||
ObjectData[] removed, int dir)
|
ObjectData[] removed, int dir)
|
||||||
{
|
{
|
||||||
DirectionHeight dirheight = new DirectionHeight();
|
DirectionType dirtype = new DirectionType();
|
||||||
|
|
||||||
List<ObjectData> objects = getObjectData(getAdjacentEdge(data.bounds,
|
List<ObjectData> objects = getObjectData(getAdjacentEdge(data.bounds,
|
||||||
DirectionUtil.getOpposite(dir)), added, removed);
|
DirectionUtil.getOpposite(dir)), added, removed);
|
||||||
for (int i = 0, size = objects.size(); i < size; i++) {
|
for (int i = 0, size = objects.size(); i < size; i++) {
|
||||||
ObjectData odata = objects.get(i);
|
ObjectData odata = objects.get(i);
|
||||||
if (getConstraintDirectionHeight(odata, ObjectTileSet.ATTACH,
|
if (getConstraintDirectionType(odata, ObjectTileSet.ATTACH,
|
||||||
dirheight) && !isAttached(odata, added, removed,
|
dirtype) && !isAttached(odata, added, removed,
|
||||||
dirheight.dir, dirheight.low)) {
|
dirtype.dir, dirtype.type)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -354,10 +357,11 @@ public class PlacementConstraints
|
|||||||
* specified direction.
|
* specified direction.
|
||||||
*/
|
*/
|
||||||
protected boolean isOnWall (ObjectData data, ObjectData[] added,
|
protected boolean isOnWall (ObjectData data, ObjectData[] added,
|
||||||
ObjectData[] removed, int dir)
|
ObjectData[] removed, int dir, int type)
|
||||||
{
|
{
|
||||||
return isCovered(data.bounds, added, removed,
|
return isCovered(data.bounds, added, removed,
|
||||||
getDirectionalConstraint(ObjectTileSet.WALL, dir), null);
|
getDirectionalConstraint(ObjectTileSet.WALL, dir), (type == DirectionType.LOW) ?
|
||||||
|
getDirectionalConstraint(ObjectTileSet.WALL, dir, DirectionType.LOW) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -365,11 +369,11 @@ public class PlacementConstraints
|
|||||||
* the specified direction and at the specified height.
|
* the specified direction and at the specified height.
|
||||||
*/
|
*/
|
||||||
protected boolean isAttached (ObjectData data, ObjectData[] added,
|
protected boolean isAttached (ObjectData data, ObjectData[] added,
|
||||||
ObjectData[] removed, int dir, boolean low)
|
ObjectData[] removed, int dir, int type)
|
||||||
{
|
{
|
||||||
return isCovered(getAdjacentEdge(data.bounds, dir), added, removed,
|
return isCovered(getAdjacentEdge(data.bounds, dir), added, removed,
|
||||||
getDirectionalConstraint(ObjectTileSet.WALL, dir), low ?
|
getDirectionalConstraint(ObjectTileSet.WALL, dir), (type == DirectionType.LOW) ?
|
||||||
getDirectionalConstraint(ObjectTileSet.WALL, dir, true) : null);
|
getDirectionalConstraint(ObjectTileSet.WALL, dir, DirectionType.LOW) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -437,9 +441,9 @@ public class PlacementConstraints
|
|||||||
*/
|
*/
|
||||||
protected int getConstraintDirection (ObjectData data, String prefix)
|
protected int getConstraintDirection (ObjectData data, String prefix)
|
||||||
{
|
{
|
||||||
DirectionHeight dirheight = new DirectionHeight();
|
DirectionType dirtype = new DirectionType();
|
||||||
return getConstraintDirectionHeight(data, prefix, dirheight) ?
|
return getConstraintDirectionType(data, prefix, dirtype) ?
|
||||||
dirheight.dir : NONE;
|
dirtype.dir : NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -449,8 +453,8 @@ public class PlacementConstraints
|
|||||||
* @return true if the object was successfully populated, false if there is
|
* @return true if the object was successfully populated, false if there is
|
||||||
* no such constraint
|
* no such constraint
|
||||||
*/
|
*/
|
||||||
protected boolean getConstraintDirectionHeight (ObjectData data,
|
protected boolean getConstraintDirectionType (ObjectData data,
|
||||||
String prefix, DirectionHeight dirheight)
|
String prefix, DirectionType dirtype)
|
||||||
{
|
{
|
||||||
String[] constraints = data.tile.getConstraints();
|
String[] constraints = data.tile.getConstraints();
|
||||||
if (constraints == null) {
|
if (constraints == null) {
|
||||||
@@ -461,34 +465,38 @@ public class PlacementConstraints
|
|||||||
if (constraint.startsWith(prefix)) {
|
if (constraint.startsWith(prefix)) {
|
||||||
int fromidx = prefix.length(),
|
int fromidx = prefix.length(),
|
||||||
toidx = constraint.indexOf('_', fromidx);
|
toidx = constraint.indexOf('_', fromidx);
|
||||||
dirheight.dir = DirectionUtil.fromShortString(toidx == -1 ?
|
dirtype.dir = DirectionUtil.fromShortString(toidx == -1 ?
|
||||||
constraint.substring(fromidx) :
|
constraint.substring(fromidx) :
|
||||||
constraint.substring(fromidx, toidx));
|
constraint.substring(fromidx, toidx));
|
||||||
dirheight.low = constraint.endsWith(ObjectTileSet.LOW);
|
dirtype.type = getConstraintWallType(constraint);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected int getConstraintWallType (String constraint)
|
||||||
|
{
|
||||||
|
return constraint.endsWith(ObjectTileSet.LOW) ? DirectionType.LOW : DirectionType.NORM;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a constraint prefix and a direction, returns the directional
|
* Given a constraint prefix and a direction, returns the directional
|
||||||
* constraint.
|
* constraint.
|
||||||
*/
|
*/
|
||||||
protected String getDirectionalConstraint (String prefix, int dir)
|
protected String getDirectionalConstraint (String prefix, int dir)
|
||||||
{
|
{
|
||||||
return getDirectionalConstraint(prefix, dir, false);
|
return getDirectionalConstraint(prefix, dir, DirectionType.NORM);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a constraint prefix, direction, and height, returns the
|
* Given a constraint prefix, direction, and height, returns the
|
||||||
* directional constraint.
|
* directional constraint.
|
||||||
*/
|
*/
|
||||||
protected String getDirectionalConstraint (String prefix, int dir,
|
protected String getDirectionalConstraint (String prefix, int dir, int type)
|
||||||
boolean low)
|
|
||||||
{
|
{
|
||||||
return prefix + DirectionUtil.toShortString(dir) +
|
return prefix + DirectionUtil.toShortString(dir) +
|
||||||
(low ? ObjectTileSet.LOW : "");
|
(type == DirectionType.LOW ? ObjectTileSet.LOW : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -552,10 +560,13 @@ public class PlacementConstraints
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Contains the direction and height of a constraint. */
|
/** Contains the direction and height of a constraint. */
|
||||||
protected class DirectionHeight
|
protected static class DirectionType
|
||||||
{
|
{
|
||||||
public int dir;
|
public int dir;
|
||||||
public boolean low;
|
public int type;
|
||||||
|
|
||||||
|
public static int NORM = 0;
|
||||||
|
public static int LOW = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The tile manager to use for object dimensions and constraints. */
|
/** The tile manager to use for object dimensions and constraints. */
|
||||||
|
|||||||
Reference in New Issue
Block a user