coherent-gameface-interaction-manager
Version:
Library for the most common UI interactions
3 lines (2 loc) • 1.46 kB
JavaScript
var actions=(()=>{var a=(r,e)=>()=>(r&&(e=r(r=0)),e);var I=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var o,i,s=a(()=>{o=class r{constructor(){this.actions=[],this.keyboardFunctions=[],this.gamepadFunctions=[]}init(){window._IM||(window._IM=new r)}getKeys(e){return _IM.keyboardFunctions.filter(n=>n.keys.every(t=>e.includes(t)))}getKeysIndex(e){return _IM.keyboardFunctions.findIndex(n=>n.keys.every(t=>e.includes(t)))}getGamepadAction({actions:e,type:n}){return _IM.gamepadFunctions.find(t=>t.actions.every(g=>e.includes(g))&&t.type===n&&t.actions.length===e.length)}getGamepadActions(e){return _IM.gamepadFunctions.filter(n=>n.actions.every(t=>e.includes(t))&&n.actions.length===e.length)}getGamepadActionIndex(e){return _IM.gamepadFunctions.findIndex(n=>n.actions.every(t=>e.includes(t)))}getAction(e){return _IM.actions.find(n=>n.name===e)}getActionIndex(e){return _IM.actions.findIndex(n=>n.name===e)}},i=new o});var c,d,u=a(()=>{s();c=class{register(e,n){if(i.getAction(e))return console.error(`The following action "${e}" is already registered!`);_IM.actions.push({name:e,callback:n})}remove(e){let n=i.getActionIndex(e);if(n===-1)return console.error(`${e} is not a registered action!`);_IM.actions.splice(n,1)}execute(e,n){let t=i.getAction(e);if(!t)return console.error(`${e} is not a registered action!`);t.callback(n)}},d=new c});var f=I((h,l)=>{u();s();i.init();l.exports=d});return f();})();
//# sourceMappingURL=actions.min.js.map