2017-05-30 16:24:55 +00:00
|
|
|
/// <reference path="../TestGame.ts"/>
|
|
|
|
/// <reference path="../../core/events/BaseBattleEvent.ts"/>
|
|
|
|
|
2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac.UI.Specs {
|
2017-05-30 16:24:55 +00:00
|
|
|
class FakeEvent extends BaseBattleEvent {
|
|
|
|
diff: number
|
|
|
|
|
|
|
|
constructor(diff = 1) {
|
|
|
|
super("fake");
|
|
|
|
|
|
|
|
this.diff = diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
apply(battle: Battle) {
|
2017-10-25 22:45:53 +00:00
|
|
|
battle.cycle += this.diff;
|
2017-05-30 16:24:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getReverse(): BaseBattleEvent {
|
|
|
|
return new FakeEvent(-this.diff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
testing("LogProcessor", test => {
|
2017-10-29 21:08:55 +00:00
|
|
|
let testgame = setupBattleview(test);
|
2017-05-30 16:24:55 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("steps forward and backward in time", check => {
|
2017-10-09 21:13:56 +00:00
|
|
|
let battle = testgame.view.battle;
|
2017-05-30 16:24:55 +00:00
|
|
|
battle.log.clear();
|
2017-10-09 21:13:56 +00:00
|
|
|
let processor = new LogProcessor(testgame.view);
|
2017-05-30 16:24:55 +00:00
|
|
|
processor.register(event => {
|
|
|
|
event.apply(battle);
|
|
|
|
return 0;
|
|
|
|
});
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(battle.cycle, 1);
|
|
|
|
check.equals(processor.atStart(), true);
|
|
|
|
check.equals(processor.atEnd(), true);
|
2017-05-30 16:24:55 +00:00
|
|
|
|
|
|
|
processor.stepForward();
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(battle.cycle, 1);
|
|
|
|
check.equals(processor.atStart(), true);
|
|
|
|
check.equals(processor.atEnd(), true);
|
2017-05-30 16:24:55 +00:00
|
|
|
|
|
|
|
battle.log.add(new FakeEvent());
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(battle.cycle, 1);
|
|
|
|
check.equals(processor.atStart(), true);
|
|
|
|
check.equals(processor.atEnd(), false);
|
2017-05-30 16:24:55 +00:00
|
|
|
|
|
|
|
processor.stepForward();
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(battle.cycle, 2);
|
|
|
|
check.equals(processor.atStart(), false);
|
|
|
|
check.equals(processor.atEnd(), true);
|
2017-05-30 16:24:55 +00:00
|
|
|
|
|
|
|
processor.stepForward();
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(battle.cycle, 2);
|
|
|
|
check.equals(processor.atStart(), false);
|
|
|
|
check.equals(processor.atEnd(), true);
|
2017-05-30 16:24:55 +00:00
|
|
|
|
|
|
|
processor.stepBackward();
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(battle.cycle, 1);
|
|
|
|
check.equals(processor.atStart(), true);
|
|
|
|
check.equals(processor.atEnd(), false);
|
2017-05-30 16:24:55 +00:00
|
|
|
|
|
|
|
processor.stepBackward();
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(battle.cycle, 1);
|
|
|
|
check.equals(processor.atStart(), true);
|
|
|
|
check.equals(processor.atEnd(), false);
|
2017-05-30 16:24:55 +00:00
|
|
|
|
|
|
|
processor.stepForward();
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(battle.cycle, 2);
|
|
|
|
check.equals(processor.atStart(), false);
|
|
|
|
check.equals(processor.atEnd(), true);
|
2017-05-30 16:24:55 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|