evotars 0.0.8 → 0.0.9

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.
Files changed (80) hide show
  1. package/.editorconfig +13 -0
  2. package/.prettierrc.json +3 -0
  3. package/README.md +3 -5
  4. package/index.html +13 -0
  5. package/package.json +2 -16
  6. package/playground/main.ts +48 -0
  7. package/playground/styles.css +17 -0
  8. package/public/evotars/agent/data.json +18 -0
  9. package/public/evotars/agent/sprite.json +166 -0
  10. package/public/evotars/agent/sprite.png +0 -0
  11. package/public/evotars/cat/data.json +18 -0
  12. package/public/evotars/cat/sprite.json +231 -0
  13. package/public/evotars/cat/sprite.png +0 -0
  14. package/public/evotars/dude/data.json +18 -0
  15. package/public/evotars/dude/sprite.json +231 -0
  16. package/public/evotars/dude/sprite.png +0 -0
  17. package/public/evotars/girl/data.json +18 -0
  18. package/public/evotars/girl/sprite.json +231 -0
  19. package/public/evotars/girl/sprite.png +0 -0
  20. package/public/evotars/nerd/data.json +18 -0
  21. package/public/evotars/nerd/sprite.json +231 -0
  22. package/public/evotars/nerd/sprite.png +0 -0
  23. package/public/evotars/senior/data.json +18 -0
  24. package/public/evotars/senior/sprite.json +231 -0
  25. package/public/evotars/senior/sprite.png +0 -0
  26. package/public/evotars/set.json +10 -0
  27. package/public/evotars/sith/data.json +18 -0
  28. package/public/evotars/sith/sprite.json +166 -0
  29. package/public/evotars/sith/sprite.png +0 -0
  30. package/public/evotars/sponge/data.json +18 -0
  31. package/public/evotars/sponge/sprite.json +231 -0
  32. package/public/evotars/sponge/sprite.png +0 -0
  33. package/public/fonts/Rubik.ttf +0 -0
  34. package/public/sounds/jump.mp3 +0 -0
  35. package/src/app.ts +71 -0
  36. package/src/config/constants.ts +1 -0
  37. package/src/entities/EmoteSpitter.ts +102 -0
  38. package/src/entities/Evotar.ts +468 -0
  39. package/src/entities/Message.ts +164 -0
  40. package/src/entities/Name.ts +33 -0
  41. package/src/entities/SpriteContainer.ts +65 -0
  42. package/src/entities/TrailEffect.ts +73 -0
  43. package/src/evotars.ts +75 -0
  44. package/src/evotarsManager.ts +313 -0
  45. package/src/helpers/timer.ts +43 -0
  46. package/src/helpers/types.ts +4 -0
  47. package/src/services/soundService.ts +30 -0
  48. package/src/services/spriteService.ts +167 -0
  49. package/src/types/dto/action.ts +79 -0
  50. package/{dist/types/dto/chatter.d.ts → src/types/dto/chatter.ts} +2 -2
  51. package/src/types/dto/event.ts +9 -0
  52. package/src/types/dto/message.ts +8 -0
  53. package/src/types/dto/settings.ts +5 -0
  54. package/src/types/dto/user.ts +13 -0
  55. package/tsconfig.json +23 -0
  56. package/vite.config.js +26 -0
  57. package/dist/app.d.ts +0 -24
  58. package/dist/config/constants.d.ts +0 -1
  59. package/dist/entities/EmoteSpitter.d.ts +0 -15
  60. package/dist/entities/Evotar.d.ts +0 -78
  61. package/dist/entities/Message.d.ts +0 -27
  62. package/dist/entities/Name.d.ts +0 -14
  63. package/dist/entities/SpriteContainer.d.ts +0 -16
  64. package/dist/entities/TrailEffect.d.ts +0 -15
  65. package/dist/evotars.d.ts +0 -15
  66. package/dist/evotars.js +0 -722
  67. package/dist/evotars.umd.cjs +0 -1
  68. package/dist/evotarsManager.d.ts +0 -30
  69. package/dist/helpers/timer.d.ts +0 -14
  70. package/dist/helpers/types.d.ts +0 -10
  71. package/dist/services/soundService.d.ts +0 -14
  72. package/dist/services/spriteService.d.ts +0 -63
  73. package/dist/types/dto/action.d.ts +0 -56
  74. package/dist/types/dto/event.d.ts +0 -9
  75. package/dist/types/dto/message.d.ts +0 -8
  76. package/dist/types/dto/settings.d.ts +0 -5
  77. package/dist/types/dto/user.d.ts +0 -12
  78. /package/{dist/index.d.ts → src/index.ts} +0 -0
  79. /package/{dist/types/dto/index.d.ts → src/types/dto/index.ts} +0 -0
  80. /package/{dist/types/index.d.ts → src/types/index.ts} +0 -0
