gameforge
Version:
Lightweight HTML5 boilerplate for quick 2D game prototyping
2 lines (1 loc) • 5.89 kB
JavaScript
var _=Object.defineProperty;var b=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable;var f=(i,t,e)=>t in i?_(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,l=(i,t)=>{for(var e in t||(t={}))U.call(t,e)&&f(i,e,t[e]);if(b)for(var e of b(t))S.call(t,e)&&f(i,e,t[e]);return i};var h=(i,t)=>{for(var e in t)_(i,e,{get:t[e],enumerable:!0})};import*as G from"pixi.js";import*as H from"@pixi/sound";import{default as Ft}from"webfontloader";var K=i=>i,T=i=>i*i*i,x=i=>{let t=i-1;return t*t*t+1},V=i=>B(T,x,i);function B(i,t,e){return e<.5?.5*i(e*2):.5*t((e-.5)*2)+.5}var v={linear:K,easeIn:T,easeOut:x,easeInOut:V};import{Ticker as F}from"pixi.js";var a=class{get prev(){return this._prev}get next(){return this._next}constructor(){this._prev=this,this._next=this}bind(t){let e=this,r=t,n=this._next;e._next=r,r._prev=e,e!==n&&(r._next=n,n._prev=r)}unbind(){let{_prev:t,_next:e}=this;t._next=e,e._prev=t,this._prev=this,this._next=this}};var p=class i extends a{get data(){return this._data}constructor(t){super(),this._data=t}static parse(t){return t instanceof i?t:new i(t)}};var g=class i{get first(){return 0<this._length?this._head.next:void 0}get last(){return 0<this._length?this._tail.prev:void 0}get length(){return this._length}constructor(){this._head=new a,this._tail=new a,this._head.bind(this._tail),this._length=0}unshift(t){return this.link(this._head,t)}push(t){return this.link(this._tail.prev,t)}shift(){return this.unlink(this.first)}pop(){return this.unlink(this.last)}clear(){for(;0<this.length;)this.shift()}find(t){for(let e of this)if(e.data&&e.data===t)return e}contains(t){return this.find(t)!=null}forEach(t,e){let r=0;for(let n of this)t.call(e,n.data,r++,this)}map(t,e){let r=new i,n=0;for(let P of this)r.push(t.call(e,P.data,n++,this));return r}*[Symbol.iterator](){let t=this.first;for(;t&&t!==this._tail;)yield t,t=t.next}link(t,e){let r=p.parse(e);return t.bind(r),this._length++,r}unlink(t){if(t!=null)return t.unbind(),this._length--,t}};var d={};h(d,{interpolate:()=>q});import{Color as O}from"pixi.js";var s={};h(s,{clamp:()=>m,lerp:()=>o,qerp:()=>u,round:()=>j,shuffle:()=>D});function j(i,t=0){return t=Math.pow(10,t),Math.round(i*t)/t}function m(i,t=0,e=1){return Math.max(t,Math.min(i,e))}function o(i,t,e){return(1-e)*i+e*t}function u(i,t,e,r){return(1-r)*(1-r)*i+2*(1-r)*r*t+r*r*e}function D(i){for(let t=i.length-1;t>0;t--){let e=Math.floor(Math.random()*(t+1));[i[t],i[e]]=[i[e],i[t]]}return i}function q(i,t,e,r){return e=m(e),r!=null||(r=new O),r.value=[o(i.red,t.red,e),o(i.green,t.green,e),o(i.blue,t.blue,e),o(i.alpha,t.alpha,e)],r}var c={};h(c,{distance:()=>L,lerp:()=>N,qerp:()=>A});import{Point as y}from"pixi.js";function N(i,t,e,r){return r!=null||(r=new y),r.x=o(i.x,t.x,e),r.y=o(i.y,t.y,e),r}function A(i,t,e,r,n){return n!=null||(n=new y),n.x=u(i.x,t.x,e.x,r),n.y=u(i.y,t.y,e.y,r),n}function L(i,t){let e=t.x-i.x,r=t.y-i.y;return Math.hypot(e,r)}var R={target:{},duration:0,delay:0,transition:v.linear,onComplete:()=>{},ticker:F.shared},C=class i{constructor(t){this.update=()=>{if(this._elapsedTime+=this._ticker.deltaMS,this._elapsedTime<0)return;let t=s.clamp(this._elapsedTime/this._duration);t=this._transition(t);for(let[e,r]of this._startValues){let n=this._endValues.get(e);this._target[e]=s.lerp(r,n,t)}t===1&&(this._elapsedTime=this._duration,this.stop())};({target:this._target,duration:this._duration,delay:this._delay,transition:this._transition,onComplete:this._onComplete,ticker:this._ticker}=i.parseConfig(t)),this._startValues=new Map,this._endValues=new Map,this._elapsedTime=0,this._isComplete=!1}get target(){return this._target}get duration(){return this._duration}get delay(){return this._delay}get transition(){return this._transition}get isComplete(){return this._isComplete}setTarget(t){return this._target=t,this}setDuration(t){return this._duration=t,this}setDelay(t){return this._delay=t,this}setTransition(t){return this._transition=t,this}onComplete(t){return this._onComplete=t,this}animate(t,e){return!this._target||typeof this._target!="object"||!(t in this._target)||typeof this._target[t]!="number"?this:(this._startValues.set(t,this._target[t]),this._endValues.set(t,e),this)}play(){for(let[t,e]of this._startValues)this._target[t]=e;this._elapsedTime=-this._delay,this._isComplete=!1,this._ticker.add(this.update)}stop(){this._ticker.remove(this.update),this._isComplete=!0;for(let[t,e]of this._endValues)this._target[t]=e;this._onComplete()}static parseConfig(t){return l(l({},R),t)}};var M=(t=>(t.EVENT="sceneevent",t))(M||{});import{AnimatedSprite as W}from"pixi.js";var k=class extends W{constructor(...t){super(t),this.eventMode="static",this.cursor="pointer"}disable(t=!1){this.eventMode="none",this.visible=!t}enable(){this.eventMode="static",this.visible=!0}};import{Sprite as $}from"pixi.js";var E=class extends ${constructor(t){super(t),this.eventMode="passive"}disable(t=!1){this.eventMode="none",this.visible=!t}enable(){this.eventMode="passive",this.visible=!0}};import{Container as z}from"pixi.js";var w=class extends z{constructor(t){super(),this.name=t}on(t,e,r){return super.on(t,e,r)}emit(t,...e){return super.emit(t,...e)}onEnter(){this.visible=!0}onExit(){this.visible=!1}};var I=class{constructor(t){this._stage=t,this._scenes=new Map}addScene(t){if(this._stage.addChild(t),this._scenes.set(t.name,t),t.on("sceneevent",e=>this.setScene(e)),!this._current){this.setScene(t.name);return}t.visible=!1}setScene(t){var e;if((e=this._current)==null||e.onExit(),this._current=this._scenes.get(t),!this._current)throw new Error(`Scene with name "${t}" does not exist.`);this._current.onEnter()}};export{a as Binder,k as Button,d as ColorUtil,p as Item,g as List,s as MathUtil,E as Panel,G as Pixi,H as PixiSound,c as PointUtil,w as Scene,M as SceneEvent,I as SceneManager,v as Transitions,C as Tween,Ft as WebFontLoader};