diff --git a/src/java/com/threerings/util/DirectionCodes.java b/src/java/com/threerings/util/DirectionCodes.java new file mode 100644 index 000000000..8b1625621 --- /dev/null +++ b/src/java/com/threerings/util/DirectionCodes.java @@ -0,0 +1,41 @@ +// +// $Id: DirectionCodes.java,v 1.1 2001/12/17 03:32:32 mdb Exp $ + +package com.threerings.util; + +/** + * A single, top-level location for the definition of compass direction + * constants, which are used by a variety of Narya services. + */ +public interface DirectionCodes +{ + /** A direction code indicating no direction. */ + public static final int NONE = -1; + + /** A direction code indicating southwest. */ + public static final int SOUTHWEST = 0; + + /** A direction code indicating west. */ + public static final int WEST = 1; + + /** A direction code indicating northwest. */ + public static final int NORTHWEST = 2; + + /** A direction code indicating north. */ + public static final int NORTH = 3; + + /** A direction code indicating northeast. */ + public static final int NORTHEAST = 4; + + /** A direction code indicating east. */ + public static final int EAST = 5; + + /** A direction code indicating southeast. */ + public static final int SOUTHEAST = 6; + + /** A direction code indicating south. */ + public static final int SOUTH = 7; + + /** The total number of directions. */ + public static final int DIRECTION_COUNT = 8; +} diff --git a/src/java/com/threerings/util/DirectionUtil.java b/src/java/com/threerings/util/DirectionUtil.java new file mode 100644 index 000000000..0ac9e5b0e --- /dev/null +++ b/src/java/com/threerings/util/DirectionUtil.java @@ -0,0 +1,56 @@ +// +// $Id: DirectionUtil.java,v 1.1 2001/12/17 03:32:32 mdb Exp $ + +package com.threerings.util; + +/** + * Direction related utility functions. + */ +public class DirectionUtil implements DirectionCodes +{ + /** + * Returns a string representation of the supplied direction code. + */ + public static String toString (int direction) + { + return ((direction >= SOUTHWEST) && (direction <= SOUTH)) ? + DIR_STRINGS[direction] : "INVALID"; + } + + /** + * Returns an abbreviated string representation of the supplied + * direction code. + */ + public static String toShortString (int direction) + { + return ((direction >= SOUTHWEST) && (direction <= SOUTH)) ? + SHORT_DIR_STRINGS[direction] : "?"; + } + + /** + * Returns a string representation of an array of direction codes. The + * directions are represented by the abbreviated names. + */ + public static String toString (int[] directions) + { + StringBuffer buf = new StringBuffer(); + for (int i = 0; i < directions.length; i++) { + if (i > 0) { + buf.append(", "); + } + buf.append(toShortString(directions[i])); + } + return buf.toString(); + } + + /** Direction constant string names. */ + protected static final String[] DIR_STRINGS = { + "SOUTHWEST", "WEST", "NORTHWEST", "NORTH", + "NORTHEAST", "EAST", "SOUTHEAST", "SOUTH" + }; + + /** Abbreviated direction constant string names. */ + protected static final String[] SHORT_DIR_STRINGS = { + "SW", "W", "NW", "N", "NE", "E", "SE", "S" + }; +}