Only one angular command can be active at a time. Only one velocity command can be active at a time. #story[1196]
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package mock.model;
|
package mock.model;
|
||||||
|
|
||||||
|
import mock.model.commandFactory.ActiveObserverCommand;
|
||||||
|
import mock.model.commandFactory.ObserverCommand;
|
||||||
import mock.model.wind.WindGenerator;
|
import mock.model.wind.WindGenerator;
|
||||||
import javafx.animation.AnimationTimer;
|
import javafx.animation.AnimationTimer;
|
||||||
import mock.model.collider.ColliderRegistry;
|
import mock.model.collider.ColliderRegistry;
|
||||||
@@ -64,6 +66,8 @@ public class MockRace extends RaceState {
|
|||||||
*/
|
*/
|
||||||
private Polars polars;
|
private Polars polars;
|
||||||
|
|
||||||
|
private ActiveObserverCommand activeObserverCommand;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -81,6 +85,7 @@ public class MockRace extends RaceState {
|
|||||||
this.setRaceDataSource(raceDataSource);
|
this.setRaceDataSource(raceDataSource);
|
||||||
this.setRegattaDataSource(regattaDataSource);
|
this.setRegattaDataSource(regattaDataSource);
|
||||||
|
|
||||||
|
this.activeObserverCommand = new ActiveObserverCommand();
|
||||||
this.polars = polars;
|
this.polars = polars;
|
||||||
this.scaleFactor = timeScale;
|
this.scaleFactor = timeScale;
|
||||||
|
|
||||||
@@ -715,4 +720,12 @@ public class MockRace extends RaceState {
|
|||||||
public void setChanged() {
|
public void setChanged() {
|
||||||
super.setChanged();
|
super.setChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addVelocityCommand(ObserverCommand c) {
|
||||||
|
this.activeObserverCommand.changeVelocityCommand(this, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAngularCommand(ObserverCommand c) {
|
||||||
|
this.activeObserverCommand.changeAngularCommand(this, c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package mock.model.commandFactory;
|
||||||
|
|
||||||
|
import java.util.Observable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to track the current active observer command. This is to ensure two commands that do similar things do not overlap.
|
||||||
|
*/
|
||||||
|
public class ActiveObserverCommand {
|
||||||
|
private ObserverCommand currentVelocityCommand;
|
||||||
|
private ObserverCommand currentAngularCommand;
|
||||||
|
|
||||||
|
public ActiveObserverCommand() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void changeVelocityCommand(Observable o, ObserverCommand c) {
|
||||||
|
o.deleteObserver(currentVelocityCommand);
|
||||||
|
o.addObserver(c);
|
||||||
|
currentVelocityCommand = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void changeAngularCommand(Observable o, ObserverCommand c) {
|
||||||
|
o.deleteObserver(currentAngularCommand);
|
||||||
|
o.addObserver(c);
|
||||||
|
currentAngularCommand = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,6 +16,5 @@ public abstract class ObserverCommand implements Command, Observer {
|
|||||||
this.race = race;
|
this.race = race;
|
||||||
this.boat = boat;
|
this.boat = boat;
|
||||||
boat.setAutoVMG(false);
|
boat.setAutoVMG(false);
|
||||||
race.addObserver(this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ public class SailsCommand extends ObserverCommand {
|
|||||||
|
|
||||||
public SailsCommand(MockRace race, MockBoat boat, boolean sailsOut) {
|
public SailsCommand(MockRace race, MockBoat boat, boolean sailsOut) {
|
||||||
super(race, boat);
|
super(race, boat);
|
||||||
|
race.addVelocityCommand(this);
|
||||||
this.sailsOut = sailsOut;
|
this.sailsOut = sailsOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ public class TackGybeCommand extends ObserverCommand {
|
|||||||
*/
|
*/
|
||||||
public TackGybeCommand(MockRace race, MockBoat boat) {
|
public TackGybeCommand(MockRace race, MockBoat boat) {
|
||||||
super(race, boat);
|
super(race, boat);
|
||||||
|
race.addAngularCommand(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ public class VMGCommand extends ObserverCommand {
|
|||||||
*/
|
*/
|
||||||
public VMGCommand(MockRace race, MockBoat boat) {
|
public VMGCommand(MockRace race, MockBoat boat) {
|
||||||
super(race, boat);
|
super(race, boat);
|
||||||
|
race.addAngularCommand(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ public class WindCommand extends ObserverCommand {
|
|||||||
*/
|
*/
|
||||||
public WindCommand(MockRace race, MockBoat boat, boolean upwind) {
|
public WindCommand(MockRace race, MockBoat boat, boolean upwind) {
|
||||||
super(race, boat);
|
super(race, boat);
|
||||||
|
race.addAngularCommand(this);
|
||||||
this.direction = upwind? -1 : 1;
|
this.direction = upwind? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,6 +43,6 @@ public class WindCommand extends ObserverCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Observable o, Object arg) {
|
public void update(Observable o, Object arg) {
|
||||||
|
race.deleteObserver(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user