-
Notifications
You must be signed in to change notification settings - Fork 0
/
Action.ts
71 lines (59 loc) · 1.27 KB
/
Action.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import {
RuleRegistry,
instance as ruleRegistryInstance,
} from '@civ-clone/core-rule/RuleRegistry';
import {
DataObject,
IDataObject,
} from '@civ-clone/core-data-object/DataObject';
import Tile from '@civ-clone/core-world/Tile';
import Unit from './Unit';
export interface IAction extends IDataObject {
forUnit(unit: Unit): Action;
from(): Tile;
perform(...args: any[]): void;
ruleRegistry(): RuleRegistry;
to(): Tile;
unit(): Unit;
}
export class Action extends DataObject implements IAction {
#from: Tile;
#ruleRegistry: RuleRegistry;
#to: Tile;
#unit: Unit;
constructor(
from: Tile,
to: Tile,
unit: Unit,
ruleRegistry: RuleRegistry = ruleRegistryInstance
) {
super();
this.#from = from;
this.#ruleRegistry = ruleRegistry;
this.#to = to;
this.#unit = unit;
this.addKey('from', 'to');
}
forUnit(unit: Unit): Action {
return new (<typeof Action>this.constructor)(
this.#from,
this.#to,
unit,
this.#ruleRegistry
);
}
from(): Tile {
return this.#from;
}
perform(...args: any[]): void {}
ruleRegistry(): RuleRegistry {
return this.#ruleRegistry;
}
to(): Tile {
return this.#to;
}
unit(): Unit {
return this.#unit;
}
}
export default Action;