-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAction.js
227 lines (227 loc) · 8.91 KB
/
Action.js
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
}
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var AAction = /** @class */ (function () {
function AAction(actionid, actionli) {
this.actionid = actionid;
this.actionli = actionli;
}
AAction.prototype.enter = function (success) {
$(this.actionli).stop(true).animate({ backgroundColor: (success ? "#00ff00" : "#ff0000") }, 100);
};
AAction.prototype.exit = function () {
$(this.actionli).stop(true).animate({ backgroundColor: "" }, 100);
};
AAction.prototype.delete = function () { };
AAction.prototype.toText = function () { return this.actionid; };
return AAction;
}());
var AActionFactory = /** @class */ (function () {
function AActionFactory(actionid, clsnames, imgname, text) {
var _this = this;
this.actionid = actionid;
this.clsnames = clsnames;
this.imgname = imgname;
this.text = text;
var actionli = document.createElement("li");
clsnames.forEach(function (clsname) { actionli.classList.add(clsname); });
var actionimg = document.createElement("img");
actionimg.src = imgname;
actionli.appendChild(actionimg);
var actiontext = document.createElement("span");
actiontext.innerText = text;
actionli.appendChild(actiontext);
this.actionli = actionli;
this.actionli = actionli;
$(actionli).draggable({
helper: function () { return _this.construct(); },
revert: "invalid",
//start: function (event, ui) {
// var anyelem: any = ui.helper[0];
// anyelem.Action = construct(<HTMLLIElement>ui.helper[0]);
//},
stop: function (event, ui) {
addActionDeleteButton(ui.helper[0]);
}
});
}
AActionFactory.prototype.getId = function () { return this.actionid; };
AActionFactory.prototype.construct = function () {
var actionli = document.createElement("li");
this.clsnames.forEach(function (clsname) { actionli.classList.add(clsname); });
var actionimg = document.createElement("img");
actionimg.src = this.imgname;
actionli.appendChild(actionimg);
var actiontext = document.createElement("span");
actiontext.innerText = this.text;
actionli.appendChild(actiontext);
actionli.Action = this.makeAction(actionli);
return actionli;
};
AActionFactory.prototype.getElement = function () {
return this.actionli;
};
return AActionFactory;
}());
var MoveForwardAction = /** @class */ (function (_super) {
__extends(MoveForwardAction, _super);
function MoveForwardAction(actionli) {
return _super.call(this, "FWD", actionli) || this;
}
MoveForwardAction.prototype.runnable = function (world) {
var newx = world.getX();
var newy = world.getY();
switch (world.getDirection()) {
case Direction.East:
newx++;
break;
case Direction.South:
newy++;
break;
case Direction.West:
newx--;
break;
case Direction.North:
newy--;
break;
}
return world.getMap().canMoveTo(newx, newy);
};
MoveForwardAction.prototype.run = function (world) {
return world.moveForward();
};
return MoveForwardAction;
}(AAction));
var MoveForwardActionFactory = /** @class */ (function (_super) {
__extends(MoveForwardActionFactory, _super);
function MoveForwardActionFactory() {
return _super.call(this, "FWD", ["actionmoveforward"], "forward.png", "Forward") || this;
}
MoveForwardActionFactory.prototype.makeAction = function (li) { return new MoveForwardAction(li); };
return MoveForwardActionFactory;
}(AActionFactory));
var TurnLeftAction = /** @class */ (function (_super) {
__extends(TurnLeftAction, _super);
function TurnLeftAction(actionli) {
return _super.call(this, "TNL", actionli) || this;
}
TurnLeftAction.prototype.runnable = function (world) {
return true;
};
TurnLeftAction.prototype.run = function (world) {
return world.turnLeft();
};
return TurnLeftAction;
}(AAction));
var TurnLeftActionFactory = /** @class */ (function (_super) {
__extends(TurnLeftActionFactory, _super);
function TurnLeftActionFactory() {
return _super.call(this, "TNL", ["actionturnleft"], "turnleft.png", "Turn Left") || this;
}
TurnLeftActionFactory.prototype.makeAction = function (li) { return new TurnLeftAction(li); };
return TurnLeftActionFactory;
}(AActionFactory));
var TurnRightAction = /** @class */ (function (_super) {
__extends(TurnRightAction, _super);
function TurnRightAction(actionli) {
return _super.call(this, "TNR", actionli) || this;
}
TurnRightAction.prototype.runnable = function (world) {
return true;
};
TurnRightAction.prototype.run = function (world) {
return world.turnRight();
};
return TurnRightAction;
}(AAction));
var TurnRightActionFactory = /** @class */ (function (_super) {
__extends(TurnRightActionFactory, _super);
function TurnRightActionFactory() {
return _super.call(this, "TNR", ["actionturnright"], "turnright.png", "Turn Right") || this;
}
TurnRightActionFactory.prototype.makeAction = function (li) { return new TurnRightAction(li); };
return TurnRightActionFactory;
}(AActionFactory));
//class RememberAction<W extends IWorld<W>> extends AAction<W> {
// constructor(actionli: HTMLLIElement) {
// super(actionli);
// }
// memory: MemoryLabel;
// runnable(world: W): boolean {
// return true;
// }
// run(world: W): W {
// return world.remember(this.memory);
// }
//}
var Memory = /** @class */ (function (_super) {
__extends(Memory, _super);
function Memory(memory, actionli) {
var _this = _super.call(this, "M" + memory.getId(), actionli) || this;
_this.memory = memory;
var span = ($(_this.actionli).find("span")[0]);
//var input: HTMLInputElement = <HTMLInputElement><any>($(actionli).find("input")[0]);
//var span = document.createElement("span");
//span.innerText = input.value;
//input.parentNode.insertBefore(span, input);
//input.parentNode.removeChild(input);
_this.nameChangeHandler = function (name) { return span.innerText = name; };
_this.memory.addNameChangeHandler(_this.nameChangeHandler);
return _this;
//$(this.actionli).draggable({ connectToSortable: ".memorydroppable", revert: "invalid" });
}
Memory.prototype.runnable = function (world) {
return true;
};
Memory.prototype.run = function (world) {
return world.remember(this.memory);
};
//check(world: W): IConditionFailure[] {
// if (!world.remembers(this.memory)) {
// return [new ElementConditionFailure(this.actionli)];
// }
// return [];
//}
Memory.prototype.delete = function () {
this.memory.removeNameChangeHandler(this.nameChangeHandler);
};
return Memory;
}(AAction));
var MemoryActionFactory = /** @class */ (function (_super) {
__extends(MemoryActionFactory, _super);
function MemoryActionFactory(memory) {
var _this = _super.call(this, "M" + memory.getId(), ["memory", memory.getName().replace(" ", "").toLowerCase()], "memory.png", memory.getName()) || this;
_this.memory = memory;
var span = ($(_this.actionli).find("span")[0]);
var input = document.createElement("input");
input.type = "text";
input.maxLength = 15;
input.onkeyup = function () { _this.text = input.value; memory.setName(input.value); };
input.value = span.innerText;
_this.actionli.insertBefore(input, span);
_this.actionli.removeChild(span);
return _this;
}
MemoryActionFactory.prototype.makeAction = function (li) {
$(li).draggable({ connectToSortable: ".memorydroppable", revert: "invalid" });
return new Memory(this.memory, li);
};
MemoryActionFactory.prototype.construct = function () {
var actionli = _super.prototype.construct.call(this);
var span = ($(actionli).find("span")[0]);
span.innerText = this.memory.getName();
return actionli;
};
return MemoryActionFactory;
}(AActionFactory));
//# sourceMappingURL=Action.js.map