/*
Copyright (C) 2005 David Green <green@couchpotato.net>
All Rights Reserved.

This file is part of Aelfengard.

Aelfengard is proprietary software. You may not redistribute it without
prior written permission from the copyright holder.
*/

package common;

import java.awt.Point;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public enum Direction {

    NORTH("n", "north", new Point(0, -1)),
    NORTHEAST("ne", "northeast", new Point(1, -1)),
    EAST("e", "east", new Point(1, 0)),
    SOUTHEAST("se", "southeast", new Point(1, 1)),
    SOUTH("s", "south", new Point(0, 1)),
    SOUTHWEST("sw", "southwest", new Point(-1, 1)),
    WEST("w", "west", new Point(-1, 0)),
    NORTHWEST("nw", "northwest", new Point(-1, -1));
    
    private static final Map<String,Direction> dirForName = new HashMap<String,Direction>();

    static {
        NORTH.opposingDirection = SOUTH;
        NORTHEAST.opposingDirection = SOUTHWEST;
        EAST.opposingDirection = WEST;
        SOUTHEAST.opposingDirection = NORTHWEST;
        SOUTH.opposingDirection = NORTH;
        SOUTHWEST.opposingDirection = NORTHEAST;
        WEST.opposingDirection = EAST;
        NORTHWEST.opposingDirection = SOUTHEAST;
        
        for (Direction dir : Direction.values()) {
            dirForName.put(dir.abbr, dir);
            dirForName.put(dir.full, dir);
        }
        
    }
    
    private final String abbr;
    private final String full;
    private final Point offsets;
    private Direction opposingDirection;

    private Direction(String abbr, String full, Point offsets) {
        this.abbr = abbr;
        this.full = full;
        this.offsets = offsets;
    }
    
    public Point getOffsets() {
        return offsets;
    }

    public static Direction parseDirection(String dirName) {
        return dirForName.get(dirName);
    }

    public Direction getOpposingDirection() {
        return opposingDirection;
    }

    public static Collection<String> getValidDirectionNames() {
        return Collections.unmodifiableSet(dirForName.keySet());
    }
    
    public String getFullName() {
        return full;
    }
    
    public String getAbbreviation() {
        return abbr;
    }
    
}