wanisramdani / tramway

Process-based simulation in Java/JavaFX à la MVC (more like MVP actually)
1 stars 0 forks source link

How to manage complexity in WorldView #6

Closed djalilhebal closed 4 years ago

djalilhebal commented 4 years ago
// Doesn't need to be public
class Wrapper {
  public Shape shape;
  public PathTransition pathTransition;

  Wrapper(Shape shape, PathTransition pathTransition) {
    this.shape = shape;
    this.pathTransition pathTransition;
  }

}

HashMap<String, Wrapper> things = new HashMap<String, Wrapper>();

Now you can implement WorldViewInterface methods like this (same for Cars):

addTram(id):
  things.add("tram" + id, new Wrapper(new Rec, new PathTransition));

getTramProgress(id):
  return things.get("tram" + id).pathTransition.getCurrentTime();

setTramProgress(id, dur):
  things.get("tram" + id).pathTransition.setCurrentTime(dur);

setTramDynamic(id, yes):
  if (yes) things.get("tram" + id).pathTransition.play();
  else things.get("tram" + id).pathTransition.pause;
djalilhebal commented 4 years ago

"Bulk operations" are even simpler:

void playAll() {
  for (Wrapper thing : things) {
    thing.pathTransition.play();
  }
}

void pauseAll() {
  for (Wrapper thing : things) {
    thing.pathTransition.pause();
  }
}

void resetAll() {
  for (Wrapper thing : things) {
    thing.pathTransition.playFromStart();
  }
}