refactoring tile delete method

This commit is contained in:
Stephan Richter
2020-12-03 13:33:45 +01:00
parent 50a5508a33
commit 5aa66099fe
30 changed files with 81 additions and 161 deletions

View File

@@ -45,7 +45,6 @@ public class Car extends BaseClass implements Comparable<Car>{
public int length;
protected String stockId = "";
private Train train;
protected Plan plan;
protected int maxSpeed = 0;
public Car(String name) {
@@ -66,8 +65,8 @@ public class Car extends BaseClass implements Comparable<Car>{
switch (params.get(ACTION)) {
case ACTION_ADD:
if (isSet(car)) {
car.clone().plan(plan);
} else new Car(params.get(Car.NAME)).plan(plan);
car.clone();
} else new Car(params.get(Car.NAME)).parent(plan);
return Car.manager();
case ACTION_PROPS:
return car == null ? Car.manager() : car.properties();
@@ -85,6 +84,7 @@ public class Car extends BaseClass implements Comparable<Car>{
clone.length = length;
clone.tags = new HashSet<String>(tags);
clone.notes = notes;
clone.parent(parent());
return clone;
}
@@ -136,7 +136,7 @@ public class Car extends BaseClass implements Comparable<Car>{
String name = json.getString(Car.NAME);
Id id = Id.from(json);
Car car = json.has(Locomotive.LOCOMOTIVE) ? new Locomotive(name, id) : new Car(name,id);
car.load(json).plan(plan);
car.load(json).parent(plan);
line = file.readLine();
}
@@ -189,15 +189,6 @@ public class Car extends BaseClass implements Comparable<Car>{
return name;
}
public Plan plan() {
return plan;
}
public Car plan(Plan plan) {
this.plan = plan;
return this;
}
@Override
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
formInputs.add(t("Name"),new Input(NAME,name));

View File

@@ -49,7 +49,7 @@ public class Locomotive extends Car implements Constants,Device{
Locomotive loco = id == null ? null : Locomotive.get(id);
switch (params.get(ACTION)) {
case ACTION_ADD:
new Locomotive(params.get(Locomotive.NAME)).plan(plan);
new Locomotive(params.get(Locomotive.NAME)).parent(plan);
return Locomotive.manager();
case ACTION_FASTER10:
return loco.faster(10);

View File

@@ -78,6 +78,11 @@ public class Train extends BaseClass implements Comparable<Train> {
private Block currentBlock,destination = null;
LinkedList<Tile> trace = new LinkedList<Tile>();
public int speed = 0;
private Autopilot autopilot = null;
private Route nextRoute;
private class Autopilot extends Thread{
boolean stop = false;
int waitTime = 100;
@@ -102,13 +107,6 @@ public class Train extends BaseClass implements Comparable<Train> {
}
}
}
public int speed = 0;
private Autopilot autopilot = null;
private Plan plan;
private Route nextRoute;
public Train(Locomotive loco) {
this(loco,null);
@@ -257,7 +255,8 @@ public class Train extends BaseClass implements Comparable<Train> {
private static Object create(HashMap<String, String> params, Plan plan) {
Locomotive loco = (Locomotive) Locomotive.get(params.get(Train.LOCO_ID));
if (isNull(loco)) return t("unknown locomotive: {}",params.get(ID));
Train train = new Train(loco).plan(plan);
Train train = new Train(loco);
train.parent(plan);
if (params.containsKey(NAME)) train.name(params.get(NAME));
return train;
}
@@ -379,7 +378,7 @@ public class Train extends BaseClass implements Comparable<Train> {
JSONObject json = new JSONObject(line);
Train train = new Train(null,Id.from(json));
train.plan(plan).load(json);
train.load(json).parent(plan);
line = file.readLine();
}
@@ -497,12 +496,7 @@ public class Train extends BaseClass implements Comparable<Train> {
this.name = newName;
return this;
}
private Train plan(Plan plan) {
this.plan = plan;
return this;
}
@Override
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
Fieldset otherTrainProsps = new Fieldset(t("other train properties"));
@@ -570,6 +564,7 @@ public class Train extends BaseClass implements Comparable<Train> {
@Override
public void removeChild(BaseClass child) {
if (child == route) route = null;
if (child == nextRoute) nextRoute = null;
if (child == currentBlock) currentBlock = null;
if (child == destination) destination = null;
cars.remove(child);