LinkedSpace.java

src/net/sourceforge/pain/data/type/LinkedSpace.java · 2.5 KB

From the archive pain_0_41.zip

Download the archive   « Back to the archive contents

package net.sourceforge.pain.data.type;


import net.sourceforge.pain.data.*;
import net.sourceforge.pain.db.*;


/*
 If Space is LinkedSpace it has exits (6 in current world)
 All links are references to Exit objects
 */

public final class LinkedSpace extends Role {

	private static final int NORTH = 1 + LAST_BASE_FIELD_INDEX;
	private static final int EAST = 2 + LAST_BASE_FIELD_INDEX;
	private static final int SOUTH = 3 + LAST_BASE_FIELD_INDEX;
	private static final int WEST = 4 + LAST_BASE_FIELD_INDEX;
	private static final int UP = 5 + LAST_BASE_FIELD_INDEX;
	private static final int DOWN = 6 + LAST_BASE_FIELD_INDEX;
	private static final int NFIELDS = 7 + LAST_BASE_FIELD_INDEX;

	private static final int[] dbDirects = new int[]{NORTH, EAST, SOUTH, WEST, UP, DOWN};

	public final static Class[] superroles = new Class[]{Space.class};

	public LinkedSpace() {
	}

	public LinkedSpace(PainDB db) {
		super(db);
	}

	public Class[] getSuperroles() {
		return superroles;
	}

	public DbClassSchema provideSchema() {
		byte types[] = new byte[NFIELDS];
		String names[] = new String[NFIELDS];
		fillSuperSchema(types, names);
		types[NORTH] = DbType.REFERENCE;
		names[NORTH] = "north";
		types[EAST] = DbType.REFERENCE;
		names[EAST] = "east";
		types[SOUTH] = DbType.REFERENCE;
		names[SOUTH] = "south";
		types[WEST] = DbType.REFERENCE;
		names[WEST] = "west";
		types[UP] = DbType.REFERENCE;
		names[UP] = "up";
		types[DOWN] = DbType.REFERENCE;
		names[DOWN] = "down";
		return new DbClassSchema(types, names);
	}

	public Exit getExit(int direction) {
		if (direction < 0 || direction > 6) {
			throw new IllegalArgumentException("wrong direction:" + direction);
		}
		return (Exit) getReference(dbDirects[direction]);
	}

	public void setExit(int direction, Exit exit) {
		if (direction < 0 || direction > 6) {
			throw new IllegalArgumentException("wrong direction:" + direction);
		}
		setReference(dbDirects[direction], exit);
	}

	public static final int DIR_NORTH = 0;
	public static final int DIR_EAST = 1;
	public static final int DIR_SOUTH = 2;
	public static final int DIR_WEST = 3;
	public static final int DIR_UP = 4;
	public static final int DIR_DOWN = 5;

	public final static int FIRST_DIR = DIR_NORTH;
	public final static int LAST_DIR = DIR_DOWN;

	public static final int[] reverseDir = new int[]{DIR_SOUTH, DIR_WEST, DIR_NORTH, DIR_EAST, DIR_DOWN, DIR_UP};

	public Space asSpace() {
		return (Space) getRole(Space.class);
	}

}

Site Stats

Snippets: 1791
Codebases: 571