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:
@@ -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.boat = boat;
|
||||
boat.setAutoVMG(false);
|
||||
race.addObserver(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ public class SailsCommand extends ObserverCommand {
|
||||
|
||||
public SailsCommand(MockRace race, MockBoat boat, boolean sailsOut) {
|
||||
super(race, boat);
|
||||
race.addVelocityCommand(this);
|
||||
this.sailsOut = sailsOut;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ public class TackGybeCommand extends ObserverCommand {
|
||||
*/
|
||||
public TackGybeCommand(MockRace race, MockBoat boat) {
|
||||
super(race, boat);
|
||||
race.addAngularCommand(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,6 +24,7 @@ public class VMGCommand extends ObserverCommand {
|
||||
*/
|
||||
public VMGCommand(MockRace race, MockBoat boat) {
|
||||
super(race, boat);
|
||||
race.addAngularCommand(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,6 +20,7 @@ public class WindCommand extends ObserverCommand {
|
||||
*/
|
||||
public WindCommand(MockRace race, MockBoat boat, boolean upwind) {
|
||||
super(race, boat);
|
||||
race.addAngularCommand(this);
|
||||
this.direction = upwind? -1 : 1;
|
||||
}
|
||||
|
||||
@@ -42,6 +43,6 @@ public class WindCommand extends ObserverCommand {
|
||||
|
||||
@Override
|
||||
public void update(Observable o, Object arg) {
|
||||
|
||||
race.deleteObserver(this);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user