evotars 0.0.2 → 0.0.4
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 +24 -0
- package/dist/config/constants.d.ts +1 -0
- package/dist/entities/EmoteSpitter.d.ts +15 -0
- package/dist/entities/Evotar.d.ts +78 -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 +15 -0
- package/dist/evotars.js +705 -0
- package/dist/evotars.umd.cjs +1 -0
- package/dist/evotarsManager.d.ts +30 -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/soundService.d.ts +14 -0
- package/dist/services/spriteService.d.ts +63 -0
- package/dist/types/dto/action.d.ts +56 -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/index.ts +0 -1
- 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 -1
- package/src/main.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,705 @@
|
|
|
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";
|
|
9
|
+
const m = 0.02 * 1e3;
|
|
10
|
+
class f {
|
|
11
|
+
constructor(t = 0, e) {
|
|
12
|
+
s(this, "isCompleted", !1);
|
|
13
|
+
this.current = t, this.onComplete = e;
|
|
14
|
+
}
|
|
15
|
+
tick(t = m) {
|
|
16
|
+
var e;
|
|
17
|
+
this.isCompleted || (this.current -= t, this.current < 0 && (this.isCompleted = !0, (e = this.onComplete) == null || e.call(this)));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
class V {
|
|
21
|
+
constructor() {
|
|
22
|
+
s(this, "timers", []);
|
|
23
|
+
}
|
|
24
|
+
add(t, e) {
|
|
25
|
+
this.timers.push(new f(t, e));
|
|
26
|
+
}
|
|
27
|
+
tick(t = m) {
|
|
28
|
+
const e = [];
|
|
29
|
+
for (const i of this.timers)
|
|
30
|
+
i.isCompleted || (i.tick(t), e.push(i));
|
|
31
|
+
this.timers = e;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
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 {
|
|
36
|
+
constructor() {
|
|
37
|
+
s(this, "assets", {});
|
|
38
|
+
}
|
|
39
|
+
async initialize(t) {
|
|
40
|
+
this.assets = Object.fromEntries(
|
|
41
|
+
Array.from(Object.entries(t ?? {})).map(([e, i]) => [e, new Audio(i.src)])
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
play(t) {
|
|
45
|
+
const e = this.assets[t];
|
|
46
|
+
e && (e.volume = 0.2, e.pause(), e.currentTime = 0, e.play());
|
|
47
|
+
}
|
|
48
|
+
}
|
|
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
|
|
74
|
+
}
|
|
75
|
+
}, this.sprites[t];
|
|
76
|
+
}
|
|
77
|
+
getAnimatedSprites(t) {
|
|
78
|
+
if (!t)
|
|
79
|
+
throw Error("Sheet is not defined");
|
|
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;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const S = new X();
|
|
102
|
+
class N {
|
|
103
|
+
constructor() {
|
|
104
|
+
s(this, "container", new c.Container());
|
|
105
|
+
s(this, "emotes", []);
|
|
106
|
+
s(this, "moveSpeed", 50);
|
|
107
|
+
s(this, "alphaSpeed", 1);
|
|
108
|
+
s(this, "scaleSpeed", 0.5);
|
|
109
|
+
s(this, "timer");
|
|
110
|
+
}
|
|
111
|
+
add(t) {
|
|
112
|
+
const e = c.Sprite.from(t);
|
|
113
|
+
e.anchor.set(0.5, 0.5), e.scale.set(0, 0), this.emotes.push(e);
|
|
114
|
+
}
|
|
115
|
+
update(t) {
|
|
116
|
+
var e;
|
|
117
|
+
(e = this.timer) == null || e.tick(), (!this.timer || this.timer.isCompleted) && this.emotes.length > 0 && (this.timer = new f(2e3, () => {
|
|
118
|
+
const i = this.emotes.shift();
|
|
119
|
+
i && this.container.addChild(i);
|
|
120
|
+
})), this.container.position.x = t.position.x ?? this.container.position.x, this.container.position.y = t.position.y ?? this.container.position.y;
|
|
121
|
+
for (const i of this.container.children)
|
|
122
|
+
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);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
class _ {
|
|
126
|
+
constructor(t) {
|
|
127
|
+
s(this, "container", new c.Container());
|
|
128
|
+
s(this, "animated", new c.Container());
|
|
129
|
+
s(this, "text", new c.Text(void 0, {
|
|
130
|
+
fontFamily: "Rubik",
|
|
131
|
+
fontSize: 20,
|
|
132
|
+
fill: 2236962,
|
|
133
|
+
align: "left",
|
|
134
|
+
breakWords: !0,
|
|
135
|
+
wordWrap: !0,
|
|
136
|
+
wordWrapWidth: 200
|
|
137
|
+
}));
|
|
138
|
+
s(this, "padding", 10);
|
|
139
|
+
s(this, "borderRadius", 10);
|
|
140
|
+
s(this, "boxColor", 15658734);
|
|
141
|
+
s(this, "fadeShift", 10);
|
|
142
|
+
s(this, "isChecking", !0);
|
|
143
|
+
s(this, "messageQueue", []);
|
|
144
|
+
s(this, "showTween");
|
|
145
|
+
s(this, "hideTween");
|
|
146
|
+
s(this, "timer");
|
|
147
|
+
this.beforeShow = t, this.container.addChild(this.animated), this.text.anchor.set(0.5, 1), this.text.position.set(0, -this.padding);
|
|
148
|
+
}
|
|
149
|
+
trim(t) {
|
|
150
|
+
const e = c.TextMetrics.measureText(t.text, t.style);
|
|
151
|
+
return e.lines.length > 4 ? e.lines.slice(0, 4).join(" ").slice(0, -3) + "..." : t.text;
|
|
152
|
+
}
|
|
153
|
+
update(t) {
|
|
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) {
|
|
156
|
+
this.isChecking = !1;
|
|
157
|
+
const p = this.messageQueue.shift();
|
|
158
|
+
p && (this.beforeShow(), this.show(p));
|
|
159
|
+
}
|
|
160
|
+
this.container.position.x = t.position.x ?? this.container.position.x, this.container.position.y = t.position.y ?? this.container.position.y;
|
|
161
|
+
const e = ((o = this.showTween) == null ? void 0 : o.isPlaying()) || ((h = this.hideTween) == null ? void 0 : h.isPlaying());
|
|
162
|
+
!this.isChecking && !e && this.timer && (this.animated.position.y = Math.sin(this.timer.current * 25e-4) * 4 - 2);
|
|
163
|
+
}
|
|
164
|
+
add(t) {
|
|
165
|
+
this.messageQueue.push(t);
|
|
166
|
+
}
|
|
167
|
+
drawBox(t) {
|
|
168
|
+
const e = {
|
|
169
|
+
x: t.x - this.padding - t.width * t.anchor.x,
|
|
170
|
+
y: t.y - this.padding - t.height * t.anchor.y,
|
|
171
|
+
w: t.width + this.padding * 2,
|
|
172
|
+
h: t.height + this.padding * 2
|
|
173
|
+
}, i = new c.Graphics();
|
|
174
|
+
return i.beginFill(this.boxColor), i.drawRoundedRect(
|
|
175
|
+
e.x,
|
|
176
|
+
e.y,
|
|
177
|
+
e.w,
|
|
178
|
+
e.h,
|
|
179
|
+
this.borderRadius
|
|
180
|
+
), i.drawPolygon(
|
|
181
|
+
{
|
|
182
|
+
x: e.x + e.w / 2 - 10,
|
|
183
|
+
y: e.y + e.h
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
x: e.x + e.w / 2 + 10,
|
|
187
|
+
y: e.y + e.h
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
x: e.x + e.w / 2,
|
|
191
|
+
y: e.y + e.h + 10 - 4
|
|
192
|
+
}
|
|
193
|
+
), i.endFill(), i;
|
|
194
|
+
}
|
|
195
|
+
show(t) {
|
|
196
|
+
this.text.text = t, this.text.text = this.trim(this.text), this.animated.alpha = 0, this.animated.position.y = this.fadeShift;
|
|
197
|
+
const e = this.drawBox(this.text);
|
|
198
|
+
this.animated.removeChildren(), this.animated.addChild(e, this.text);
|
|
199
|
+
const i = {
|
|
200
|
+
alpha: 1,
|
|
201
|
+
y: this.animated.y - this.fadeShift
|
|
202
|
+
}, n = {
|
|
203
|
+
alpha: 0,
|
|
204
|
+
y: this.animated.y + this.fadeShift
|
|
205
|
+
};
|
|
206
|
+
this.hideTween = new T(this.animated).to(n, 500).onComplete(() => {
|
|
207
|
+
this.isChecking = !0;
|
|
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();
|
|
212
|
+
});
|
|
213
|
+
}), this.showTween.start();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
class G {
|
|
217
|
+
constructor() {
|
|
218
|
+
s(this, "text", new c.Text(void 0, {
|
|
219
|
+
fontFamily: "Rubik",
|
|
220
|
+
fontSize: 18,
|
|
221
|
+
fill: 16777215,
|
|
222
|
+
align: "center",
|
|
223
|
+
lineJoin: "round",
|
|
224
|
+
strokeThickness: 4,
|
|
225
|
+
stroke: "black"
|
|
226
|
+
}));
|
|
227
|
+
s(this, "rect", () => ({
|
|
228
|
+
x: this.text.x,
|
|
229
|
+
y: this.text.y,
|
|
230
|
+
w: this.text.width,
|
|
231
|
+
h: this.text.height
|
|
232
|
+
}));
|
|
233
|
+
this.text.anchor.set(0.5, 1), this.text.zIndex = 100;
|
|
234
|
+
}
|
|
235
|
+
update(t) {
|
|
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;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
class Y {
|
|
240
|
+
constructor(t) {
|
|
241
|
+
s(this, "container", new c.Container());
|
|
242
|
+
s(this, "sprites");
|
|
243
|
+
this.sprites = t, this.container.sortableChildren = !0;
|
|
244
|
+
let e = 0;
|
|
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();
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
update(t) {
|
|
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);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
t.scale.x && (i.animationSpeed = 4 / Math.abs(t.scale.x));
|
|
261
|
+
}
|
|
262
|
+
this.container.scale.set(t.scale.x, t.scale.y);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
class Q {
|
|
266
|
+
constructor() {
|
|
267
|
+
s(this, "container", new c.Container());
|
|
268
|
+
s(this, "timer");
|
|
269
|
+
s(this, "sprite");
|
|
270
|
+
s(this, "opacityStep", 0.1);
|
|
271
|
+
s(this, "shadowStep", 50);
|
|
272
|
+
l.stage.addChild(this.container);
|
|
273
|
+
}
|
|
274
|
+
setSprite(t) {
|
|
275
|
+
this.sprite = t;
|
|
276
|
+
}
|
|
277
|
+
update(t) {
|
|
278
|
+
for (const e of this.container.children)
|
|
279
|
+
e.alpha > 0 && (e.alpha = e.alpha - this.opacityStep);
|
|
280
|
+
if (this.timer && !this.timer.isCompleted)
|
|
281
|
+
this.timer.tick();
|
|
282
|
+
else if (t.play) {
|
|
283
|
+
this.timer = new f(this.shadowStep);
|
|
284
|
+
const e = new c.Container();
|
|
285
|
+
if (this.sprite)
|
|
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(
|
|
289
|
+
this.sprite.container.scale.x,
|
|
290
|
+
this.sprite.container.scale.y
|
|
291
|
+
), e.pivot.set(
|
|
292
|
+
this.sprite.container.pivot.x,
|
|
293
|
+
this.sprite.container.pivot.y
|
|
294
|
+
);
|
|
295
|
+
const h = this.sprite.container.getGlobalPosition();
|
|
296
|
+
e.position.set(h.x, h.y);
|
|
297
|
+
}
|
|
298
|
+
this.container.addChild(e);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
class y {
|
|
303
|
+
constructor() {
|
|
304
|
+
s(this, "container", new c.Container());
|
|
305
|
+
s(this, "userState", {});
|
|
306
|
+
s(this, "state", {
|
|
307
|
+
name: "",
|
|
308
|
+
sprite: "",
|
|
309
|
+
color: new c.Color("#969696"),
|
|
310
|
+
direction: 1,
|
|
311
|
+
scale: 1,
|
|
312
|
+
isAnonymous: !1,
|
|
313
|
+
zIndex: 0
|
|
314
|
+
});
|
|
315
|
+
s(this, "animationState", d.Idle);
|
|
316
|
+
// TODO: Refactor sprite initializing, move logic to separate file
|
|
317
|
+
s(this, "sprite");
|
|
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());
|
|
334
|
+
s(this, "message", new _(() => {
|
|
335
|
+
this.state.zIndex = w.zIndexEvotarMax(this.container.zIndex);
|
|
336
|
+
}));
|
|
337
|
+
s(this, "emoteSpitter", new N());
|
|
338
|
+
s(this, "velocity", {
|
|
339
|
+
x: 0,
|
|
340
|
+
y: 0
|
|
341
|
+
});
|
|
342
|
+
s(this, "runSpeed", 0.05);
|
|
343
|
+
s(this, "gravity", 0.2);
|
|
344
|
+
s(this, "dashAcc", 3);
|
|
345
|
+
s(this, "isJumping", !1);
|
|
346
|
+
s(this, "isDashing", !1);
|
|
347
|
+
s(this, "isDespawned", !1);
|
|
348
|
+
s(this, "landTimer");
|
|
349
|
+
s(this, "stateTimer");
|
|
350
|
+
s(this, "scaleTimer");
|
|
351
|
+
s(this, "spawnTween");
|
|
352
|
+
s(this, "fadeTween");
|
|
353
|
+
s(this, "scaleTween");
|
|
354
|
+
this.container.addChild(this.name.text), this.container.addChild(this.emoteSpitter.container), this.container.addChild(this.message.container), this.container.sortableChildren = !0;
|
|
355
|
+
}
|
|
356
|
+
spawn(t = { isFalling: !1 }) {
|
|
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();
|
|
361
|
+
}
|
|
362
|
+
this.stateTimer = new f(5e3, () => {
|
|
363
|
+
this.isJumping || this.setAnimationState(d.Run);
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
despawn(t = {}) {
|
|
367
|
+
this.fadeTween && this.fadeTween.isPlaying() || (this.fadeTween = new g.Tween(this.container).to({ alpha: 0 }, 1e3).onComplete(() => {
|
|
368
|
+
this.isDespawned = !0, t.onComplete && t.onComplete();
|
|
369
|
+
}).start());
|
|
370
|
+
}
|
|
371
|
+
scale(t) {
|
|
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();
|
|
375
|
+
});
|
|
376
|
+
}).start());
|
|
377
|
+
}
|
|
378
|
+
jump(t) {
|
|
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"));
|
|
380
|
+
}
|
|
381
|
+
dash(t) {
|
|
382
|
+
this.isDespawned || this.isDashing || (this.isDashing = !0, this.velocity.x = this.state.direction * (t.force ?? 14));
|
|
383
|
+
}
|
|
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
|
+
}
|
|
391
|
+
}
|
|
392
|
+
async setProps(t) {
|
|
393
|
+
t.sprite && await this.setSprite(t.sprite), this.state = { ...this.state, ...t };
|
|
394
|
+
}
|
|
395
|
+
setUserProps(t) {
|
|
396
|
+
this.userState = { ...this.userState, ...t };
|
|
397
|
+
}
|
|
398
|
+
move() {
|
|
399
|
+
var i;
|
|
400
|
+
const t = this.spriteData.collider, e = {
|
|
401
|
+
x: this.container.position.x,
|
|
402
|
+
y: this.container.position.y
|
|
403
|
+
};
|
|
404
|
+
if (this.isDashing) {
|
|
405
|
+
const n = Math.sign(this.velocity.x);
|
|
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;
|
|
407
|
+
} else {
|
|
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) {
|
|
411
|
+
const n = this.runSpeed * this.state.direction;
|
|
412
|
+
this.velocity.x = n * m;
|
|
413
|
+
}
|
|
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);
|
|
417
|
+
}
|
|
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));
|
|
421
|
+
}
|
|
422
|
+
this.container.position.set(e.x, e.y);
|
|
423
|
+
}
|
|
424
|
+
update() {
|
|
425
|
+
var e, i, n, a, o, h;
|
|
426
|
+
if (this.isDespawned)
|
|
427
|
+
return;
|
|
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({
|
|
431
|
+
name: this.state.name,
|
|
432
|
+
isVisible: !this.state.isAnonymous,
|
|
433
|
+
position: {
|
|
434
|
+
y: -t.h * this.state.scale * this.spriteData.scale
|
|
435
|
+
}
|
|
436
|
+
}), this.message.update({
|
|
437
|
+
position: {
|
|
438
|
+
y: this.name.text.position.y - this.name.text.height - 6
|
|
439
|
+
}
|
|
440
|
+
}), this.emoteSpitter.update({
|
|
441
|
+
position: {
|
|
442
|
+
y: this.message.container.position.y - this.message.container.height
|
|
443
|
+
}
|
|
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({
|
|
461
|
+
play: this.isDashing
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
isOnGround(t) {
|
|
465
|
+
return t > l.renderer.height;
|
|
466
|
+
}
|
|
467
|
+
addMessage(t) {
|
|
468
|
+
var e;
|
|
469
|
+
this.message.add(t), this.state.isAnonymous = !1, (e = this.fadeTween) == null || e.stop(), this.fadeTween = void 0, this.container.alpha = 1;
|
|
470
|
+
}
|
|
471
|
+
spitEmotes(t) {
|
|
472
|
+
for (const e of t)
|
|
473
|
+
this.emoteSpitter.add(e);
|
|
474
|
+
}
|
|
475
|
+
async setAnimationState(t, e = !1) {
|
|
476
|
+
if (this.animationState == t && !e || !this.animatedSprites)
|
|
477
|
+
return;
|
|
478
|
+
this.animationState = t, this.sprite && this.container.removeChild(this.sprite.container);
|
|
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
|
|
483
|
+
), this.container.addChild(this.sprite.container);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
const B = 1e3 * 60 * 5;
|
|
487
|
+
class q {
|
|
488
|
+
constructor() {
|
|
489
|
+
s(this, "viewers", {});
|
|
490
|
+
s(this, "raiders", []);
|
|
491
|
+
s(this, "lastEvotarActivity", {});
|
|
492
|
+
s(this, "subscriptions", []);
|
|
493
|
+
s(this, "hasActivity", (t) => !!this.lastEvotarActivity[t]);
|
|
494
|
+
}
|
|
495
|
+
subscribe(t) {
|
|
496
|
+
this.subscriptions.push(t);
|
|
497
|
+
}
|
|
498
|
+
update() {
|
|
499
|
+
for (const t in this.viewers) {
|
|
500
|
+
const e = this.viewers[t];
|
|
501
|
+
e && e.update();
|
|
502
|
+
}
|
|
503
|
+
for (const t of this.raiders)
|
|
504
|
+
t.update();
|
|
505
|
+
}
|
|
506
|
+
processRaid(t) {
|
|
507
|
+
if (!l.settings.fallingRaiders)
|
|
508
|
+
return;
|
|
509
|
+
const e = 1 / t.viewers * 5e3;
|
|
510
|
+
for (let o = 0; o < t.viewers; o++) {
|
|
511
|
+
const h = new y();
|
|
512
|
+
h.setProps({
|
|
513
|
+
isAnonymous: !0,
|
|
514
|
+
zIndex: -1,
|
|
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({
|
|
521
|
+
onComplete: () => {
|
|
522
|
+
this.deleteRaider(h);
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
const i = this.viewers[t.broadcaster.id], n = {
|
|
528
|
+
...this.prepareEvotarProps(
|
|
529
|
+
t.broadcaster.info.displayName,
|
|
530
|
+
t.broadcaster.info.color
|
|
531
|
+
),
|
|
532
|
+
scale: 8
|
|
533
|
+
}, a = () => {
|
|
534
|
+
const o = new y();
|
|
535
|
+
o.setProps(n), this.addViewer(t.broadcaster.id, o), o.spawn({ isFalling: !0, positionX: 0.5 });
|
|
536
|
+
};
|
|
537
|
+
this.lastEvotarActivity[t.broadcaster.id] = performance.now(), i ? i.despawn({
|
|
538
|
+
onComplete: () => {
|
|
539
|
+
a();
|
|
540
|
+
}
|
|
541
|
+
}) : a();
|
|
542
|
+
}
|
|
543
|
+
async processChatters(t) {
|
|
544
|
+
for (const e in this.viewers) {
|
|
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({
|
|
549
|
+
onComplete: () => {
|
|
550
|
+
this.deleteViewer(e, a);
|
|
551
|
+
}
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
if (l.settings.showAnonymousEvotars) {
|
|
556
|
+
for (const e of t)
|
|
557
|
+
if (!this.viewers[e.userId]) {
|
|
558
|
+
const n = {
|
|
559
|
+
name: e.name,
|
|
560
|
+
isAnonymous: !this.hasActivity(e.userId)
|
|
561
|
+
}, a = new y();
|
|
562
|
+
await a.setProps(n), a.spawn(), this.addViewer(e.userId, a);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
doAction(t, e) {
|
|
567
|
+
if (L(t) && e.jump({
|
|
568
|
+
velocityX: t.data.velocityX,
|
|
569
|
+
velocityY: t.data.velocityY,
|
|
570
|
+
cooldown: t.cooldown
|
|
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) });
|
|
574
|
+
}
|
|
575
|
+
J(t) && e.scale({
|
|
576
|
+
value: t.data.scale,
|
|
577
|
+
duration: t.data.duration,
|
|
578
|
+
cooldown: t.cooldown
|
|
579
|
+
}), O(t) && e.setSprite(t.data.sprite);
|
|
580
|
+
}
|
|
581
|
+
prepareEvotarProps(t, e, i) {
|
|
582
|
+
const n = {
|
|
583
|
+
name: t,
|
|
584
|
+
isAnonymous: !1
|
|
585
|
+
};
|
|
586
|
+
if (i && (n.sprite = i), e)
|
|
587
|
+
try {
|
|
588
|
+
n.color = new c.Color(e);
|
|
589
|
+
} catch {
|
|
590
|
+
}
|
|
591
|
+
return n;
|
|
592
|
+
}
|
|
593
|
+
async processAction(t) {
|
|
594
|
+
const e = this.viewers[t.userId], i = this.prepareEvotarProps(
|
|
595
|
+
t.info.displayName,
|
|
596
|
+
t.info.color,
|
|
597
|
+
t.info.sprite
|
|
598
|
+
);
|
|
599
|
+
if (e)
|
|
600
|
+
await e.setProps(i), this.doAction(t, e);
|
|
601
|
+
else {
|
|
602
|
+
const n = new y();
|
|
603
|
+
await n.setProps(i), n.spawn({
|
|
604
|
+
onComplete: () => {
|
|
605
|
+
const a = this.viewers[t.userId];
|
|
606
|
+
a && this.doAction(t, a);
|
|
607
|
+
}
|
|
608
|
+
}), this.addViewer(t.userId, n);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
async processMessage(t) {
|
|
612
|
+
const e = this.prepareEvotarProps(
|
|
613
|
+
t.info.displayName,
|
|
614
|
+
t.info.color,
|
|
615
|
+
t.info.sprite
|
|
616
|
+
);
|
|
617
|
+
let i = this.viewers[t.userId];
|
|
618
|
+
if (i)
|
|
619
|
+
i.setProps(e);
|
|
620
|
+
else {
|
|
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);
|
|
623
|
+
}
|
|
624
|
+
this.lastEvotarActivity[t.userId] = performance.now(), t.message && i.addMessage(t.message), t.emotes.length > 0 && i.spitEmotes(t.emotes);
|
|
625
|
+
}
|
|
626
|
+
addViewer(t, e) {
|
|
627
|
+
this.subscriptions.forEach((i) => i.onAdd(e)), this.viewers[t] = e;
|
|
628
|
+
}
|
|
629
|
+
deleteViewer(t, e) {
|
|
630
|
+
this.subscriptions.forEach((i) => i.onDelete(e)), delete this.viewers[t];
|
|
631
|
+
}
|
|
632
|
+
addRaider(t) {
|
|
633
|
+
this.subscriptions.forEach((e) => e.onAdd(t)), this.raiders.push(t);
|
|
634
|
+
}
|
|
635
|
+
deleteRaider(t) {
|
|
636
|
+
this.subscriptions.forEach((e) => e.onDelete(t)), this.raiders = this.raiders.filter((e) => e != t);
|
|
637
|
+
}
|
|
638
|
+
zIndexEvotarMax(t) {
|
|
639
|
+
return Object.values(this.viewers).reduce((e, i) => i && e <= i.container.zIndex ? i.container.zIndex + 1 : e, t);
|
|
640
|
+
}
|
|
641
|
+
zIndexEvotarMin(t) {
|
|
642
|
+
return Object.values(this.viewers).reduce((e, i) => i && e >= i.container.zIndex ? i.container.zIndex - 1 : e, t);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
const w = new q();
|
|
646
|
+
class H {
|
|
647
|
+
constructor() {
|
|
648
|
+
s(this, "stage", new c.Container());
|
|
649
|
+
s(this, "evotars", {});
|
|
650
|
+
s(this, "chatterIds", []);
|
|
651
|
+
s(this, "settings", {});
|
|
652
|
+
s(this, "renderer");
|
|
653
|
+
}
|
|
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,
|
|
658
|
+
backgroundAlpha: 0
|
|
659
|
+
}), t.appendChild(this.renderer.view), window.onresize = () => {
|
|
660
|
+
this.renderer.resize(t.clientWidth, t.clientHeight);
|
|
661
|
+
}, this.stage.sortableChildren = !0, w.subscribe({
|
|
662
|
+
onAdd: (i) => this.stage.addChild(i.container),
|
|
663
|
+
onDelete: (i) => {
|
|
664
|
+
this.stage.removeChild(i.container), this.stage.removeChild(i.trail.container);
|
|
665
|
+
}
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
updateSettings(t) {
|
|
669
|
+
this.settings = t;
|
|
670
|
+
}
|
|
671
|
+
update() {
|
|
672
|
+
v.tick(), w.update(), this.renderer.render(this.stage);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
const l = new H();
|
|
676
|
+
class et {
|
|
677
|
+
constructor(t, e) {
|
|
678
|
+
s(this, "isRendered", !1);
|
|
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;
|
|
684
|
+
}
|
|
685
|
+
updateSettings(t) {
|
|
686
|
+
l.updateSettings(t);
|
|
687
|
+
}
|
|
688
|
+
async run() {
|
|
689
|
+
if (this.isRendered)
|
|
690
|
+
return;
|
|
691
|
+
this.isRendered = !0, await (async () => {
|
|
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);
|
|
699
|
+
}
|
|
700
|
+
})();
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
export {
|
|
704
|
+
et as Evotars
|
|
705
|
+
};
|