evotars 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/app.d.ts +19 -0
- package/dist/config/config.d.ts +22 -0
- package/dist/config/constants.d.ts +1 -0
- package/dist/entities/EmoteSpitter.d.ts +15 -0
- package/dist/entities/Evotar.d.ts +79 -0
- package/dist/entities/Message.d.ts +27 -0
- package/dist/entities/Name.d.ts +14 -0
- package/dist/entities/SpriteContainer.d.ts +16 -0
- package/dist/entities/TrailEffect.d.ts +15 -0
- package/dist/evotars.d.ts +14 -0
- package/dist/evotars.js +789 -0
- package/dist/evotars.umd.cjs +1 -0
- package/dist/helpers/timer.d.ts +14 -0
- package/dist/helpers/types.d.ts +10 -0
- package/dist/index.d.ts +1 -0
- package/dist/services/assetsLoader.d.ts +14 -0
- package/dist/services/evotarsManager.d.ts +30 -0
- package/dist/services/soundService.d.ts +12 -0
- package/dist/services/spriteProvider.d.ts +33 -0
- package/dist/types/dto/action.d.ts +49 -0
- package/{src/types/dto/chatter.ts → dist/types/dto/chatter.d.ts} +2 -2
- package/dist/types/dto/event.d.ts +9 -0
- package/dist/types/dto/message.d.ts +8 -0
- package/dist/types/dto/settings.d.ts +5 -0
- package/dist/types/dto/user.d.ts +12 -0
- package/package.json +30 -3
- package/.editorconfig +0 -13
- package/.prettierrc.json +0 -3
- package/index.html +0 -13
- package/public/fonts/Rubik.ttf +0 -0
- package/public/sounds/jump.mp3 +0 -0
- package/public/sprites/agent/agent.json +0 -166
- package/public/sprites/agent/agent.png +0 -0
- package/public/sprites/cat/cat.json +0 -231
- package/public/sprites/cat/cat.png +0 -0
- package/public/sprites/dude/dude.json +0 -231
- package/public/sprites/dude/dude.png +0 -0
- package/public/sprites/girl/girl.json +0 -231
- package/public/sprites/girl/girl.png +0 -0
- package/public/sprites/nerd/nerd.json +0 -231
- package/public/sprites/nerd/nerd.png +0 -0
- package/public/sprites/senior/senior.json +0 -231
- package/public/sprites/senior/senior.png +0 -0
- package/public/sprites/sith/sith.json +0 -166
- package/public/sprites/sith/sith.png +0 -0
- package/src/app.ts +0 -63
- package/src/config/config.ts +0 -133
- package/src/config/constants.ts +0 -1
- package/src/dudes.ts +0 -71
- package/src/entities/Dude.ts +0 -453
- package/src/entities/DudeEmoteSpitter.ts +0 -60
- package/src/entities/DudeMessage.ts +0 -163
- package/src/entities/DudeName.ts +0 -39
- package/src/entities/DudeSpriteContainer.ts +0 -68
- package/src/entities/DudeTrailEffect.ts +0 -72
- package/src/helpers/timer.ts +0 -43
- package/src/helpers/types.ts +0 -11
- package/src/index.ts +0 -75
- package/src/services/assetsLoader.ts +0 -27
- package/src/services/dudesManager.ts +0 -305
- package/src/services/soundService.ts +0 -28
- package/src/services/spriteProvider.ts +0 -93
- package/src/styles.css +0 -16
- package/src/types/dto/action.ts +0 -68
- package/src/types/dto/event.ts +0 -9
- package/src/types/dto/message.ts +0 -8
- package/src/types/dto/settings.ts +0 -5
- package/src/types/dto/user.ts +0 -13
- package/tsconfig.json +0 -23
- /package/{src/types/dto/index.ts → dist/types/dto/index.d.ts} +0 -0
- /package/{src/types/index.ts → dist/types/index.d.ts} +0 -0
package/dist/evotars.js
ADDED
|
@@ -0,0 +1,789 @@
|
|
|
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";
|
|
8
|
+
const m = 0.02 * 1e3;
|
|
9
|
+
class w {
|
|
10
|
+
constructor(t = 0, e) {
|
|
11
|
+
s(this, "isCompleted", !1);
|
|
12
|
+
this.current = t, this.onComplete = e;
|
|
13
|
+
}
|
|
14
|
+
tick(t = m) {
|
|
15
|
+
var e;
|
|
16
|
+
this.isCompleted || (this.current -= t, this.current < 0 && (this.isCompleted = !0, (e = this.onComplete) == null || e.call(this)));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
class P {
|
|
20
|
+
constructor() {
|
|
21
|
+
s(this, "timers", []);
|
|
22
|
+
}
|
|
23
|
+
add(t, e) {
|
|
24
|
+
this.timers.push(new w(t, e));
|
|
25
|
+
}
|
|
26
|
+
tick(t = m) {
|
|
27
|
+
const e = [];
|
|
28
|
+
for (const i of this.timers)
|
|
29
|
+
i.isCompleted || (i.tick(t), e.push(i));
|
|
30
|
+
this.timers = e;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
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 {
|
|
153
|
+
constructor() {
|
|
154
|
+
s(this, "assets", {});
|
|
155
|
+
}
|
|
156
|
+
async init(t) {
|
|
157
|
+
this.assets = Object.fromEntries(
|
|
158
|
+
Array.from(Object.entries(t)).map(([e, i]) => [e, new Audio(i)])
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
play(t) {
|
|
162
|
+
const e = this.assets[t];
|
|
163
|
+
e && (e.volume = 0.2, e.pause(), e.currentTime = 0, e.play());
|
|
164
|
+
}
|
|
165
|
+
}
|
|
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
|
+
}
|
|
181
|
+
}
|
|
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");
|
|
188
|
+
}
|
|
189
|
+
createTagAnimatedSprites(t) {
|
|
190
|
+
if (!t)
|
|
191
|
+
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
|
+
);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const A = new J();
|
|
200
|
+
class W {
|
|
201
|
+
constructor() {
|
|
202
|
+
s(this, "container", new h.Container());
|
|
203
|
+
s(this, "emotes", []);
|
|
204
|
+
s(this, "moveSpeed", 50);
|
|
205
|
+
s(this, "alphaSpeed", 1);
|
|
206
|
+
s(this, "scaleSpeed", 0.5);
|
|
207
|
+
s(this, "timer");
|
|
208
|
+
}
|
|
209
|
+
add(t) {
|
|
210
|
+
const e = h.Sprite.from(t);
|
|
211
|
+
e.anchor.set(0.5, 0.5), e.scale.set(0, 0), this.emotes.push(e);
|
|
212
|
+
}
|
|
213
|
+
update(t) {
|
|
214
|
+
var e;
|
|
215
|
+
(e = this.timer) == null || e.tick(), (!this.timer || this.timer.isCompleted) && this.emotes.length > 0 && (this.timer = new w(2e3, () => {
|
|
216
|
+
const i = this.emotes.shift();
|
|
217
|
+
i && this.container.addChild(i);
|
|
218
|
+
})), this.container.position.x = t.position.x ?? this.container.position.x, this.container.position.y = t.position.y ?? this.container.position.y;
|
|
219
|
+
for (const i of this.container.children)
|
|
220
|
+
i.position.y -= m * this.moveSpeed / 1e3, i.scale.x += m * this.scaleSpeed / 1e3, i.scale.y += m * this.scaleSpeed / 1e3, i.scale.x > 1 && (i.alpha -= m * this.alphaSpeed / 1e3), i.alpha <= 0 && this.container.removeChild(i);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
class _ {
|
|
224
|
+
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, {
|
|
228
|
+
fontFamily: "Rubik",
|
|
229
|
+
fontSize: 20,
|
|
230
|
+
fill: 2236962,
|
|
231
|
+
align: "left",
|
|
232
|
+
breakWords: !0,
|
|
233
|
+
wordWrap: !0,
|
|
234
|
+
wordWrapWidth: 200
|
|
235
|
+
}));
|
|
236
|
+
s(this, "padding", 10);
|
|
237
|
+
s(this, "borderRadius", 10);
|
|
238
|
+
s(this, "boxColor", 15658734);
|
|
239
|
+
s(this, "fadeShift", 10);
|
|
240
|
+
s(this, "isChecking", !0);
|
|
241
|
+
s(this, "messageQueue", []);
|
|
242
|
+
s(this, "showTween");
|
|
243
|
+
s(this, "hideTween");
|
|
244
|
+
s(this, "timer");
|
|
245
|
+
this.beforeShow = t, this.container.addChild(this.animated), this.text.anchor.set(0.5, 1), this.text.position.set(0, -this.padding);
|
|
246
|
+
}
|
|
247
|
+
trim(t) {
|
|
248
|
+
const e = h.TextMetrics.measureText(t.text, t.style);
|
|
249
|
+
return e.lines.length > 4 ? e.lines.slice(0, 4).join(" ").slice(0, -3) + "..." : t.text;
|
|
250
|
+
}
|
|
251
|
+
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) {
|
|
254
|
+
this.isChecking = !1;
|
|
255
|
+
const d = this.messageQueue.shift();
|
|
256
|
+
d && (this.beforeShow(), this.show(d));
|
|
257
|
+
}
|
|
258
|
+
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());
|
|
260
|
+
!this.isChecking && !e && this.timer && (this.animated.position.y = Math.sin(this.timer.current * 25e-4) * 4 - 2);
|
|
261
|
+
}
|
|
262
|
+
add(t) {
|
|
263
|
+
this.messageQueue.push(t);
|
|
264
|
+
}
|
|
265
|
+
drawBox(t) {
|
|
266
|
+
const e = {
|
|
267
|
+
x: t.x - this.padding - t.width * t.anchor.x,
|
|
268
|
+
y: t.y - this.padding - t.height * t.anchor.y,
|
|
269
|
+
w: t.width + this.padding * 2,
|
|
270
|
+
h: t.height + this.padding * 2
|
|
271
|
+
}, i = new h.Graphics();
|
|
272
|
+
return i.beginFill(this.boxColor), i.drawRoundedRect(
|
|
273
|
+
e.x,
|
|
274
|
+
e.y,
|
|
275
|
+
e.w,
|
|
276
|
+
e.h,
|
|
277
|
+
this.borderRadius
|
|
278
|
+
), i.drawPolygon(
|
|
279
|
+
{
|
|
280
|
+
x: e.x + e.w / 2 - 10,
|
|
281
|
+
y: e.y + e.h
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
x: e.x + e.w / 2 + 10,
|
|
285
|
+
y: e.y + e.h
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
x: e.x + e.w / 2,
|
|
289
|
+
y: e.y + e.h + 10 - 4
|
|
290
|
+
}
|
|
291
|
+
), i.endFill(), i;
|
|
292
|
+
}
|
|
293
|
+
show(t) {
|
|
294
|
+
this.text.text = t, this.text.text = this.trim(this.text), this.animated.alpha = 0, this.animated.position.y = this.fadeShift;
|
|
295
|
+
const e = this.drawBox(this.text);
|
|
296
|
+
this.animated.removeChildren(), this.animated.addChild(e, this.text);
|
|
297
|
+
const i = {
|
|
298
|
+
alpha: 1,
|
|
299
|
+
y: this.animated.y - this.fadeShift
|
|
300
|
+
}, n = {
|
|
301
|
+
alpha: 0,
|
|
302
|
+
y: this.animated.y + this.fadeShift
|
|
303
|
+
};
|
|
304
|
+
this.hideTween = new S(this.animated).to(n, 500).onComplete(() => {
|
|
305
|
+
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();
|
|
310
|
+
});
|
|
311
|
+
}), this.showTween.start();
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
class B {
|
|
315
|
+
constructor() {
|
|
316
|
+
s(this, "text", new h.Text(void 0, {
|
|
317
|
+
fontFamily: "Rubik",
|
|
318
|
+
fontSize: 18,
|
|
319
|
+
fill: 16777215,
|
|
320
|
+
align: "center",
|
|
321
|
+
lineJoin: "round",
|
|
322
|
+
strokeThickness: 4,
|
|
323
|
+
stroke: "black"
|
|
324
|
+
}));
|
|
325
|
+
s(this, "rect", () => ({
|
|
326
|
+
x: this.text.x,
|
|
327
|
+
y: this.text.y,
|
|
328
|
+
w: this.text.width,
|
|
329
|
+
h: this.text.height
|
|
330
|
+
}));
|
|
331
|
+
this.text.anchor.set(0.5, 1), this.text.zIndex = 100;
|
|
332
|
+
}
|
|
333
|
+
update(t) {
|
|
334
|
+
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
|
+
}
|
|
336
|
+
}
|
|
337
|
+
class U {
|
|
338
|
+
constructor(t) {
|
|
339
|
+
s(this, "container", new h.Container());
|
|
340
|
+
s(this, "sprites");
|
|
341
|
+
this.sprites = t, this.container.sortableChildren = !0;
|
|
342
|
+
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();
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
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);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
t.scale.x && (e.sprite.animationSpeed = x / Math.abs(t.scale.x));
|
|
358
|
+
}
|
|
359
|
+
this.container.scale.set(t.scale.x, t.scale.y);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
class X {
|
|
363
|
+
constructor() {
|
|
364
|
+
s(this, "container", new h.Container());
|
|
365
|
+
s(this, "timer");
|
|
366
|
+
s(this, "sprite");
|
|
367
|
+
s(this, "opacityStep", 0.1);
|
|
368
|
+
s(this, "shadowStep", 50);
|
|
369
|
+
p.stage.addChild(this.container);
|
|
370
|
+
}
|
|
371
|
+
setSprite(t) {
|
|
372
|
+
this.sprite = t;
|
|
373
|
+
}
|
|
374
|
+
update(t) {
|
|
375
|
+
for (const e of this.container.children)
|
|
376
|
+
e.alpha > 0 && (e.alpha = e.alpha - this.opacityStep);
|
|
377
|
+
if (this.timer && !this.timer.isCompleted)
|
|
378
|
+
this.timer.tick();
|
|
379
|
+
else if (t.play) {
|
|
380
|
+
this.timer = new w(this.shadowStep);
|
|
381
|
+
const e = new h.Container();
|
|
382
|
+
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(
|
|
386
|
+
this.sprite.container.scale.x,
|
|
387
|
+
this.sprite.container.scale.y
|
|
388
|
+
), e.pivot.set(
|
|
389
|
+
this.sprite.container.pivot.x,
|
|
390
|
+
this.sprite.container.pivot.y
|
|
391
|
+
);
|
|
392
|
+
const r = this.sprite.container.getGlobalPosition();
|
|
393
|
+
e.position.set(r.x, r.y);
|
|
394
|
+
}
|
|
395
|
+
this.container.addChild(e);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
const x = 4;
|
|
400
|
+
class f {
|
|
401
|
+
constructor(t = {}) {
|
|
402
|
+
s(this, "container", new h.Container());
|
|
403
|
+
s(this, "userState", {});
|
|
404
|
+
s(this, "state", {
|
|
405
|
+
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"),
|
|
422
|
+
direction: 1,
|
|
423
|
+
scale: x,
|
|
424
|
+
isAnonymous: !1,
|
|
425
|
+
zIndex: 0
|
|
426
|
+
});
|
|
427
|
+
s(this, "animationState");
|
|
428
|
+
// TODO: Refactor sprite initializing, move logic to separate file
|
|
429
|
+
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());
|
|
433
|
+
s(this, "message", new _(() => {
|
|
434
|
+
this.state.zIndex = u.zIndexEvotarMax(this.container.zIndex);
|
|
435
|
+
}));
|
|
436
|
+
s(this, "emoteSpitter", new W());
|
|
437
|
+
s(this, "velocity", {
|
|
438
|
+
x: 0,
|
|
439
|
+
y: 0
|
|
440
|
+
});
|
|
441
|
+
s(this, "runSpeed", 0.05);
|
|
442
|
+
s(this, "gravity", 0.2);
|
|
443
|
+
s(this, "dashAcc", 3);
|
|
444
|
+
s(this, "isJumping", !1);
|
|
445
|
+
s(this, "isDashing", !1);
|
|
446
|
+
s(this, "isDespawned", !1);
|
|
447
|
+
s(this, "landTimer");
|
|
448
|
+
s(this, "stateTimer");
|
|
449
|
+
s(this, "scaleTimer");
|
|
450
|
+
s(this, "spawnTween");
|
|
451
|
+
s(this, "fadeTween");
|
|
452
|
+
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
|
+
});
|
|
456
|
+
}
|
|
457
|
+
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();
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
despawn(t = {}) {
|
|
465
|
+
this.fadeTween && this.fadeTween.isPlaying() || (this.fadeTween = new y.Tween(this.container).to({ alpha: 0 }, 1e3).onComplete(() => {
|
|
466
|
+
this.isDespawned = !0, t.onComplete && t.onComplete();
|
|
467
|
+
}).start());
|
|
468
|
+
}
|
|
469
|
+
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();
|
|
476
|
+
});
|
|
477
|
+
}).start());
|
|
478
|
+
}
|
|
479
|
+
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"));
|
|
481
|
+
}
|
|
482
|
+
dash(t) {
|
|
483
|
+
this.isDespawned || this.isDashing || (this.isDashing = !0, this.velocity.x = this.state.direction * (t.force ?? 14));
|
|
484
|
+
}
|
|
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));
|
|
487
|
+
}
|
|
488
|
+
setProps(t) {
|
|
489
|
+
t.sprite && this.setSprite(t.sprite), this.state = { ...this.state, ...t };
|
|
490
|
+
}
|
|
491
|
+
setUserProps(t) {
|
|
492
|
+
this.userState = { ...this.userState, ...t };
|
|
493
|
+
}
|
|
494
|
+
move() {
|
|
495
|
+
var i;
|
|
496
|
+
const t = this.state.sprite.collider, e = {
|
|
497
|
+
x: this.container.position.x,
|
|
498
|
+
y: this.container.position.y
|
|
499
|
+
};
|
|
500
|
+
if (this.isDashing) {
|
|
501
|
+
const n = Math.sign(this.velocity.x);
|
|
502
|
+
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
|
+
} 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) {
|
|
507
|
+
const n = this.runSpeed * this.state.direction;
|
|
508
|
+
this.velocity.x = n * m;
|
|
509
|
+
}
|
|
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);
|
|
513
|
+
}
|
|
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));
|
|
517
|
+
}
|
|
518
|
+
this.container.position.set(e.x, e.y);
|
|
519
|
+
}
|
|
520
|
+
update() {
|
|
521
|
+
var e, i, n, o, r, c;
|
|
522
|
+
if (this.isDespawned)
|
|
523
|
+
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({
|
|
527
|
+
name: this.state.name,
|
|
528
|
+
isVisible: !this.state.isAnonymous,
|
|
529
|
+
position: {
|
|
530
|
+
y: -(this.state.sprite.h / 2 - t.y + this.state.sprite.pivot.y) * this.state.scale
|
|
531
|
+
}
|
|
532
|
+
}), this.message.update({
|
|
533
|
+
position: {
|
|
534
|
+
y: this.name.text.position.y - this.name.text.height - 6
|
|
535
|
+
}
|
|
536
|
+
}), this.emoteSpitter.update({
|
|
537
|
+
position: {
|
|
538
|
+
y: this.message.container.position.y - this.message.container.height
|
|
539
|
+
}
|
|
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({
|
|
550
|
+
play: this.isDashing
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
isOnGround(t) {
|
|
554
|
+
return t > p.renderer.height;
|
|
555
|
+
}
|
|
556
|
+
addMessage(t) {
|
|
557
|
+
var e;
|
|
558
|
+
this.message.add(t), this.state.isAnonymous = !1, (e = this.fadeTween) == null || e.stop(), this.fadeTween = void 0, this.container.alpha = 1;
|
|
559
|
+
}
|
|
560
|
+
spitEmotes(t) {
|
|
561
|
+
for (const e of t)
|
|
562
|
+
this.emoteSpitter.add(e);
|
|
563
|
+
}
|
|
564
|
+
async setAnimationState(t, e = !1) {
|
|
565
|
+
if (this.animationState == t && !e)
|
|
566
|
+
return;
|
|
567
|
+
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
|
|
572
|
+
), this.container.addChild(this.sprite.container);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
const G = 1e3 * 60 * 5;
|
|
576
|
+
class N {
|
|
577
|
+
constructor() {
|
|
578
|
+
s(this, "viewers", {});
|
|
579
|
+
s(this, "raiders", []);
|
|
580
|
+
s(this, "lastEvotarActivity", {});
|
|
581
|
+
s(this, "subscriptions", []);
|
|
582
|
+
s(this, "hasActivity", (t) => !!this.lastEvotarActivity[t]);
|
|
583
|
+
}
|
|
584
|
+
subscribe(t) {
|
|
585
|
+
this.subscriptions.push(t);
|
|
586
|
+
}
|
|
587
|
+
update() {
|
|
588
|
+
for (const t in this.viewers) {
|
|
589
|
+
const e = this.viewers[t];
|
|
590
|
+
e && e.update();
|
|
591
|
+
}
|
|
592
|
+
for (const t of this.raiders)
|
|
593
|
+
t.update();
|
|
594
|
+
}
|
|
595
|
+
processRaid(t) {
|
|
596
|
+
if (!p.settings.fallingRaiders)
|
|
597
|
+
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({
|
|
601
|
+
isAnonymous: !0,
|
|
602
|
+
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({
|
|
610
|
+
onComplete: () => {
|
|
611
|
+
this.deleteRaider(d);
|
|
612
|
+
}
|
|
613
|
+
});
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
const n = this.viewers[t.broadcaster.id], o = {
|
|
617
|
+
...this.prepareEvotarProps(
|
|
618
|
+
t.broadcaster.info.displayName,
|
|
619
|
+
t.broadcaster.info.color
|
|
620
|
+
),
|
|
621
|
+
scale: 8
|
|
622
|
+
}, r = () => {
|
|
623
|
+
const c = new f(o);
|
|
624
|
+
this.addViewer(t.broadcaster.id, c), c.spawn({ isFalling: !0, positionX: 0.5 });
|
|
625
|
+
};
|
|
626
|
+
this.lastEvotarActivity[t.broadcaster.id] = performance.now(), n ? n.despawn({
|
|
627
|
+
onComplete: () => {
|
|
628
|
+
r();
|
|
629
|
+
}
|
|
630
|
+
}) : r();
|
|
631
|
+
}
|
|
632
|
+
processChatters(t) {
|
|
633
|
+
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({
|
|
638
|
+
onComplete: () => {
|
|
639
|
+
this.deleteViewer(e, o);
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
if (p.settings.showAnonymousEvotars) {
|
|
645
|
+
for (const e of t)
|
|
646
|
+
if (!this.viewers[e.userId]) {
|
|
647
|
+
const n = {
|
|
648
|
+
name: e.name,
|
|
649
|
+
isAnonymous: !this.hasActivity(e.userId)
|
|
650
|
+
}, o = new f(n);
|
|
651
|
+
o.spawn(), this.addViewer(e.userId, o);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
doAction(t, e) {
|
|
656
|
+
if (F(t) && e.jump({
|
|
657
|
+
velocityX: t.data.velocityX,
|
|
658
|
+
velocityY: t.data.velocityY,
|
|
659
|
+
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) });
|
|
663
|
+
}
|
|
664
|
+
V(t) && e.scale({
|
|
665
|
+
value: t.data.scale,
|
|
666
|
+
duration: t.data.duration,
|
|
667
|
+
cooldown: t.cooldown
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
prepareEvotarProps(t, e, i) {
|
|
671
|
+
const n = {
|
|
672
|
+
name: t,
|
|
673
|
+
isAnonymous: !1
|
|
674
|
+
}, o = i ? C.sprites[i] : null;
|
|
675
|
+
return o && (n.sprite = o), e && (n.color = new h.Color(e)), n;
|
|
676
|
+
}
|
|
677
|
+
processAction(t) {
|
|
678
|
+
const e = this.viewers[t.userId], i = this.prepareEvotarProps(
|
|
679
|
+
t.info.displayName,
|
|
680
|
+
t.info.color,
|
|
681
|
+
t.info.sprite
|
|
682
|
+
);
|
|
683
|
+
if (e)
|
|
684
|
+
this.doAction(t, e), e.setProps(i);
|
|
685
|
+
else {
|
|
686
|
+
const n = new f(i);
|
|
687
|
+
n.spawn({
|
|
688
|
+
onComplete: () => {
|
|
689
|
+
const o = this.viewers[t.userId];
|
|
690
|
+
o && this.doAction(t, o);
|
|
691
|
+
}
|
|
692
|
+
}), this.addViewer(t.userId, n);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
processMessage(t) {
|
|
696
|
+
const e = this.prepareEvotarProps(
|
|
697
|
+
t.info.displayName,
|
|
698
|
+
t.info.color,
|
|
699
|
+
t.info.sprite
|
|
700
|
+
);
|
|
701
|
+
let i = this.viewers[t.userId];
|
|
702
|
+
if (i)
|
|
703
|
+
i.setProps(e);
|
|
704
|
+
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);
|
|
707
|
+
}
|
|
708
|
+
this.lastEvotarActivity[t.userId] = performance.now(), t.message && i.addMessage(t.message), t.emotes.length > 0 && i.spitEmotes(t.emotes);
|
|
709
|
+
}
|
|
710
|
+
addViewer(t, e) {
|
|
711
|
+
this.subscriptions.forEach((i) => i.onAdd(e)), this.viewers[t] = e;
|
|
712
|
+
}
|
|
713
|
+
deleteViewer(t, e) {
|
|
714
|
+
this.subscriptions.forEach((i) => i.onDelete(e)), delete this.viewers[t];
|
|
715
|
+
}
|
|
716
|
+
addRaider(t) {
|
|
717
|
+
this.subscriptions.forEach((e) => e.onAdd(t)), this.raiders.push(t);
|
|
718
|
+
}
|
|
719
|
+
deleteRaider(t) {
|
|
720
|
+
this.subscriptions.forEach((e) => e.onDelete(t)), this.raiders = this.raiders.filter((e) => e != t);
|
|
721
|
+
}
|
|
722
|
+
zIndexEvotarMax(t) {
|
|
723
|
+
return Object.values(this.viewers).reduce((e, i) => i && e <= i.container.zIndex ? i.container.zIndex + 1 : e, t);
|
|
724
|
+
}
|
|
725
|
+
zIndexEvotarMin(t) {
|
|
726
|
+
return Object.values(this.viewers).reduce((e, i) => i && e >= i.container.zIndex ? i.container.zIndex - 1 : e, t);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
const u = new N();
|
|
730
|
+
class Y {
|
|
731
|
+
constructor() {
|
|
732
|
+
s(this, "stage", new h.Container());
|
|
733
|
+
s(this, "evotars", {});
|
|
734
|
+
s(this, "chatterIds", []);
|
|
735
|
+
s(this, "settings", {});
|
|
736
|
+
s(this, "renderer");
|
|
737
|
+
}
|
|
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,
|
|
742
|
+
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({
|
|
746
|
+
onAdd: (i) => this.stage.addChild(i.container),
|
|
747
|
+
onDelete: (i) => {
|
|
748
|
+
this.stage.removeChild(i.container), this.stage.removeChild(i.trail.container);
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
updateSettings(t) {
|
|
753
|
+
this.settings = t;
|
|
754
|
+
}
|
|
755
|
+
update() {
|
|
756
|
+
v.tick(), u.update(), this.renderer.render(this.stage);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
const p = new Y();
|
|
760
|
+
class K {
|
|
761
|
+
constructor(t) {
|
|
762
|
+
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;
|
|
768
|
+
}
|
|
769
|
+
updateSettings(t) {
|
|
770
|
+
p.updateSettings(t);
|
|
771
|
+
}
|
|
772
|
+
async run(t) {
|
|
773
|
+
if (this.isRendered)
|
|
774
|
+
return;
|
|
775
|
+
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);
|
|
783
|
+
}
|
|
784
|
+
})();
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
export {
|
|
788
|
+
K as Evotars
|
|
789
|
+
};
|