-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathruleTransform.ts
63 lines (57 loc) · 2.49 KB
/
ruleTransform.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
module tileworld.ruleediting {
const transformMap = [ RuleTransforms.None, RuleTransforms.HorzMirror, RuleTransforms.VertMirror,
RuleTransforms.LeftRotate, RuleTransforms.RightRotate, RuleTransforms.Rotate3Way];
const transformImages = [ include2, flipHoriz, flipVert, leftRotate, rightRotate, rotate3way];
export class RuleViewDisplay extends RuleDisplay {
private ruleViews: RuleView[];
constructor(p: Project, private baseRule: RuleView) {
super(p, baseRule);
this.setCol(0); this.setRow(0);
this.ruleViews = this.baseRule.getDerivedRules();
controller.A.onEvent(ControllerButtonEvent.Pressed, () => {
if (this.row() == 0 && this.col() >=1 && this.col() <= 6) {
this.baseRule.setTransforms(transformMap[this.col()-1]);
this.ruleViews = this.baseRule.getDerivedRules();
}
});
controller.B.onEvent(ControllerButtonEvent.Pressed, () => {
this.p.saveRule(this.baseRule);
game.popScene();
return;
});
}
protected cursorMove(dir: MoveDirection, pressed: boolean): void {
super.cursorMove(dir, pressed);
this.cursorToView()
this.update();
}
private cursorToView() {
const t = this.baseRule.getTransforms();
this.rule = this.baseRule;
if (this.row() == 1 && t != RuleTransforms.None && this.ruleViews.length > 0) {
const index = transformMap.indexOf(t);
if (this.col() == index+1) {
this.rule = this.ruleViews[0];
} else if (this.ruleViews.length > 1 && this.col() > 6 && this.col() <= 8) {
this.rule = this.ruleViews[this.col()-6];
}
}
this.update();
}
protected update(): void {
super.update();
// menu options
transformImages.forEach((img, i) => {
this.drawImage(i+1, 0, img);
});
// which one selected
const index = transformMap.indexOf(this.baseRule.getTransforms());
this.drawImage(1 + index, 0, cursorOut);
// resulting rules
const col = index+1;
this.ruleViews.forEach((rv, index) => {
this.drawImage(col+index, 1, include2);
});
}
}
}