evotars 0.0.3 → 0.0.5

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/evotars.js CHANGED
@@ -1,12 +1,13 @@
1
- var M = Object.defineProperty;
2
- var k = (a, t, e) => t in a ? M(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
3
- var s = (a, t, e) => (k(a, typeof t != "symbol" ? t + "" : t, e), e);
4
- import * as h from "pixi.js";
5
- import D from "tinycolor2";
6
- import * as y from "@tweenjs/tween.js";
7
- import { Tween as S } from "@tweenjs/tween.js";
1
+ var I = Object.defineProperty;
2
+ var z = (r, t, e) => t in r ? I(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var s = (r, t, e) => (z(r, typeof t != "symbol" ? t + "" : t, e), e);
4
+ import * as c from "pixi.js";
5
+ import { Assets as R, Spritesheet as M, AnimatedSprite as P, SCALE_MODES as k } from "pixi.js";
6
+ import F from "tinycolor2";
7
+ import * as g from "@tweenjs/tween.js";
8
+ import { Tween as T } from "@tweenjs/tween.js";
8
9
  const m = 0.02 * 1e3;
9
- class w {
10
+ class f {
10
11
  constructor(t = 0, e) {
11
12
  s(this, "isCompleted", !1);
12
13
  this.current = t, this.onComplete = e;
@@ -16,12 +17,12 @@ class w {
16
17
  this.isCompleted || (this.current -= t, this.current < 0 && (this.isCompleted = !0, (e = this.onComplete) == null || e.call(this)));
17
18
  }
18
19
  }
19
- class P {
20
+ class V {
20
21
  constructor() {
21
22
  s(this, "timers", []);
22
23
  }
23
24
  add(t, e) {
24
- this.timers.push(new w(t, e));
25
+ this.timers.push(new f(t, e));
25
26
  }
26
27
  tick(t = m) {
27
28
  const e = [];
@@ -30,132 +31,14 @@ class P {
30
31
  this.timers = e;
31
32
  }
32
33
  }
33
- const v = new P();
34
- class z {
35
- constructor() {
36
- s(this, "isLoaded", !1);
37
- s(this, "sheets", {});
38
- }
39
- async load(t) {
40
- this.isLoaded || (this.isLoaded = !0, await h.Assets.init({ manifest: t }), this.sheets = await h.Assets.loadBundle("main"), await h.Assets.loadBundle("fonts"));
41
- }
42
- }
43
- const T = new z(), F = (a) => a.name == "jump", L = (a) => a.name == "color", V = (a) => a.name == "grow", j = (a) => a.name == "dash", C = {
44
- sprites: {
45
- sith: {
46
- name: "sith",
47
- w: 32,
48
- h: 32,
49
- collider: {
50
- x: 8,
51
- y: 5,
52
- w: 16,
53
- h: 20
54
- },
55
- pivot: {
56
- x: 0,
57
- y: 9
58
- }
59
- },
60
- agent: {
61
- name: "agent",
62
- w: 32,
63
- h: 32,
64
- collider: {
65
- x: 8,
66
- y: 7,
67
- w: 16,
68
- h: 18
69
- },
70
- pivot: {
71
- x: 0,
72
- y: 9
73
- }
74
- },
75
- nerd: {
76
- name: "nerd",
77
- w: 32,
78
- h: 32,
79
- collider: {
80
- x: 8,
81
- y: 7,
82
- w: 16,
83
- h: 18
84
- },
85
- pivot: {
86
- x: 0,
87
- y: 9
88
- }
89
- },
90
- girl: {
91
- name: "girl",
92
- w: 32,
93
- h: 32,
94
- collider: {
95
- x: 8,
96
- y: 5,
97
- w: 16,
98
- h: 20
99
- },
100
- pivot: {
101
- x: 0,
102
- y: 9
103
- }
104
- },
105
- cat: {
106
- name: "cat",
107
- w: 32,
108
- h: 32,
109
- collider: {
110
- x: 8,
111
- y: 4,
112
- w: 16,
113
- h: 21
114
- },
115
- pivot: {
116
- x: 0,
117
- y: 9
118
- }
119
- },
120
- senior: {
121
- name: "senior",
122
- w: 32,
123
- h: 32,
124
- collider: {
125
- x: 8,
126
- y: 4,
127
- w: 16,
128
- h: 21
129
- },
130
- pivot: {
131
- x: 0,
132
- y: 9
133
- }
134
- },
135
- sponge: {
136
- name: "sponge",
137
- w: 32,
138
- h: 32,
139
- collider: {
140
- x: 8,
141
- y: 7,
142
- w: 16,
143
- h: 18
144
- },
145
- pivot: {
146
- x: 0,
147
- y: 9
148
- }
149
- }
150
- }
151
- };
152
- class O {
34
+ const v = new V(), L = (r) => r.name == "jump", j = (r) => r.name == "color", J = (r) => r.name == "grow", W = (r) => r.name == "dash", O = (r) => r.name == "sprite";
35
+ class U {
153
36
  constructor() {
154
37
  s(this, "assets", {});
155
38
  }
156
- async init(t) {
39
+ async initialize(t) {
157
40
  this.assets = Object.fromEntries(
158
- Array.from(Object.entries(t)).map(([e, i]) => [e, new Audio(i)])
41
+ Array.from(Object.entries(t ?? {})).map(([e, i]) => [e, new Audio(i.src)])
159
42
  );
160
43
  }
161
44
  play(t) {
@@ -163,43 +46,62 @@ class O {
163
46
  e && (e.volume = 0.2, e.pause(), e.currentTime = 0, e.play());
164
47
  }
165
48
  }
166
- const E = new O();
167
- var b = /* @__PURE__ */ ((a) => (a.Body = "Body", a.Eyes = "Eyes", a))(b || {}), l = /* @__PURE__ */ ((a) => (a.Idle = "Idle", a.Jump = "Jump", a.Fall = "Fall", a.Land = "Land", a.Run = "Run", a.Die = "Die", a))(l || {});
168
- class J {
169
- createLayerAnimatedSprites(t, e, i) {
170
- const n = e.data.meta.layers;
171
- if (n) {
172
- const o = Object.fromEntries(
173
- n.map((r) => [r.name, []])
174
- );
175
- for (let r = i.from; r <= i.to; r++) {
176
- const c = r.toString();
177
- for (const d in o) {
178
- const g = t + "_" + d + "_" + c, I = e.textures[g], R = e.data.frames[g].duration;
179
- o[d].push({ texture: I, time: R });
180
- }
49
+ const A = new U();
50
+ var d = /* @__PURE__ */ ((r) => (r.Idle = "Idle", r.Jump = "Jump", r.Fall = "Fall", r.Land = "Land", r.Run = "Run", r.Die = "Die", r))(d || {});
51
+ class X {
52
+ constructor() {
53
+ s(this, "spriteLoaderFn");
54
+ s(this, "sprites", {});
55
+ }
56
+ initialize(t) {
57
+ this.spriteLoaderFn = t;
58
+ }
59
+ async getSpriteData(t) {
60
+ const e = await this.spriteLoaderFn(t);
61
+ if (!e)
62
+ return;
63
+ if (this.sprites[t])
64
+ return this.sprites[t];
65
+ const i = await R.load(e.image), n = new M({
66
+ texture: i,
67
+ data: e.sprite
68
+ });
69
+ return await n.parse(), this.sprites[t] = {
70
+ sheet: n,
71
+ data: {
72
+ ...e.data,
73
+ scale: e.data.scale ?? 1
181
74
  }
182
- return Object.entries(o).map((r) => {
183
- const c = new h.AnimatedSprite(r[1]);
184
- return c.texture.baseTexture.scaleMode = h.SCALE_MODES.NEAREST, { layer: r[0], sprite: c };
185
- });
186
- }
187
- throw Error("Sprite sheet doesn't have layers");
75
+ }, this.sprites[t];
188
76
  }
189
- createTagAnimatedSprites(t) {
77
+ getAnimatedSprites(t) {
190
78
  if (!t)
191
79
  throw Error("Sheet is not defined");
192
- const e = T.sheets[t];
193
- return (e.data.meta.frameTags ?? []).reduce(
194
- (i, n) => (n && n.name && (i[n.name] = this.createLayerAnimatedSprites(t, e, n)), i),
195
- {}
196
- );
80
+ if (!this.sprites[t])
81
+ throw Error("Sprite is not loaded");
82
+ const e = this.sprites[t].data, i = this.sprites[t].sheet, n = {};
83
+ for (const a of i.data.meta.frameTags ?? []) {
84
+ if (!i.data.meta.layers)
85
+ throw Error("Layers are not defined");
86
+ const o = {};
87
+ for (const h of i.data.meta.layers) {
88
+ const p = [];
89
+ for (let u = a.from; u <= a.to; u++) {
90
+ const E = u.toString(), C = e.name + "_" + h.name + "_" + E, b = i.textures[C], D = i.data.frames[C].duration;
91
+ p.push({ texture: b, time: D });
92
+ }
93
+ const x = new P(p);
94
+ x.texture.baseTexture.scaleMode = k.NEAREST, o[h.name] = x;
95
+ }
96
+ a.name && (n[a.name] = o);
97
+ }
98
+ return n;
197
99
  }
198
100
  }
199
- const A = new J();
200
- class W {
101
+ const S = new X();
102
+ class N {
201
103
  constructor() {
202
- s(this, "container", new h.Container());
104
+ s(this, "container", new c.Container());
203
105
  s(this, "emotes", []);
204
106
  s(this, "moveSpeed", 50);
205
107
  s(this, "alphaSpeed", 1);
@@ -207,12 +109,12 @@ class W {
207
109
  s(this, "timer");
208
110
  }
209
111
  add(t) {
210
- const e = h.Sprite.from(t);
112
+ const e = c.Sprite.from(t);
211
113
  e.anchor.set(0.5, 0.5), e.scale.set(0, 0), this.emotes.push(e);
212
114
  }
213
115
  update(t) {
214
116
  var e;
215
- (e = this.timer) == null || e.tick(), (!this.timer || this.timer.isCompleted) && this.emotes.length > 0 && (this.timer = new w(2e3, () => {
117
+ (e = this.timer) == null || e.tick(), (!this.timer || this.timer.isCompleted) && this.emotes.length > 0 && (this.timer = new f(2e3, () => {
216
118
  const i = this.emotes.shift();
217
119
  i && this.container.addChild(i);
218
120
  })), this.container.position.x = t.position.x ?? this.container.position.x, this.container.position.y = t.position.y ?? this.container.position.y;
@@ -222,9 +124,9 @@ class W {
222
124
  }
223
125
  class _ {
224
126
  constructor(t) {
225
- s(this, "container", new h.Container());
226
- s(this, "animated", new h.Container());
227
- s(this, "text", new h.Text(void 0, {
127
+ s(this, "container", new c.Container());
128
+ s(this, "animated", new c.Container());
129
+ s(this, "text", new c.Text(void 0, {
228
130
  fontFamily: "Rubik",
229
131
  fontSize: 20,
230
132
  fill: 2236962,
@@ -245,18 +147,18 @@ class _ {
245
147
  this.beforeShow = t, this.container.addChild(this.animated), this.text.anchor.set(0.5, 1), this.text.position.set(0, -this.padding);
246
148
  }
247
149
  trim(t) {
248
- const e = h.TextMetrics.measureText(t.text, t.style);
150
+ const e = c.TextMetrics.measureText(t.text, t.style);
249
151
  return e.lines.length > 4 ? e.lines.slice(0, 4).join(" ").slice(0, -3) + "..." : t.text;
250
152
  }
251
153
  update(t) {
252
- var i, n, o, r, c;
253
- if ((i = this.timer) == null || i.tick(), (n = this.showTween) == null || n.update(), (o = this.hideTween) == null || o.update(), this.isChecking && this.messageQueue.length > 0) {
154
+ var i, n, a, o, h;
155
+ if ((i = this.timer) == null || i.tick(), (n = this.showTween) == null || n.update(), (a = this.hideTween) == null || a.update(), this.isChecking && this.messageQueue.length > 0) {
254
156
  this.isChecking = !1;
255
- const d = this.messageQueue.shift();
256
- d && (this.beforeShow(), this.show(d));
157
+ const p = this.messageQueue.shift();
158
+ p && (this.beforeShow(), this.show(p));
257
159
  }
258
160
  this.container.position.x = t.position.x ?? this.container.position.x, this.container.position.y = t.position.y ?? this.container.position.y;
259
- const e = ((r = this.showTween) == null ? void 0 : r.isPlaying()) || ((c = this.hideTween) == null ? void 0 : c.isPlaying());
161
+ const e = ((o = this.showTween) == null ? void 0 : o.isPlaying()) || ((h = this.hideTween) == null ? void 0 : h.isPlaying());
260
162
  !this.isChecking && !e && this.timer && (this.animated.position.y = Math.sin(this.timer.current * 25e-4) * 4 - 2);
261
163
  }
262
164
  add(t) {
@@ -268,7 +170,7 @@ class _ {
268
170
  y: t.y - this.padding - t.height * t.anchor.y,
269
171
  w: t.width + this.padding * 2,
270
172
  h: t.height + this.padding * 2
271
- }, i = new h.Graphics();
173
+ }, i = new c.Graphics();
272
174
  return i.beginFill(this.boxColor), i.drawRoundedRect(
273
175
  e.x,
274
176
  e.y,
@@ -301,19 +203,19 @@ class _ {
301
203
  alpha: 0,
302
204
  y: this.animated.y + this.fadeShift
303
205
  };
304
- this.hideTween = new S(this.animated).to(n, 500).onComplete(() => {
206
+ this.hideTween = new T(this.animated).to(n, 500).onComplete(() => {
305
207
  this.isChecking = !0;
306
- }), this.showTween = new S(this.animated).to(i, 500).onComplete(() => {
307
- this.timer = new w(1e4, () => {
308
- var o;
309
- (o = this.hideTween) == null || o.start();
208
+ }), this.showTween = new T(this.animated).to(i, 500).onComplete(() => {
209
+ this.timer = new f(1e4, () => {
210
+ var a;
211
+ (a = this.hideTween) == null || a.start();
310
212
  });
311
213
  }), this.showTween.start();
312
214
  }
313
215
  }
314
- class B {
216
+ class G {
315
217
  constructor() {
316
- s(this, "text", new h.Text(void 0, {
218
+ s(this, "text", new c.Text(void 0, {
317
219
  fontFamily: "Rubik",
318
220
  fontSize: 18,
319
221
  fill: 16777215,
@@ -334,39 +236,40 @@ class B {
334
236
  this.text.text = t.name ?? "", this.text.visible = t.isVisible, this.text.position.x = t.position.x ?? this.text.position.x, this.text.position.y = t.position.y ?? this.text.position.y;
335
237
  }
336
238
  }
337
- class U {
239
+ class Y {
338
240
  constructor(t) {
339
- s(this, "container", new h.Container());
241
+ s(this, "container", new c.Container());
340
242
  s(this, "sprites");
341
243
  this.sprites = t, this.container.sortableChildren = !0;
342
244
  let e = 0;
343
- for (const i of this.sprites) {
344
- const n = i.sprite;
345
- this.container.addChild(n), n.zIndex = ++e, n.anchor.set(0.5, 0.5), n.autoUpdate = !1, n.play();
245
+ for (const i in this.sprites) {
246
+ const n = this.sprites[i];
247
+ this.container.addChild(n), n.zIndex = ++e, n.anchor.set(0.5, 0), n.autoUpdate = !1, n.play();
346
248
  }
347
249
  }
348
250
  update(t) {
349
- for (const e of this.sprites) {
350
- if (t.play && e.sprite.update(m * 0.06), t.color) {
351
- for (const i in t.color)
352
- if (i == e.layer) {
353
- const n = t.color[i];
354
- n && (e.sprite.alpha = n.alpha, e.sprite.tint = n);
251
+ for (const e in this.sprites) {
252
+ const i = this.sprites[e];
253
+ if (t.play && i.update(m * 0.06), t.color) {
254
+ for (const n in t.color)
255
+ if (n == e) {
256
+ const a = t.color[n];
257
+ a && (i.alpha = a.alpha, i.tint = a);
355
258
  }
356
259
  }
357
- t.scale.x && (e.sprite.animationSpeed = x / Math.abs(t.scale.x));
260
+ t.scale.x && (i.animationSpeed = 4 / Math.abs(t.scale.x));
358
261
  }
359
262
  this.container.scale.set(t.scale.x, t.scale.y);
360
263
  }
361
264
  }
362
- class X {
265
+ class Q {
363
266
  constructor() {
364
- s(this, "container", new h.Container());
267
+ s(this, "container", new c.Container());
365
268
  s(this, "timer");
366
269
  s(this, "sprite");
367
270
  s(this, "opacityStep", 0.1);
368
271
  s(this, "shadowStep", 50);
369
- p.stage.addChild(this.container);
272
+ l.stage.addChild(this.container);
370
273
  }
371
274
  setSprite(t) {
372
275
  this.sprite = t;
@@ -377,63 +280,61 @@ class X {
377
280
  if (this.timer && !this.timer.isCompleted)
378
281
  this.timer.tick();
379
282
  else if (t.play) {
380
- this.timer = new w(this.shadowStep);
381
- const e = new h.Container();
283
+ this.timer = new f(this.shadowStep);
284
+ const e = new c.Container();
382
285
  if (this.sprite)
383
- for (const i of this.sprite.sprites) {
384
- const n = i.sprite.texture.clone(), o = new h.Sprite(n);
385
- o.anchor.set(0.5, 0.5), o.alpha = i.sprite.alpha, o.tint = i.sprite.tint, e.addChild(o), e.scale.set(
286
+ for (const i in this.sprite.sprites) {
287
+ const n = this.sprite.sprites[i], a = n.texture.clone(), o = new c.Sprite(a);
288
+ o.anchor.set(0.5, 0), o.alpha = n.alpha, o.tint = n.tint, e.addChild(o), e.scale.set(
386
289
  this.sprite.container.scale.x,
387
290
  this.sprite.container.scale.y
388
291
  ), e.pivot.set(
389
292
  this.sprite.container.pivot.x,
390
293
  this.sprite.container.pivot.y
391
294
  );
392
- const r = this.sprite.container.getGlobalPosition();
393
- e.position.set(r.x, r.y);
295
+ const h = this.sprite.container.getGlobalPosition();
296
+ e.position.set(h.x, h.y);
394
297
  }
395
298
  this.container.addChild(e);
396
299
  }
397
300
  }
398
301
  }
399
- const x = 4;
400
- class f {
401
- constructor(t = {}) {
402
- s(this, "container", new h.Container());
302
+ class y {
303
+ constructor() {
304
+ s(this, "container", new c.Container());
403
305
  s(this, "userState", {});
404
306
  s(this, "state", {
405
307
  name: "",
406
- sprite: {
407
- name: "dude",
408
- w: 32,
409
- h: 32,
410
- collider: {
411
- x: 8,
412
- y: 7,
413
- w: 16,
414
- h: 18
415
- },
416
- pivot: {
417
- x: 0,
418
- y: 9
419
- }
420
- },
421
- color: new h.Color("#969696"),
308
+ sprite: "",
309
+ color: new c.Color("#969696"),
422
310
  direction: 1,
423
- scale: x,
311
+ scale: 1,
424
312
  isAnonymous: !1,
425
313
  zIndex: 0
426
314
  });
427
- s(this, "animationState");
315
+ s(this, "animationState", d.Idle);
428
316
  // TODO: Refactor sprite initializing, move logic to separate file
429
317
  s(this, "sprite");
430
- s(this, "tagSprites", A.createTagAnimatedSprites(this.state.sprite.name));
431
- s(this, "trail", new X());
432
- s(this, "name", new B());
318
+ s(this, "spriteData", {
319
+ name: "evotar",
320
+ collider: {
321
+ x: 0,
322
+ y: 0,
323
+ w: 0,
324
+ h: 0
325
+ },
326
+ size: { w: 0, h: 0 },
327
+ scale: 1,
328
+ flip: !1,
329
+ colored: []
330
+ });
331
+ s(this, "animatedSprites");
332
+ s(this, "trail", new Q());
333
+ s(this, "name", new G());
433
334
  s(this, "message", new _(() => {
434
- this.state.zIndex = u.zIndexEvotarMax(this.container.zIndex);
335
+ this.state.zIndex = w.zIndexEvotarMax(this.container.zIndex);
435
336
  }));
436
- s(this, "emoteSpitter", new W());
337
+ s(this, "emoteSpitter", new N());
437
338
  s(this, "velocity", {
438
339
  x: 0,
439
340
  y: 0
@@ -450,50 +351,53 @@ class f {
450
351
  s(this, "spawnTween");
451
352
  s(this, "fadeTween");
452
353
  s(this, "scaleTween");
453
- this.container.addChild(this.name.text), this.container.addChild(this.emoteSpitter.container), this.container.addChild(this.message.container), this.setAnimationState(l.Idle), t.sprite && this.setSprite(t.sprite), this.state = { ...this.state, ...t }, this.stateTimer = new w(5e3, () => {
454
- this.isJumping || this.setAnimationState(l.Run);
455
- });
354
+ this.container.addChild(this.name.text), this.container.addChild(this.emoteSpitter.container), this.container.addChild(this.message.container), this.container.sortableChildren = !0;
456
355
  }
457
356
  spawn(t = { isFalling: !1 }) {
458
- const e = this.state.sprite.collider, i = -(e.y + e.h - this.state.sprite.h / 2), n = t.isFalling ? i : p.renderer.height, o = this.state.sprite.w * this.state.scale, r = t.positionX != null ? t.positionX * p.renderer.width : Math.random() * (p.renderer.width - o) + o / 2, c = n * this.state.scale;
459
- if (this.container.x = r, this.container.y = c, this.state.direction = Math.random() > 0.5 ? 1 : -1, !t.isFalling) {
460
- const d = u.zIndexEvotarMin(this.container.zIndex);
461
- this.state.zIndex = d, this.container.alpha = 0, this.spawnTween = new y.Tween(this.container).to({ alpha: 1 }, 500).onComplete(t.onComplete).start();
357
+ const e = this.spriteData.collider, i = -(e.y + e.h - this.spriteData.size.h / 2), n = t.isFalling ? i : l.renderer.height, a = this.spriteData.size.w * this.state.scale * this.spriteData.scale, o = t.positionX != null ? t.positionX * l.renderer.width : Math.random() * (l.renderer.width - a) + a / 2, h = n * this.state.scale * this.spriteData.scale;
358
+ if (this.container.x = o, this.container.y = h, this.state.direction = Math.random() > 0.5 ? 1 : -1, !t.isFalling) {
359
+ const p = w.zIndexEvotarMin(this.container.zIndex);
360
+ this.state.zIndex = p, this.container.alpha = 0, this.spawnTween = new g.Tween(this.container).to({ alpha: 1 }, 500).onComplete(t.onComplete).start();
462
361
  }
362
+ this.stateTimer = new f(5e3, () => {
363
+ this.isJumping || this.setAnimationState(d.Run);
364
+ });
463
365
  }
464
366
  despawn(t = {}) {
465
- this.fadeTween && this.fadeTween.isPlaying() || (this.fadeTween = new y.Tween(this.container).to({ alpha: 0 }, 1e3).onComplete(() => {
367
+ this.fadeTween && this.fadeTween.isPlaying() || (this.fadeTween = new g.Tween(this.container).to({ alpha: 0 }, 1e3).onComplete(() => {
466
368
  this.isDespawned = !0, t.onComplete && t.onComplete();
467
369
  }).start());
468
370
  }
469
371
  scale(t) {
470
- this.scaleTween && this.scaleTween.isPlaying() || this.scaleTimer && !this.scaleTimer.isCompleted || (this.scaleTween = new y.Tween(this).to(
471
- { state: { scale: x * (t.value ?? 2) } },
472
- 2e3
473
- ).onComplete(() => {
474
- this.scaleTimer = new w((t.duration ?? 10) * 1e3, () => {
475
- this.scaleTween = new y.Tween(this).to({ state: { scale: x } }, 2e3).start();
372
+ this.scaleTween && this.scaleTween.isPlaying() || this.scaleTimer && !this.scaleTimer.isCompleted || (this.scaleTween = new g.Tween(this).to({ state: { scale: t.value ?? 2 } }, 2e3).onComplete(() => {
373
+ this.scaleTimer = new f((t.duration ?? 10) * 1e3, () => {
374
+ this.scaleTween = new g.Tween(this).to({ state: { scale: 1 } }, 2e3).start();
476
375
  });
477
376
  }).start());
478
377
  }
479
378
  jump(t) {
480
- this.isDespawned || this.isJumping || (this.isJumping = !0, this.velocity.x = this.state.direction * (t.velocityX ?? 3.5), this.velocity.y = t.velocityY ?? -8, this.setAnimationState(l.Jump), E.play("jump"));
379
+ this.isDespawned || this.isJumping || (this.isJumping = !0, this.velocity.x = this.state.direction * (t.velocityX ?? 3.5), this.velocity.y = t.velocityY ?? -8, this.setAnimationState(d.Jump), A.play("jump"));
481
380
  }
482
381
  dash(t) {
483
382
  this.isDespawned || this.isDashing || (this.isDashing = !0, this.velocity.x = this.state.direction * (t.force ?? 14));
484
383
  }
485
- setSprite(t) {
486
- t.name && t.name != this.state.sprite.name && (this.tagSprites = A.createTagAnimatedSprites(t.name), this.animationState && this.setAnimationState(this.animationState, !0));
384
+ async setSprite(t) {
385
+ if (t && t != this.state.sprite) {
386
+ const e = await S.getSpriteData(t);
387
+ if (!e)
388
+ return;
389
+ this.spriteData = e.data, this.animatedSprites = S.getAnimatedSprites(t), this.setAnimationState(this.animationState, !0);
390
+ }
487
391
  }
488
- setProps(t) {
489
- t.sprite && this.setSprite(t.sprite), this.state = { ...this.state, ...t };
392
+ async setProps(t) {
393
+ t.sprite && await this.setSprite(t.sprite), this.state = { ...this.state, ...t };
490
394
  }
491
395
  setUserProps(t) {
492
396
  this.userState = { ...this.userState, ...t };
493
397
  }
494
398
  move() {
495
399
  var i;
496
- const t = this.state.sprite.collider, e = {
400
+ const t = this.spriteData.collider, e = {
497
401
  x: this.container.position.x,
498
402
  y: this.container.position.y
499
403
  };
@@ -501,33 +405,33 @@ class f {
501
405
  const n = Math.sign(this.velocity.x);
502
406
  this.velocity.x = this.velocity.x - n * this.dashAcc / Math.abs(this.velocity.x), n != Math.sign(this.velocity.x) ? (this.isDashing = !1, this.velocity.x = 0) : e.x += this.velocity.x;
503
407
  } else {
504
- if ((i = this.stateTimer) != null && i.isCompleted && (this.stateTimer = new w(Math.random() * 5e3, () => {
505
- this.animationState == l.Idle ? this.setAnimationState(l.Run) : this.animationState == l.Run && this.setAnimationState(l.Idle);
506
- })), this.animationState == l.Run) {
408
+ if ((i = this.stateTimer) != null && i.isCompleted && (this.stateTimer = new f(Math.random() * 5e3, () => {
409
+ this.animationState == d.Idle ? this.setAnimationState(d.Run) : this.animationState == d.Run && this.setAnimationState(d.Idle);
410
+ })), this.animationState == d.Run) {
507
411
  const n = this.runSpeed * this.state.direction;
508
412
  this.velocity.x = n * m;
509
413
  }
510
- this.velocity.y = this.velocity.y + this.gravity, e.x += this.velocity.x, e.y += this.velocity.y, this.isOnGround(e.y) && (this.velocity.y = 0, this.velocity.x = 0, e.y = p.renderer.height, this.animationState == l.Fall && (this.setAnimationState(l.Land), this.landTimer = new w(200, () => {
511
- this.setAnimationState(l.Idle), this.isJumping = !1;
512
- }))), this.velocity.y > 0 && this.setAnimationState(l.Fall);
414
+ this.velocity.y = this.velocity.y + this.gravity, e.x += this.velocity.x, e.y += this.velocity.y, this.isOnGround(e.y) && (this.velocity.y = 0, this.velocity.x = 0, e.y = l.renderer.height, this.animationState == d.Fall && (this.setAnimationState(d.Land), this.landTimer = new f(200, () => {
415
+ this.setAnimationState(d.Idle), this.isJumping = !1;
416
+ }))), this.velocity.y > 0 && this.setAnimationState(d.Fall);
513
417
  }
514
- if (this.animationState != l.Idle || this.isDashing) {
515
- const n = t.w / 2 * this.state.scale, o = this.container.x - n < 0, r = this.container.x + n > p.renderer.width;
516
- (o || r) && (this.state.direction = -this.state.direction, this.velocity.x = -this.velocity.x, o && (e.x = n), r && (e.x = p.renderer.width - n));
418
+ if (this.animationState != d.Idle || this.isDashing) {
419
+ const n = t.w / 2 * this.state.scale * this.spriteData.scale, a = this.container.x - n < 0, o = this.container.x + n > l.renderer.width;
420
+ (a || o) && (this.state.direction = -this.state.direction, this.velocity.x = -this.velocity.x, a && (e.x = n), o && (e.x = l.renderer.width - n));
517
421
  }
518
422
  this.container.position.set(e.x, e.y);
519
423
  }
520
424
  update() {
521
- var e, i, n, o, r, c;
425
+ var e, i, n, a, o, h;
522
426
  if (this.isDespawned)
523
427
  return;
524
- (e = this.landTimer) == null || e.tick(), (i = this.stateTimer) == null || i.tick(), (n = this.scaleTimer) == null || n.tick(), (o = this.fadeTween) == null || o.update(), (r = this.spawnTween) == null || r.update(), (c = this.scaleTween) == null || c.update(), this.container.zIndex = this.state.zIndex;
525
- const t = this.state.sprite.collider;
526
- this.name.update({
428
+ (e = this.landTimer) == null || e.tick(), (i = this.stateTimer) == null || i.tick(), (n = this.scaleTimer) == null || n.tick(), (a = this.fadeTween) == null || a.update(), (o = this.spawnTween) == null || o.update(), (h = this.scaleTween) == null || h.update(), this.container.zIndex = this.state.zIndex;
429
+ const t = this.spriteData.collider;
430
+ if (this.name.update({
527
431
  name: this.state.name,
528
432
  isVisible: !this.state.isAnonymous,
529
433
  position: {
530
- y: -(this.state.sprite.h / 2 - t.y + this.state.sprite.pivot.y) * this.state.scale
434
+ y: -t.h * this.state.scale * this.spriteData.scale
531
435
  }
532
436
  }), this.message.update({
533
437
  position: {
@@ -537,21 +441,28 @@ class f {
537
441
  position: {
538
442
  y: this.message.container.position.y - this.message.container.height
539
443
  }
540
- }), this.move(), this.sprite && this.sprite.update({
541
- color: {
542
- [b.Body]: this.userState.color ? this.userState.color : this.state.color
543
- },
544
- scale: {
545
- x: this.state.direction * this.state.scale,
546
- y: this.state.scale
547
- },
548
- play: !this.isDashing
549
- }), this.trail.update({
444
+ }), this.move(), this.sprite) {
445
+ const p = Object.fromEntries(
446
+ this.spriteData.colored.map((u) => [
447
+ u,
448
+ this.userState.color ? this.userState.color : this.state.color
449
+ ])
450
+ ), x = this.spriteData.flip ? this.state.direction : 1;
451
+ this.sprite.update({
452
+ color: p,
453
+ scale: {
454
+ x: x * this.state.scale * this.spriteData.scale,
455
+ y: this.state.scale * this.spriteData.scale
456
+ },
457
+ play: !this.isDashing
458
+ });
459
+ }
460
+ this.trail.update({
550
461
  play: this.isDashing
551
462
  });
552
463
  }
553
464
  isOnGround(t) {
554
- return t > p.renderer.height;
465
+ return t > l.renderer.height;
555
466
  }
556
467
  addMessage(t) {
557
468
  var e;
@@ -562,18 +473,18 @@ class f {
562
473
  this.emoteSpitter.add(e);
563
474
  }
564
475
  async setAnimationState(t, e = !1) {
565
- if (this.animationState == t && !e)
476
+ if (this.animationState == t && !e || !this.animatedSprites)
566
477
  return;
567
478
  this.animationState = t, this.sprite && this.container.removeChild(this.sprite.container);
568
- const i = this.tagSprites[this.animationState];
569
- this.sprite = new U(i), this.trail.setSprite(this.sprite), this.sprite.container.pivot.set(
570
- this.state.sprite.pivot.x,
571
- this.state.sprite.pivot.y
479
+ const i = this.animatedSprites[this.animationState] ?? this.animatedSprites[d.Idle];
480
+ this.sprite = new Y(i), this.trail.setSprite(this.sprite), this.sprite.container.pivot.set(
481
+ 0,
482
+ this.spriteData.collider.y + this.spriteData.collider.h
572
483
  ), this.container.addChild(this.sprite.container);
573
484
  }
574
485
  }
575
- const G = 1e3 * 60 * 5;
576
- class N {
486
+ const B = 1e3 * 60 * 5;
487
+ class q {
577
488
  constructor() {
578
489
  s(this, "viewers", {});
579
490
  s(this, "raiders", []);
@@ -593,106 +504,111 @@ class N {
593
504
  t.update();
594
505
  }
595
506
  processRaid(t) {
596
- if (!p.settings.fallingRaiders)
507
+ if (!l.settings.fallingRaiders)
597
508
  return;
598
- const e = 1 / t.viewers * 5e3, i = C.sprites.agent;
599
- for (let c = 0; c < t.viewers; c++) {
600
- const d = new f({
509
+ const e = 1 / t.viewers * 5e3;
510
+ for (let o = 0; o < t.viewers; o++) {
511
+ const h = new y();
512
+ h.setProps({
601
513
  isAnonymous: !0,
602
514
  zIndex: -1,
603
- sprite: i,
604
- color: new h.Color(t.broadcaster.info.color)
605
- });
606
- v.add(e * c, () => {
607
- this.addRaider(d), d.spawn({ isFalling: !0 });
608
- }), v.add(c * e + 3e4, () => {
609
- d.despawn({
515
+ sprite: "agent",
516
+ color: new c.Color(t.broadcaster.info.color)
517
+ }), v.add(e * o, () => {
518
+ this.addRaider(h), h.spawn({ isFalling: !0 });
519
+ }), v.add(o * e + 3e4, () => {
520
+ h.despawn({
610
521
  onComplete: () => {
611
- this.deleteRaider(d);
522
+ this.deleteRaider(h);
612
523
  }
613
524
  });
614
525
  });
615
526
  }
616
- const n = this.viewers[t.broadcaster.id], o = {
527
+ const i = this.viewers[t.broadcaster.id], n = {
617
528
  ...this.prepareEvotarProps(
618
529
  t.broadcaster.info.displayName,
619
530
  t.broadcaster.info.color
620
531
  ),
621
532
  scale: 8
622
- }, r = () => {
623
- const c = new f(o);
624
- this.addViewer(t.broadcaster.id, c), c.spawn({ isFalling: !0, positionX: 0.5 });
533
+ }, a = () => {
534
+ const o = new y();
535
+ o.setProps(n), this.addViewer(t.broadcaster.id, o), o.spawn({ isFalling: !0, positionX: 0.5 });
625
536
  };
626
- this.lastEvotarActivity[t.broadcaster.id] = performance.now(), n ? n.despawn({
537
+ this.lastEvotarActivity[t.broadcaster.id] = performance.now(), i ? i.despawn({
627
538
  onComplete: () => {
628
- r();
539
+ a();
629
540
  }
630
- }) : r();
541
+ }) : a();
631
542
  }
632
- processChatters(t) {
543
+ async processChatters(t) {
633
544
  for (const e in this.viewers) {
634
- const i = this.lastEvotarActivity[e], n = !!i && performance.now() - i < G;
635
- if (t.every((o) => o.userId != e) && !n) {
636
- const o = this.viewers[e];
637
- o && o.despawn({
545
+ const i = this.lastEvotarActivity[e], n = !!i && performance.now() - i < B;
546
+ if (t.every((a) => a.userId != e) && !n) {
547
+ const a = this.viewers[e];
548
+ a && a.despawn({
638
549
  onComplete: () => {
639
- this.deleteViewer(e, o);
550
+ this.deleteViewer(e, a);
640
551
  }
641
552
  });
642
553
  }
643
554
  }
644
- if (p.settings.showAnonymousEvotars) {
555
+ if (l.settings.showAnonymousEvotars) {
645
556
  for (const e of t)
646
557
  if (!this.viewers[e.userId]) {
647
558
  const n = {
648
559
  name: e.name,
649
560
  isAnonymous: !this.hasActivity(e.userId)
650
- }, o = new f(n);
651
- o.spawn(), this.addViewer(e.userId, o);
561
+ }, a = new y();
562
+ await a.setProps(n), a.spawn(), this.addViewer(e.userId, a);
652
563
  }
653
564
  }
654
565
  }
655
566
  doAction(t, e) {
656
- if (F(t) && e.jump({
567
+ if (L(t) && e.jump({
657
568
  velocityX: t.data.velocityX,
658
569
  velocityY: t.data.velocityY,
659
570
  cooldown: t.cooldown
660
- }), j(t) && e.dash({ force: t.data.force, cooldown: t.cooldown }), L(t)) {
661
- const i = D(t.data.color);
662
- i && i.isValid() && e.setUserProps({ color: new h.Color(t.data.color) });
571
+ }), W(t) && e.dash({ force: t.data.force, cooldown: t.cooldown }), j(t)) {
572
+ const i = F(t.data.color);
573
+ i && i.isValid() && e.setUserProps({ color: new c.Color(t.data.color) });
663
574
  }
664
- V(t) && e.scale({
575
+ J(t) && e.scale({
665
576
  value: t.data.scale,
666
577
  duration: t.data.duration,
667
578
  cooldown: t.cooldown
668
- });
579
+ }), O(t) && e.setSprite(t.data.sprite);
669
580
  }
670
581
  prepareEvotarProps(t, e, i) {
671
582
  const n = {
672
583
  name: t,
673
584
  isAnonymous: !1
674
- }, o = i ? C.sprites[i] : null;
675
- return o && (n.sprite = o), e && (n.color = new h.Color(e)), n;
585
+ };
586
+ if (i && (n.sprite = i), e)
587
+ try {
588
+ n.color = new c.Color(e);
589
+ } catch {
590
+ }
591
+ return n;
676
592
  }
677
- processAction(t) {
593
+ async processAction(t) {
678
594
  const e = this.viewers[t.userId], i = this.prepareEvotarProps(
679
595
  t.info.displayName,
680
596
  t.info.color,
681
597
  t.info.sprite
682
598
  );
683
599
  if (e)
684
- this.doAction(t, e), e.setProps(i);
600
+ await e.setProps(i), this.doAction(t, e);
685
601
  else {
686
- const n = new f(i);
687
- n.spawn({
602
+ const n = new y();
603
+ await n.setProps(i), n.spawn({
688
604
  onComplete: () => {
689
- const o = this.viewers[t.userId];
690
- o && this.doAction(t, o);
605
+ const a = this.viewers[t.userId];
606
+ a && this.doAction(t, a);
691
607
  }
692
608
  }), this.addViewer(t.userId, n);
693
609
  }
694
610
  }
695
- processMessage(t) {
611
+ async processMessage(t) {
696
612
  const e = this.prepareEvotarProps(
697
613
  t.info.displayName,
698
614
  t.info.color,
@@ -702,8 +618,8 @@ class N {
702
618
  if (i)
703
619
  i.setProps(e);
704
620
  else {
705
- const n = p.settings.fallingEvotars ? !this.hasActivity(t.userId) : !1;
706
- i = new f(e), i.spawn({ isFalling: n }), this.addViewer(t.userId, i);
621
+ const n = l.settings.fallingEvotars ? !this.hasActivity(t.userId) : !1;
622
+ i = new y(), await i.setProps(e), i.spawn({ isFalling: n }), this.addViewer(t.userId, i);
707
623
  }
708
624
  this.lastEvotarActivity[t.userId] = performance.now(), t.message && i.addMessage(t.message), t.emotes.length > 0 && i.spitEmotes(t.emotes);
709
625
  }
@@ -726,23 +642,23 @@ class N {
726
642
  return Object.values(this.viewers).reduce((e, i) => i && e >= i.container.zIndex ? i.container.zIndex - 1 : e, t);
727
643
  }
728
644
  }
729
- const u = new N();
730
- class Y {
645
+ const w = new q();
646
+ class H {
731
647
  constructor() {
732
- s(this, "stage", new h.Container());
648
+ s(this, "stage", new c.Container());
733
649
  s(this, "evotars", {});
734
650
  s(this, "chatterIds", []);
735
651
  s(this, "settings", {});
736
652
  s(this, "renderer");
737
653
  }
738
- async init(t, e) {
739
- await T.load(t.manifest), E.init(t.sound), this.renderer = new h.Renderer({
740
- width: e.clientWidth,
741
- height: e.clientHeight,
654
+ async initialize(t, e) {
655
+ S.initialize(e.spriteLoaderFn), A.initialize(e.sounds), this.renderer = new c.Renderer({
656
+ width: t.clientWidth,
657
+ height: t.clientHeight,
742
658
  backgroundAlpha: 0
743
- }), e.appendChild(this.renderer.view), window.onresize = () => {
744
- this.renderer.resize(e.clientWidth, e.clientHeight);
745
- }, this.stage.sortableChildren = !0, u.subscribe({
659
+ }), t.appendChild(this.renderer.view), window.onresize = () => {
660
+ this.renderer.resize(t.clientWidth, t.clientHeight);
661
+ }, this.stage.sortableChildren = !0, w.subscribe({
746
662
  onAdd: (i) => this.stage.addChild(i.container),
747
663
  onDelete: (i) => {
748
664
  this.stage.removeChild(i.container), this.stage.removeChild(i.trail.container);
@@ -753,37 +669,37 @@ class Y {
753
669
  this.settings = t;
754
670
  }
755
671
  update() {
756
- v.tick(), u.update(), this.renderer.render(this.stage);
672
+ v.tick(), w.update(), this.renderer.render(this.stage);
757
673
  }
758
674
  }
759
- const p = new Y();
760
- class K {
761
- constructor(t) {
675
+ const l = new H();
676
+ class et {
677
+ constructor(t, e) {
762
678
  s(this, "isRendered", !1);
763
- s(this, "processMessage", (t) => u.processMessage(t));
764
- s(this, "processAction", (t) => u.processAction(t));
765
- s(this, "processChatters", (t) => u.processChatters(t));
766
- s(this, "processRaid", (t) => u.processRaid(t));
767
- this.root = t;
679
+ s(this, "processMessage", (t) => w.processMessage(t));
680
+ s(this, "processAction", (t) => w.processAction(t));
681
+ s(this, "processChatters", (t) => w.processChatters(t));
682
+ s(this, "processRaid", (t) => w.processRaid(t));
683
+ this.root = t, this.options = e;
768
684
  }
769
685
  updateSettings(t) {
770
- p.updateSettings(t);
686
+ l.updateSettings(t);
771
687
  }
772
- async run(t) {
688
+ async run() {
773
689
  if (this.isRendered)
774
690
  return;
775
691
  this.isRendered = !0, await (async () => {
776
- await p.init(t, this.root), performance.now();
777
- let i = -1;
778
- const o = 1e3 / 60;
779
- requestAnimationFrame(r);
780
- function r(c = performance.now()) {
781
- const d = c - i | 0;
782
- d > o && (i = c - d % o, p.update()), requestAnimationFrame(r);
692
+ await l.initialize(this.root, this.options), performance.now();
693
+ let e = -1;
694
+ const n = 1e3 / 60;
695
+ requestAnimationFrame(a);
696
+ function a(o = performance.now()) {
697
+ const h = o - e | 0;
698
+ h > n && (e = o - h % n, l.update()), requestAnimationFrame(a);
783
699
  }
784
700
  })();
785
701
  }
786
702
  }
787
703
  export {
788
- K as Evotars
704
+ et as Evotars
789
705
  };