{"version":3,"sources":["webpack://PhaserLifecyclePlugin/webpack/universalModuleDefinition","webpack://PhaserLifecyclePlugin/webpack/bootstrap","webpack://PhaserLifecyclePlugin/external {\"root\":\"Phaser\",\"commonjs\":\"phaser\",\"commonjs2\":\"phaser\",\"amd\":\"phaser\"}","webpack://PhaserLifecyclePlugin/./phaser-lifecycle-plugin.js","webpack://PhaserLifecyclePlugin/./index.js"],"names":["LifecyclePlugin","scene","pluginManager","systems","sys","hasStarted","camelCaseEvents","setEventsToTrack","settings","isBooted","events","once","boot","unsubscribeSceneEvents","eventNames","map","s","toLowerCase","possibleMethodNames","Set","oldListeners","listeners","forEach","name","Map","eventHandlers","onSceneEvent","bind","subscribeSceneEvents","emitter","on","shutdown","start","destroy","off","eventName","args","method","object","apply","eventMapping","methodName","Object","entries","listenerMap","set","delete","clear","removeAll","onShutdown","Phaser","Plugins","ScenePlugin"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;ACVA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,kDAA0C,gCAAgC;AAC1E;AACA;;AAEA;AACA;AACA;AACA,gEAAwD,kBAAkB;AAC1E;AACA,yDAAiD,cAAc;AAC/D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iDAAyC,iCAAiC;AAC1E,wHAAgH,mBAAmB,EAAE;AACrI;AACA;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;AACvD,yCAAiC,eAAe;AAChD;AACA;AACA;;AAEA;AACA,8DAAsD,+DAA+D;;AAErH;AACA;;;AAGA;AACA;;;;;;;AClFA,gD;;;;;;;;;;;;;;;;;;;;;;;;;;ACAA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;;;;;;;I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;;EAtH0C,0EAAAE,CAAOC,OAAP,CAAeC,W;;4DAAvCpD,e;;ACfrB;;AAEA,2EAAe,uBAAf,E","file":"phaser-lifecycle-plugin.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"phaser\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"phaser\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"PhaserLifecyclePlugin\"] = factory(require(\"phaser\"));\n\telse\n\t\troot[\"PhaserLifecyclePlugin\"] = factory(root[\"Phaser\"]);\n})(window, function(__WEBPACK_EXTERNAL_MODULE__0__) {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 1);\n","module.exports = __WEBPACK_EXTERNAL_MODULE__0__;","// TODO:\r\n// - add config option to add() to allow custom mapping to update/preupdate/postupdate\r\n// - add priority/\r\n// - docs\r\n// - more tests\r\n\r\nimport Phaser from \"phaser\";\r\n\r\n/**\r\n * Plugin that wraps around Phaser's event system. This allows us to avoid the issues around the\r\n * EventEmitter library Phaser uses where the EE caches the listeners at the start of an event. This\r\n * leads to bugs if a listener gets unsubscribed during an event (e.g. the physics system\r\n * unsubscribing a listener via a CB before the listener's update method). This plugin immediately\r\n * unsubscribes the listener.\r\n */\r\nexport default class LifecyclePlugin extends Phaser.Plugins.ScenePlugin {\r\n constructor(scene, pluginManager) {\r\n super(scene, pluginManager);\r\n\r\n this.scene = scene;\r\n this.systems = scene.sys;\r\n\r\n this.hasStarted = false;\r\n\r\n const camelCaseEvents = [\r\n \"update\",\r\n \"preUpdate\",\r\n \"postUpdate\",\r\n \"render\",\r\n \"shutdown\",\r\n \"destroy\",\r\n \"start\",\r\n \"ready\",\r\n \"boot\",\r\n \"sleep\",\r\n \"wake\",\r\n \"pause\",\r\n \"resume\",\r\n \"resize\",\r\n \"transitionInit\",\r\n \"transitionStart\",\r\n \"transitionOut\",\r\n \"transitionComplete\"\r\n ];\r\n this.setEventsToTrack(camelCaseEvents);\r\n\r\n if (!scene.sys.settings.isBooted) this.systems.events.once(\"boot\", this.boot, this);\r\n }\r\n\r\n setEventsToTrack(camelCaseEvents) {\r\n // Rather than selectively unsubing & resubing, nuke all and resub later\r\n if (this.hasStarted) this.unsubscribeSceneEvents();\r\n\r\n this.eventNames = camelCaseEvents.map(s => s.toLowerCase());\r\n this.possibleMethodNames = new Set([...camelCaseEvents, ...this.eventNames]);\r\n\r\n const oldListeners = this.listeners || {};\r\n this.listeners = {};\r\n this.eventNames.forEach(name => {\r\n this.listeners[name] = oldListeners[name] ? oldListeners[name] : new Map();\r\n });\r\n\r\n this.eventHandlers = {};\r\n this.eventNames.forEach(name => {\r\n this.eventHandlers[name] = this.onSceneEvent.bind(this, name);\r\n });\r\n if (this.hasStarted) this.subscribeSceneEvents();\r\n }\r\n\r\n boot() {\r\n const emitter = this.systems.events;\r\n emitter.on(\"shutdown\", this.shutdown, this);\r\n emitter.on(\"start\", this.start, this);\r\n emitter.once(\"destroy\", this.destroy, this);\r\n }\r\n\r\n start() {\r\n this.hasStarted = true;\r\n this.subscribeSceneEvents();\r\n }\r\n\r\n subscribeSceneEvents() {\r\n const emitter = this.systems.events;\r\n this.eventNames.forEach(name => emitter.on(name, this.eventHandlers[name]));\r\n }\r\n\r\n unsubscribeSceneEvents() {\r\n const emitter = this.systems.events;\r\n this.eventNames.forEach(name => emitter.off(name, this.eventHandlers[name]));\r\n }\r\n\r\n onSceneEvent(eventName, ...args) {\r\n this.listeners[eventName].forEach((method, object) => method.apply(object, args));\r\n }\r\n\r\n add(object, eventMapping) {\r\n // No mapping given, default to checking for methods named after the event\r\n if (!eventMapping) {\r\n eventMapping = {};\r\n this.possibleMethodNames.forEach(methodName => {\r\n if (typeof object[methodName] === \"function\") {\r\n const eventName = methodName.toLowerCase();\r\n eventMapping[eventName] = object[methodName];\r\n }\r\n });\r\n }\r\n\r\n Object.entries(eventMapping).forEach(([eventName, method]) => {\r\n const listenerMap = this.listeners[eventName];\r\n if (listenerMap) listenerMap.set(object, method);\r\n });\r\n }\r\n\r\n remove(object) {\r\n this.eventNames.forEach(name => this.listeners[name].delete(object));\r\n }\r\n\r\n removeAll() {\r\n this.eventNames.forEach(name => this.listeners[name].clear());\r\n }\r\n\r\n shutdown() {\r\n this.hasStarted = false;\r\n this.removeAll();\r\n this.unsubscribeSceneEvents();\r\n }\r\n\r\n destroy() {\r\n if (this.eventHandlers[\"destroy\"]) this.eventHandlers[\"destroy\"]();\r\n const emitter = this.systems.events;\r\n emitter.off(\"shutdown\", this.onShutdown, this);\r\n this.unsubscribeSceneEvents();\r\n this.removeAll();\r\n }\r\n}\r\n","import PhaserLifecyclePlugin from \"./phaser-lifecycle-plugin\";\r\n\r\nexport default PhaserLifecyclePlugin;\r\n"],"sourceRoot":""}