@sepveneto/dao 0.0.1

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/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # Vue 3 + TypeScript + Vite
2
+
3
+ This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
4
+
5
+ Learn more about the recommended Project Setup and IDE Support in the [Vue Docs TypeScript Guide](https://vuejs.org/guide/typescript/overview.html#project-setup).
package/dist/dao.js ADDED
@@ -0,0 +1,466 @@
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();
11
+ }
12
+ A.restore(k);
13
+ }
14
+ }, EventSystem = class {
15
+ constructor() {
16
+ this.events = /* @__PURE__ */ new Map();
17
+ }
18
+ on(l, k) {
19
+ this.events.has(l) || this.events.set(l, /* @__PURE__ */ new Set()), this.events.get(l).add(k);
20
+ }
21
+ off(l, k) {
22
+ this.events.has(l) && this.events.get(l).delete(k);
23
+ }
24
+ emit(l, ...k) {
25
+ if (this.events.has(l)) for (let A of this.events.get(l)) A(...k);
26
+ }
27
+ };
28
+ function _typeof(l) {
29
+ "@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);
35
+ }
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;
42
+ throw TypeError("@@toPrimitive must return a primitive value.");
43
+ }
44
+ return (k === "string" ? String : Number)(l);
45
+ }
46
+ function toPropertyKey(l) {
47
+ var k = toPrimitive(l, "string");
48
+ return _typeof(k) == "symbol" ? k : k + "";
49
+ }
50
+ function _defineProperty(l, k, A) {
51
+ return (k = toPropertyKey(k)) in l ? Object.defineProperty(l, k, {
52
+ value: A,
53
+ enumerable: !0,
54
+ configurable: !0,
55
+ writable: !0
56
+ }) : l[k] = A, l;
57
+ }
58
+ function ownKeys(l, k) {
59
+ var A = Object.keys(l);
60
+ 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);
65
+ }
66
+ return A;
67
+ }
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));
75
+ });
76
+ }
77
+ return l;
78
+ }
79
+ const InputEventType = {
80
+ KEY_DOWN: Symbol("keyDown"),
81
+ KEY_UP: Symbol("keyUp"),
82
+ POINTER_DOWN: Symbol("pointerDown"),
83
+ POINTER_MOVE: Symbol("pointerMove"),
84
+ POINTER_UP: Symbol("pointerUp")
85
+ };
86
+ var InputSystem = class {
87
+ constructor(l, k) {
88
+ this.keys = /* @__PURE__ */ new Set(), this.pointer = {
89
+ x: 0,
90
+ y: 0,
91
+ dx: 0,
92
+ dy: 0,
93
+ down: !1,
94
+ justDown: !1,
95
+ justUp: !1,
96
+ 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));
102
+ }
103
+ update() {
104
+ this.pointer.justDown = !1, this.pointer.justUp = !1, this.pointer.dx = 0, this.pointer.dy = 0;
105
+ }
106
+ isKeyboardDown(l) {
107
+ return this.keys.has(l);
108
+ }
109
+ onDown(l) {
110
+ l.preventDefault();
111
+ let k = this._getPoint(l);
112
+ if (!k) {
113
+ console.warn("missing point");
114
+ return;
115
+ }
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));
117
+ }
118
+ onMove(l) {
119
+ if (!this.pointer.down) return;
120
+ l.preventDefault();
121
+ let k = this._getPoint(l);
122
+ if (!k) {
123
+ console.warn("missing point");
124
+ return;
125
+ }
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));
127
+ }
128
+ onUp() {
129
+ this.pointer.down = !1, this.pointer.justUp = !0, this.pointer.id = null, this.events.emit(InputEventType.POINTER_UP, _objectSpread2({}, this.pointer));
130
+ }
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;
138
+ return {
139
+ x: A - k.left,
140
+ y: j - k.top,
141
+ id: M
142
+ };
143
+ }
144
+ }, Camera = class {
145
+ get width() {
146
+ return this.viewport.width;
147
+ }
148
+ get height() {
149
+ return this.viewport.height;
150
+ }
151
+ constructor(l) {
152
+ this.viewport = {
153
+ x: 0,
154
+ y: 0,
155
+ width: 0,
156
+ 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;
158
+ }
159
+ setOrigin(l, k) {
160
+ this.originX = l, this.originY = k;
161
+ }
162
+ setViewport(l, k, A, j) {
163
+ this.viewport = {
164
+ x: l,
165
+ y: k,
166
+ width: A,
167
+ height: j
168
+ };
169
+ }
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));
172
+ }
173
+ restore(l) {
174
+ l.restore();
175
+ }
176
+ project(l, k, A = 0) {
177
+ let { px: j, py: M } = this.projection.project(l, k, A);
178
+ return {
179
+ px: j - this.x,
180
+ py: M - this.y
181
+ };
182
+ }
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;
186
+ }
187
+ stopFollow() {
188
+ this._followTarget = void 0;
189
+ }
190
+ update() {
191
+ 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;
194
+ }
195
+ }, CameraController = class {
196
+ constructor(l, k) {
197
+ this.speed = 300, this.camera = l, this.input = k;
198
+ }
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);
202
+ }
203
+ }, DisplayObject = class {
204
+ constructor() {
205
+ this.x = 0, this.y = 0, this.originX = .5, this.originY = .5;
206
+ }
207
+ }, 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;
210
+ }
211
+ render(l) {
212
+ l.drawImage(this.texture, this.x - this.width * this.originX, this.y - this.height * this.originY, this.width, this.height);
213
+ }
214
+ }, DisplayList = class {
215
+ constructor() {
216
+ this.list = [];
217
+ }
218
+ add(l) {
219
+ this.list.push(l);
220
+ }
221
+ render(l) {
222
+ this.list.forEach((k) => k.render(l));
223
+ }
224
+ };
225
+ function asyncGeneratorStep(l, k, A, j, M, N, P) {
226
+ try {
227
+ var F = l[N](P), I = F.value;
228
+ } catch (l) {
229
+ A(l);
230
+ return;
231
+ }
232
+ F.done ? k(I) : Promise.resolve(I).then(j, M);
233
+ }
234
+ function _asyncToGenerator(l) {
235
+ 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);
241
+ }
242
+ function F(l) {
243
+ asyncGeneratorStep(N, j, M, P, F, "throw", l);
244
+ }
245
+ P(void 0);
246
+ });
247
+ };
248
+ }
249
+ var File = class {
250
+ constructor(l, k) {
251
+ this.key = l, this.url = k;
252
+ }
253
+ }, ImageFile = class extends File {
254
+ 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;
258
+ });
259
+ }
260
+ }, Loader = class {
261
+ constructor(l) {
262
+ this.queue = [], this.textures = l;
263
+ }
264
+ image(l, k) {
265
+ return this.queue.push(new ImageFile(l, k)), this;
266
+ }
267
+ load() {
268
+ var l = this;
269
+ return _asyncToGenerator(function* () {
270
+ let k = l.queue.map((k) => k.load().then((A) => {
271
+ k instanceof ImageFile && l.textures.add(k.key, A);
272
+ }));
273
+ l.queue.length = 0, yield Promise.all(k);
274
+ })();
275
+ }
276
+ }, _ResourceManager, Cache = class {
277
+ constructor() {
278
+ this.map = /* @__PURE__ */ new Map();
279
+ }
280
+ add(l, k) {
281
+ this.map.has(l) || this.map.set(l, k);
282
+ }
283
+ get(l) {
284
+ let k = this.map.get(l);
285
+ if (!k) throw Error(`Asset ${l} not found`);
286
+ return k;
287
+ }
288
+ has(l) {
289
+ return this.map.has(l);
290
+ }
291
+ remove(l) {
292
+ this.map.delete(l);
293
+ }
294
+ clear() {
295
+ this.map.clear();
296
+ }
297
+ }, ResourceManager = class {};
298
+ _ResourceManager = ResourceManager, _ResourceManager.textures = new Cache(), _ResourceManager.loader = new Loader(_ResourceManager.textures);
299
+ var AddFactory = class {
300
+ constructor(l) {
301
+ this.rm = ResourceManager, this.displayList = l;
302
+ }
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;
306
+ }
307
+ }, SortSystem = class {
308
+ constructor(l, k) {
309
+ this.world = l, this.strategy = k;
310
+ }
311
+ 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);
313
+ }
314
+ }, 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;
319
+ }
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;
325
+ }
326
+ reset() {
327
+ this.elapsed = 0;
328
+ }
329
+ };
330
+ 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);
335
+ }
336
+ };
337
+ 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
346
+ }));
347
+ this.loop = l.loop || !1, this.onComplete = l.onComplete;
348
+ }
349
+ update(l) {
350
+ 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());
354
+ else {
355
+ var A;
356
+ this.finished = !0, (A = this.onComplete) == null || A.call(this);
357
+ }
358
+ }
359
+ }, TweenManager = class {
360
+ constructor() {
361
+ this.tweens = [];
362
+ }
363
+ add(l) {
364
+ let k = new Tween(l);
365
+ return this.tweens.push(k), k;
366
+ }
367
+ update(l) {
368
+ for (let k of this.tweens) k.update(l);
369
+ this.tweens = this.tweens.filter((l) => !l.finished);
370
+ }
371
+ }, World = class {
372
+ constructor() {
373
+ this.objects = [];
374
+ }
375
+ add(l) {
376
+ this.objects.push(l);
377
+ }
378
+ update(l) {
379
+ for (let k of this.objects) k.update(l);
380
+ }
381
+ }, 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);
384
+ }
385
+ _boot(l) {
386
+ this.input = l.input, this.events = l.events, this.config = l.config;
387
+ }
388
+ registerSystem(l) {
389
+ this.system.push(l);
390
+ }
391
+ create() {}
392
+ resize(l, k) {
393
+ this.camera.setViewport(0, 0, l, k);
394
+ }
395
+ update(l) {
396
+ for (let A of this.system) {
397
+ var k;
398
+ (k = A.update) == null || k.call(A, l);
399
+ }
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);
416
+ }
417
+ update(l) {}
418
+ }, Projection2D = class {
419
+ constructor(l = 1, k = 1) {
420
+ this.scaleX = l, this.scaleY = k;
421
+ }
422
+ project(l, k) {
423
+ return {
424
+ px: l * this.scaleX,
425
+ py: k * this.scaleY
426
+ };
427
+ }
428
+ }, IsoProjection = class {
429
+ constructor(l, k, A) {
430
+ this.tileWidth = l, this.tileHeight = k, this.zHeight = A;
431
+ }
432
+ project(l, k, A = 0) {
433
+ return {
434
+ px: (l - k) * this.tileWidth / 2,
435
+ py: (l + k) * this.tileHeight / 2 - A * this.zHeight
436
+ };
437
+ }
438
+ }, IsoStragety = class {
439
+ getKey(l) {
440
+ return l.x + l.y + l.z;
441
+ }
442
+ }, ZIndexStragety = class {
443
+ getKey(l) {
444
+ return l.zIndex;
445
+ }
446
+ }, Game = class {
447
+ constructor(A, j) {
448
+ this.lastTime = 0, this.scene = null, this.config = _objectSpread2({
449
+ width: window.innerWidth,
450
+ 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);
457
+ }
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));
460
+ }
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));
464
+ }
465
+ };
466
+ export { Cache, Camera, CameraController, Easings, Game, GameObject, InputEventType, InputSystem, IsoProjection, IsoStragety, Projection2D, ResourceManager, Scene, TweenManager, ZIndexStragety };
@@ -0,0 +1 @@
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.Dao={}))})(this,function(e){var t=class{constructor(e){this.ctx=e}render(e){let t=this.ctx,n=e.camera;t.clearRect(0,0,t.canvas.width,t.canvas.height),n.apply(t),e.displayList.render(t);for(let r of e.world.objects){let{px:e,py:i}=n.projection.project(r.x,r.y,r.z);t.save(),t.translate(e,i),r.draw(t),t.restore()}n.restore(t)}},n=class{constructor(){this.events=new Map}on(e,t){this.events.has(e)||this.events.set(e,new Set),this.events.get(e).add(t)}off(e,t){this.events.has(e)&&this.events.get(e).delete(t)}emit(e,...t){if(this.events.has(e))for(let n of this.events.get(e))n(...t)}};function r(e){"@babel/helpers - typeof";return r=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},r(e)}function i(e,t){if(r(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var i=n.call(e,t||`default`);if(r(i)!=`object`)return i;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function a(e){var t=i(e,`string`);return r(t)==`symbol`?t:t+``}function o(e,t,n){return(t=a(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function s(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function c(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?s(Object(n),!0).forEach(function(t){o(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):s(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}let l={KEY_DOWN:Symbol(`keyDown`),KEY_UP:Symbol(`keyUp`),POINTER_DOWN:Symbol(`pointerDown`),POINTER_MOVE:Symbol(`pointerMove`),POINTER_UP:Symbol(`pointerUp`)};var u=class{constructor(e,t){this.keys=new Set,this.pointer={x:0,y:0,dx:0,dy:0,down:!1,justDown:!1,justUp:!1,id:null},this.target=e,this.events=t,window.addEventListener(`keydown`,e=>{e.preventDefault(),this.keys.add(e.code),this.events.emit(l.KEY_DOWN,e)}),window.addEventListener(`keyup`,e=>{this.keys.delete(e.code),this.events.emit(l.KEY_UP,e)}),e.addEventListener(`mousedown`,this.onDown.bind(this)),e.addEventListener(`mousemove`,this.onMove.bind(this)),e.addEventListener(`mouseup`,this.onUp.bind(this)),e.addEventListener(`touchstart`,this.onDown.bind(this),{passive:!1}),e.addEventListener(`touchmove`,this.onMove.bind(this),{passive:!1}),e.addEventListener(`touchend`,this.onUp.bind(this))}update(){this.pointer.justDown=!1,this.pointer.justUp=!1,this.pointer.dx=0,this.pointer.dy=0}isKeyboardDown(e){return this.keys.has(e)}onDown(e){e.preventDefault();let t=this._getPoint(e);if(!t){console.warn(`missing point`);return}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(l.POINTER_DOWN,c({},this.pointer))}onMove(e){if(!this.pointer.down)return;e.preventDefault();let t=this._getPoint(e);if(!t){console.warn(`missing point`);return}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(l.POINTER_MOVE,c({},this.pointer))}onUp(){this.pointer.down=!1,this.pointer.justUp=!0,this.pointer.id=null,this.events.emit(l.POINTER_UP,c({},this.pointer))}_getPoint(e){let t=this.target.getBoundingClientRect(),n,r,i=`mouse`;if(e instanceof TouchEvent){let t=e.touches[0]||e.changedTouches[0];if(!t)return;n=t.clientX,r=t.clientY,i=t.identifier}else n=e.clientX,r=e.clientY;return{x:n-t.left,y:r-t.top,id:i}}},d=class{get width(){return this.viewport.width}get height(){return this.viewport.height}constructor(e){this.viewport={x:0,y:0,width:0,height:0},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=e}setOrigin(e,t){this.originX=e,this.originY=t}setViewport(e,t,n,r){this.viewport={x:e,y:t,width:n,height:r}}apply(e){e.save(),e.translate(this.originX*this.viewport.width,this.originY*this.viewport.height),e.scale(this.zoom,this.zoom),e.translate(-Math.round(this.x),-Math.round(this.y))}restore(e){e.restore()}project(e,t,n=0){let{px:r,py:i}=this.projection.project(e,t,n);return{px:r-this.x,py:i-this.y}}follow(e,t){var n,r,i;this._followTarget=e,this._followLerp=(n=t==null?void 0:t.lerp)==null?1:n,this._offsetX=(r=t==null?void 0:t.offsetX)==null?0:r,this._offsetY=(i=t==null?void 0:t.offsetY)==null?0:i}stopFollow(){this._followTarget=void 0}update(){if(!this._followTarget)return;let{x:e,y:t,z:n}=this._followTarget,{px:r,py:i}=this.project(e,t,n),a=r+this._offsetX,o=i+this._offsetY;this.x+=a*this._followLerp,this.y+=o*this._followLerp}},f=class{constructor(e,t){this.speed=300,this.camera=e,this.input=t}update(e){let t=this.speed*e/1e3;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)}},p=class{constructor(){this.x=0,this.y=0,this.originX=.5,this.originY=.5}},m=class extends p{constructor(e,t,n,r=1){super(),this.resolution=1,this.x=e,this.y=t,this.texture=n,this.resolution=r,this.width=n.width/r,this.height=n.height/r}render(e){e.drawImage(this.texture,this.x-this.width*this.originX,this.y-this.height*this.originY,this.width,this.height)}},h=class{constructor(){this.list=[]}add(e){this.list.push(e)}render(e){this.list.forEach(t=>t.render(e))}};function g(e,t,n,r,i,a,o){try{var s=e[a](o),c=s.value}catch(e){n(e);return}s.done?t(c):Promise.resolve(c).then(r,i)}function _(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var a=e.apply(t,n);function o(e){g(a,r,i,o,s,`next`,e)}function s(e){g(a,r,i,o,s,`throw`,e)}o(void 0)})}}var v=class{constructor(e,t){this.key=e,this.url=t}},y=class extends v{load(){return new Promise((e,t)=>{let n=new Image;n.onload=()=>e(n),n.onerror=()=>t(Error(`Failed to load ${this.url}`)),n.src=this.url})}},b=class{constructor(e){this.queue=[],this.textures=e}image(e,t){return this.queue.push(new y(e,t)),this}load(){var e=this;return _(function*(){let t=e.queue.map(t=>t.load().then(n=>{t instanceof y&&e.textures.add(t.key,n)}));e.queue.length=0,yield Promise.all(t)})()}},x,S=class{constructor(){this.map=new Map}add(e,t){this.map.has(e)||this.map.set(e,t)}get(e){let t=this.map.get(e);if(!t)throw Error(`Asset ${e} not found`);return t}has(e){return this.map.has(e)}remove(e){this.map.delete(e)}clear(){this.map.clear()}},C=class{};x=C,x.textures=new S,x.loader=new b(x.textures);var w=class{constructor(e){this.rm=C,this.displayList=e}image(e,t,n,r=1){let i=new m(e,t,this.rm.textures.get(n),r);return this.displayList.add(i),i}},T=class{constructor(e,t){this.world=e,this.strategy=t}update(){this.world.objects.sort((e,t)=>this.strategy.getKey(e)-this.strategy.getKey(t)),this.world.objects.sort((e,t)=>e.zIndex-t.zIndex)}},E=class{constructor(e){this.elapsed=0,this.target=e.target,this.key=e.key,this.start=e.target[e.key],this.end=e.to,this.duration=e.duration,this.delay=e.delay||0;let t=e.easing||`Linear`;typeof t==`string`?this.easing=D[t]:this.easing=t}update(e){if(this.delay>0)return this.delay-=e,!1;this.elapsed+=e;let t=Math.min(this.elapsed/this.duration,1),n=this.easing(t);return this.target[this.key]=this.start+(this.end-this.start)*n,t===1?(this.target[this.key]=this.end,!0):!1}reset(){this.elapsed=0}};let D={Linear:e=>e,EaseOutBack:e=>{let t=3.70158,n=e-1;return 1+n*n*((t+1)*n+t)}};var O=class{constructor(e){for(let t in this.datas=[],this.finished=!1,this.loop=!1,e.to)this.datas.push(new E({target:e.target,key:t,to:e.to[t],duration:e.duration,easing:e.easing,delay:e.delay}));this.loop=e.loop||!1,this.onComplete=e.onComplete}update(e){if(this.finished)return;let t=!0;for(let n of this.datas)n.update(e)||(t=!1);if(t)if(this.loop)this.datas.forEach(e=>e.reset());else{var n;this.finished=!0,(n=this.onComplete)==null||n.call(this)}}},k=class{constructor(){this.tweens=[]}add(e){let t=new O(e);return this.tweens.push(t),t}update(e){for(let t of this.tweens)t.update(e);this.tweens=this.tweens.filter(e=>!e.finished)}},A=class{constructor(){this.objects=[]}add(e){this.objects.push(e)}update(e){for(let t of this.objects)t.update(e)}},j=class{constructor(e,t){this.world=new A,this.system=[],this.displayList=new h,this.add=new w(this.displayList),this.camera=new d(e),this.tween=new k,this.system.push(new T(this.world,t)),this.system.push(this.tween)}_boot(e){this.input=e.input,this.events=e.events,this.config=e.config}registerSystem(e){this.system.push(e)}create(){}resize(e,t){this.camera.setViewport(0,0,e,t)}update(e){for(let n of this.system){var t;(t=n.update)==null||t.call(n,e)}this.camera.update(),this.world.update(e)}},M=class{constructor(e,t,n=0){this.width=0,this.height=0,this.zIndex=0,this.originX=0,this.originY=0,this.rotation=0,this.x=e,this.y=t,this.z=n}setOrigin(e,t){this.originX=e,this.originY=t}draw(e){e.save(),e.rotate(this.rotation),this.render(e),e.restore()}render(e){if(!this.texture)return;let t=this.width||this.texture.width,n=this.height||this.texture.height;e.drawImage(this.texture,-t*this.originX,-n*this.originY,t,n)}update(e){}},N=class{constructor(e=1,t=1){this.scaleX=e,this.scaleY=t}project(e,t){return{px:e*this.scaleX,py:t*this.scaleY}}},P=class{constructor(e,t,n){this.tileWidth=e,this.tileHeight=t,this.zHeight=n}project(e,t,n=0){return{px:(e-t)*this.tileWidth/2,py:(e+t)*this.tileHeight/2-n*this.zHeight}}},F=class{getKey(e){return e.x+e.y+e.z}},I=class{getKey(e){return e.zIndex}},L=class{constructor(e,r){this.lastTime=0,this.scene=null,this.config=c({width:window.innerWidth,height:window.innerHeight},r);let i=window.innerWidth/this.config.width,a=window.devicePixelRatio;e.width=this.config.width*i*a,e.height=this.config.height*i*a,e.style.width=`${this.config.width*i}px`,e.style.height=`${this.config.height*i}px`;let o=e.getContext(`2d`);if(!o)throw Error(`Canvas 2D context not found`);this.events=new n,this.input=new u(e,this.events),this.renderer=new t(o),o.scale(i*a,i*a)}start(e){this.scene=e,e._boot(this),e.registerSystem(this.input),e.registerSystem(this.events),e.create(),e.resize(this.config.width,this.config.height),window.requestAnimationFrame(this.loop.bind(this))}loop(e){let t=e-this.lastTime;this.lastTime=e,this.scene&&(this.scene.update(t),this.renderer.render(this.scene)),window.requestAnimationFrame(this.loop.bind(this))}};e.Cache=S,e.Camera=d,e.CameraController=f,e.Easings=D,e.Game=L,e.GameObject=M,e.InputEventType=l,e.InputSystem=u,e.IsoProjection=P,e.IsoStragety=F,e.Projection2D=N,e.ResourceManager=C,e.Scene=j,e.TweenManager=k,e.ZIndexStragety=I});
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@sepveneto/dao",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "main": "./dist/dao.umd.cjs",
9
+ "module": "./dist/dao.js",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/dao.js",
13
+ "require": "./dist/dao.umd.cjs"
14
+ }
15
+ },
16
+ "devDependencies": {
17
+ "vue": "^3.5.24",
18
+ "@types/node": "^24.10.1",
19
+ "@vitejs/plugin-vue": "^6.0.1",
20
+ "@vue/tsconfig": "^0.8.1",
21
+ "bumpp": "^10.3.2",
22
+ "typescript": "~5.9.3",
23
+ "vite": "npm:rolldown-vite@7.2.5",
24
+ "vue-tsc": "^3.1.4"
25
+ },
26
+ "scripts": {
27
+ "dev": "vite",
28
+ "build": "vite build",
29
+ "release": "bumpp",
30
+ "preview": "vite preview"
31
+ }
32
+ }