@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/Camera.d.ts +46 -0
- package/dist/Container.d.ts +17 -0
- package/dist/Display.d.ts +60 -0
- package/dist/Factory.d.ts +7 -0
- package/dist/GameObject.d.ts +17 -0
- package/dist/Loader.d.ts +18 -0
- package/dist/Projection.d.ts +25 -0
- package/dist/Renderer.d.ts +6 -0
- package/dist/ResourceManager.d.ts +13 -0
- package/dist/Scene.d.ts +27 -0
- package/dist/SortStragety.d.ts +10 -0
- package/dist/World.d.ts +7 -0
- package/dist/dao.cjs +2 -0
- package/dist/dao.d.ts +2 -0
- package/dist/dao.js +329 -254
- package/dist/main.d.ts +28 -0
- package/dist/system/EventSystem.d.ts +8 -0
- package/dist/system/InputSystem.d.ts +37 -0
- package/dist/system/SortSystem.d.ts +8 -0
- package/dist/system/TweenManager.d.ts +49 -0
- package/dist/utils.d.ts +5 -0
- package/package.json +18 -10
- package/dist/dao.umd.cjs +0 -1
package/dist/dao.js
CHANGED
|
@@ -1,80 +1,134 @@
|
|
|
1
|
-
var
|
|
2
|
-
constructor(
|
|
3
|
-
this.
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
66
|
+
D.restore(E);
|
|
13
67
|
}
|
|
14
68
|
}, EventSystem = class {
|
|
15
69
|
constructor() {
|
|
16
70
|
this.events = /* @__PURE__ */ new Map();
|
|
17
71
|
}
|
|
18
|
-
on(
|
|
19
|
-
this.events.has(
|
|
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(
|
|
22
|
-
this.events.has(
|
|
75
|
+
off(r, T) {
|
|
76
|
+
this.events.has(r) && this.events.get(r).delete(T);
|
|
23
77
|
}
|
|
24
|
-
emit(
|
|
25
|
-
if (this.events.has(
|
|
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(
|
|
82
|
+
function _typeof(r) {
|
|
29
83
|
"@babel/helpers - typeof";
|
|
30
|
-
return _typeof = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(
|
|
31
|
-
return typeof
|
|
32
|
-
} : function(
|
|
33
|
-
return
|
|
34
|
-
}, _typeof(
|
|
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(
|
|
37
|
-
if (_typeof(
|
|
38
|
-
var
|
|
39
|
-
if (
|
|
40
|
-
var
|
|
41
|
-
if (_typeof(
|
|
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 (
|
|
98
|
+
return (T === "string" ? String : Number)(r);
|
|
45
99
|
}
|
|
46
|
-
function toPropertyKey(
|
|
47
|
-
var
|
|
48
|
-
return _typeof(
|
|
100
|
+
function toPropertyKey(r) {
|
|
101
|
+
var T = toPrimitive(r, "string");
|
|
102
|
+
return _typeof(T) == "symbol" ? T : T + "";
|
|
49
103
|
}
|
|
50
|
-
function _defineProperty(
|
|
51
|
-
return (
|
|
52
|
-
value:
|
|
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
|
-
}) :
|
|
110
|
+
}) : r[T] = E, r;
|
|
57
111
|
}
|
|
58
|
-
function ownKeys(
|
|
59
|
-
var
|
|
112
|
+
function ownKeys(r, T) {
|
|
113
|
+
var E = Object.keys(r);
|
|
60
114
|
if (Object.getOwnPropertySymbols) {
|
|
61
|
-
var
|
|
62
|
-
|
|
63
|
-
return Object.getOwnPropertyDescriptor(
|
|
64
|
-
})),
|
|
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
|
|
120
|
+
return E;
|
|
67
121
|
}
|
|
68
|
-
function _objectSpread2(
|
|
69
|
-
for (var
|
|
70
|
-
var
|
|
71
|
-
|
|
72
|
-
_defineProperty(
|
|
73
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(
|
|
74
|
-
Object.defineProperty(
|
|
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
|
|
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(
|
|
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 =
|
|
98
|
-
|
|
99
|
-
}), window.addEventListener("keyup", (
|
|
100
|
-
this.keys.delete(
|
|
101
|
-
}),
|
|
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(
|
|
107
|
-
return this.keys.has(
|
|
160
|
+
isKeyboardDown(r) {
|
|
161
|
+
return this.keys.has(r);
|
|
108
162
|
}
|
|
109
|
-
onDown(
|
|
110
|
-
|
|
111
|
-
let
|
|
112
|
-
if (!
|
|
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 =
|
|
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(
|
|
172
|
+
onMove(r) {
|
|
119
173
|
if (!this.pointer.down) return;
|
|
120
|
-
|
|
121
|
-
let
|
|
122
|
-
if (!
|
|
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 +=
|
|
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(
|
|
132
|
-
let
|
|
133
|
-
if (
|
|
134
|
-
let
|
|
135
|
-
if (!
|
|
136
|
-
|
|
137
|
-
} else
|
|
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:
|
|
140
|
-
y:
|
|
141
|
-
id:
|
|
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(
|
|
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 =
|
|
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(
|
|
160
|
-
this.originX =
|
|
213
|
+
setOrigin(r, T) {
|
|
214
|
+
this.originX = r, this.originY = T;
|
|
161
215
|
}
|
|
162
|
-
setViewport(
|
|
216
|
+
setViewport(r, T, E, D) {
|
|
163
217
|
this.viewport = {
|
|
164
|
-
x:
|
|
165
|
-
y:
|
|
166
|
-
width:
|
|
167
|
-
height:
|
|
218
|
+
x: r,
|
|
219
|
+
y: T,
|
|
220
|
+
width: E,
|
|
221
|
+
height: D
|
|
168
222
|
};
|
|
169
223
|
}
|
|
170
|
-
apply(
|
|
171
|
-
|
|
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(
|
|
174
|
-
|
|
227
|
+
restore(r) {
|
|
228
|
+
r.restore();
|
|
175
229
|
}
|
|
176
|
-
project(
|
|
177
|
-
let { px:
|
|
230
|
+
project(r, T, E = 0) {
|
|
231
|
+
let { px: D, py: O } = this.projection.project(r, T, E);
|
|
178
232
|
return {
|
|
179
|
-
px:
|
|
180
|
-
py:
|
|
233
|
+
px: D - this.x,
|
|
234
|
+
py: O - this.y
|
|
181
235
|
};
|
|
182
236
|
}
|
|
183
|
-
follow(
|
|
184
|
-
var
|
|
185
|
-
this._followTarget =
|
|
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:
|
|
193
|
-
this.x +=
|
|
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(
|
|
197
|
-
this.speed = 300, this.camera =
|
|
250
|
+
constructor(r, T) {
|
|
251
|
+
this.speed = 300, this.camera = r, this.input = T;
|
|
198
252
|
}
|
|
199
|
-
update(
|
|
200
|
-
let
|
|
201
|
-
this.input.isKeyboardDown("ArrowUp") && (this.camera.y +=
|
|
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(
|
|
209
|
-
super(), this.resolution = 1, this.x =
|
|
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(
|
|
212
|
-
|
|
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(
|
|
219
|
-
this.list.push(
|
|
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(
|
|
222
|
-
this.
|
|
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(
|
|
316
|
+
function asyncGeneratorStep(r, T, E, D, O, k, A) {
|
|
226
317
|
try {
|
|
227
|
-
var
|
|
228
|
-
} catch (
|
|
229
|
-
|
|
318
|
+
var j = r[k](A), M = j.value;
|
|
319
|
+
} catch (r) {
|
|
320
|
+
E(r);
|
|
230
321
|
return;
|
|
231
322
|
}
|
|
232
|
-
|
|
323
|
+
j.done ? T(M) : Promise.resolve(M).then(D, O);
|
|
233
324
|
}
|
|
234
|
-
function _asyncToGenerator(
|
|
325
|
+
function _asyncToGenerator(r) {
|
|
235
326
|
return function() {
|
|
236
|
-
var
|
|
237
|
-
return new Promise(function(
|
|
238
|
-
var
|
|
239
|
-
function
|
|
240
|
-
asyncGeneratorStep(
|
|
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
|
|
243
|
-
asyncGeneratorStep(
|
|
333
|
+
function j(r) {
|
|
334
|
+
asyncGeneratorStep(k, D, O, A, j, "throw", r);
|
|
244
335
|
}
|
|
245
|
-
|
|
336
|
+
A(void 0);
|
|
246
337
|
});
|
|
247
338
|
};
|
|
248
339
|
}
|
|
249
340
|
var File = class {
|
|
250
|
-
constructor(
|
|
251
|
-
this.key =
|
|
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((
|
|
256
|
-
let
|
|
257
|
-
|
|
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(
|
|
262
|
-
this.queue = [], this.textures =
|
|
352
|
+
constructor(r) {
|
|
353
|
+
this.queue = [], this.textures = r;
|
|
263
354
|
}
|
|
264
|
-
image(
|
|
265
|
-
return this.queue.push(new ImageFile(
|
|
355
|
+
image(r, T) {
|
|
356
|
+
return this.queue.push(new ImageFile(r, T)), this;
|
|
266
357
|
}
|
|
267
358
|
load() {
|
|
268
|
-
var
|
|
359
|
+
var r = this;
|
|
269
360
|
return _asyncToGenerator(function* () {
|
|
270
|
-
let
|
|
271
|
-
|
|
361
|
+
let T = r.queue.map((T) => T.load().then((E) => {
|
|
362
|
+
T instanceof ImageFile && r.textures.add(T.key, E);
|
|
272
363
|
}));
|
|
273
|
-
|
|
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(
|
|
281
|
-
this.map.has(
|
|
371
|
+
add(r, T) {
|
|
372
|
+
this.map.has(r) || this.map.set(r, T);
|
|
282
373
|
}
|
|
283
|
-
get(
|
|
284
|
-
let
|
|
285
|
-
if (!
|
|
286
|
-
return
|
|
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(
|
|
289
|
-
return this.map.has(
|
|
379
|
+
has(r) {
|
|
380
|
+
return this.map.has(r);
|
|
290
381
|
}
|
|
291
|
-
remove(
|
|
292
|
-
this.map.delete(
|
|
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(
|
|
301
|
-
this.rm = ResourceManager, this.displayList =
|
|
391
|
+
constructor(r) {
|
|
392
|
+
this.rm = ResourceManager, this.displayList = r;
|
|
302
393
|
}
|
|
303
|
-
image(
|
|
304
|
-
let
|
|
305
|
-
return this.displayList.add(
|
|
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(
|
|
309
|
-
this.world =
|
|
399
|
+
constructor(r, T) {
|
|
400
|
+
this.world = r, this.strategy = T;
|
|
310
401
|
}
|
|
311
402
|
update() {
|
|
312
|
-
this.world.objects.sort((
|
|
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(
|
|
316
|
-
this.elapsed = 0, this.target =
|
|
317
|
-
let
|
|
318
|
-
typeof
|
|
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(
|
|
321
|
-
if (this.delay > 0) return this.delay -=
|
|
322
|
-
this.elapsed +=
|
|
323
|
-
let
|
|
324
|
-
return this.target[this.key] = this.start + (this.end - this.start) *
|
|
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: (
|
|
332
|
-
EaseOutBack: (
|
|
333
|
-
let
|
|
334
|
-
return 1 +
|
|
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(
|
|
339
|
-
for (let
|
|
340
|
-
target:
|
|
341
|
-
key:
|
|
342
|
-
to:
|
|
343
|
-
duration:
|
|
344
|
-
easing:
|
|
345
|
-
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 =
|
|
438
|
+
this.loop = r.loop || !1, this.onComplete = r.onComplete;
|
|
348
439
|
}
|
|
349
|
-
update(
|
|
440
|
+
update(r) {
|
|
350
441
|
if (this.finished) return;
|
|
351
|
-
let
|
|
352
|
-
for (let
|
|
353
|
-
if (
|
|
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
|
|
356
|
-
this.finished = !0, (
|
|
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(
|
|
364
|
-
let
|
|
365
|
-
return this.tweens.push(
|
|
454
|
+
add(r) {
|
|
455
|
+
let T = new Tween(r);
|
|
456
|
+
return this.tweens.push(T), T;
|
|
366
457
|
}
|
|
367
|
-
update(
|
|
368
|
-
for (let
|
|
369
|
-
this.tweens = this.tweens.filter((
|
|
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(
|
|
376
|
-
this.objects.push(
|
|
466
|
+
add(r) {
|
|
467
|
+
this.objects.push(r);
|
|
377
468
|
}
|
|
378
|
-
update(
|
|
379
|
-
for (let
|
|
469
|
+
update(r) {
|
|
470
|
+
for (let T of this.objects) T.update(r);
|
|
380
471
|
}
|
|
381
472
|
}, Scene = class {
|
|
382
|
-
constructor(
|
|
383
|
-
this.world = new World(), this.system = [], this.displayList = new DisplayList(), this.add = new AddFactory(this.displayList), this.camera = new Camera(
|
|
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(
|
|
386
|
-
this.input =
|
|
476
|
+
_boot(r) {
|
|
477
|
+
this.input = r.input, this.events = r.events, this.config = r.config;
|
|
387
478
|
}
|
|
388
|
-
registerSystem(
|
|
389
|
-
this.system.push(
|
|
479
|
+
registerSystem(r) {
|
|
480
|
+
this.system.push(r);
|
|
390
481
|
}
|
|
391
482
|
create() {}
|
|
392
|
-
resize(
|
|
393
|
-
this.camera.setViewport(0, 0,
|
|
483
|
+
resize(r, T) {
|
|
484
|
+
this.camera.setViewport(0, 0, r, T);
|
|
394
485
|
}
|
|
395
|
-
update(
|
|
396
|
-
for (let
|
|
397
|
-
var
|
|
398
|
-
(
|
|
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(
|
|
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(
|
|
420
|
-
this.scaleX =
|
|
494
|
+
constructor(r = 1, T = 1) {
|
|
495
|
+
this.scaleX = r, this.scaleY = T;
|
|
421
496
|
}
|
|
422
|
-
project(
|
|
497
|
+
project(r, T) {
|
|
423
498
|
return {
|
|
424
|
-
px:
|
|
425
|
-
py:
|
|
499
|
+
px: r * this.scaleX,
|
|
500
|
+
py: T * this.scaleY
|
|
426
501
|
};
|
|
427
502
|
}
|
|
428
503
|
}, IsoProjection = class {
|
|
429
|
-
constructor(
|
|
430
|
-
this.tileWidth =
|
|
504
|
+
constructor(r, T, E) {
|
|
505
|
+
this.tileWidth = r, this.tileHeight = T, this.zHeight = E;
|
|
431
506
|
}
|
|
432
|
-
project(
|
|
507
|
+
project(r, T, E = 0) {
|
|
433
508
|
return {
|
|
434
|
-
px: (
|
|
435
|
-
py: (
|
|
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(
|
|
440
|
-
return
|
|
514
|
+
getKey(r) {
|
|
515
|
+
return r.x + r.y + r.z;
|
|
441
516
|
}
|
|
442
517
|
}, ZIndexStragety = class {
|
|
443
|
-
getKey(
|
|
444
|
-
return
|
|
518
|
+
getKey(r) {
|
|
519
|
+
return r.zIndex;
|
|
445
520
|
}
|
|
446
521
|
}, Game = class {
|
|
447
|
-
constructor(
|
|
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
|
-
},
|
|
452
|
-
let
|
|
453
|
-
|
|
454
|
-
let
|
|
455
|
-
if (!
|
|
456
|
-
this.events = new EventSystem(), this.input = new InputSystem(
|
|
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(
|
|
459
|
-
this.scene =
|
|
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(
|
|
462
|
-
let
|
|
463
|
-
this.lastTime =
|
|
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 };
|