Skip to content

Commit

Permalink
Added a color map for the tracks.
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianCassayre committed Apr 8, 2016
1 parent 61fb1a8 commit d195462
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/me/cassayre/florian/netherrail/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ else if(args[0].equals("list"))
System.out.print(object);
return;
}
else if(args[0].equals("colors"))
{
System.out.println(NetworkAreas.toJson());
return;
}
else
{
throw new IllegalArgumentException(args[0]);
Expand Down
123 changes: 123 additions & 0 deletions src/main/java/me/cassayre/florian/netherrail/NetworkAreas.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package me.cassayre.florian.netherrail;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;

import java.awt.Color;
import java.util.*;

public class NetworkAreas
{
private final static List<Area> areas = new ArrayList<>();

static
{
registerX(-714, new Color(255, 236, 39));
registerX(-529, new Color(255, 189, 206));
registerX(-341, new Color(94, 116, 255));
registerX(-234, new Color(110, 244, 5));
registerX(30, new Color(165, 178, 255));
registerX(540, new Color(64, 168, 186));

registerY(539, new Color(110, 176, 86));
registerY(47, new Color(221, 72, 70));
registerY(-301, new Color(0, 0, 0));
registerY(-702, new Color(255, 170, 20));
registerY(-1069, new Color(119, 98, 40));
registerY(-1436, new Color(255, 122, 238));
}

public static void registerX(int coordinate, Color color)
{
register(Area.Orientation.VERTICAL, coordinate, color);
}

public static void registerY(int coordinate, Color color)
{
register(Area.Orientation.HORIZONTAL, coordinate, color);
}

private static void register(Area.Orientation orientation, int coordinate, Color color)
{
if(orientation == null)
throw new IllegalArgumentException("Orientation cannot be null.");

if(color == null)
throw new IllegalArgumentException("Color cannot be null.");

areas.add(new Area(orientation, coordinate, color));
}

public static List<Area> getAreas(Area.Orientation orientation)
{
List<Area> list = new ArrayList<>();

for(Area area : areas)
{
if(area.ORIENTATION == orientation)
list.add(area);
}

return list;
}

public static JsonObject toJson()
{
JsonObject object = new JsonObject();

JsonArray arrayX = new JsonArray();
JsonArray arrayY = new JsonArray();

for(Area area : areas)
{
JsonObject areaObject = new JsonObject();

areaObject.add("coordinate", new JsonPrimitive(area.COORDINATE));

areaObject.add("color", colorToJson(area.COLOR));

if(area.ORIENTATION == Area.Orientation.VERTICAL)
arrayX.add(areaObject);
else if(area.ORIENTATION == Area.Orientation.HORIZONTAL)
arrayY.add(areaObject);
}

object.add("northsouth", arrayX);

object.add("eastwest", arrayY);

return object;
}

public static JsonObject colorToJson(Color color)
{
JsonObject object = new JsonObject();

object.add("red", new JsonPrimitive(color.getRed()));
object.add("green", new JsonPrimitive(color.getGreen()));
object.add("blue", new JsonPrimitive(color.getBlue()));

return object;
}
}

class Area
{
public final Orientation ORIENTATION;
public final int COORDINATE;
public final Color COLOR;

public Area(Orientation orientation, int coordinate, Color color)
{
ORIENTATION = orientation;
COORDINATE = coordinate;
COLOR = color;
}

static enum Orientation
{
VERTICAL,
HORIZONTAL;
}
}

0 comments on commit d195462

Please sign in to comment.