|
|
@ -118,6 +118,7 @@ public class Plan { |
|
|
|
public static final String REALM_ROUTE = "route"; |
|
|
|
public static final String REALM_ROUTE = "route"; |
|
|
|
public static final String REALM_TILE = "tile"; |
|
|
|
public static final String REALM_TILE = "tile"; |
|
|
|
public static final String REALM_CAR = "car"; |
|
|
|
public static final String REALM_CAR = "car"; |
|
|
|
|
|
|
|
private static final String ACTION_CONNECT = "connect"; |
|
|
|
|
|
|
|
|
|
|
|
public HashMap<String,Tile> tiles = new HashMap<String,Tile>(); |
|
|
|
public HashMap<String,Tile> tiles = new HashMap<String,Tile>(); |
|
|
|
private HashSet<Block> blocks = new HashSet<Block>(); |
|
|
|
private HashSet<Block> blocks = new HashSet<Block>(); |
|
|
@ -193,6 +194,15 @@ public class Plan { |
|
|
|
return tile.click(); |
|
|
|
return tile.click(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Object connect(HashMap<String, String> params) throws IOException { |
|
|
|
|
|
|
|
if (params.containsKey(REALM)) switch (params.get(REALM)) { |
|
|
|
|
|
|
|
case REALM_CU: |
|
|
|
|
|
|
|
controlUnit.restart(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return html(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Object cuProps(HashMap<String, String> params) { |
|
|
|
private Object cuProps(HashMap<String, String> params) { |
|
|
|
return controlUnit.properties(); |
|
|
|
return controlUnit.properties(); |
|
|
|
} |
|
|
|
} |
|
|
@ -271,22 +281,28 @@ public class Plan { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static Plan load(String filename) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { |
|
|
|
public static Plan load(String filename) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { |
|
|
|
|
|
|
|
Plan plan = new Plan(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
Car.loadAll(filename+".cars"); |
|
|
|
Car.loadAll(filename+".cars",plan); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
LOG.debug("Was not able to load cars!",e); |
|
|
|
LOG.warn("Was not able to load cars!",e); |
|
|
|
} |
|
|
|
} |
|
|
|
try { |
|
|
|
try { |
|
|
|
Train.loadAll(filename+".trains"); |
|
|
|
Train.loadAll(filename+".trains"); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
LOG.debug("Was not able to load trains!",e); |
|
|
|
LOG.warn("Was not able to load trains!",e); |
|
|
|
} |
|
|
|
} |
|
|
|
Plan plan = new Plan(); |
|
|
|
|
|
|
|
Tile.loadAll(filename+".plan",plan); |
|
|
|
Tile.loadAll(filename+".plan",plan); |
|
|
|
try { |
|
|
|
try { |
|
|
|
Route.loadAll(filename+".routes",plan); |
|
|
|
Route.loadAll(filename+".routes",plan); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
LOG.debug("Was not able to load routes!",e); |
|
|
|
LOG.warn("Was not able to load routes!",e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
plan.controlUnit.load(filename+".cu"); |
|
|
|
|
|
|
|
plan.controlUnit.start(); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
LOG.warn("Was not able to load control unit settings!",e); |
|
|
|
} |
|
|
|
} |
|
|
|
return plan; |
|
|
|
return plan; |
|
|
|
} |
|
|
|
} |
|
|
@ -401,6 +417,8 @@ public class Plan { |
|
|
|
return carAction(params); |
|
|
|
return carAction(params); |
|
|
|
case ACTION_CLICK: |
|
|
|
case ACTION_CLICK: |
|
|
|
return click(get(params.get(Tile.ID),true)); |
|
|
|
return click(get(params.get(Tile.ID),true)); |
|
|
|
|
|
|
|
case ACTION_CONNECT: |
|
|
|
|
|
|
|
return connect(params); |
|
|
|
case ACTION_CU_PROPS: |
|
|
|
case ACTION_CU_PROPS: |
|
|
|
return cuProps(params); |
|
|
|
return cuProps(params); |
|
|
|
case ACTION_ANALYZE: |
|
|
|
case ACTION_ANALYZE: |
|
|
@ -479,6 +497,7 @@ public class Plan { |
|
|
|
Tile.saveAll(tiles,name+".plan"); |
|
|
|
Tile.saveAll(tiles,name+".plan"); |
|
|
|
Train.saveAll(name+".trains"); // refers to cars, blocks
|
|
|
|
Train.saveAll(name+".trains"); // refers to cars, blocks
|
|
|
|
Route.saveAll(routes.values(),name+".routes"); // refers to tiles
|
|
|
|
Route.saveAll(routes.values(),name+".routes"); // refers to tiles
|
|
|
|
|
|
|
|
controlUnit.save(name+".cu"); |
|
|
|
return t("Plan saved as \"{}\".",name); |
|
|
|
return t("Plan saved as \"{}\".",name); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -606,4 +625,8 @@ public class Plan { |
|
|
|
public void warn(Contact contact) { |
|
|
|
public void warn(Contact contact) { |
|
|
|
stream(t("Warning: {}",t("Ghost train @ {}",contact))); |
|
|
|
stream(t("Warning: {}",t("Ghost train @ {}",contact))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void queue(String command) { |
|
|
|
|
|
|
|
controlUnit.queue(command); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|