@@ -1 +0,0 @@
1
- (function(l,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("pixi.js"),require("tinycolor2"),require("@tweenjs/tween.js"),require("@pixi/gif")):typeof define=="function"&&define.amd?define(["exports","pixi.js","tinycolor2","@tweenjs/tween.js","@pixi/gif"],d):(l=typeof globalThis<"u"?globalThis:l||self,d(l.evotars={},l.PIXI,l.tinycolor,l.TWEEN,l.gif))})(this,function(l,d,x,T,z){"use strict";var H=Object.defineProperty;var K=(l,d,x)=>d in l?H(l,d,{enumerable:!0,configurable:!0,writable:!0,value:x}):l[d]=x;var s=(l,d,x)=>(K(l,typeof d!="symbol"?d+"":d,x),x);function E(r){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const e in r)if(e!=="default"){const i=Object.getOwnPropertyDescriptor(r,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:()=>r[e]})}}return t.default=r,Object.freeze(t)}const c=E(d),S=E(T),u=.02*1e3;class w{constructor(t=0,e){s(this,"isCompleted",!1);this.current=t,this.onComplete=e}tick(t=u){var e;this.isCompleted||(this.current-=t,this.current<0&&(this.isCompleted=!0,(e=this.onComplete)==null||e.call(this)))}}class M{constructor(){s(this,"timers",[])}add(t,e){this.timers.push(new w(t,e))}tick(t=u){const e=[];for(const i of this.timers)i.isCompleted||(i.tick(t),e.push(i));this.timers=e}}const A=new M,R=r=>r.name=="jump",k=r=>r.name=="color",P=r=>r.name=="grow",F=r=>r.name=="dash",j=r=>r.name=="sprite";class O{constructor(){s(this,"assets",{})}async initialize(t){this.assets=Object.fromEntries(Array.from(Object.entries(t??{})).map(([e,i])=>[e,new Audio(i.src)]))}play(t){const e=this.assets[t];e&&(e.volume=.2,e.pause(),e.currentTime=0,e.play())}}const D=new O;var p=(r=>(r.Idle="Idle",r.Jump="Jump",r.Fall="Fall",r.Land="Land",r.Run="Run",r.Die="Die",r))(p||{});class V{constructor(){s(this,"spriteLoaderFn");s(this,"sprites",{})}initialize(t){this.spriteLoaderFn=t}async getSpriteData(t){const e=await this.spriteLoaderFn(t);if(!e)return;if(this.sprites[t])return this.sprites[t];const i=await d.Assets.load(e.image),n=new d.Spritesheet({texture:i,data:e.sprite});return await n.parse(),this.sprites[t]={sheet:n,data:{...e.data,scale:e.data.scale??1}},this.sprites[t]}getAnimatedSprites(t){if(!t)throw Error("Sheet is not defined");if(!this.sprites[t])throw Error("Sprite is not loaded");const e=this.sprites[t].data,i=this.sprites[t].sheet,n={};for(const a of i.data.meta.frameTags??[]){if(!i.data.meta.layers)throw Error("Layers are not defined");const o={};for(const h of i.data.meta.layers){const f=[];for(let v=a.from;v<=a.to;v++){const X=v.toString(),I=e.name+"_"+h.name+"_"+X,Y=i.textures[I],Q=i.data.frames[I].duration;f.push({texture:Y,time:Q})}const C=new d.AnimatedSprite(f);C.texture.baseTexture.scaleMode=d.SCALE_MODES.NEAREST,o[h.name]=C}a.name&&(n[a.name]=o)}return n}}const b=new V;class _{constructor(){s(this,"container",new c.Container);s(this,"emotes",[]);s(this,"moveSpeed",50);s(this,"alphaSpeed",1);s(this,"scaleSpeed",.5);s(this,"timer")}async add(t){const e=await fetch(t),i=e.headers.get("content-type");let n;switch(i){case"image/gif":{const a=await e.arrayBuffer();n=z.AnimatedGIF.fromBuffer(a);break}case"image/png":{n=c.Sprite.from(t);break}default:{console.warn("Unsupported content type: ",t);return}}n.anchor.set(.5,.5),n.scale.set(0,0),this.emotes.push(n)}update(t){var e;(e=this.timer)==null||e.tick(),(!this.timer||this.timer.isCompleted)&&this.emotes.length>0&&(this.timer=new w(2e3,()=>{const i=this.emotes.shift();i&&this.container.addChild(i)})),this.container.position.x=t.position.x??this.container.position.x,this.container.position.y=t.position.y??this.container.position.y;for(const i of this.container.children)i.position.y-=u*this.moveSpeed/1e3,i.scale.x+=u*this.scaleSpeed/1e3,i.scale.y+=u*this.scaleSpeed/1e3,i.scale.x>1&&(i.alpha-=u*this.alphaSpeed/1e3),i.alpha<=0&&this.container.removeChild(i)}}class L{constructor(t){s(this,"container",new c.Container);s(this,"animated",new c.Container);s(this,"text",new c.Text(void 0,{fontFamily:"Rubik",fontSize:20,fill:2236962,align:"left",breakWords:!0,wordWrap:!0,wordWrapWidth:200}));s(this,"padding",10);s(this,"borderRadius",10);s(this,"boxColor",15658734);s(this,"fadeShift",10);s(this,"isChecking",!0);s(this,"messageQueue",[]);s(this,"showTween");s(this,"hideTween");s(this,"timer");this.beforeShow=t,this.container.addChild(this.animated),this.text.anchor.set(.5,1),this.text.position.set(0,-this.padding)}trim(t){const e=c.TextMetrics.measureText(t.text,t.style);return e.lines.length>4?e.lines.slice(0,4).join(" ").slice(0,-3)+"...":t.text}update(t){var i,n,a,o,h;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){this.isChecking=!1;const f=this.messageQueue.shift();f&&(this.beforeShow(),this.show(f))}this.container.position.x=t.position.x??this.container.position.x,this.container.position.y=t.position.y??this.container.position.y;const e=((o=this.showTween)==null?void 0:o.isPlaying())||((h=this.hideTween)==null?void 0:h.isPlaying());!this.isChecking&&!e&&this.timer&&(this.animated.position.y=Math.sin(this.timer.current*.0025)*4-2)}add(t){this.messageQueue.push(t)}drawBox(t){const e={x:t.x-this.padding-t.width*t.anchor.x,y:t.y-this.padding-t.height*t.anchor.y,w:t.width+this.padding*2,h:t.height+this.padding*2},i=new c.Graphics;return i.beginFill(this.boxColor),i.drawRoundedRect(e.x,e.y,e.w,e.h,this.borderRadius),i.drawPolygon({x:e.x+e.w/2-10,y:e.y+e.h},{x:e.x+e.w/2+10,y:e.y+e.h},{x:e.x+e.w/2,y:e.y+e.h+10-4}),i.endFill(),i}show(t){this.text.text=t,this.text.text=this.trim(this.text),this.animated.alpha=0,this.animated.position.y=this.fadeShift;const e=this.drawBox(this.text);this.animated.removeChildren(),this.animated.addChild(e,this.text);const i={alpha:1,y:this.animated.y-this.fadeShift},n={alpha:0,y:this.animated.y+this.fadeShift};this.hideTween=new T.Tween(this.animated).to(n,500).onComplete(()=>{this.isChecking=!0}),this.showTween=new T.Tween(this.animated).to(i,500).onComplete(()=>{this.timer=new w(1e4,()=>{var a;(a=this.hideTween)==null||a.start()})}),this.showTween.start()}}class J{constructor(){s(this,"text",new c.Text(void 0,{fontFamily:"Rubik",fontSize:18,fill:16777215,align:"center",lineJoin:"round",strokeThickness:4,stroke:"black"}));s(this,"rect",()=>({x:this.text.x,y:this.text.y,w:this.text.width,h:this.text.height}));this.text.anchor.set(.5,1),this.text.zIndex=100}update(t){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}}class U{constructor(t){s(this,"container",new c.Container);s(this,"sprites");this.sprites=t,this.container.sortableChildren=!0;let e=0;for(const i in this.sprites){const n=this.sprites[i];this.container.addChild(n),n.zIndex=++e,n.anchor.set(.5,0),n.autoUpdate=!1,n.play()}}update(t){for(const e in this.sprites){const i=this.sprites[e];if(t.play&&i.update(u*.06),t.color){for(const n in t.color)if(n==e){const a=t.color[n];a&&(i.alpha=a.alpha,i.tint=a)}}t.scale.x&&(i.animationSpeed=4/Math.abs(t.scale.x))}this.container.scale.set(t.scale.x,t.scale.y)}}class W{constructor(){s(this,"container",new c.Container);s(this,"timer");s(this,"sprite");s(this,"opacityStep",.1);s(this,"shadowStep",50);m.stage.addChild(this.container)}setSprite(t){this.sprite=t}update(t){for(const e of this.container.children)e.alpha>0&&(e.alpha=e.alpha-this.opacityStep);if(this.timer&&!this.timer.isCompleted)this.timer.tick();else if(t.play){this.timer=new w(this.shadowStep);const e=new c.Container;if(this.sprite)for(const i in this.sprite.sprites){const n=this.sprite.sprites[i],a=n.texture.clone(),o=new c.Sprite(a);o.anchor.set(.5,0),o.alpha=n.alpha,o.tint=n.tint,e.addChild(o),e.scale.set(this.sprite.container.scale.x,this.sprite.container.scale.y),e.pivot.set(this.sprite.container.pivot.x,this.sprite.container.pivot.y);const h=this.sprite.container.getGlobalPosition();e.position.set(h.x,h.y)}this.container.addChild(e)}}}class g{constructor(){s(this,"container",new c.Container);s(this,"userState",{});s(this,"state",{name:"",sprite:"",color:new c.Color("#969696"),direction:1,scale:1,isAnonymous:!1,zIndex:0});s(this,"animationState",p.Idle);s(this,"sprite");s(this,"spriteData",{name:"evotar",collider:{x:0,y:0,w:0,h:0},size:{w:0,h:0},scale:1,flip:!1,colored:[]});s(this,"animatedSprites");s(this,"trail",new W);s(this,"name",new J);s(this,"message",new L(()=>{this.state.zIndex=y.zIndexEvotarMax(this.container.zIndex)}));s(this,"emoteSpitter",new _);s(this,"velocity",{x:0,y:0});s(this,"runSpeed",.05);s(this,"gravity",.2);s(this,"dashAcc",3);s(this,"isJumping",!1);s(this,"isDashing",!1);s(this,"isDespawned",!1);s(this,"landTimer");s(this,"stateTimer");s(this,"scaleTimer");s(this,"spawnTween");s(this,"fadeTween");s(this,"scaleTween");this.container.addChild(this.name.text),this.container.addChild(this.emoteSpitter.container),this.container.addChild(this.message.container),this.container.sortableChildren=!0}spawn(t={isFalling:!1}){const e=this.spriteData.collider,i=-(e.y+e.h-this.spriteData.size.h/2),n=t.isFalling?i:m.renderer.height,a=this.spriteData.size.w*this.state.scale*this.spriteData.scale,o=t.positionX!=null?t.positionX*m.renderer.width:Math.random()*(m.renderer.width-a)+a/2,h=n*this.state.scale*this.spriteData.scale;if(this.container.x=o,this.container.y=h,this.state.direction=Math.random()>.5?1:-1,!t.isFalling){const f=y.zIndexEvotarMin(this.container.zIndex);this.state.zIndex=f,this.container.alpha=0,this.spawnTween=new S.Tween(this.container).to({alpha:1},500).onComplete(t.onComplete).start()}this.stateTimer=new w(5e3,()=>{this.isJumping||this.setAnimationState(p.Run)})}despawn(t={}){this.fadeTween&&this.fadeTween.isPlaying()||(this.fadeTween=new S.Tween(this.container).to({alpha:0},1e3).onComplete(()=>{this.isDespawned=!0,t.onComplete&&t.onComplete()}).start())}scale(t){this.scaleTween&&this.scaleTween.isPlaying()||this.scaleTimer&&!this.scaleTimer.isCompleted||(this.scaleTween=new S.Tween(this).to({state:{scale:t.value??2}},2e3).onComplete(()=>{this.scaleTimer=new w((t.duration??10)*1e3,()=>{this.scaleTween=new S.Tween(this).to({state:{scale:1}},2e3).start()})}).start())}jump(t){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(p.Jump),D.play("jump"))}dash(t){this.isDespawned||this.isDashing||(this.isDashing=!0,this.velocity.x=this.state.direction*(t.force??14))}async setSprite(t){if(t&&t!=this.state.sprite){const e=await b.getSpriteData(t);if(!e)return;this.state.sprite=t,this.spriteData=e.data,this.animatedSprites=b.getAnimatedSprites(t),this.setAnimationState(this.animationState,!0)}}async setProps(t){t.sprite&&await this.setSprite(t.sprite),this.state={...this.state,...t}}setUserProps(t){this.userState={...this.userState,...t}}move(){var i;const t=this.spriteData.collider,e={x:this.container.position.x,y:this.container.position.y};if(this.isDashing){const n=Math.sign(this.velocity.x);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}else{if((i=this.stateTimer)!=null&&i.isCompleted&&(this.stateTimer=new w(Math.random()*5e3,()=>{this.animationState==p.Idle?this.setAnimationState(p.Run):this.animationState==p.Run&&this.setAnimationState(p.Idle)})),this.animationState==p.Run){const n=this.runSpeed*this.state.direction;this.velocity.x=n*u}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=m.renderer.height,this.animationState==p.Fall&&(this.setAnimationState(p.Land),this.landTimer=new w(200,()=>{this.setAnimationState(p.Idle),this.isJumping=!1}))),this.velocity.y>0&&this.setAnimationState(p.Fall)}if(this.animationState!=p.Idle||this.isDashing){const n=t.w/2*this.state.scale*this.spriteData.scale,a=this.container.x-n<0,o=this.container.x+n>m.renderer.width;(a||o)&&(this.state.direction=-this.state.direction,this.velocity.x=-this.velocity.x,a&&(e.x=n),o&&(e.x=m.renderer.width-n))}this.container.position.set(e.x,e.y)}update(){var e,i,n,a,o,h;if(this.isDespawned)return;(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;const t=this.spriteData.collider;if(this.name.update({name:this.state.name,isVisible:!this.state.isAnonymous,position:{y:-t.h*this.state.scale*this.spriteData.scale}}),this.message.update({position:{y:this.name.text.position.y-this.name.text.height-6}}),this.emoteSpitter.update({position:{y:this.message.container.position.y-this.message.container.height}}),this.move(),this.sprite){const f=Object.fromEntries(this.spriteData.colored.map(v=>[v,this.userState.color?this.userState.color:this.state.color])),C=this.spriteData.flip?this.state.direction:1;this.sprite.update({color:f,scale:{x:C*this.state.scale*this.spriteData.scale,y:this.state.scale*this.spriteData.scale},play:!this.isDashing})}this.trail.update({play:this.isDashing})}isOnGround(t){return t>m.renderer.height}addMessage(t){var e;this.message.add(t),this.state.isAnonymous=!1,(e=this.fadeTween)==null||e.stop(),this.fadeTween=void 0,this.container.alpha=1}spitEmotes(t){for(const e of t)this.emoteSpitter.add(e)}async setAnimationState(t,e=!1){if(this.animationState==t&&!e||!this.animatedSprites)return;this.animationState=t,this.sprite&&this.container.removeChild(this.sprite.container);const i=this.animatedSprites[this.animationState]??this.animatedSprites[p.Idle];this.sprite=new U(i),this.trail.setSprite(this.sprite),this.sprite.container.pivot.set(0,this.spriteData.collider.y+this.spriteData.collider.h),this.container.addChild(this.sprite.container)}}const N=1e3*60*5;class q{constructor(){s(this,"viewers",{});s(this,"raiders",[]);s(this,"lastEvotarActivity",{});s(this,"subscriptions",[]);s(this,"hasActivity",t=>!!this.lastEvotarActivity[t])}subscribe(t){this.subscriptions.push(t)}update(){for(const t in this.viewers){const e=this.viewers[t];e&&e.update()}for(const t of this.raiders)t.update()}processRaid(t){if(!m.settings.fallingRaiders)return;const e=1/t.viewers*5e3;for(let o=0;o<t.viewers;o++){const h=new g;h.setProps({isAnonymous:!0,zIndex:-1,sprite:"agent",color:new c.Color(t.broadcaster.info.color)}),A.add(e*o,()=>{this.addRaider(h),h.spawn({isFalling:!0})}),A.add(o*e+3e4,()=>{h.despawn({onComplete:()=>{this.deleteRaider(h)}})})}const i=this.viewers[t.broadcaster.id],n={...this.prepareEvotarProps(t.broadcaster.info.displayName,t.broadcaster.info.color),scale:8},a=()=>{const o=new g;o.setProps(n),this.addViewer(t.broadcaster.id,o),o.spawn({isFalling:!0,positionX:.5})};this.lastEvotarActivity[t.broadcaster.id]=performance.now(),i?i.despawn({onComplete:()=>{a()}}):a()}async processChatters(t){for(const e in this.viewers){const i=this.lastEvotarActivity[e],n=!!i&&performance.now()-i<N;if(t.every(a=>a.userId!=e)&&!n){const a=this.viewers[e];a&&a.despawn({onComplete:()=>{this.deleteViewer(e,a)}})}}if(m.settings.showAnonymousEvotars){for(const e of t)if(!this.viewers[e.userId]){const n={name:e.name,isAnonymous:!this.hasActivity(e.userId)},a=new g;await a.setProps(n),a.spawn(),this.addViewer(e.userId,a)}}}doAction(t,e){if(R(t)&&e.jump({velocityX:t.data.velocityX,velocityY:t.data.velocityY,cooldown:t.cooldown}),F(t)&&e.dash({force:t.data.force,cooldown:t.cooldown}),k(t)){const i=x(t.data.color);i&&i.isValid()&&e.setUserProps({color:new c.Color(t.data.color)})}P(t)&&e.scale({value:t.data.scale,duration:t.data.duration,cooldown:t.cooldown}),j(t)&&e.setSprite(t.data.sprite)}prepareEvotarProps(t,e,i){const n={name:t,isAnonymous:!1};if(i&&(n.sprite=i),e)try{n.color=new c.Color(e)}catch{}return n}async processAction(t){const e=this.viewers[t.userId],i=this.prepareEvotarProps(t.info.displayName,t.info.color,t.info.sprite);if(e)await e.setProps(i),this.doAction(t,e);else{const n=new g;await n.setProps(i),n.spawn({onComplete:()=>{const a=this.viewers[t.userId];a&&this.doAction(t,a)}}),this.addViewer(t.userId,n)}}async processMessage(t){const e=this.prepareEvotarProps(t.info.displayName,t.info.color,t.info.sprite);let i=this.viewers[t.userId];if(i)i.setProps(e);else{const n=m.settings.fallingEvotars?!this.hasActivity(t.userId):!1;i=new g,await i.setProps(e),i.spawn({isFalling:n}),this.addViewer(t.userId,i)}this.lastEvotarActivity[t.userId]=performance.now(),t.message&&i.addMessage(t.message),t.emotes.length>0&&i.spitEmotes(t.emotes)}addViewer(t,e){this.subscriptions.forEach(i=>i.onAdd(e)),this.viewers[t]=e}deleteViewer(t,e){this.subscriptions.forEach(i=>i.onDelete(e)),delete this.viewers[t]}addRaider(t){this.subscriptions.forEach(e=>e.onAdd(t)),this.raiders.push(t)}deleteRaider(t){this.subscriptions.forEach(e=>e.onDelete(t)),this.raiders=this.raiders.filter(e=>e!=t)}zIndexEvotarMax(t){return Object.values(this.viewers).reduce((e,i)=>i&&e<=i.container.zIndex?i.container.zIndex+1:e,t)}zIndexEvotarMin(t){return Object.values(this.viewers).reduce((e,i)=>i&&e>=i.container.zIndex?i.container.zIndex-1:e,t)}}const y=new q;class G{constructor(){s(this,"stage",new c.Container);s(this,"evotars",{});s(this,"chatterIds",[]);s(this,"settings",{});s(this,"renderer")}async initialize(t,e){b.initialize(e.spriteLoaderFn),D.initialize(e.sounds),this.renderer=new c.Renderer({width:t.clientWidth,height:t.clientHeight,backgroundAlpha:0}),t.appendChild(this.renderer.view),window.onresize=()=>{this.renderer.resize(t.clientWidth,t.clientHeight)},this.stage.sortableChildren=!0,y.subscribe({onAdd:i=>this.stage.addChild(i.container),onDelete:i=>{this.stage.removeChild(i.container),this.stage.removeChild(i.trail.container)}})}updateSettings(t){this.settings=t}update(){A.tick(),y.update(),this.renderer.render(this.stage)}}const m=new G;class B{constructor(t,e){s(this,"isRendered",!1);s(this,"processMessage",t=>y.processMessage(t));s(this,"processAction",t=>y.processAction(t));s(this,"processChatters",t=>y.processChatters(t));s(this,"processRaid",t=>y.processRaid(t));this.root=t,this.options=e}updateSettings(t){m.updateSettings(t)}async run(){if(this.isRendered)return;this.isRendered=!0,await(async()=>{await m.initialize(this.root,this.options),performance.now();let e=-1;const n=1e3/60;requestAnimationFrame(a);function a(o=performance.now()){const h=o-e|0;h>n&&(e=o-h%n,m.update()),requestAnimationFrame(a)}})()}}l.Evotars=B,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
@@ -1,30 +0,0 @@
1
- import { Evotar } from './entities/Evotar';
2
- import { MessageEntity, RaidData, TwitchChatterEntity, UserActionEntity } from './types';
3
-
4
- type EvotarsManagerSubscription = {
5
- onAdd: (evotar: Evotar) => void;
6
- onDelete: (evotar: Evotar) => void;
7
- };
8
- declare class EvotarsManager {
9
- private viewers;
10
- private raiders;
11
- private lastEvotarActivity;
12
- private subscriptions;
13
- subscribe(subscription: EvotarsManagerSubscription): void;
14
- update(): void;
15
- processRaid(data: RaidData): void;
16
- processChatters(data: TwitchChatterEntity[]): Promise<void>;
17
- private hasActivity;
18
- doAction(action: UserActionEntity, evotar: Evotar): void;
19
- private prepareEvotarProps;
20
- processAction(action: UserActionEntity): Promise<void>;
21
- processMessage(data: MessageEntity): Promise<void>;
22
- addViewer(id: string, evotar: Evotar): void;
23
- deleteViewer(id: string, evotar: Evotar): void;
24
- addRaider(evotar: Evotar): void;
25
- deleteRaider(evotar: Evotar): void;
26
- zIndexEvotarMax(from: number): number;
27
- zIndexEvotarMin(from: number): number;
28
- }
29
- export declare const evotarsManager: EvotarsManager;
30
- export {};
@@ -1,14 +0,0 @@
1
- export declare class Timer {
2
- current: number;
3
- private onComplete?;
4
- isCompleted: boolean;
5
- constructor(current?: number, onComplete?: (() => void) | undefined);
6
- tick(delta?: number): void;
7
- }
8
- declare class Timers {
9
- private timers;
10
- add(current?: number, onComplete?: () => void): void;
11
- tick(delta?: number): void;
12
- }
13
- export declare const timers: Timers;
14
- export {};
@@ -1,10 +0,0 @@
1
- export type Point = {
2
- x?: number;
3
- y?: number;
4
- };
5
- export type Rect = {
6
- x: number;
7
- y: number;
8
- w: number;
9
- h: number;
10
- };
@@ -1,14 +0,0 @@
1
- export type SoundOptions = {
2
- jump?: {
3
- src: string;
4
- };
5
- };
6
- declare class SoundService {
7
- assets: {
8
- [key: string]: HTMLAudioElement;
9
- };
10
- initialize(options?: SoundOptions): Promise<void>;
11
- play(name: string): void;
12
- }
13
- export declare const soundService: SoundService;
14
- export {};
@@ -1,63 +0,0 @@
1
- import { AnimatedSprite, ISpritesheetData, ISpritesheetFrameData, Spritesheet } from 'pixi.js';
2
-
3
- export type EvotarSpriteData = {
4
- name: string;
5
- collider: Collider;
6
- size: SpriteSize;
7
- scale: number;
8
- flip: boolean;
9
- colored: string[];
10
- };
11
- export type SpriteLoaderFn = (name: string) => Promise<{
12
- sprite: SpritesheetData;
13
- data: EvotarSpriteData;
14
- image: string;
15
- } | undefined>;
16
- export type Collider = {
17
- x: number;
18
- y: number;
19
- w: number;
20
- h: number;
21
- };
22
- export interface SpritesheetFrameData extends ISpritesheetFrameData {
23
- duration: number;
24
- }
25
- export interface SpritesheetData extends ISpritesheetData {
26
- frames: Record<string, SpritesheetFrameData>;
27
- }
28
- export type EvotarLayerSprites = {
29
- [layer in string]: AnimatedSprite;
30
- };
31
- export type EvotarAnimatedSprites = {
32
- [tag in string]: EvotarLayerSprites;
33
- };
34
- export declare enum EvotarSpriteTags {
35
- Idle = "Idle",
36
- Jump = "Jump",
37
- Fall = "Fall",
38
- Land = "Land",
39
- Run = "Run",
40
- Die = "Die"
41
- }
42
- export type FrameTag = {
43
- from: number;
44
- name: string;
45
- to: number;
46
- direction: string;
47
- };
48
- export type SpriteSize = {
49
- w: number;
50
- h: number;
51
- };
52
- export type SpriteData = {
53
- sheet: Spritesheet<SpritesheetData>;
54
- data: EvotarSpriteData;
55
- };
56
- export declare class SpriteService {
57
- private spriteLoaderFn;
58
- private sprites;
59
- initialize(spriteLoaderFn: SpriteLoaderFn): void;
60
- getSpriteData(name: string): Promise<SpriteData | undefined>;
61
- getAnimatedSprites(name: string): EvotarAnimatedSprites;
62
- }
63
- export declare const spriteService: SpriteService;
@@ -1,56 +0,0 @@
1
- import { UserInfo } from './user';
2
-
3
- export type ActionData = Record<string, string | number | undefined>;
4
- export type ActionableData = {
5
- arguments: string[];
6
- action: ActionData;
7
- };
8
- export type ActionEntity = {
9
- id: number;
10
- name: string;
11
- title: string;
12
- description: string;
13
- data: ActionData;
14
- };
15
- export type UserActionEntity = {
16
- userId: string;
17
- cooldown: number;
18
- info: UserInfo;
19
- } & ActionEntity;
20
- export type JumpUserActionEntity = {
21
- name: 'jump';
22
- data: {
23
- velocityX: number;
24
- velocityY: number;
25
- };
26
- } & UserActionEntity;
27
- export type ColorUserActionEntity = {
28
- name: 'color';
29
- data: {
30
- color: string;
31
- };
32
- } & UserActionEntity;
33
- export type GrowUserActionEntity = {
34
- name: 'grow';
35
- data: {
36
- duration: number;
37
- scale: number;
38
- };
39
- } & UserActionEntity;
40
- export type DashUserActionEntity = {
41
- name: 'dash';
42
- data: {
43
- force: number;
44
- };
45
- } & UserActionEntity;
46
- export type SpriteUserActionEntity = {
47
- name: 'sprite';
48
- data: {
49
- sprite: string;
50
- };
51
- } & UserActionEntity;
52
- export declare const isJumpUserActionEntity: (entity: ActionEntity) => entity is JumpUserActionEntity;
53
- export declare const isColorUserActionEntity: (entity: ActionEntity) => entity is ColorUserActionEntity;
54
- export declare const isGrowUserActionEntity: (entity: ActionEntity) => entity is GrowUserActionEntity;
55
- export declare const isDashUserActionEntity: (entity: ActionEntity) => entity is DashUserActionEntity;
56
- export declare const isSpriteUserActionEntity: (entity: ActionEntity) => entity is SpriteUserActionEntity;
@@ -1,9 +0,0 @@
1
- import { UserInfo } from './user';
2
-
3
- export type RaidData = {
4
- broadcaster: {
5
- id: string;
6
- info: UserInfo;
7
- };
8
- viewers: number;
9
- };
@@ -1,8 +0,0 @@
1
- import { UserInfo } from './user';
2
-
3
- export type MessageEntity = {
4
- userId: string;
5
- message: string;
6
- emotes: string[];
7
- info: UserInfo;
8
- };
@@ -1,5 +0,0 @@
1
- export type SettingsEntity = {
2
- showAnonymousEvotars?: boolean;
3
- fallingEvotars?: boolean;
4
- fallingRaiders?: boolean;
5
- };
@@ -1,12 +0,0 @@
1
- export type UserEntity = {
2
- userId: number;
3
- guid: string;
4
- displayName: string;
5
- profileImageUrl: string;
6
- previewUrl: string;
7
- };
8
- export type UserInfo = {
9
- displayName: string;
10
- color?: string;
11
- sprite?: string;
12
- };
File without changes
File without changes