@sepveneto/dao 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dao.js CHANGED
@@ -1,80 +1,134 @@
1
- var Renderer = class {
2
- constructor(l) {
3
- this.ctx = l;
4
- }
5
- render(l) {
6
- let k = this.ctx, A = l.camera;
7
- k.clearRect(0, 0, k.canvas.width, k.canvas.height), A.apply(k), l.displayList.render(k);
8
- for (let j of l.world.objects) {
9
- let { px: l, py: M } = A.projection.project(j.x, j.y, j.z);
10
- k.save(), k.translate(l, M), j.draw(k), k.restore();
1
+ var GameObject = class {
2
+ constructor() {
3
+ this.x = 0, this.y = 0, this.z = 0, this.width = 0, this.height = 0, this.zIndex = 0, this.originX = 0, this.originY = 0, this.rotation = 0;
4
+ }
5
+ setOrigin(r, T) {
6
+ this.originX = r, this.originY = T;
7
+ }
8
+ draw(r, T) {
9
+ r.save(), r.rotate(this.rotation), this.render(r), r.restore();
10
+ }
11
+ render(r) {
12
+ if (!this.texture) return;
13
+ let T = this.width || this.texture.width, E = this.height || this.texture.height;
14
+ r.drawImage(this.texture, -T * this.originX, -E * this.originY, T, E);
15
+ }
16
+ update(r) {}
17
+ }, Container = class extends GameObject {
18
+ constructor(...r) {
19
+ super(...r), this.x = 0, this.y = 0, this.z = 0, this.rotation = 0, this.scaleX = 1, this.scaleY = 1, this.children = [];
20
+ }
21
+ add(r) {
22
+ this.children.push(r), this.updateBounds();
23
+ }
24
+ updateBounds() {
25
+ if (!this.children.length) {
26
+ this.width = 0, this.height = 0;
27
+ return;
28
+ }
29
+ let r = Infinity, T = Infinity, E = -Infinity, D = -Infinity;
30
+ this.children.forEach((O) => {
31
+ let k = O.width || 0, A = O.height || 0, j = O.x, M = O.y;
32
+ r = Math.min(r, j), T = Math.min(T, M), E = Math.max(E, j + k), D = Math.max(D, M + A);
33
+ }), this.width = E - r, this.height = D - T;
34
+ }
35
+ remove(r) {
36
+ let T = this.children.indexOf(r);
37
+ T !== -1 && (this.children.splice(T, 1), this.updateBounds());
38
+ }
39
+ update(r) {
40
+ this.children.forEach((T) => {
41
+ var E;
42
+ return (E = T.update) == null ? void 0 : E.call(T, r);
43
+ });
44
+ }
45
+ draw(r, T) {
46
+ this.children.forEach((E) => {
47
+ this.drawChild(E, r, T);
48
+ });
49
+ }
50
+ drawChild(r, T, E) {
51
+ let D = this.width * this.originX, O = this.height * this.originY, k = Math.cos(this.rotation), A = Math.sin(this.rotation), j = (r.x - D) * this.scaleX, M = (r.y - O) * this.scaleY, N = this.x + j * k - M * A, P = this.y + j * A + M * k, F = this.z + r.z, I = this.rotation + r.rotation, { px: L, py: R } = E.projection.project(N, P, F);
52
+ console.log(N, P, this.x, this.y), T.save(), T.translate(L, R), T.rotate(I), r.render(T), T.restore();
53
+ }
54
+ }, Renderer = class {
55
+ constructor(r) {
56
+ this.ctx = r;
57
+ }
58
+ render(r) {
59
+ let E = this.ctx, D = r.camera;
60
+ E.clearRect(0, 0, E.canvas.width, E.canvas.height), D.apply(E), r.displayList.render(E);
61
+ for (let O of r.world.objects) if (O instanceof Container) O.draw(E, D);
62
+ else {
63
+ let { px: r, py: T } = D.projection.project(O.x, O.y, O.z);
64
+ E.save(), E.translate(r, T), O.draw(E, D), E.restore();
11
65
  }
12
- A.restore(k);
66
+ D.restore(E);
13
67
  }
14
68
  }, EventSystem = class {
15
69
  constructor() {
16
70
  this.events = /* @__PURE__ */ new Map();
17
71
  }
18
- on(l, k) {
19
- this.events.has(l) || this.events.set(l, /* @__PURE__ */ new Set()), this.events.get(l).add(k);
72
+ on(r, T) {
73
+ this.events.has(r) || this.events.set(r, /* @__PURE__ */ new Set()), this.events.get(r).add(T);
20
74
  }
21
- off(l, k) {
22
- this.events.has(l) && this.events.get(l).delete(k);
75
+ off(r, T) {
76
+ this.events.has(r) && this.events.get(r).delete(T);
23
77
  }
24
- emit(l, ...k) {
25
- if (this.events.has(l)) for (let A of this.events.get(l)) A(...k);
78
+ emit(r, ...T) {
79
+ if (this.events.has(r)) for (let E of this.events.get(r)) E(...T);
26
80
  }
27
81
  };
28
- function _typeof(l) {
82
+ function _typeof(r) {
29
83
  "@babel/helpers - typeof";
30
- return _typeof = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(l) {
31
- return typeof l;
32
- } : function(l) {
33
- return l && typeof Symbol == "function" && l.constructor === Symbol && l !== Symbol.prototype ? "symbol" : typeof l;
34
- }, _typeof(l);
84
+ return _typeof = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(r) {
85
+ return typeof r;
86
+ } : function(r) {
87
+ return r && typeof Symbol == "function" && r.constructor === Symbol && r !== Symbol.prototype ? "symbol" : typeof r;
88
+ }, _typeof(r);
35
89
  }
36
- function toPrimitive(l, k) {
37
- if (_typeof(l) != "object" || !l) return l;
38
- var j = l[Symbol.toPrimitive];
39
- if (j !== void 0) {
40
- var M = j.call(l, k || "default");
41
- if (_typeof(M) != "object") return M;
90
+ function toPrimitive(r, T) {
91
+ if (_typeof(r) != "object" || !r) return r;
92
+ var E = r[Symbol.toPrimitive];
93
+ if (E !== void 0) {
94
+ var D = E.call(r, T || "default");
95
+ if (_typeof(D) != "object") return D;
42
96
  throw TypeError("@@toPrimitive must return a primitive value.");
43
97
  }
44
- return (k === "string" ? String : Number)(l);
98
+ return (T === "string" ? String : Number)(r);
45
99
  }
46
- function toPropertyKey(l) {
47
- var k = toPrimitive(l, "string");
48
- return _typeof(k) == "symbol" ? k : k + "";
100
+ function toPropertyKey(r) {
101
+ var T = toPrimitive(r, "string");
102
+ return _typeof(T) == "symbol" ? T : T + "";
49
103
  }
50
- function _defineProperty(l, k, A) {
51
- return (k = toPropertyKey(k)) in l ? Object.defineProperty(l, k, {
52
- value: A,
104
+ function _defineProperty(r, T, E) {
105
+ return (T = toPropertyKey(T)) in r ? Object.defineProperty(r, T, {
106
+ value: E,
53
107
  enumerable: !0,
54
108
  configurable: !0,
55
109
  writable: !0
56
- }) : l[k] = A, l;
110
+ }) : r[T] = E, r;
57
111
  }
58
- function ownKeys(l, k) {
59
- var A = Object.keys(l);
112
+ function ownKeys(r, T) {
113
+ var E = Object.keys(r);
60
114
  if (Object.getOwnPropertySymbols) {
61
- var j = Object.getOwnPropertySymbols(l);
62
- k && (j = j.filter(function(k) {
63
- return Object.getOwnPropertyDescriptor(l, k).enumerable;
64
- })), A.push.apply(A, j);
115
+ var D = Object.getOwnPropertySymbols(r);
116
+ T && (D = D.filter(function(T) {
117
+ return Object.getOwnPropertyDescriptor(r, T).enumerable;
118
+ })), E.push.apply(E, D);
65
119
  }
66
- return A;
120
+ return E;
67
121
  }
68
- function _objectSpread2(l) {
69
- for (var k = 1; k < arguments.length; k++) {
70
- var A = arguments[k] == null ? {} : arguments[k];
71
- k % 2 ? ownKeys(Object(A), !0).forEach(function(k) {
72
- _defineProperty(l, k, A[k]);
73
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(l, Object.getOwnPropertyDescriptors(A)) : ownKeys(Object(A)).forEach(function(k) {
74
- Object.defineProperty(l, k, Object.getOwnPropertyDescriptor(A, k));
122
+ function _objectSpread2(r) {
123
+ for (var T = 1; T < arguments.length; T++) {
124
+ var E = arguments[T] == null ? {} : arguments[T];
125
+ T % 2 ? ownKeys(Object(E), !0).forEach(function(T) {
126
+ _defineProperty(r, T, E[T]);
127
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(r, Object.getOwnPropertyDescriptors(E)) : ownKeys(Object(E)).forEach(function(T) {
128
+ Object.defineProperty(r, T, Object.getOwnPropertyDescriptor(E, T));
75
129
  });
76
130
  }
77
- return l;
131
+ return r;
78
132
  }
79
133
  const InputEventType = {
80
134
  KEY_DOWN: Symbol("keyDown"),
@@ -84,7 +138,7 @@ const InputEventType = {
84
138
  POINTER_UP: Symbol("pointerUp")
85
139
  };
86
140
  var InputSystem = class {
87
- constructor(l, k) {
141
+ constructor(r, T) {
88
142
  this.keys = /* @__PURE__ */ new Set(), this.pointer = {
89
143
  x: 0,
90
144
  y: 0,
@@ -94,51 +148,51 @@ var InputSystem = class {
94
148
  justDown: !1,
95
149
  justUp: !1,
96
150
  id: null
97
- }, this.target = l, this.events = k, window.addEventListener("keydown", (l) => {
98
- l.preventDefault(), this.keys.add(l.code), this.events.emit(InputEventType.KEY_DOWN, l);
99
- }), window.addEventListener("keyup", (l) => {
100
- this.keys.delete(l.code), this.events.emit(InputEventType.KEY_UP, l);
101
- }), l.addEventListener("mousedown", this.onDown.bind(this)), l.addEventListener("mousemove", this.onMove.bind(this)), l.addEventListener("mouseup", this.onUp.bind(this)), l.addEventListener("touchstart", this.onDown.bind(this), { passive: !1 }), l.addEventListener("touchmove", this.onMove.bind(this), { passive: !1 }), l.addEventListener("touchend", this.onUp.bind(this));
151
+ }, this.target = r, this.events = T, window.addEventListener("keydown", (r) => {
152
+ r.preventDefault(), this.keys.add(r.code), this.events.emit(InputEventType.KEY_DOWN, r);
153
+ }), window.addEventListener("keyup", (r) => {
154
+ this.keys.delete(r.code), this.events.emit(InputEventType.KEY_UP, r);
155
+ }), r.addEventListener("mousedown", this.onDown.bind(this)), r.addEventListener("mousemove", this.onMove.bind(this)), r.addEventListener("mouseup", this.onUp.bind(this)), r.addEventListener("touchstart", this.onDown.bind(this), { passive: !1 }), r.addEventListener("touchmove", this.onMove.bind(this), { passive: !1 }), r.addEventListener("touchend", this.onUp.bind(this));
102
156
  }
103
157
  update() {
104
158
  this.pointer.justDown = !1, this.pointer.justUp = !1, this.pointer.dx = 0, this.pointer.dy = 0;
105
159
  }
106
- isKeyboardDown(l) {
107
- return this.keys.has(l);
160
+ isKeyboardDown(r) {
161
+ return this.keys.has(r);
108
162
  }
109
- onDown(l) {
110
- l.preventDefault();
111
- let k = this._getPoint(l);
112
- if (!k) {
163
+ onDown(r) {
164
+ r.preventDefault();
165
+ let T = this._getPoint(r);
166
+ if (!T) {
113
167
  console.warn("missing point");
114
168
  return;
115
169
  }
116
- this.pointer.down = !0, this.pointer.justDown = !0, this.pointer.x = k.x, this.pointer.y = k.y, this.pointer.id = k.id, this.events.emit(InputEventType.POINTER_DOWN, _objectSpread2({}, this.pointer));
170
+ this.pointer.down = !0, this.pointer.justDown = !0, this.pointer.x = T.x, this.pointer.y = T.y, this.pointer.id = T.id, this.events.emit(InputEventType.POINTER_DOWN, _objectSpread2({}, this.pointer));
117
171
  }
118
- onMove(l) {
172
+ onMove(r) {
119
173
  if (!this.pointer.down) return;
120
- l.preventDefault();
121
- let k = this._getPoint(l);
122
- if (!k) {
174
+ r.preventDefault();
175
+ let T = this._getPoint(r);
176
+ if (!T) {
123
177
  console.warn("missing point");
124
178
  return;
125
179
  }
126
- this.pointer.dx += k.x - this.pointer.x, this.pointer.dy += k.y - this.pointer.y, this.pointer.x = k.x, this.pointer.y = k.y, this.events.emit(InputEventType.POINTER_MOVE, _objectSpread2({}, this.pointer));
180
+ this.pointer.dx += T.x - this.pointer.x, this.pointer.dy += T.y - this.pointer.y, this.pointer.x = T.x, this.pointer.y = T.y, this.events.emit(InputEventType.POINTER_MOVE, _objectSpread2({}, this.pointer));
127
181
  }
128
182
  onUp() {
129
183
  this.pointer.down = !1, this.pointer.justUp = !0, this.pointer.id = null, this.events.emit(InputEventType.POINTER_UP, _objectSpread2({}, this.pointer));
130
184
  }
131
- _getPoint(l) {
132
- let k = this.target.getBoundingClientRect(), A, j, M = "mouse";
133
- if (l instanceof TouchEvent) {
134
- let k = l.touches[0] || l.changedTouches[0];
135
- if (!k) return;
136
- A = k.clientX, j = k.clientY, M = k.identifier;
137
- } else A = l.clientX, j = l.clientY;
185
+ _getPoint(r) {
186
+ let T = this.target.getBoundingClientRect(), E, D, O = "mouse";
187
+ if (r instanceof TouchEvent) {
188
+ let T = r.touches[0] || r.changedTouches[0];
189
+ if (!T) return;
190
+ E = T.clientX, D = T.clientY, O = T.identifier;
191
+ } else E = r.clientX, D = r.clientY;
138
192
  return {
139
- x: A - k.left,
140
- y: j - k.top,
141
- id: M
193
+ x: E - T.left,
194
+ y: D - T.top,
195
+ id: O
142
196
  };
143
197
  }
144
198
  }, Camera = class {
@@ -148,148 +202,185 @@ var InputSystem = class {
148
202
  get height() {
149
203
  return this.viewport.height;
150
204
  }
151
- constructor(l) {
205
+ constructor(r) {
152
206
  this.viewport = {
153
207
  x: 0,
154
208
  y: 0,
155
209
  width: 0,
156
210
  height: 0
157
- }, this.x = 0, this.y = 0, this.zoom = 1, this._followLerp = 1, this._offsetX = 0, this._offsetY = 0, this.originX = 0, this.originY = 0, this.projection = l;
211
+ }, this.x = 0, this.y = 0, this.zoom = 1, this._followLerp = 1, this._offsetX = 0, this._offsetY = 0, this.originX = 0, this.originY = 0, this.projection = r;
158
212
  }
159
- setOrigin(l, k) {
160
- this.originX = l, this.originY = k;
213
+ setOrigin(r, T) {
214
+ this.originX = r, this.originY = T;
161
215
  }
162
- setViewport(l, k, A, j) {
216
+ setViewport(r, T, E, D) {
163
217
  this.viewport = {
164
- x: l,
165
- y: k,
166
- width: A,
167
- height: j
218
+ x: r,
219
+ y: T,
220
+ width: E,
221
+ height: D
168
222
  };
169
223
  }
170
- apply(l) {
171
- l.save(), l.translate(this.originX * this.viewport.width, this.originY * this.viewport.height), l.scale(this.zoom, this.zoom), l.translate(-Math.round(this.x), -Math.round(this.y));
224
+ apply(r) {
225
+ r.save(), r.translate(this.originX * this.viewport.width, this.originY * this.viewport.height), r.scale(this.zoom, this.zoom), r.translate(-Math.round(this.x), -Math.round(this.y));
172
226
  }
173
- restore(l) {
174
- l.restore();
227
+ restore(r) {
228
+ r.restore();
175
229
  }
176
- project(l, k, A = 0) {
177
- let { px: j, py: M } = this.projection.project(l, k, A);
230
+ project(r, T, E = 0) {
231
+ let { px: D, py: O } = this.projection.project(r, T, E);
178
232
  return {
179
- px: j - this.x,
180
- py: M - this.y
233
+ px: D - this.x,
234
+ py: O - this.y
181
235
  };
182
236
  }
183
- follow(l, k) {
184
- var A, j, M;
185
- this._followTarget = l, this._followLerp = (A = k == null ? void 0 : k.lerp) == null ? 1 : A, this._offsetX = (j = k == null ? void 0 : k.offsetX) == null ? 0 : j, this._offsetY = (M = k == null ? void 0 : k.offsetY) == null ? 0 : M;
237
+ follow(r, T) {
238
+ var E, D, O;
239
+ this._followTarget = r, this._followLerp = (E = T == null ? void 0 : T.lerp) == null ? 1 : E, this._offsetX = (D = T == null ? void 0 : T.offsetX) == null ? 0 : D, this._offsetY = (O = T == null ? void 0 : T.offsetY) == null ? 0 : O;
186
240
  }
187
241
  stopFollow() {
188
242
  this._followTarget = void 0;
189
243
  }
190
244
  update() {
191
245
  if (!this._followTarget) return;
192
- let { x: l, y: k, z: A } = this._followTarget, { px: j, py: M } = this.project(l, k, A), N = j + this._offsetX, P = M + this._offsetY;
193
- this.x += N * this._followLerp, this.y += P * this._followLerp;
246
+ let { x: r, y: T, z: E } = this._followTarget, { px: D, py: O } = this.project(r, T, E), k = D + this._offsetX, A = O + this._offsetY;
247
+ this.x += k * this._followLerp, this.y += A * this._followLerp;
194
248
  }
195
249
  }, CameraController = class {
196
- constructor(l, k) {
197
- this.speed = 300, this.camera = l, this.input = k;
250
+ constructor(r, T) {
251
+ this.speed = 300, this.camera = r, this.input = T;
198
252
  }
199
- update(l) {
200
- let k = this.speed * l / 1e3;
201
- this.input.isKeyboardDown("ArrowUp") && (this.camera.y += k), this.input.isKeyboardDown("ArrowDown") && (this.camera.y -= k), this.input.isKeyboardDown("ArrowLeft") && (this.camera.x += k), this.input.isKeyboardDown("ArrowRight") && (this.camera.x -= k);
253
+ update(r) {
254
+ let T = this.speed * r / 1e3;
255
+ this.input.isKeyboardDown("ArrowUp") && (this.camera.y += T), this.input.isKeyboardDown("ArrowDown") && (this.camera.y -= T), this.input.isKeyboardDown("ArrowLeft") && (this.camera.x += T), this.input.isKeyboardDown("ArrowRight") && (this.camera.x -= T);
202
256
  }
203
257
  }, DisplayObject = class {
204
258
  constructor() {
205
259
  this.x = 0, this.y = 0, this.originX = .5, this.originY = .5;
206
260
  }
207
261
  }, ImageObject = class extends DisplayObject {
208
- constructor(l, k, A, j = 1) {
209
- super(), this.resolution = 1, this.x = l, this.y = k, this.texture = A, this.resolution = j, this.width = A.width / j, this.height = A.height / j;
262
+ constructor(r, T, E, D = 1) {
263
+ super(), this.resolution = 1, this.x = r, this.y = T, this.texture = E, this.resolution = D, this.width = E.width / D, this.height = E.height / D;
210
264
  }
211
- render(l) {
212
- l.drawImage(this.texture, this.x - this.width * this.originX, this.y - this.height * this.originY, this.width, this.height);
265
+ render(r) {
266
+ r.drawImage(this.texture, this.x - this.width * this.originX, this.y - this.height * this.originY, this.width, this.height);
213
267
  }
214
268
  }, DisplayList = class {
215
269
  constructor() {
216
270
  this.list = [];
217
271
  }
218
- add(l) {
219
- this.list.push(l);
272
+ add(r) {
273
+ this.list.push(r);
274
+ }
275
+ render(r) {
276
+ this.list.forEach((T) => T.render(r));
277
+ }
278
+ }, Text = class extends GameObject {
279
+ constructor(r, T) {
280
+ super(), this.x = 0, this.y = 0, this.visible = !0, this.width = 0, this.height = 0, this.dirty = !0, this.text = r, this.style = T, this.canvas = document.createElement("canvas"), this.ctx = this.canvas.getContext("2d"), this.texture = this.canvas;
281
+ }
282
+ setText(r) {
283
+ this.text !== r && (this.text = r, this.dirty = !0);
284
+ }
285
+ setStyle(r) {
286
+ Object.assign(this.style, r), this.dirty = !0;
287
+ }
288
+ rebuild() {
289
+ var r, T, E;
290
+ if (!this.dirty) return;
291
+ let D = this.ctx, O = this.style, k = this.text.split("\n"), A = (r = O.padding) == null ? {
292
+ left: 0,
293
+ right: 0,
294
+ top: 0,
295
+ bottom: 0
296
+ } : r;
297
+ D.font = `${(T = O.fontStyle) == null ? "" : T} ${O.fontSize}px ${O.fontFamily}`;
298
+ let j = 0;
299
+ for (let r of k) j = Math.max(j, D.measureText(r).width);
300
+ let M = O.fontSize * 1.2;
301
+ this.width = j + A.left + A.right, this.height = k.length * M + A.top + A.bottom, this.canvas.width = Math.ceil(this.width), this.canvas.height = Math.ceil(this.height), D.clearRect(0, 0, this.canvas.width, this.canvas.height), D.font = `${(E = O.fontStyle) == null ? "" : E} ${O.fontSize}px ${O.fontFamily}`, D.fillStyle = O.color, D.textBaseline = "top", O.shadow && (D.shadowOffsetX = O.shadow.offsetX, D.shadowOffsetY = O.shadow.offsetY, D.shadowColor = O.shadow.color, D.shadowBlur = O.shadow.blur);
302
+ let N = A.top;
303
+ for (let r of k) {
304
+ let T = A.left, E = D.measureText(r).width;
305
+ O.align === "center" ? T += (this.width - A.left - A.right - E) / 2 : O.align === "right" && (T += this.width - A.left - A.right - E), O.stroke && O.strokeThickness && (D.lineWidth = O.strokeThickness, D.strokeStyle = O.stroke, D.strokeText(r, T, N)), D.fillText(r, T, N), N += M;
306
+ }
307
+ this.dirty = !1;
220
308
  }
221
- render(l) {
222
- this.list.forEach((k) => k.render(l));
309
+ render(r) {
310
+ if (!this.texture) return;
311
+ this.rebuild();
312
+ let T = this.width || this.canvas.width, E = this.height;
313
+ r.drawImage(this.texture, -T * this.originX, -E * this.originY, T, E);
223
314
  }
224
315
  };
225
- function asyncGeneratorStep(l, k, A, j, M, N, P) {
316
+ function asyncGeneratorStep(r, T, E, D, O, k, A) {
226
317
  try {
227
- var F = l[N](P), I = F.value;
228
- } catch (l) {
229
- A(l);
318
+ var j = r[k](A), M = j.value;
319
+ } catch (r) {
320
+ E(r);
230
321
  return;
231
322
  }
232
- F.done ? k(I) : Promise.resolve(I).then(j, M);
323
+ j.done ? T(M) : Promise.resolve(M).then(D, O);
233
324
  }
234
- function _asyncToGenerator(l) {
325
+ function _asyncToGenerator(r) {
235
326
  return function() {
236
- var k = this, A = arguments;
237
- return new Promise(function(j, M) {
238
- var N = l.apply(k, A);
239
- function P(l) {
240
- asyncGeneratorStep(N, j, M, P, F, "next", l);
327
+ var T = this, E = arguments;
328
+ return new Promise(function(D, O) {
329
+ var k = r.apply(T, E);
330
+ function A(r) {
331
+ asyncGeneratorStep(k, D, O, A, j, "next", r);
241
332
  }
242
- function F(l) {
243
- asyncGeneratorStep(N, j, M, P, F, "throw", l);
333
+ function j(r) {
334
+ asyncGeneratorStep(k, D, O, A, j, "throw", r);
244
335
  }
245
- P(void 0);
336
+ A(void 0);
246
337
  });
247
338
  };
248
339
  }
249
340
  var File = class {
250
- constructor(l, k) {
251
- this.key = l, this.url = k;
341
+ constructor(r, T) {
342
+ this.key = r, this.url = T;
252
343
  }
253
344
  }, ImageFile = class extends File {
254
345
  load() {
255
- return new Promise((l, k) => {
256
- let A = new Image();
257
- A.onload = () => l(A), A.onerror = () => k(/* @__PURE__ */ Error(`Failed to load ${this.url}`)), A.src = this.url;
346
+ return new Promise((r, T) => {
347
+ let E = new Image();
348
+ E.onload = () => r(E), E.onerror = () => T(/* @__PURE__ */ Error(`Failed to load ${this.url}`)), E.src = this.url;
258
349
  });
259
350
  }
260
351
  }, Loader = class {
261
- constructor(l) {
262
- this.queue = [], this.textures = l;
352
+ constructor(r) {
353
+ this.queue = [], this.textures = r;
263
354
  }
264
- image(l, k) {
265
- return this.queue.push(new ImageFile(l, k)), this;
355
+ image(r, T) {
356
+ return this.queue.push(new ImageFile(r, T)), this;
266
357
  }
267
358
  load() {
268
- var l = this;
359
+ var r = this;
269
360
  return _asyncToGenerator(function* () {
270
- let k = l.queue.map((k) => k.load().then((A) => {
271
- k instanceof ImageFile && l.textures.add(k.key, A);
361
+ let T = r.queue.map((T) => T.load().then((E) => {
362
+ T instanceof ImageFile && r.textures.add(T.key, E);
272
363
  }));
273
- l.queue.length = 0, yield Promise.all(k);
364
+ r.queue.length = 0, yield Promise.all(T);
274
365
  })();
275
366
  }
276
367
  }, _ResourceManager, Cache = class {
277
368
  constructor() {
278
369
  this.map = /* @__PURE__ */ new Map();
279
370
  }
280
- add(l, k) {
281
- this.map.has(l) || this.map.set(l, k);
371
+ add(r, T) {
372
+ this.map.has(r) || this.map.set(r, T);
282
373
  }
283
- get(l) {
284
- let k = this.map.get(l);
285
- if (!k) throw Error(`Asset ${l} not found`);
286
- return k;
374
+ get(r) {
375
+ let T = this.map.get(r);
376
+ if (!T) throw Error(`Asset ${r} not found`);
377
+ return T;
287
378
  }
288
- has(l) {
289
- return this.map.has(l);
379
+ has(r) {
380
+ return this.map.has(r);
290
381
  }
291
- remove(l) {
292
- this.map.delete(l);
382
+ remove(r) {
383
+ this.map.delete(r);
293
384
  }
294
385
  clear() {
295
386
  this.map.clear();
@@ -297,170 +388,154 @@ var File = class {
297
388
  }, ResourceManager = class {};
298
389
  _ResourceManager = ResourceManager, _ResourceManager.textures = new Cache(), _ResourceManager.loader = new Loader(_ResourceManager.textures);
299
390
  var AddFactory = class {
300
- constructor(l) {
301
- this.rm = ResourceManager, this.displayList = l;
391
+ constructor(r) {
392
+ this.rm = ResourceManager, this.displayList = r;
302
393
  }
303
- image(l, k, A, j = 1) {
304
- let M = new ImageObject(l, k, this.rm.textures.get(A), j);
305
- return this.displayList.add(M), M;
394
+ image(r, T, E, D = 1) {
395
+ let O = new ImageObject(r, T, this.rm.textures.get(E), D);
396
+ return this.displayList.add(O), O;
306
397
  }
307
398
  }, SortSystem = class {
308
- constructor(l, k) {
309
- this.world = l, this.strategy = k;
399
+ constructor(r, T) {
400
+ this.world = r, this.strategy = T;
310
401
  }
311
402
  update() {
312
- this.world.objects.sort((l, k) => this.strategy.getKey(l) - this.strategy.getKey(k)), this.world.objects.sort((l, k) => l.zIndex - k.zIndex);
403
+ this.world.objects.sort((r, T) => this.strategy.getKey(r) - this.strategy.getKey(T)), this.world.objects.sort((r, T) => r.zIndex - T.zIndex);
313
404
  }
314
405
  }, TweenData = class {
315
- constructor(l) {
316
- this.elapsed = 0, this.target = l.target, this.key = l.key, this.start = l.target[l.key], this.end = l.to, this.duration = l.duration, this.delay = l.delay || 0;
317
- let k = l.easing || "Linear";
318
- typeof k == "string" ? this.easing = Easings[k] : this.easing = k;
406
+ constructor(r) {
407
+ this.elapsed = 0, this.target = r.target, this.key = r.key, this.start = r.target[r.key], this.end = r.to, this.duration = r.duration, this.delay = r.delay || 0;
408
+ let T = r.easing || "Linear";
409
+ typeof T == "string" ? this.easing = Easings[T] : this.easing = T;
319
410
  }
320
- update(l) {
321
- if (this.delay > 0) return this.delay -= l, !1;
322
- this.elapsed += l;
323
- let k = Math.min(this.elapsed / this.duration, 1), A = this.easing(k);
324
- return this.target[this.key] = this.start + (this.end - this.start) * A, k === 1 ? (this.target[this.key] = this.end, !0) : !1;
411
+ update(r) {
412
+ if (this.delay > 0) return this.delay -= r, !1;
413
+ this.elapsed += r;
414
+ let T = Math.min(this.elapsed / this.duration, 1), E = this.easing(T);
415
+ return this.target[this.key] = this.start + (this.end - this.start) * E, T === 1 ? (this.target[this.key] = this.end, !0) : !1;
325
416
  }
326
417
  reset() {
327
418
  this.elapsed = 0;
328
419
  }
329
420
  };
330
421
  const Easings = {
331
- Linear: (l) => l,
332
- EaseOutBack: (l) => {
333
- let k = 3.70158, A = l - 1;
334
- return 1 + A * A * ((k + 1) * A + k);
422
+ Linear: (r) => r,
423
+ EaseOutBack: (r) => {
424
+ let T = 3.70158, E = r - 1;
425
+ return 1 + E * E * ((T + 1) * E + T);
335
426
  }
336
427
  };
337
428
  var Tween = class {
338
- constructor(l) {
339
- for (let k in this.datas = [], this.finished = !1, this.loop = !1, l.to) this.datas.push(new TweenData({
340
- target: l.target,
341
- key: k,
342
- to: l.to[k],
343
- duration: l.duration,
344
- easing: l.easing,
345
- delay: l.delay
429
+ constructor(r) {
430
+ for (let T in this.datas = [], this.finished = !1, this.loop = !1, r.to) this.datas.push(new TweenData({
431
+ target: r.target,
432
+ key: T,
433
+ to: r.to[T],
434
+ duration: r.duration,
435
+ easing: r.easing,
436
+ delay: r.delay
346
437
  }));
347
- this.loop = l.loop || !1, this.onComplete = l.onComplete;
438
+ this.loop = r.loop || !1, this.onComplete = r.onComplete;
348
439
  }
349
- update(l) {
440
+ update(r) {
350
441
  if (this.finished) return;
351
- let k = !0;
352
- for (let A of this.datas) A.update(l) || (k = !1);
353
- if (k) if (this.loop) this.datas.forEach((l) => l.reset());
442
+ let T = !0;
443
+ for (let E of this.datas) E.update(r) || (T = !1);
444
+ if (T) if (this.loop) this.datas.forEach((r) => r.reset());
354
445
  else {
355
- var A;
356
- this.finished = !0, (A = this.onComplete) == null || A.call(this);
446
+ var E;
447
+ this.finished = !0, (E = this.onComplete) == null || E.call(this);
357
448
  }
358
449
  }
359
450
  }, TweenManager = class {
360
451
  constructor() {
361
452
  this.tweens = [];
362
453
  }
363
- add(l) {
364
- let k = new Tween(l);
365
- return this.tweens.push(k), k;
454
+ add(r) {
455
+ let T = new Tween(r);
456
+ return this.tweens.push(T), T;
366
457
  }
367
- update(l) {
368
- for (let k of this.tweens) k.update(l);
369
- this.tweens = this.tweens.filter((l) => !l.finished);
458
+ update(r) {
459
+ for (let T of this.tweens) T.update(r);
460
+ this.tweens = this.tweens.filter((r) => !r.finished);
370
461
  }
371
462
  }, World = class {
372
463
  constructor() {
373
464
  this.objects = [];
374
465
  }
375
- add(l) {
376
- this.objects.push(l);
466
+ add(r) {
467
+ this.objects.push(r);
377
468
  }
378
- update(l) {
379
- for (let k of this.objects) k.update(l);
469
+ update(r) {
470
+ for (let T of this.objects) T.update(r);
380
471
  }
381
472
  }, Scene = class {
382
- constructor(l, k) {
383
- this.world = new World(), this.system = [], this.displayList = new DisplayList(), this.add = new AddFactory(this.displayList), this.camera = new Camera(l), this.tween = new TweenManager(), this.system.push(new SortSystem(this.world, k)), this.system.push(this.tween);
473
+ constructor(r, T) {
474
+ this.world = new World(), this.system = [], this.displayList = new DisplayList(), this.add = new AddFactory(this.displayList), this.camera = new Camera(r), this.tween = new TweenManager(), this.system.push(new SortSystem(this.world, T)), this.system.push(this.tween);
384
475
  }
385
- _boot(l) {
386
- this.input = l.input, this.events = l.events, this.config = l.config;
476
+ _boot(r) {
477
+ this.input = r.input, this.events = r.events, this.config = r.config;
387
478
  }
388
- registerSystem(l) {
389
- this.system.push(l);
479
+ registerSystem(r) {
480
+ this.system.push(r);
390
481
  }
391
482
  create() {}
392
- resize(l, k) {
393
- this.camera.setViewport(0, 0, l, k);
483
+ resize(r, T) {
484
+ this.camera.setViewport(0, 0, r, T);
394
485
  }
395
- update(l) {
396
- for (let A of this.system) {
397
- var k;
398
- (k = A.update) == null || k.call(A, l);
486
+ update(r) {
487
+ for (let E of this.system) {
488
+ var T;
489
+ (T = E.update) == null || T.call(E, r);
399
490
  }
400
- this.camera.update(), this.world.update(l);
401
- }
402
- }, GameObject = class {
403
- constructor(l, k, A = 0) {
404
- this.width = 0, this.height = 0, this.zIndex = 0, this.originX = 0, this.originY = 0, this.rotation = 0, this.x = l, this.y = k, this.z = A;
405
- }
406
- setOrigin(l, k) {
407
- this.originX = l, this.originY = k;
408
- }
409
- draw(l) {
410
- l.save(), l.rotate(this.rotation), this.render(l), l.restore();
411
- }
412
- render(l) {
413
- if (!this.texture) return;
414
- let k = this.width || this.texture.width, A = this.height || this.texture.height;
415
- l.drawImage(this.texture, -k * this.originX, -A * this.originY, k, A);
491
+ this.camera.update(), this.world.update(r);
416
492
  }
417
- update(l) {}
418
493
  }, Projection2D = class {
419
- constructor(l = 1, k = 1) {
420
- this.scaleX = l, this.scaleY = k;
494
+ constructor(r = 1, T = 1) {
495
+ this.scaleX = r, this.scaleY = T;
421
496
  }
422
- project(l, k) {
497
+ project(r, T) {
423
498
  return {
424
- px: l * this.scaleX,
425
- py: k * this.scaleY
499
+ px: r * this.scaleX,
500
+ py: T * this.scaleY
426
501
  };
427
502
  }
428
503
  }, IsoProjection = class {
429
- constructor(l, k, A) {
430
- this.tileWidth = l, this.tileHeight = k, this.zHeight = A;
504
+ constructor(r, T, E) {
505
+ this.tileWidth = r, this.tileHeight = T, this.zHeight = E;
431
506
  }
432
- project(l, k, A = 0) {
507
+ project(r, T, E = 0) {
433
508
  return {
434
- px: (l - k) * this.tileWidth / 2,
435
- py: (l + k) * this.tileHeight / 2 - A * this.zHeight
509
+ px: (r - T) * this.tileWidth / 2,
510
+ py: (r + T) * this.tileHeight / 2 - E * this.zHeight
436
511
  };
437
512
  }
438
513
  }, IsoStragety = class {
439
- getKey(l) {
440
- return l.x + l.y + l.z;
514
+ getKey(r) {
515
+ return r.x + r.y + r.z;
441
516
  }
442
517
  }, ZIndexStragety = class {
443
- getKey(l) {
444
- return l.zIndex;
518
+ getKey(r) {
519
+ return r.zIndex;
445
520
  }
446
521
  }, Game = class {
447
- constructor(A, j) {
522
+ constructor(r, T) {
448
523
  this.lastTime = 0, this.scene = null, this.config = _objectSpread2({
449
524
  width: window.innerWidth,
450
525
  height: window.innerHeight
451
- }, j);
452
- let M = window.innerWidth / this.config.width, N = window.devicePixelRatio;
453
- A.width = this.config.width * M * N, A.height = this.config.height * M * N, A.style.width = `${this.config.width * M}px`, A.style.height = `${this.config.height * M}px`;
454
- let P = A.getContext("2d");
455
- if (!P) throw Error("Canvas 2D context not found");
456
- this.events = new EventSystem(), this.input = new InputSystem(A, this.events), this.renderer = new Renderer(P), P.scale(M * N, M * N);
526
+ }, T);
527
+ let O = window.innerWidth / this.config.width, k = window.devicePixelRatio;
528
+ r.width = this.config.width * O * k, r.height = this.config.height * O * k, r.style.width = `${this.config.width * O}px`, r.style.height = `${this.config.height * O}px`;
529
+ let A = r.getContext("2d");
530
+ if (!A) throw Error("Canvas 2D context not found");
531
+ this.events = new EventSystem(), this.input = new InputSystem(r, this.events), this.renderer = new Renderer(A), A.scale(O * k, O * k);
457
532
  }
458
- start(l) {
459
- this.scene = l, l._boot(this), l.registerSystem(this.input), l.registerSystem(this.events), l.create(), l.resize(this.config.width, this.config.height), window.requestAnimationFrame(this.loop.bind(this));
533
+ start(r) {
534
+ this.scene = r, r._boot(this), r.registerSystem(this.input), r.registerSystem(this.events), r.create(), r.resize(this.config.width, this.config.height), window.requestAnimationFrame(this.loop.bind(this));
460
535
  }
461
- loop(l) {
462
- let k = l - this.lastTime;
463
- this.lastTime = l, this.scene && (this.scene.update(k), this.renderer.render(this.scene)), window.requestAnimationFrame(this.loop.bind(this));
536
+ loop(r) {
537
+ let T = r - this.lastTime;
538
+ this.lastTime = r, this.scene && (this.scene.update(T), this.renderer.render(this.scene)), window.requestAnimationFrame(this.loop.bind(this));
464
539
  }
465
540
  };
466
- export { Cache, Camera, CameraController, Easings, Game, GameObject, InputEventType, InputSystem, IsoProjection, IsoStragety, Projection2D, ResourceManager, Scene, TweenManager, ZIndexStragety };
541
+ export { Cache, Camera, CameraController, DisplayList, Easings, Game, GameObject, ImageObject, InputEventType, InputSystem, IsoProjection, IsoStragety, Projection2D, ResourceManager, Scene, Text, TweenManager, ZIndexStragety };