{"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":["root","factory","exports","module","require","define","amd","window","__WEBPACK_EXTERNAL_MODULE__0__","installedModules","__webpack_require__","moduleId","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","LifecyclePlugin","scene","pluginManager","_classCallCheck","this","_this","_possibleConstructorReturn","__proto__","getPrototypeOf","systems","sys","hasStarted","setEventsToTrack","settings","isBooted","events","once","boot","external_root_Phaser_commonjs_phaser_commonjs2_phaser_amd_phaser_default","a","Plugins","ScenePlugin","camelCaseEvents","_this2","unsubscribeSceneEvents","eventNames","map","toLowerCase","possibleMethodNames","Set","concat","_toConsumableArray","oldListeners","listeners","forEach","Map","eventHandlers","onSceneEvent","subscribeSceneEvents","emitter","on","shutdown","start","destroy","_this3","_this4","off","eventName","_len","arguments","length","args","Array","_key","method","apply","eventMapping","_this5","methodName","entries","_ref","_ref2","_slicedToArray","listenerMap","set","_this6","delete","_this7","clear","removeAll","onShutdown","__webpack_exports__"],"mappings":"CAAA,SAAAA,EAAAC,GACA,iBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,EAAAG,QAAA,WACA,mBAAAC,eAAAC,IACAD,QAAA,UAAAJ,GACA,iBAAAC,QACAA,QAAA,sBAAAD,EAAAG,QAAA,WAEAJ,EAAA,sBAAAC,EAAAD,EAAA,QARA,CASCO,OAAA,SAAAC,GACD,mBCTA,IAAAC,KAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAT,QA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C,cAAL,UACnBhC,KAAKK,QAAQM,OACrB+B,IAAI,WAAY1C,KAAKkE,WAAYlE,MACzCA,KAAKoB,yBACLpB,KAAKiE,qBClITE,EAAA","file":"phaser-lifecycle-plugin.min.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":""}