Factions3/src/com/massivecraft/factions/util/AsciiCompass.java

65 lines
1.9 KiB
Java
Raw Normal View History

2011-07-18 22:06:02 +02:00
package com.massivecraft.factions.util;
2011-02-06 13:36:11 +01:00
import com.massivecraft.massivecore.collections.MassiveList;
2017-03-24 13:05:58 +01:00
import java.util.List;
import static com.massivecraft.factions.util.AsciiCompassDirection.E;
import static com.massivecraft.factions.util.AsciiCompassDirection.N;
import static com.massivecraft.factions.util.AsciiCompassDirection.NE;
import static com.massivecraft.factions.util.AsciiCompassDirection.NONE;
import static com.massivecraft.factions.util.AsciiCompassDirection.NW;
import static com.massivecraft.factions.util.AsciiCompassDirection.S;
import static com.massivecraft.factions.util.AsciiCompassDirection.SE;
import static com.massivecraft.factions.util.AsciiCompassDirection.SW;
import static com.massivecraft.factions.util.AsciiCompassDirection.W;
2011-02-06 13:36:11 +01:00
2011-10-10 01:21:05 +02:00
public class AsciiCompass
{
// -------------------------------------------- //
// COMPASS
// -------------------------------------------- //
public static List<String> getAsciiCompass(double degrees)
2011-10-10 01:21:05 +02:00
{
return getAsciiCompass(AsciiCompassDirection.getByDegrees(degrees));
2011-02-06 13:36:11 +01:00
}
private static List<String> getAsciiCompass(AsciiCompassDirection directionFacing)
2011-10-10 01:21:05 +02:00
{
// Create
List<String> ret = new MassiveList<>();
// Fill
ret.add(visualizeRow(directionFacing, NW, N, NE));
ret.add(visualizeRow(directionFacing, W, NONE, E));
ret.add(visualizeRow(directionFacing, SW, S, SE));
2011-02-06 13:36:11 +01:00
// Return
return ret;
}
2011-02-06 13:36:11 +01:00
// -------------------------------------------- //
// VISUALIZE ROW
// -------------------------------------------- //
private static String visualizeRow(AsciiCompassDirection directionFacing, AsciiCompassDirection... cardinals)
2011-10-10 01:21:05 +02:00
{
// Catch
if (cardinals == null) throw new NullPointerException("cardinals");
2011-02-06 13:36:11 +01:00
// Create
StringBuilder ret = new StringBuilder(cardinals.length);
2011-02-06 13:36:11 +01:00
// Fill
for (AsciiCompassDirection asciiCardinal : cardinals)
{
ret.append(asciiCardinal.visualize(directionFacing));
}
2011-02-06 13:36:11 +01:00
// Return
return ret.toString();
2011-02-06 13:36:11 +01:00
}
}