Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Mar 6, 2025. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathrulesBase.ts
More file actions
Latest commit
140 lines (115 loc) · 5.3 KB
/
Copy pathrulesBase.ts
File metadata and controls
140 lines (115 loc) · 5.3 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
module tileworld{
exportconstyoff=6;
exportclassBackgroundBase{
constructor(){
game.onPaint(function(){
this.update();
})
}
protectedupdate(): void{0;}
}
exportclassRuleVisualsBaseextendsBackgroundBase{
protectedcursor: Sprite;
protectedtileSaved: Sprite;// remember the tile that we are editing
protectedhelpCursor: Sprite;
// rule type state
protectedruleTypeMap: Image;// mapping of tile to rule type
protecteddirMap: Image;// mapping of tile to direction
constructor(protectedp: Project){
super();
this.ruleTypeMap=image.create(10,7);
this.dirMap=image.create(10,7);
this.ruleTypeMap.fill(0xf);
this.dirMap.fill(0xf);
this.cursor=sprites.create(cursorIn);
this.cursor.x=24;
this.cursor.y=yoff+40;
utilities.cursorAnimation(this.cursor,cursorOut);
this.helpCursor=sprites.create(cursorIn);
this.helpCursor.setFlag(SpriteFlag.Invisible,true);
this.tileSaved=sprites.create(cursorOut);
this.tileSaved.setFlag(SpriteFlag.Invisible,true);
controller.left.onEvent(ControllerButtonEvent.Pressed,()=>this.moveInX(MoveDirection.Left));
controller.left.onEvent(ControllerButtonEvent.Repeated,()=>this.moveInX(MoveDirection.Left));
controller.left.onEvent(ControllerButtonEvent.Released,()=>{
if(!this.okToMove())return;
this.cursorMove(MoveDirection.Left,false);
});
controller.right.onEvent(ControllerButtonEvent.Pressed,()=>this.moveInX(MoveDirection.Right));
controller.right.onEvent(ControllerButtonEvent.Repeated,()=>this.moveInX(MoveDirection.Right));
controller.right.onEvent(ControllerButtonEvent.Released,()=>{
if(!this.okToMove())return;
this.cursorMove(MoveDirection.Right,false);
});
controller.up.onEvent(ControllerButtonEvent.Pressed,()=>this.moveUp());
controller.up.onEvent(ControllerButtonEvent.Repeated,()=>this.moveUp());
controller.up.onEvent(ControllerButtonEvent.Released,()=>{
if(!this.okToMove())return;
this.cursorMove(MoveDirection.Up,false);
});
controller.down.onEvent(ControllerButtonEvent.Pressed,()=>this.moveDown());
controller.down.onEvent(ControllerButtonEvent.Repeated,()=>this.moveDown());
controller.down.onEvent(ControllerButtonEvent.Released,()=>{
if(!this.okToMove())return;
this.cursorMove(MoveDirection.Down,false);
});
}
privatemoveInX(dir: MoveDirection){
if(!this.okToMove())return;
if(dir==MoveDirection.Left&&this.col()>0||
dir==MoveDirection.Right&&this.col()<9)
this.cursor.x+=16*moveXdelta(dir);
this.cursorMove(dir);
}
privatemoveUp(){
if(!this.okToMove())return;
if(this.row()>0)
this.cursor.y-=16;
this.cursorMove(MoveDirection.Up);
}
privatemoveDown(){
if(!this.okToMove())return;
if(this.row()<6)
this.cursor.y+=16;
this.cursorMove(MoveDirection.Down);
}
protectedokToMove(): boolean{returntrue;}
protectedgetRulesForTypeDir(rules: RuleView[],rt: RuleType,dir: MoveDirection): RuleView[]{
returnrules.filter(rv=>rv.getRuleType()==rt&&rv.getDirFromRule()==dir);
}
protectedsetCol(col: number): void{
this.cursor.x=(col<<4)+8;
}
protectedsetRow(row: number): void{
this.cursor.y=(row<<4)+8+yoff;
}
protectedcol(curr=true): number{
returncurr ? this.cursor.x>>4 : this.tileSaved.x>>4;
}
protectedrow(curr=true): number{
returncurr ? (this.cursor.y-yoff)>>4 : (this.tileSaved.y-yoff)>>4;
}
protecteddrawImage(c: number,r: number,img: Image): void{
screen.drawTransparentImage(img,c<<4,yoff+(r<<4));
}
protecteddrawImageAbs(x: number,y: number,img: Image): void{
screen.drawTransparentImage(img,x,y);
}
protecteddrawOutline(c: number,r: number,col=12): void{
screen.drawRect(c<<4,yoff+(r<<4),17,17,col);
}
protectedfillTile(c: number,r: number,col: color): void{
screen.fillRect((c<<4)+1,yoff+(r<<4)+1,15,15,col);
}
protectedsetTileSaved(): void{
this.tileSaved.x=this.cursor.x;
this.tileSaved.y=this.cursor.y;
this.tileSaved.z=100;
this.tileSaved.setFlag(SpriteFlag.Invisible,false);
}
protectedisTileSaved(): boolean{
return!(this.tileSaved.flags&SpriteFlag.Invisible);
}
protectedcursorMove(dir: MoveDirection,pressed=true): void{0;}
}
}