{"ast":null,"code":"import { Observable } from \"../Misc/observable.js\";\n/**\n * The current state of the timer\n */\nexport var TimerState;\n(function (TimerState) {\n /**\n * Timer initialized, not yet started\n */\n TimerState[TimerState[\"INIT\"] = 0] = \"INIT\";\n /**\n * Timer started and counting\n */\n TimerState[TimerState[\"STARTED\"] = 1] = \"STARTED\";\n /**\n * Timer ended (whether aborted or time reached)\n */\n TimerState[TimerState[\"ENDED\"] = 2] = \"ENDED\";\n})(TimerState || (TimerState = {}));\n/**\n * A simple version of the timer. Will take options and start the timer immediately after calling it\n *\n * @param options options with which to initialize this timer\n * @returns an observer that can be used to stop the timer\n */\nexport function setAndStartTimer(options) {\n var _options$observablePa;\n let timer = 0;\n const startTime = Date.now();\n options.observableParameters = (_options$observablePa = options.observableParameters) !== null && _options$observablePa !== void 0 ? _options$observablePa : {};\n const observer = options.contextObservable.add(payload => {\n const now = Date.now();\n timer = now - startTime;\n const data = {\n startTime,\n currentTime: now,\n deltaTime: timer,\n completeRate: timer / options.timeout,\n payload\n };\n options.onTick && options.onTick(data);\n if (options.breakCondition && options.breakCondition()) {\n options.contextObservable.remove(observer);\n options.onAborted && options.onAborted(data);\n }\n if (timer >= options.timeout) {\n options.contextObservable.remove(observer);\n options.onEnded && options.onEnded(data);\n }\n }, options.observableParameters.mask, options.observableParameters.insertFirst, options.observableParameters.scope);\n return observer;\n}\n/**\n * An advanced implementation of a timer class\n */\nexport class AdvancedTimer {\n /**\n * Will construct a new advanced timer based on the options provided. Timer will not start until start() is called.\n * @param options construction options for this advanced timer\n */\n constructor(options) {\n var _options$observablePa2, _options$breakConditi;\n /**\n * Will notify each time the timer calculates the remaining time\n */\n this.onEachCountObservable = new Observable();\n /**\n * Will trigger when the timer was aborted due to the break condition\n */\n this.onTimerAbortedObservable = new Observable();\n /**\n * Will trigger when the timer ended successfully\n */\n this.onTimerEndedObservable = new Observable();\n /**\n * Will trigger when the timer state has changed\n */\n this.onStateChangedObservable = new Observable();\n this._observer = null;\n this._breakOnNextTick = false;\n this._tick = payload => {\n const now = Date.now();\n this._timer = now - this._startTime;\n const data = {\n startTime: this._startTime,\n currentTime: now,\n deltaTime: this._timer,\n completeRate: this._timer / this._timeToEnd,\n payload\n };\n const shouldBreak = this._breakOnNextTick || this._breakCondition(data);\n if (shouldBreak || this._timer >= this._timeToEnd) {\n this._stop(data, shouldBreak);\n } else {\n this.onEachCountObservable.notifyObservers(data);\n }\n };\n this._setState(0 /* TimerState.INIT */);\n this._contextObservable = options.contextObservable;\n this._observableParameters = (_options$observablePa2 = options.observableParameters) !== null && _options$observablePa2 !== void 0 ? _options$observablePa2 : {};\n this._breakCondition = (_options$breakConditi = options.breakCondition) !== null && _options$breakConditi !== void 0 ? _options$breakConditi : () => false;\n this._timeToEnd = options.timeout;\n if (options.onEnded) {\n this.onTimerEndedObservable.add(options.onEnded);\n }\n if (options.onTick) {\n this.onEachCountObservable.add(options.onTick);\n }\n if (options.onAborted) {\n this.onTimerAbortedObservable.add(options.onAborted);\n }\n }\n /**\n * set a breaking condition for this timer. Default is to never break during count\n * @param predicate the new break condition. Returns true to break, false otherwise\n */\n set breakCondition(predicate) {\n this._breakCondition = predicate;\n }\n /**\n * Reset ALL associated observables in this advanced timer\n */\n clearObservables() {\n this.onEachCountObservable.clear();\n this.onTimerAbortedObservable.clear();\n this.onTimerEndedObservable.clear();\n this.onStateChangedObservable.clear();\n }\n /**\n * Will start a new iteration of this timer. Only one instance of this timer can run at a time.\n *\n * @param timeToEnd how much time to measure until timer ended\n */\n start(timeToEnd = this._timeToEnd) {\n if (this._state === 1 /* TimerState.STARTED */) {\n throw new Error(\"Timer already started. Please stop it before starting again\");\n }\n this._timeToEnd = timeToEnd;\n this._startTime = Date.now();\n this._timer = 0;\n this._observer = this._contextObservable.add(this._tick, this._observableParameters.mask, this._observableParameters.insertFirst, this._observableParameters.scope);\n this._setState(1 /* TimerState.STARTED */);\n }\n /**\n * Will force a stop on the next tick.\n */\n stop() {\n if (this._state !== 1 /* TimerState.STARTED */) {\n return;\n }\n this._breakOnNextTick = true;\n }\n /**\n * Dispose this timer, clearing all resources\n */\n dispose() {\n if (this._observer) {\n this._contextObservable.remove(this._observer);\n }\n this.clearObservables();\n }\n _setState(newState) {\n this._state = newState;\n this.onStateChangedObservable.notifyObservers(this._state);\n }\n _stop(data, aborted = false) {\n this._contextObservable.remove(this._observer);\n this._setState(2 /* TimerState.ENDED */);\n if (aborted) {\n this.onTimerAbortedObservable.notifyObservers(data);\n } else {\n this.onTimerEndedObservable.notifyObservers(data);\n }\n }\n}","map":{"version":3,"names":["Observable","TimerState","setAndStartTimer","options","_options$observablePa","timer","startTime","Date","now","observableParameters","observer","contextObservable","add","payload","data","currentTime","deltaTime","completeRate","timeout","onTick","breakCondition","remove","onAborted","onEnded","mask","insertFirst","scope","AdvancedTimer","constructor","_options$observablePa2","_options$breakConditi","onEachCountObservable","onTimerAbortedObservable","onTimerEndedObservable","onStateChangedObservable","_observer","_breakOnNextTick","_tick","_timer","_startTime","_timeToEnd","shouldBreak","_breakCondition","_stop","notifyObservers","_setState","_contextObservable","_observableParameters","predicate","clearObservables","clear","start","timeToEnd","_state","Error","stop","dispose","newState","aborted"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/Misc/timer.js"],"sourcesContent":["import { Observable } from \"../Misc/observable.js\";\n/**\n * The current state of the timer\n */\nexport var TimerState;\n(function (TimerState) {\n /**\n * Timer initialized, not yet started\n */\n TimerState[TimerState[\"INIT\"] = 0] = \"INIT\";\n /**\n * Timer started and counting\n */\n TimerState[TimerState[\"STARTED\"] = 1] = \"STARTED\";\n /**\n * Timer ended (whether aborted or time reached)\n */\n TimerState[TimerState[\"ENDED\"] = 2] = \"ENDED\";\n})(TimerState || (TimerState = {}));\n/**\n * A simple version of the timer. Will take options and start the timer immediately after calling it\n *\n * @param options options with which to initialize this timer\n * @returns an observer that can be used to stop the timer\n */\nexport function setAndStartTimer(options) {\n let timer = 0;\n const startTime = Date.now();\n options.observableParameters = options.observableParameters ?? {};\n const observer = options.contextObservable.add((payload) => {\n const now = Date.now();\n timer = now - startTime;\n const data = {\n startTime,\n currentTime: now,\n deltaTime: timer,\n completeRate: timer / options.timeout,\n payload,\n };\n options.onTick && options.onTick(data);\n if (options.breakCondition && options.breakCondition()) {\n options.contextObservable.remove(observer);\n options.onAborted && options.onAborted(data);\n }\n if (timer >= options.timeout) {\n options.contextObservable.remove(observer);\n options.onEnded && options.onEnded(data);\n }\n }, options.observableParameters.mask, options.observableParameters.insertFirst, options.observableParameters.scope);\n return observer;\n}\n/**\n * An advanced implementation of a timer class\n */\nexport class AdvancedTimer {\n /**\n * Will construct a new advanced timer based on the options provided. Timer will not start until start() is called.\n * @param options construction options for this advanced timer\n */\n constructor(options) {\n /**\n * Will notify each time the timer calculates the remaining time\n */\n this.onEachCountObservable = new Observable();\n /**\n * Will trigger when the timer was aborted due to the break condition\n */\n this.onTimerAbortedObservable = new Observable();\n /**\n * Will trigger when the timer ended successfully\n */\n this.onTimerEndedObservable = new Observable();\n /**\n * Will trigger when the timer state has changed\n */\n this.onStateChangedObservable = new Observable();\n this._observer = null;\n this._breakOnNextTick = false;\n this._tick = (payload) => {\n const now = Date.now();\n this._timer = now - this._startTime;\n const data = {\n startTime: this._startTime,\n currentTime: now,\n deltaTime: this._timer,\n completeRate: this._timer / this._timeToEnd,\n payload,\n };\n const shouldBreak = this._breakOnNextTick || this._breakCondition(data);\n if (shouldBreak || this._timer >= this._timeToEnd) {\n this._stop(data, shouldBreak);\n }\n else {\n this.onEachCountObservable.notifyObservers(data);\n }\n };\n this._setState(0 /* TimerState.INIT */);\n this._contextObservable = options.contextObservable;\n this._observableParameters = options.observableParameters ?? {};\n this._breakCondition = options.breakCondition ?? (() => false);\n this._timeToEnd = options.timeout;\n if (options.onEnded) {\n this.onTimerEndedObservable.add(options.onEnded);\n }\n if (options.onTick) {\n this.onEachCountObservable.add(options.onTick);\n }\n if (options.onAborted) {\n this.onTimerAbortedObservable.add(options.onAborted);\n }\n }\n /**\n * set a breaking condition for this timer. Default is to never break during count\n * @param predicate the new break condition. Returns true to break, false otherwise\n */\n set breakCondition(predicate) {\n this._breakCondition = predicate;\n }\n /**\n * Reset ALL associated observables in this advanced timer\n */\n clearObservables() {\n this.onEachCountObservable.clear();\n this.onTimerAbortedObservable.clear();\n this.onTimerEndedObservable.clear();\n this.onStateChangedObservable.clear();\n }\n /**\n * Will start a new iteration of this timer. Only one instance of this timer can run at a time.\n *\n * @param timeToEnd how much time to measure until timer ended\n */\n start(timeToEnd = this._timeToEnd) {\n if (this._state === 1 /* TimerState.STARTED */) {\n throw new Error(\"Timer already started. Please stop it before starting again\");\n }\n this._timeToEnd = timeToEnd;\n this._startTime = Date.now();\n this._timer = 0;\n this._observer = this._contextObservable.add(this._tick, this._observableParameters.mask, this._observableParameters.insertFirst, this._observableParameters.scope);\n this._setState(1 /* TimerState.STARTED */);\n }\n /**\n * Will force a stop on the next tick.\n */\n stop() {\n if (this._state !== 1 /* TimerState.STARTED */) {\n return;\n }\n this._breakOnNextTick = true;\n }\n /**\n * Dispose this timer, clearing all resources\n */\n dispose() {\n if (this._observer) {\n this._contextObservable.remove(this._observer);\n }\n this.clearObservables();\n }\n _setState(newState) {\n this._state = newState;\n this.onStateChangedObservable.notifyObservers(this._state);\n }\n _stop(data, aborted = false) {\n this._contextObservable.remove(this._observer);\n this._setState(2 /* TimerState.ENDED */);\n if (aborted) {\n this.onTimerAbortedObservable.notifyObservers(data);\n }\n else {\n this.onTimerEndedObservable.notifyObservers(data);\n }\n }\n}\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ,uBAAuB;AAClD;AACA;AACA;AACA,OAAO,IAAIC,UAAU;AACrB,CAAC,UAAUA,UAAU,EAAE;EACnB;AACJ;AACA;EACIA,UAAU,CAACA,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM;EAC3C;AACJ;AACA;EACIA,UAAU,CAACA,UAAU,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GA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