@caperjs/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +62 -0
- package/cli/add.mjs +197 -0
- package/cli/audio/cc.mjs +128 -0
- package/cli/audio/index.mjs +42 -0
- package/cli/audio/utils.mjs +56 -0
- package/cli/create-caper.mjs +8 -0
- package/cli/create.mjs +351 -0
- package/cli/install-peerdeps.mjs +57 -0
- package/cli/update.mjs +9 -0
- package/cli/utils.mjs +81 -0
- package/cli/vite.mjs +55 -0
- package/cli/voiceover/generateVoiceoverCSV.mjs +158 -0
- package/cli/voiceover/index.mjs +1 -0
- package/cli.mjs +157 -0
- package/client.d.ts +7 -0
- package/config/assetpack.mjs +212 -0
- package/config/tsconfig.base.json +28 -0
- package/config/vite.mjs +2464 -0
- package/extras/css/accessibility.css +9 -0
- package/extras/css/fullscreen.css +28 -0
- package/extras/css/loader.css +67 -0
- package/extras/llms.txt +1602 -0
- package/lib/CaptionsPlugin-Dc8fIrjy.js +277 -0
- package/lib/CaptionsPlugin-Dc8fIrjy.js.map +1 -0
- package/lib/DataAdapter-BY2114sp.js +84 -0
- package/lib/DataAdapter-BY2114sp.js.map +1 -0
- package/lib/DebugRenderer-BJMLILqI.js +1385 -0
- package/lib/DebugRenderer-BJMLILqI.js.map +1 -0
- package/lib/DevToolsPlugin-wQ5rOkn0.js +31 -0
- package/lib/DevToolsPlugin-wQ5rOkn0.js.map +1 -0
- package/lib/GSAPPlugin-DHhSZKv8.js +350 -0
- package/lib/GSAPPlugin-DHhSZKv8.js.map +1 -0
- package/lib/LayoutPlugin-B-DF9SYM.js +1271 -0
- package/lib/LayoutPlugin-B-DF9SYM.js.map +1 -0
- package/lib/SpinePlugin-Dz_3dljz.js +6077 -0
- package/lib/SpinePlugin-Dz_3dljz.js.map +1 -0
- package/lib/StatsPlugin-Cg82JMBD.js +70 -0
- package/lib/StatsPlugin-Cg82JMBD.js.map +1 -0
- package/lib/VoiceOverPlugin-BR3ImT8C.js +114 -0
- package/lib/VoiceOverPlugin-BR3ImT8C.js.map +1 -0
- package/lib/caper.mjs +1233 -0
- package/lib/caper.mjs.map +1 -0
- package/lib/core/Application.d.ts +268 -0
- package/lib/core/Application.d.ts.map +1 -0
- package/lib/core/config.d.ts +39 -0
- package/lib/core/config.d.ts.map +1 -0
- package/lib/core/create.d.ts +41 -0
- package/lib/core/create.d.ts.map +1 -0
- package/lib/core/globals.d.ts +51 -0
- package/lib/core/globals.d.ts.map +1 -0
- package/lib/core/index.d.ts +7 -0
- package/lib/core/index.d.ts.map +1 -0
- package/lib/core/interfaces/IApplication.d.ts +566 -0
- package/lib/core/interfaces/IApplication.d.ts.map +1 -0
- package/lib/core/interfaces/IApplicationOptions.d.ts +65 -0
- package/lib/core/interfaces/IApplicationOptions.d.ts.map +1 -0
- package/lib/core/interfaces/ICoreFunctions.d.ts +49 -0
- package/lib/core/interfaces/ICoreFunctions.d.ts.map +1 -0
- package/lib/core/interfaces/ICoreSignals.d.ts +57 -0
- package/lib/core/interfaces/ICoreSignals.d.ts.map +1 -0
- package/lib/core/interfaces/IStorageCapability.d.ts +20 -0
- package/lib/core/interfaces/IStorageCapability.d.ts.map +1 -0
- package/lib/core/interfaces/IStorageCapability.test.d.ts +2 -0
- package/lib/core/interfaces/IStorageCapability.test.d.ts.map +1 -0
- package/lib/core/interfaces/index.d.ts +7 -0
- package/lib/core/interfaces/index.d.ts.map +1 -0
- package/lib/core/registries.d.ts +8 -0
- package/lib/core/registries.d.ts.map +1 -0
- package/lib/core/types.d.ts +12 -0
- package/lib/core/types.d.ts.map +1 -0
- package/lib/display/AnimatedSprite.d.ts +40 -0
- package/lib/display/AnimatedSprite.d.ts.map +1 -0
- package/lib/display/Camera.d.ts +102 -0
- package/lib/display/Camera.d.ts.map +1 -0
- package/lib/display/Container.d.ts +115 -0
- package/lib/display/Container.d.ts.map +1 -0
- package/lib/display/Entity.d.ts +46 -0
- package/lib/display/Entity.d.ts.map +1 -0
- package/lib/display/ParticleContainer.d.ts +58 -0
- package/lib/display/ParticleContainer.d.ts.map +1 -0
- package/lib/display/Scene.d.ts +250 -0
- package/lib/display/Scene.d.ts.map +1 -0
- package/lib/display/SceneTransition.d.ts +41 -0
- package/lib/display/SceneTransition.d.ts.map +1 -0
- package/lib/display/SpineAnimation.d.ts +76 -0
- package/lib/display/SpineAnimation.d.ts.map +1 -0
- package/lib/display/Svg.d.ts +5 -0
- package/lib/display/Svg.d.ts.map +1 -0
- package/lib/display/index.d.ts +10 -0
- package/lib/display/index.d.ts.map +1 -0
- package/lib/env.d.ts +6 -0
- package/lib/hello.d.ts +2 -0
- package/lib/hello.d.ts.map +1 -0
- package/lib/index.d.ts +15 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/mixins/animated.d.ts +53 -0
- package/lib/mixins/animated.d.ts.map +1 -0
- package/lib/mixins/factory/Factory.d.ts +8 -0
- package/lib/mixins/factory/Factory.d.ts.map +1 -0
- package/lib/mixins/factory/const.d.ts +67 -0
- package/lib/mixins/factory/const.d.ts.map +1 -0
- package/lib/mixins/factory/index.d.ts +8 -0
- package/lib/mixins/factory/index.d.ts.map +1 -0
- package/lib/mixins/factory/methods.d.ts +3 -0
- package/lib/mixins/factory/methods.d.ts.map +1 -0
- package/lib/mixins/factory/props.d.ts +160 -0
- package/lib/mixins/factory/props.d.ts.map +1 -0
- package/lib/mixins/factory/registry.d.ts +27 -0
- package/lib/mixins/factory/registry.d.ts.map +1 -0
- package/lib/mixins/factory/registry.test.d.ts +2 -0
- package/lib/mixins/factory/registry.test.d.ts.map +1 -0
- package/lib/mixins/factory/schema.d.ts +71 -0
- package/lib/mixins/factory/schema.d.ts.map +1 -0
- package/lib/mixins/factory/ui-registry.d.ts +20 -0
- package/lib/mixins/factory/ui-registry.d.ts.map +1 -0
- package/lib/mixins/factory/utils.d.ts +11 -0
- package/lib/mixins/factory/utils.d.ts.map +1 -0
- package/lib/mixins/focus.d.ts +15 -0
- package/lib/mixins/focus.d.ts.map +1 -0
- package/lib/mixins/index.d.ts +6 -0
- package/lib/mixins/index.d.ts.map +1 -0
- package/lib/mixins/interaction.d.ts +20 -0
- package/lib/mixins/interaction.d.ts.map +1 -0
- package/lib/mixins/signals.d.ts +15 -0
- package/lib/mixins/signals.d.ts.map +1 -0
- package/lib/plugins/AssetsPlugin.d.ts +79 -0
- package/lib/plugins/AssetsPlugin.d.ts.map +1 -0
- package/lib/plugins/DataAdapter.d.ts +95 -0
- package/lib/plugins/DataAdapter.d.ts.map +1 -0
- package/lib/plugins/DevToolsPlugin.d.ts +97 -0
- package/lib/plugins/DevToolsPlugin.d.ts.map +1 -0
- package/lib/plugins/FullScreenPlugin.d.ts +240 -0
- package/lib/plugins/FullScreenPlugin.d.ts.map +1 -0
- package/lib/plugins/GSAPPlugin.d.ts +634 -0
- package/lib/plugins/GSAPPlugin.d.ts.map +1 -0
- package/lib/plugins/KeyboardPlugin.d.ts +53 -0
- package/lib/plugins/KeyboardPlugin.d.ts.map +1 -0
- package/lib/plugins/LayoutPlugin.d.ts +100 -0
- package/lib/plugins/LayoutPlugin.d.ts.map +1 -0
- package/lib/plugins/LookupPlugin.d.ts +223 -0
- package/lib/plugins/LookupPlugin.d.ts.map +1 -0
- package/lib/plugins/Plugin.d.ts +132 -0
- package/lib/plugins/Plugin.d.ts.map +1 -0
- package/lib/plugins/Plugin.test.d.ts +2 -0
- package/lib/plugins/Plugin.test.d.ts.map +1 -0
- package/lib/plugins/PopupManagerPlugin.d.ts +108 -0
- package/lib/plugins/PopupManagerPlugin.d.ts.map +1 -0
- package/lib/plugins/ResizerPlugin.d.ts +62 -0
- package/lib/plugins/ResizerPlugin.d.ts.map +1 -0
- package/lib/plugins/SceneManagerPlugin.d.ts +122 -0
- package/lib/plugins/SceneManagerPlugin.d.ts.map +1 -0
- package/lib/plugins/StatsPlugin.d.ts +8 -0
- package/lib/plugins/StatsPlugin.d.ts.map +1 -0
- package/lib/plugins/TimerPlugin.d.ts +401 -0
- package/lib/plugins/TimerPlugin.d.ts.map +1 -0
- package/lib/plugins/WebEventsPlugin.d.ts +60 -0
- package/lib/plugins/WebEventsPlugin.d.ts.map +1 -0
- package/lib/plugins/actions/ActionsPlugin.d.ts +39 -0
- package/lib/plugins/actions/ActionsPlugin.d.ts.map +1 -0
- package/lib/plugins/actions/constants.d.ts +52 -0
- package/lib/plugins/actions/constants.d.ts.map +1 -0
- package/lib/plugins/actions/index.d.ts +5 -0
- package/lib/plugins/actions/index.d.ts.map +1 -0
- package/lib/plugins/actions/methods.d.ts +11 -0
- package/lib/plugins/actions/methods.d.ts.map +1 -0
- package/lib/plugins/actions/types.d.ts +25 -0
- package/lib/plugins/actions/types.d.ts.map +1 -0
- package/lib/plugins/audio/AudioChannel.d.ts +46 -0
- package/lib/plugins/audio/AudioChannel.d.ts.map +1 -0
- package/lib/plugins/audio/AudioChannel.test.d.ts +2 -0
- package/lib/plugins/audio/AudioChannel.test.d.ts.map +1 -0
- package/lib/plugins/audio/AudioInstance.d.ts +79 -0
- package/lib/plugins/audio/AudioInstance.d.ts.map +1 -0
- package/lib/plugins/audio/AudioManagerPlugin.d.ts +323 -0
- package/lib/plugins/audio/AudioManagerPlugin.d.ts.map +1 -0
- package/lib/plugins/audio/VoiceOverPlugin.d.ts +69 -0
- package/lib/plugins/audio/VoiceOverPlugin.d.ts.map +1 -0
- package/lib/plugins/audio/index.d.ts +4 -0
- package/lib/plugins/audio/index.d.ts.map +1 -0
- package/lib/plugins/breakpoints/BreakpointPlugin.d.ts +109 -0
- package/lib/plugins/breakpoints/BreakpointPlugin.d.ts.map +1 -0
- package/lib/plugins/breakpoints/BreakpointPlugin.test.d.ts +2 -0
- package/lib/plugins/breakpoints/BreakpointPlugin.test.d.ts.map +1 -0
- package/lib/plugins/breakpoints/evaluate.d.ts +53 -0
- package/lib/plugins/breakpoints/evaluate.d.ts.map +1 -0
- package/lib/plugins/breakpoints/evaluate.test.d.ts +2 -0
- package/lib/plugins/breakpoints/evaluate.test.d.ts.map +1 -0
- package/lib/plugins/breakpoints/index.d.ts +4 -0
- package/lib/plugins/breakpoints/index.d.ts.map +1 -0
- package/lib/plugins/breakpoints/methods.d.ts +23 -0
- package/lib/plugins/breakpoints/methods.d.ts.map +1 -0
- package/lib/plugins/breakpoints/types.d.ts +70 -0
- package/lib/plugins/breakpoints/types.d.ts.map +1 -0
- package/lib/plugins/captions/CaptionsPlugin.d.ts +150 -0
- package/lib/plugins/captions/CaptionsPlugin.d.ts.map +1 -0
- package/lib/plugins/captions/CaptionsRenderer.d.ts +37 -0
- package/lib/plugins/captions/CaptionsRenderer.d.ts.map +1 -0
- package/lib/plugins/captions/index.d.ts +3 -0
- package/lib/plugins/captions/index.d.ts.map +1 -0
- package/lib/plugins/defaults.d.ts +4 -0
- package/lib/plugins/defaults.d.ts.map +1 -0
- package/lib/plugins/focus/FocusManagerPlugin.d.ts +148 -0
- package/lib/plugins/focus/FocusManagerPlugin.d.ts.map +1 -0
- package/lib/plugins/focus/FocusOutliner.d.ts +32 -0
- package/lib/plugins/focus/FocusOutliner.d.ts.map +1 -0
- package/lib/plugins/focus/index.d.ts +3 -0
- package/lib/plugins/focus/index.d.ts.map +1 -0
- package/lib/plugins/i18nPlugin.d.ts +128 -0
- package/lib/plugins/i18nPlugin.d.ts.map +1 -0
- package/lib/plugins/index.d.ts +18 -0
- package/lib/plugins/index.d.ts.map +1 -0
- package/lib/plugins/input/AbstractControls.d.ts +8 -0
- package/lib/plugins/input/AbstractControls.d.ts.map +1 -0
- package/lib/plugins/input/Controls.d.ts +16 -0
- package/lib/plugins/input/Controls.d.ts.map +1 -0
- package/lib/plugins/input/InputPlugin.d.ts +52 -0
- package/lib/plugins/input/InputPlugin.d.ts.map +1 -0
- package/lib/plugins/input/constants.d.ts +8 -0
- package/lib/plugins/input/constants.d.ts.map +1 -0
- package/lib/plugins/input/index.d.ts +10 -0
- package/lib/plugins/input/index.d.ts.map +1 -0
- package/lib/plugins/input/interfaces.d.ts +30 -0
- package/lib/plugins/input/interfaces.d.ts.map +1 -0
- package/lib/plugins/input/keyboard/KeyboardContols.d.ts +28 -0
- package/lib/plugins/input/keyboard/KeyboardContols.d.ts.map +1 -0
- package/lib/plugins/input/keyboard/index.d.ts +3 -0
- package/lib/plugins/input/keyboard/index.d.ts.map +1 -0
- package/lib/plugins/input/keyboard/interfaces.d.ts +18 -0
- package/lib/plugins/input/keyboard/interfaces.d.ts.map +1 -0
- package/lib/plugins/input/methods.d.ts +4 -0
- package/lib/plugins/input/methods.d.ts.map +1 -0
- package/lib/plugins/input/touch/TouchControls.d.ts +35 -0
- package/lib/plugins/input/touch/TouchControls.d.ts.map +1 -0
- package/lib/plugins/input/touch/constants.d.ts +14 -0
- package/lib/plugins/input/touch/constants.d.ts.map +1 -0
- package/lib/plugins/input/touch/index.d.ts +4 -0
- package/lib/plugins/input/touch/index.d.ts.map +1 -0
- package/lib/plugins/input/touch/interfaces.d.ts +15 -0
- package/lib/plugins/input/touch/interfaces.d.ts.map +1 -0
- package/lib/plugins/input/types.d.ts +32 -0
- package/lib/plugins/input/types.d.ts.map +1 -0
- package/lib/plugins/input/utils.d.ts +23 -0
- package/lib/plugins/input/utils.d.ts.map +1 -0
- package/lib/plugins/spine/SpinePlugin.d.ts +6 -0
- package/lib/plugins/spine/SpinePlugin.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/BatchableSpineSlot.d.ts +31 -0
- package/lib/plugins/spine/pixi-spine/BatchableSpineSlot.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/Spine.d.ts +211 -0
- package/lib/plugins/spine/pixi-spine/Spine.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/SpineDebugRenderer.d.ts +81 -0
- package/lib/plugins/spine/pixi-spine/SpineDebugRenderer.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/SpinePipe.d.ts +21 -0
- package/lib/plugins/spine/pixi-spine/SpinePipe.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/SpineTexture.d.ts +16 -0
- package/lib/plugins/spine/pixi-spine/SpineTexture.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/assets/atlasLoader.d.ts +10 -0
- package/lib/plugins/spine/pixi-spine/assets/atlasLoader.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/assets/skeletonLoader.d.ts +6 -0
- package/lib/plugins/spine/pixi-spine/assets/skeletonLoader.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/darktint/DarkTintBatchGeometry.d.ts +5 -0
- package/lib/plugins/spine/pixi-spine/darktint/DarkTintBatchGeometry.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/darktint/DarkTintBatcher.d.ts +22 -0
- package/lib/plugins/spine/pixi-spine/darktint/DarkTintBatcher.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/darktint/DarkTintShader.d.ts +5 -0
- package/lib/plugins/spine/pixi-spine/darktint/DarkTintShader.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/darktint/darkTintBit.d.ts +51 -0
- package/lib/plugins/spine/pixi-spine/darktint/darkTintBit.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/index.d.ts +9 -0
- package/lib/plugins/spine/pixi-spine/index.d.ts.map +1 -0
- package/lib/plugins/spine/pixi-spine/require-shim.d.ts +34 -0
- package/lib/plugins/spine/pixi-spine/require-shim.d.ts.map +1 -0
- package/lib/registries-CYCaYKZI.js +6885 -0
- package/lib/registries-CYCaYKZI.js.map +1 -0
- package/lib/signals/Signal.d.ts +16 -0
- package/lib/signals/Signal.d.ts.map +1 -0
- package/lib/signals/Signal.test.d.ts +2 -0
- package/lib/signals/Signal.test.d.ts.map +1 -0
- package/lib/signals/index.d.ts +3 -0
- package/lib/signals/index.d.ts.map +1 -0
- package/lib/store/Store.d.ts +56 -0
- package/lib/store/Store.d.ts.map +1 -0
- package/lib/store/Store.test.d.ts +2 -0
- package/lib/store/Store.test.d.ts.map +1 -0
- package/lib/store/index.d.ts +2 -0
- package/lib/store/index.d.ts.map +1 -0
- package/lib/types/framework.d.ts +46 -0
- package/lib/types/gsap.d.ts +23 -0
- package/lib/ui/Button.d.ts +162 -0
- package/lib/ui/Button.d.ts.map +1 -0
- package/lib/ui/FlexContainer.d.ts +109 -0
- package/lib/ui/FlexContainer.d.ts.map +1 -0
- package/lib/ui/Input.d.ts +384 -0
- package/lib/ui/Input.d.ts.map +1 -0
- package/lib/ui/Joystick.d.ts +61 -0
- package/lib/ui/Joystick.d.ts.map +1 -0
- package/lib/ui/Popup.d.ts +109 -0
- package/lib/ui/Popup.d.ts.map +1 -0
- package/lib/ui/Toast.d.ts +131 -0
- package/lib/ui/Toast.d.ts.map +1 -0
- package/lib/ui/Toaster.d.ts +188 -0
- package/lib/ui/Toaster.d.ts.map +1 -0
- package/lib/ui/UICanvas.d.ts +155 -0
- package/lib/ui/UICanvas.d.ts.map +1 -0
- package/lib/ui/index.d.ts +9 -0
- package/lib/ui/index.d.ts.map +1 -0
- package/lib/utils/array.d.ts +11 -0
- package/lib/utils/array.d.ts.map +1 -0
- package/lib/utils/bind.d.ts +21 -0
- package/lib/utils/bind.d.ts.map +1 -0
- package/lib/utils/canvas.d.ts +2 -0
- package/lib/utils/canvas.d.ts.map +1 -0
- package/lib/utils/color.d.ts +66 -0
- package/lib/utils/color.d.ts.map +1 -0
- package/lib/utils/console/Logger.d.ts +15 -0
- package/lib/utils/console/Logger.d.ts.map +1 -0
- package/lib/utils/console/index.d.ts +2 -0
- package/lib/utils/console/index.d.ts.map +1 -0
- package/lib/utils/debug.d.ts +34 -0
- package/lib/utils/debug.d.ts.map +1 -0
- package/lib/utils/define.d.ts +100 -0
- package/lib/utils/define.d.ts.map +1 -0
- package/lib/utils/env.d.ts +4 -0
- package/lib/utils/env.d.ts.map +1 -0
- package/lib/utils/events.d.ts +12 -0
- package/lib/utils/events.d.ts.map +1 -0
- package/lib/utils/framework.d.ts +12 -0
- package/lib/utils/framework.d.ts.map +1 -0
- package/lib/utils/index.d.ts +28 -0
- package/lib/utils/index.d.ts.map +1 -0
- package/lib/utils/map.d.ts +31 -0
- package/lib/utils/map.d.ts.map +1 -0
- package/lib/utils/math.d.ts +15 -0
- package/lib/utils/math.d.ts.map +1 -0
- package/lib/utils/misc.d.ts +13 -0
- package/lib/utils/misc.d.ts.map +1 -0
- package/lib/utils/number.d.ts +2 -0
- package/lib/utils/number.d.ts.map +1 -0
- package/lib/utils/object.d.ts +21 -0
- package/lib/utils/object.d.ts.map +1 -0
- package/lib/utils/padding.d.ts +4 -0
- package/lib/utils/padding.d.ts.map +1 -0
- package/lib/utils/pixi.d.ts +42 -0
- package/lib/utils/pixi.d.ts.map +1 -0
- package/lib/utils/platform.d.ts +20 -0
- package/lib/utils/platform.d.ts.map +1 -0
- package/lib/utils/point.d.ts +66 -0
- package/lib/utils/point.d.ts.map +1 -0
- package/lib/utils/promise/Queue.d.ts +60 -0
- package/lib/utils/promise/Queue.d.ts.map +1 -0
- package/lib/utils/promise/functions.d.ts +14 -0
- package/lib/utils/promise/functions.d.ts.map +1 -0
- package/lib/utils/promise/index.d.ts +3 -0
- package/lib/utils/promise/index.d.ts.map +1 -0
- package/lib/utils/random.d.ts +42 -0
- package/lib/utils/random.d.ts.map +1 -0
- package/lib/utils/rect.d.ts +26 -0
- package/lib/utils/rect.d.ts.map +1 -0
- package/lib/utils/set.d.ts +15 -0
- package/lib/utils/set.d.ts.map +1 -0
- package/lib/utils/string.d.ts +3 -0
- package/lib/utils/string.d.ts.map +1 -0
- package/lib/utils/text.d.ts +3 -0
- package/lib/utils/text.d.ts.map +1 -0
- package/lib/utils/typefilters.d.ts +4 -0
- package/lib/utils/typefilters.d.ts.map +1 -0
- package/lib/utils/types.d.ts +209 -0
- package/lib/utils/types.d.ts.map +1 -0
- package/lib/utils/vite.d.ts +25 -0
- package/lib/utils/vite.d.ts.map +1 -0
- package/lib/utils/web.d.ts +3 -0
- package/lib/utils/web.d.ts.map +1 -0
- package/lib/version.d.ts +3 -0
- package/lib/version.d.ts.map +1 -0
- package/lib/webgl-check.d.ts +2 -0
- package/lib/webgl-check.d.ts.map +1 -0
- package/package.json +138 -0
- package/src/core/Application.ts +1091 -0
- package/src/core/config.ts +168 -0
- package/src/core/create.ts +186 -0
- package/src/core/globals.ts +299 -0
- package/src/core/index.ts +6 -0
- package/src/core/interfaces/IApplication.ts +628 -0
- package/src/core/interfaces/IApplicationOptions.ts +81 -0
- package/src/core/interfaces/ICoreFunctions.ts +86 -0
- package/src/core/interfaces/ICoreSignals.ts +77 -0
- package/src/core/interfaces/IStorageCapability.test.ts +27 -0
- package/src/core/interfaces/IStorageCapability.ts +26 -0
- package/src/core/interfaces/index.ts +6 -0
- package/src/core/registries.ts +7 -0
- package/src/core/types.ts +13 -0
- package/src/display/AnimatedSprite.ts +227 -0
- package/src/display/Camera.ts +371 -0
- package/src/display/Container.ts +240 -0
- package/src/display/Entity.ts +50 -0
- package/src/display/ParticleContainer.ts +107 -0
- package/src/display/Scene.ts +305 -0
- package/src/display/SceneTransition.ts +108 -0
- package/src/display/SpineAnimation.ts +170 -0
- package/src/display/Svg.ts +9 -0
- package/src/display/index.ts +11 -0
- package/src/env.d.ts +6 -0
- package/src/hello.ts +20 -0
- package/src/index.ts +17 -0
- package/src/mixins/animated.ts +340 -0
- package/src/mixins/factory/Factory.ts +24 -0
- package/src/mixins/factory/const.ts +363 -0
- package/src/mixins/factory/index.ts +7 -0
- package/src/mixins/factory/methods.ts +21 -0
- package/src/mixins/factory/props.ts +207 -0
- package/src/mixins/factory/registry.test.ts +83 -0
- package/src/mixins/factory/registry.ts +61 -0
- package/src/mixins/factory/schema.ts +153 -0
- package/src/mixins/factory/ui-registry.ts +54 -0
- package/src/mixins/factory/utils.ts +130 -0
- package/src/mixins/focus.ts +124 -0
- package/src/mixins/index.ts +5 -0
- package/src/mixins/interaction.ts +74 -0
- package/src/mixins/signals.ts +49 -0
- package/src/plugins/AssetsPlugin.ts +407 -0
- package/src/plugins/DataAdapter.ts +259 -0
- package/src/plugins/DevToolsPlugin.ts +103 -0
- package/src/plugins/FullScreenPlugin.ts +359 -0
- package/src/plugins/GSAPPlugin.ts +811 -0
- package/src/plugins/KeyboardPlugin.ts +160 -0
- package/src/plugins/LayoutPlugin.ts +127 -0
- package/src/plugins/LookupPlugin.ts +308 -0
- package/src/plugins/Plugin.test.ts +73 -0
- package/src/plugins/Plugin.ts +200 -0
- package/src/plugins/PopupManagerPlugin.ts +263 -0
- package/src/plugins/ResizerPlugin.ts +220 -0
- package/src/plugins/SceneManagerPlugin.ts +669 -0
- package/src/plugins/StatsPlugin.ts +24 -0
- package/src/plugins/TimerPlugin.ts +841 -0
- package/src/plugins/WebEventsPlugin.ts +132 -0
- package/src/plugins/actions/ActionsPlugin.ts +113 -0
- package/src/plugins/actions/constants.ts +45 -0
- package/src/plugins/actions/index.ts +4 -0
- package/src/plugins/actions/methods.ts +28 -0
- package/src/plugins/actions/types.ts +47 -0
- package/src/plugins/audio/AudioChannel.test.ts +101 -0
- package/src/plugins/audio/AudioChannel.ts +164 -0
- package/src/plugins/audio/AudioInstance.ts +228 -0
- package/src/plugins/audio/AudioManagerPlugin.ts +903 -0
- package/src/plugins/audio/VoiceOverPlugin.ts +354 -0
- package/src/plugins/audio/index.ts +3 -0
- package/src/plugins/breakpoints/BreakpointPlugin.test.ts +228 -0
- package/src/plugins/breakpoints/BreakpointPlugin.ts +293 -0
- package/src/plugins/breakpoints/evaluate.test.ts +239 -0
- package/src/plugins/breakpoints/evaluate.ts +201 -0
- package/src/plugins/breakpoints/index.ts +3 -0
- package/src/plugins/breakpoints/methods.ts +22 -0
- package/src/plugins/breakpoints/types.ts +86 -0
- package/src/plugins/captions/CaptionsPlugin.ts +468 -0
- package/src/plugins/captions/CaptionsRenderer.ts +184 -0
- package/src/plugins/captions/font/Sans.fnt +116 -0
- package/src/plugins/captions/font/Sans.png +0 -0
- package/src/plugins/captions/index.ts +2 -0
- package/src/plugins/defaults.ts +95 -0
- package/src/plugins/focus/FocusManagerPlugin.ts +773 -0
- package/src/plugins/focus/FocusOutliner.ts +111 -0
- package/src/plugins/focus/index.ts +2 -0
- package/src/plugins/i18nPlugin.ts +284 -0
- package/src/plugins/index.ts +17 -0
- package/src/plugins/input/AbstractControls.ts +15 -0
- package/src/plugins/input/Controls.ts +55 -0
- package/src/plugins/input/InputPlugin.ts +168 -0
- package/src/plugins/input/constants.ts +12 -0
- package/src/plugins/input/index.ts +9 -0
- package/src/plugins/input/interfaces.ts +37 -0
- package/src/plugins/input/keyboard/KeyboardContols.ts +182 -0
- package/src/plugins/input/keyboard/index.ts +2 -0
- package/src/plugins/input/keyboard/interfaces.ts +21 -0
- package/src/plugins/input/methods.ts +9 -0
- package/src/plugins/input/touch/TouchControls.ts +237 -0
- package/src/plugins/input/touch/constants.ts +34 -0
- package/src/plugins/input/touch/index.ts +3 -0
- package/src/plugins/input/touch/interfaces.ts +15 -0
- package/src/plugins/input/types.ts +41 -0
- package/src/plugins/input/utils.ts +10 -0
- package/src/plugins/spine/SpinePlugin.ts +14 -0
- package/src/plugins/spine/pixi-spine/BatchableSpineSlot.ts +138 -0
- package/src/plugins/spine/pixi-spine/Spine.ts +897 -0
- package/src/plugins/spine/pixi-spine/SpineDebugRenderer.ts +615 -0
- package/src/plugins/spine/pixi-spine/SpinePipe.ts +197 -0
- package/src/plugins/spine/pixi-spine/SpineTexture.ts +143 -0
- package/src/plugins/spine/pixi-spine/assets/atlasLoader.ts +156 -0
- package/src/plugins/spine/pixi-spine/assets/skeletonLoader.ts +80 -0
- package/src/plugins/spine/pixi-spine/darktint/DarkTintBatchGeometry.ts +92 -0
- package/src/plugins/spine/pixi-spine/darktint/DarkTintBatcher.ts +186 -0
- package/src/plugins/spine/pixi-spine/darktint/DarkTintShader.ts +74 -0
- package/src/plugins/spine/pixi-spine/darktint/darkTintBit.ts +77 -0
- package/src/plugins/spine/pixi-spine/index.ts +43 -0
- package/src/plugins/spine/pixi-spine/require-shim.ts +43 -0
- package/src/signals/Signal.test.ts +54 -0
- package/src/signals/Signal.ts +68 -0
- package/src/signals/index.ts +10 -0
- package/src/store/Store.test.ts +146 -0
- package/src/store/Store.ts +192 -0
- package/src/store/index.ts +1 -0
- package/src/types/framework.d.ts +47 -0
- package/src/types/gsap.d.ts +26 -0
- package/src/ui/Button.ts +454 -0
- package/src/ui/FlexContainer.ts +526 -0
- package/src/ui/Input.ts +1274 -0
- package/src/ui/Joystick.ts +288 -0
- package/src/ui/Popup.ts +242 -0
- package/src/ui/Toast.ts +399 -0
- package/src/ui/Toaster.ts +409 -0
- package/src/ui/UICanvas.ts +812 -0
- package/src/ui/index.ts +8 -0
- package/src/utils/array.ts +24 -0
- package/src/utils/bind.ts +79 -0
- package/src/utils/canvas.ts +26 -0
- package/src/utils/color.ts +126 -0
- package/src/utils/console/Logger.ts +86 -0
- package/src/utils/console/index.ts +1 -0
- package/src/utils/debug.ts +69 -0
- package/src/utils/define.ts +120 -0
- package/src/utils/env.ts +3 -0
- package/src/utils/events.ts +10 -0
- package/src/utils/framework.ts +45 -0
- package/src/utils/index.ts +27 -0
- package/src/utils/map.ts +59 -0
- package/src/utils/math.ts +19 -0
- package/src/utils/misc.ts +45 -0
- package/src/utils/number.ts +3 -0
- package/src/utils/object.ts +43 -0
- package/src/utils/padding.ts +43 -0
- package/src/utils/pixi.ts +116 -0
- package/src/utils/platform.ts +33 -0
- package/src/utils/point.ts +123 -0
- package/src/utils/promise/Queue.ts +125 -0
- package/src/utils/promise/functions.ts +16 -0
- package/src/utils/promise/index.ts +2 -0
- package/src/utils/random.ts +69 -0
- package/src/utils/rect.ts +50 -0
- package/src/utils/set.ts +32 -0
- package/src/utils/string.ts +9 -0
- package/src/utils/text.ts +30 -0
- package/src/utils/typefilters.ts +29 -0
- package/src/utils/types.ts +426 -0
- package/src/utils/vite.ts +41 -0
- package/src/utils/web.ts +7 -0
- package/src/version.ts +3 -0
- package/src/webgl-check.ts +12 -0
- package/templates/app/default/.eslintrc.json +21 -0
- package/templates/app/default/.meta.json +4 -0
- package/templates/app/default/.nvmrc +1 -0
- package/templates/app/default/.prettierrc.json +7 -0
- package/templates/app/default/README.md +8 -0
- package/templates/app/default/assets/audio{m}/music/Cheerful Annoyance.ogg +0 -0
- package/templates/app/default/assets/audio{m}/music/Drumming Sticks.ogg +0 -0
- package/templates/app/default/assets/audio{m}/music/Game Over.ogg +0 -0
- package/templates/app/default/assets/audio{m}/music/Mishief Stroll.ogg +0 -0
- package/templates/app/default/assets/audio{m}/music/Night at the Beach.ogg +0 -0
- package/templates/app/default/assets/audio{m}/sfx/click.ogg +0 -0
- package/templates/app/default/assets/audio{m}/sfx/hover.ogg +0 -0
- package/templates/app/default/assets/required{m}/caper.png +0 -0
- package/templates/app/default/assets/required{m}/fonts{fix}/SpaceGrotesk-Bold{family=Space Grotesk}{wf}.ttf +0 -0
- package/templates/app/default/assets/required{m}/fonts{fix}/SpaceGrotesk-Medium{family=Space Grotesk}{wf}.ttf +0 -0
- package/templates/app/default/assets/required{m}/fonts{fix}/SpaceGrotesk-Regular{family=Space Grotesk}{wf}.ttf +0 -0
- package/templates/app/default/assets/required{m}/fonts{fix}/Syncopate-Bold{family=Syncopate}{wf}.ttf +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn/blue.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn/green.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn/grey.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn/orange.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn/purple.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn/red.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn/yellow.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn_a/down.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn_a/over.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn_a/up.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn_b/down.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn_b/over.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/btn_b/up.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/joystick/base.png +0 -0
- package/templates/app/default/assets/required{m}/ui{tps}/joystick/handle.png +0 -0
- package/templates/app/default/assets/required{m}/wordmark.svg +1 -0
- package/templates/app/default/assets/spine{m}/spineboy-pro.png +0 -0
- package/templates/app/default/assets/spine{m}/spineboy-pro.skel +0 -0
- package/templates/app/default/assets/spine{m}/spineboy-pro{fix}.atlas +94 -0
- package/templates/app/default/caper.config.ts +60 -0
- package/templates/app/default/index.html +23 -0
- package/templates/app/default/package.template.json +17 -0
- package/templates/app/default/public/favicon.ico +0 -0
- package/templates/app/default/src/__APPLICATION_NAME__.ts +3 -0
- package/templates/app/default/src/main.ts +9 -0
- package/templates/app/default/src/scenes/Base.ts +39 -0
- package/templates/app/default/src/scenes/Game.ts +34 -0
- package/templates/app/default/src/scenes/Splash.ts +70 -0
- package/templates/app/default/src/scenes/Start.ts +90 -0
- package/templates/app/default/src/utils/Constants.ts +3 -0
- package/templates/app/default/tsconfig.json +1 -0
- package/templates/plugin/package.template.json +33 -0
- package/templates/plugin/src/Plugin.template.ts +24 -0
- package/templates/plugin/src/index.template.ts +3 -0
- package/templates/plugin/tsconfig.template.json +43 -0
- package/templates/plugin/vite-env.template.d.ts +16 -0
- package/templates/plugin/vite.config.template.ts +19 -0
|
@@ -0,0 +1,841 @@
|
|
|
1
|
+
import { Signal } from '../signals';
|
|
2
|
+
import { randomUUID } from '../utils';
|
|
3
|
+
import { Logger } from '../utils/console/Logger';
|
|
4
|
+
import { IPlugin, Plugin } from './Plugin';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Configuration options for creating a timer.
|
|
8
|
+
*/
|
|
9
|
+
export interface TimerOptions {
|
|
10
|
+
/** Duration in milliseconds. If not provided, timer counts up indefinitely */
|
|
11
|
+
duration?: number;
|
|
12
|
+
/** Whether to start the timer immediately upon creation */
|
|
13
|
+
autoStart?: boolean;
|
|
14
|
+
/** Whether to restart the timer when it completes */
|
|
15
|
+
loop?: boolean;
|
|
16
|
+
/** Run timer in a web worker for better performance and independence from main thread */
|
|
17
|
+
useWorker?: boolean;
|
|
18
|
+
/** Update interval in milliseconds for worker-based timers. Default is 16ms (roughly 60fps) */
|
|
19
|
+
workerInterval?: number;
|
|
20
|
+
/** Callback fired when the timer completes. Not called in count-up mode */
|
|
21
|
+
onComplete?: () => void;
|
|
22
|
+
/** Callback fired on each timer tick with the remaining time (or elapsed time in count-up mode) */
|
|
23
|
+
onTick?: (remaining: number) => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Web Worker message types
|
|
27
|
+
interface WorkerMessage {
|
|
28
|
+
type: 'tick' | 'complete' | 'reset' | 'adjustTime';
|
|
29
|
+
timerId: string;
|
|
30
|
+
time: number;
|
|
31
|
+
timeAdjustment?: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type TimeFormat = 'mm:ss' | 'hh:mm:ss' | 'ms';
|
|
35
|
+
export type TimerObject = { h: number; m: number; s: number; ms: number };
|
|
36
|
+
|
|
37
|
+
function createTimerWorker() {
|
|
38
|
+
try {
|
|
39
|
+
const workerCode = `
|
|
40
|
+
const timers = new Map();
|
|
41
|
+
|
|
42
|
+
self.onmessage = (e) => {
|
|
43
|
+
const { type, timerId, options, timeAdjustment } = e.data;
|
|
44
|
+
|
|
45
|
+
switch (type) {
|
|
46
|
+
case 'start': {
|
|
47
|
+
let timer = timers.get(timerId);
|
|
48
|
+
|
|
49
|
+
if (timer) {
|
|
50
|
+
// Resume existing timer
|
|
51
|
+
timer.startTime = performance.now() - (timer.pausedTime || 0);
|
|
52
|
+
timer.interval = createInterval(timer, options, timerId);
|
|
53
|
+
} else {
|
|
54
|
+
// Create new timer
|
|
55
|
+
timer = {
|
|
56
|
+
startTime: performance.now(),
|
|
57
|
+
duration: options.duration,
|
|
58
|
+
loopCount: 0,
|
|
59
|
+
pausedTime: 0,
|
|
60
|
+
options // Store options with the timer
|
|
61
|
+
};
|
|
62
|
+
timer.interval = createInterval(timer, options, timerId);
|
|
63
|
+
timers.set(timerId, timer);
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
case 'stop': {
|
|
69
|
+
const timer = timers.get(timerId);
|
|
70
|
+
if (timer) {
|
|
71
|
+
clearInterval(timer.interval);
|
|
72
|
+
timer.interval = null;
|
|
73
|
+
timer.pausedTime = performance.now() - timer.startTime;
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
case 'reset': {
|
|
79
|
+
const timer = timers.get(timerId);
|
|
80
|
+
if (timer) {
|
|
81
|
+
timer.startTime = performance.now();
|
|
82
|
+
timer.loopCount = 0;
|
|
83
|
+
timer.pausedTime = 0;
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
case 'adjustTime': {
|
|
89
|
+
const timer = timers.get(timerId);
|
|
90
|
+
if (timer) {
|
|
91
|
+
if (timer.duration !== undefined) {
|
|
92
|
+
// For countdown timers, adjust the duration
|
|
93
|
+
timer.duration = Math.max(0, timer.duration + timeAdjustment);
|
|
94
|
+
} else {
|
|
95
|
+
// For count-up timers, adjust the start time
|
|
96
|
+
timer.startTime -= timeAdjustment;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
function createInterval(timer, options, timerId) {
|
|
105
|
+
return setInterval(() => {
|
|
106
|
+
const currentTime = performance.now();
|
|
107
|
+
const totalElapsed = currentTime - timer.startTime;
|
|
108
|
+
|
|
109
|
+
if (timer.duration !== undefined) {
|
|
110
|
+
// Calculate elapsed time within the current loop
|
|
111
|
+
const loopElapsed = totalElapsed - (timer.loopCount * timer.duration);
|
|
112
|
+
const remaining = Math.max(0, timer.duration - loopElapsed);
|
|
113
|
+
|
|
114
|
+
self.postMessage({ type: 'tick', timerId, time: remaining });
|
|
115
|
+
|
|
116
|
+
if (remaining <= 0) {
|
|
117
|
+
self.postMessage({ type: 'complete', timerId, time: 0 });
|
|
118
|
+
|
|
119
|
+
if (options.loop) {
|
|
120
|
+
timer.loopCount++;
|
|
121
|
+
} else {
|
|
122
|
+
clearInterval(timer.interval);
|
|
123
|
+
timers.delete(timerId);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
self.postMessage({ type: 'tick', timerId, time: totalElapsed });
|
|
128
|
+
}
|
|
129
|
+
}, options.workerInterval || 16);
|
|
130
|
+
}
|
|
131
|
+
`;
|
|
132
|
+
|
|
133
|
+
const blob = new Blob([workerCode], { type: 'application/javascript' });
|
|
134
|
+
return new Worker(URL.createObjectURL(blob));
|
|
135
|
+
} catch (e) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Formats a time duration in milliseconds into a human-readable string or object.
|
|
142
|
+
* Supports multiple time formats and return types for flexible time representation.
|
|
143
|
+
*
|
|
144
|
+
* @param ms - Time duration in milliseconds to format
|
|
145
|
+
* @param format - Output format for string representation
|
|
146
|
+
* - 'mm:ss' (default): Minutes and seconds (e.g., "02:30")
|
|
147
|
+
* - 'hh:mm:ss': Hours, minutes, and seconds (e.g., "01:30:45")
|
|
148
|
+
* - 'ms': Total seconds with milliseconds (e.g., "90.50")
|
|
149
|
+
* @param returnFormat - Determines the return type
|
|
150
|
+
* - 'string' (default): Returns formatted time string
|
|
151
|
+
* - 'object': Returns object with h, m, s, ms properties
|
|
152
|
+
*
|
|
153
|
+
* @returns Formatted time string or object containing time components
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* // Format as mm:ss string (default)
|
|
158
|
+
* formatTime(150000) // "02:30"
|
|
159
|
+
*
|
|
160
|
+
* // Format as hh:mm:ss string
|
|
161
|
+
* formatTime(5430000, 'hh:mm:ss') // "01:30:30"
|
|
162
|
+
*
|
|
163
|
+
* // Format as seconds with milliseconds
|
|
164
|
+
* formatTime(90500, 'ms') // "90.50"
|
|
165
|
+
*
|
|
166
|
+
* // Get time components as object
|
|
167
|
+
* formatTime(5430000, 'hh:mm:ss', 'object')
|
|
168
|
+
* // Returns: { h: 1, m: 30, s: 30, ms: 0 }
|
|
169
|
+
*
|
|
170
|
+
* // Use in a game timer display
|
|
171
|
+
* timer.onTick = (remaining) => {
|
|
172
|
+
* display.text = formatTime(remaining, 'mm:ss');
|
|
173
|
+
* };
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
export function formatTime(ms: number, format?: TimeFormat, returnFormat?: 'object'): TimerObject;
|
|
177
|
+
export function formatTime(ms: number, format?: TimeFormat, returnFormat?: 'string'): string;
|
|
178
|
+
// Implementation signature
|
|
179
|
+
export function formatTime(
|
|
180
|
+
ms: number,
|
|
181
|
+
format: TimeFormat = 'mm:ss',
|
|
182
|
+
returnFormat: 'string' | 'object' = 'string',
|
|
183
|
+
): string | TimerObject {
|
|
184
|
+
const totalSeconds = Math.floor(ms / 1000);
|
|
185
|
+
const hours = Math.floor(totalSeconds / 3600);
|
|
186
|
+
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
|
187
|
+
const seconds = totalSeconds % 60;
|
|
188
|
+
const milliseconds = Math.floor((ms % 1000) / 10);
|
|
189
|
+
|
|
190
|
+
if (returnFormat === 'string') {
|
|
191
|
+
switch (format) {
|
|
192
|
+
case 'hh:mm:ss':
|
|
193
|
+
return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
|
|
194
|
+
case 'mm:ss':
|
|
195
|
+
return `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
|
|
196
|
+
case 'ms':
|
|
197
|
+
return `${totalSeconds}.${milliseconds.toString().padStart(2, '0')}`;
|
|
198
|
+
default:
|
|
199
|
+
return `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return { h: hours, m: minutes, s: seconds, ms: milliseconds };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* A Timer instance that can count down or up, optionally running in a web worker.
|
|
208
|
+
*
|
|
209
|
+
* Features:
|
|
210
|
+
* - Count down from a duration or count up indefinitely
|
|
211
|
+
* - Run in main thread (synced with Pixi ticker) or web worker
|
|
212
|
+
* - Pause, resume, and reset functionality
|
|
213
|
+
* - Loop option for repeating timers
|
|
214
|
+
* - Tick and completion callbacks
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```typescript
|
|
218
|
+
* // Create a 10-second countdown timer
|
|
219
|
+
* const timer = new Timer({
|
|
220
|
+
* duration: 10000,
|
|
221
|
+
* autoStart: true,
|
|
222
|
+
* loop: true,
|
|
223
|
+
* onTick: (remaining) => {
|
|
224
|
+
* console.log(`${remaining / 1000} seconds remaining`);
|
|
225
|
+
* },
|
|
226
|
+
* onComplete: () => {
|
|
227
|
+
* console.log('Timer completed!');
|
|
228
|
+
* }
|
|
229
|
+
* }, timerPlugin);
|
|
230
|
+
*
|
|
231
|
+
* // Pause the timer
|
|
232
|
+
* timer.pause();
|
|
233
|
+
*
|
|
234
|
+
* // Resume the timer
|
|
235
|
+
* timer.start();
|
|
236
|
+
*
|
|
237
|
+
* // Reset the timer
|
|
238
|
+
* timer.reset();
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
export class Timer {
|
|
242
|
+
private startTime: number = performance.now();
|
|
243
|
+
private pausedTime: number = 0;
|
|
244
|
+
private isPaused: boolean = true;
|
|
245
|
+
private isDestroyed: boolean = false;
|
|
246
|
+
private timerId: string;
|
|
247
|
+
private isWorkerTimer: boolean;
|
|
248
|
+
|
|
249
|
+
constructor(
|
|
250
|
+
private options: TimerOptions = {},
|
|
251
|
+
private plugin: TimerPlugin,
|
|
252
|
+
) {
|
|
253
|
+
this.timerId = randomUUID();
|
|
254
|
+
// Check if worker is requested but not available
|
|
255
|
+
if (options.useWorker && !plugin.hasWorkerSupport) {
|
|
256
|
+
Logger.warn('Web Worker support not available, falling back to main thread timer');
|
|
257
|
+
options.useWorker = false;
|
|
258
|
+
}
|
|
259
|
+
this.isWorkerTimer = !!options.useWorker;
|
|
260
|
+
if (options.autoStart) {
|
|
261
|
+
this.start();
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Starts or resumes the timer.
|
|
267
|
+
* If the timer was paused, it will continue from where it left off.
|
|
268
|
+
*/
|
|
269
|
+
public start(): void {
|
|
270
|
+
if (!this.isPaused) return;
|
|
271
|
+
this.isPaused = false;
|
|
272
|
+
|
|
273
|
+
if (this.isWorkerTimer) {
|
|
274
|
+
this.plugin.startWorkerTimer(this.timerId, this.options);
|
|
275
|
+
} else {
|
|
276
|
+
this.startTime = performance.now() - this.pausedTime;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Pauses the timer, maintaining its current state.
|
|
282
|
+
* The timer can be resumed later from the same point.
|
|
283
|
+
*/
|
|
284
|
+
public pause(): void {
|
|
285
|
+
if (this.isPaused) return;
|
|
286
|
+
this.isPaused = true;
|
|
287
|
+
|
|
288
|
+
if (this.isWorkerTimer) {
|
|
289
|
+
this.plugin.stopWorkerTimer(this.timerId);
|
|
290
|
+
} else {
|
|
291
|
+
this.pausedTime = performance.now() - this.startTime;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Resets the timer to its initial state.
|
|
297
|
+
* If the timer is not paused, it will start running immediately after reset.
|
|
298
|
+
*/
|
|
299
|
+
public reset(): void {
|
|
300
|
+
if (this.isWorkerTimer) {
|
|
301
|
+
this.plugin.resetWorkerTimer(this.timerId);
|
|
302
|
+
} else {
|
|
303
|
+
this.startTime = performance.now();
|
|
304
|
+
this.pausedTime = 0;
|
|
305
|
+
if (!this.isPaused) {
|
|
306
|
+
this.start();
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Destroys the timer, cleaning up all resources.
|
|
313
|
+
* A destroyed timer cannot be restarted.
|
|
314
|
+
*/
|
|
315
|
+
public destroy(): void {
|
|
316
|
+
if (this.isDestroyed) return;
|
|
317
|
+
this._destroy();
|
|
318
|
+
this.plugin.destroyTimer(this);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
private _destroy(): void {
|
|
322
|
+
this.isDestroyed = true;
|
|
323
|
+
this.pause();
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
public update(): void {
|
|
327
|
+
// Skip update for destroyed, paused, or worker timers
|
|
328
|
+
if (this.isDestroyed || this.isPaused || this.isWorkerTimer) return;
|
|
329
|
+
|
|
330
|
+
const currentTime = performance.now();
|
|
331
|
+
const elapsed = currentTime - this.startTime;
|
|
332
|
+
|
|
333
|
+
if (this.options.duration !== undefined) {
|
|
334
|
+
const remaining = Math.max(0, this.options.duration - elapsed);
|
|
335
|
+
|
|
336
|
+
this.options.onTick?.(remaining);
|
|
337
|
+
|
|
338
|
+
if (remaining <= 0) {
|
|
339
|
+
this.options.onComplete?.();
|
|
340
|
+
|
|
341
|
+
if (this.options.loop) {
|
|
342
|
+
this.reset();
|
|
343
|
+
} else {
|
|
344
|
+
this.destroy();
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
} else {
|
|
348
|
+
// Count up mode
|
|
349
|
+
this.options.onTick?.(elapsed);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Gets the current time value (elapsed time for count-up, remaining time for countdown).
|
|
355
|
+
* @returns Time in milliseconds
|
|
356
|
+
*/
|
|
357
|
+
public getTime(): number {
|
|
358
|
+
if (this.isPaused) {
|
|
359
|
+
return this.pausedTime;
|
|
360
|
+
}
|
|
361
|
+
return performance.now() - this.startTime;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Gets the remaining time for countdown timers.
|
|
366
|
+
* @returns Remaining time in milliseconds, or 0 for count-up timers
|
|
367
|
+
*/
|
|
368
|
+
public getRemainingTime(): number {
|
|
369
|
+
if (!this.options.duration) return 0;
|
|
370
|
+
return Math.max(0, this.options.duration - this.getTime());
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Gets the unique ID of this timer.
|
|
375
|
+
* @returns The timer's UUID
|
|
376
|
+
*/
|
|
377
|
+
public getId(): string {
|
|
378
|
+
return this.timerId;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Gets the timer's configuration options.
|
|
383
|
+
* @returns The TimerOptions object used to create this timer
|
|
384
|
+
*/
|
|
385
|
+
public getOptions(): TimerOptions {
|
|
386
|
+
return this.options;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Checks if this timer is running in a web worker.
|
|
391
|
+
* @returns true if the timer is worker-based, false if running on main thread
|
|
392
|
+
*/
|
|
393
|
+
public isWorker(): boolean {
|
|
394
|
+
return this.isWorkerTimer;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Adds time to the timer. For countdown timers, this increases the duration.
|
|
399
|
+
* For count-up timers, this effectively adds time to the elapsed time.
|
|
400
|
+
*
|
|
401
|
+
* @param ms - Time to add in milliseconds
|
|
402
|
+
* @returns The new time value after adjustment
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```typescript
|
|
406
|
+
* // Add 5 seconds to a countdown timer
|
|
407
|
+
* timer.addTime(5000);
|
|
408
|
+
*
|
|
409
|
+
* // Add 5 seconds to a count-up timer
|
|
410
|
+
* timer.addTime(5000);
|
|
411
|
+
* ```
|
|
412
|
+
*/
|
|
413
|
+
public addTime(ms: number): number {
|
|
414
|
+
if (this.isDestroyed) return 0;
|
|
415
|
+
|
|
416
|
+
if (this.isWorkerTimer) {
|
|
417
|
+
this.plugin.adjustWorkerTimer(this.timerId, ms);
|
|
418
|
+
return this.getTime();
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
if (this.options.duration !== undefined) {
|
|
422
|
+
// For countdown timers, increase the duration
|
|
423
|
+
this.options.duration = Math.max(0, this.options.duration + ms);
|
|
424
|
+
return this.getRemainingTime();
|
|
425
|
+
} else {
|
|
426
|
+
// For count-up timers, adjust the start time to add time
|
|
427
|
+
this.startTime -= ms;
|
|
428
|
+
return this.getTime();
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Removes time from the timer. For countdown timers, this decreases the duration.
|
|
434
|
+
* For count-up timers, this effectively removes time from the elapsed time.
|
|
435
|
+
*
|
|
436
|
+
* @param ms - Time to remove in milliseconds
|
|
437
|
+
* @returns The new time value after adjustment
|
|
438
|
+
*
|
|
439
|
+
* @example
|
|
440
|
+
* ```typescript
|
|
441
|
+
* // Remove 5 seconds from a countdown timer
|
|
442
|
+
* timer.removeTime(5000);
|
|
443
|
+
*
|
|
444
|
+
* // Remove 5 seconds from a count-up timer
|
|
445
|
+
* timer.removeTime(5000);
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
public removeTime(ms: number): number {
|
|
449
|
+
return this.addTime(-ms);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Interface for the Timer Plugin which manages both main-thread and web worker timers.
|
|
455
|
+
*
|
|
456
|
+
* The Timer Plugin provides functionality for:
|
|
457
|
+
* - Creating and managing countdown and count-up timers
|
|
458
|
+
* - Running timers in a web worker for better performance
|
|
459
|
+
* - Pausing and resuming all timers
|
|
460
|
+
* - Handling timer lifecycle events
|
|
461
|
+
*
|
|
462
|
+
* @example
|
|
463
|
+
* ```typescript
|
|
464
|
+
* // Create a 5-second countdown timer
|
|
465
|
+
* const countdown = this.app.timers.createTimer({
|
|
466
|
+
* duration: 5000,
|
|
467
|
+
* autoStart: true,
|
|
468
|
+
* onTick: (remaining) => {
|
|
469
|
+
* console.log(`Time remaining: ${formatTime(remaining, 'mm:ss')}`);
|
|
470
|
+
* },
|
|
471
|
+
* onComplete: () => {
|
|
472
|
+
* console.log('Timer completed!');
|
|
473
|
+
* }
|
|
474
|
+
* });
|
|
475
|
+
*
|
|
476
|
+
* // Create a count-up timer in a web worker
|
|
477
|
+
* const stopwatch = this.app.timers.createTimer({
|
|
478
|
+
* useWorker: true,
|
|
479
|
+
* workerInterval: 100, // Update every 100ms
|
|
480
|
+
* onTick: (elapsed) => {
|
|
481
|
+
* console.log(`Time elapsed: ${formatTime(elapsed, 'mm:ss')}`);
|
|
482
|
+
* }
|
|
483
|
+
* });
|
|
484
|
+
*
|
|
485
|
+
* // Pause all timers
|
|
486
|
+
* this.app.timers.pauseAllTimers();
|
|
487
|
+
*
|
|
488
|
+
* // Resume all timers
|
|
489
|
+
* this.app.timers.resumeAllTimers();
|
|
490
|
+
* ```
|
|
491
|
+
*/
|
|
492
|
+
export interface ITimerPlugin extends IPlugin {
|
|
493
|
+
/**
|
|
494
|
+
* Signal emitted when a new timer is created.
|
|
495
|
+
* @example
|
|
496
|
+
* ```typescript
|
|
497
|
+
* this.app.timers.onTimerCreated.connect((timer) => {
|
|
498
|
+
* console.log(`New timer created with ID: ${timer.getId()}`);
|
|
499
|
+
* });
|
|
500
|
+
* ```
|
|
501
|
+
*/
|
|
502
|
+
onTimerCreated: Signal<(timer: Timer) => void>;
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Signal emitted when a timer is destroyed.
|
|
506
|
+
* @example
|
|
507
|
+
* ```typescript
|
|
508
|
+
* this.app.timers.onTimerDestroyed.connect((timer) => {
|
|
509
|
+
* console.log(`Timer destroyed: ${timer.getId()}`);
|
|
510
|
+
* });
|
|
511
|
+
* ```
|
|
512
|
+
*/
|
|
513
|
+
onTimerDestroyed: Signal<(timer: Timer) => void>;
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Signal emitted when all timers are paused.
|
|
517
|
+
* @example
|
|
518
|
+
* ```typescript
|
|
519
|
+
* this.app.timers.onAllTimersPaused.connect(() => {
|
|
520
|
+
* console.log('All timers paused');
|
|
521
|
+
* });
|
|
522
|
+
* ```
|
|
523
|
+
*/
|
|
524
|
+
onAllTimersPaused: Signal<() => void>;
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Signal emitted when all timers are resumed.
|
|
528
|
+
* @example
|
|
529
|
+
* ```typescript
|
|
530
|
+
* this.app.timers.onAllTimersResumed.connect(() => {
|
|
531
|
+
* console.log('All timers resumed');
|
|
532
|
+
* });
|
|
533
|
+
* ```
|
|
534
|
+
*/
|
|
535
|
+
onAllTimersResumed: Signal<() => void>;
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Creates a new timer with the specified options.
|
|
539
|
+
*
|
|
540
|
+
* @param options - Configuration options for the timer
|
|
541
|
+
* @returns A new Timer instance
|
|
542
|
+
*
|
|
543
|
+
* @example
|
|
544
|
+
* ```typescript
|
|
545
|
+
* // Create a looping timer that runs in a web worker
|
|
546
|
+
* const timer = this.app.timers.createTimer({
|
|
547
|
+
* duration: 1000,
|
|
548
|
+
* loop: true,
|
|
549
|
+
* useWorker: true,
|
|
550
|
+
* onTick: (remaining) => {
|
|
551
|
+
* console.log(`${remaining}ms remaining`);
|
|
552
|
+
* }
|
|
553
|
+
* });
|
|
554
|
+
* ```
|
|
555
|
+
*/
|
|
556
|
+
createTimer(options?: TimerOptions): Timer;
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Destroys a timer, cleaning up all resources and removing it from the plugin.
|
|
560
|
+
*
|
|
561
|
+
* @param timer - The timer instance to destroy
|
|
562
|
+
*
|
|
563
|
+
* @example
|
|
564
|
+
* ```typescript
|
|
565
|
+
* const timer = this.app.timers.createTimer({ duration: 5000 });
|
|
566
|
+
* // ... later ...
|
|
567
|
+
* this.app.timers.destroyTimer(timer);
|
|
568
|
+
* ```
|
|
569
|
+
*/
|
|
570
|
+
destroyTimer(timer: Timer): void;
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Pauses all active timers, both main thread and worker timers.
|
|
574
|
+
* Timers will maintain their current state and can be resumed later.
|
|
575
|
+
*
|
|
576
|
+
* @example
|
|
577
|
+
* ```typescript
|
|
578
|
+
* // Pause all timers when the game loses focus
|
|
579
|
+
* window.onblur = () => {
|
|
580
|
+
* this.app.timers.pauseAllTimers();
|
|
581
|
+
* };
|
|
582
|
+
* ```
|
|
583
|
+
*/
|
|
584
|
+
pauseAllTimers(): void;
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Resumes all paused timers, both main thread and worker timers.
|
|
588
|
+
* Timers will continue from their paused state.
|
|
589
|
+
*
|
|
590
|
+
* @example
|
|
591
|
+
* ```typescript
|
|
592
|
+
* // Resume all timers when the game regains focus
|
|
593
|
+
* window.onfocus = () => {
|
|
594
|
+
* this.app.timers.resumeAllTimers();
|
|
595
|
+
* };
|
|
596
|
+
* ```
|
|
597
|
+
*/
|
|
598
|
+
resumeAllTimers(): void;
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Destroys all active timers, both main thread and worker timers .
|
|
602
|
+
* This will remove all timers from the plugin and stop them.
|
|
603
|
+
*
|
|
604
|
+
* @example
|
|
605
|
+
* ```typescript
|
|
606
|
+
* this.app.timers.destroyAllTimers();
|
|
607
|
+
* ```
|
|
608
|
+
*/
|
|
609
|
+
destroyAllTimers(): void;
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Resets a worker timer to its initial state.
|
|
613
|
+
* This is primarily used internally by the Timer class.
|
|
614
|
+
*
|
|
615
|
+
* @param timerId - The ID of the worker timer to reset
|
|
616
|
+
*
|
|
617
|
+
* @example
|
|
618
|
+
* ```typescript
|
|
619
|
+
* // This is typically called internally by the Timer class
|
|
620
|
+
* this.app.timers.resetWorkerTimer(timer.getId());
|
|
621
|
+
* ```
|
|
622
|
+
*/
|
|
623
|
+
resetWorkerTimer(timerId: string): void;
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* Adjusts the time of a worker timer.
|
|
627
|
+
* This is primarily used internally by the Timer class.
|
|
628
|
+
*
|
|
629
|
+
* @param timerId - The ID of the worker timer to adjust
|
|
630
|
+
* @param timeAdjustment - The amount of time to add (positive) or remove (negative) in milliseconds
|
|
631
|
+
*
|
|
632
|
+
* @example
|
|
633
|
+
* ```typescript
|
|
634
|
+
* // This is typically called internally by the Timer class
|
|
635
|
+
* this.app.timers.adjustWorkerTimer(timer.getId(), 5000); // Add 5 seconds
|
|
636
|
+
* ```
|
|
637
|
+
*/
|
|
638
|
+
adjustWorkerTimer(timerId: string, timeAdjustment: number): void;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
export class TimerPlugin extends Plugin implements ITimerPlugin {
|
|
642
|
+
private mainThreadTimers: Set<Timer> = new Set();
|
|
643
|
+
private workerTimers: Set<Timer> = new Set();
|
|
644
|
+
private isPageVisible: boolean = true;
|
|
645
|
+
private worker: Worker | null = null;
|
|
646
|
+
private timerCallbacks: Map<string, TimerOptions> = new Map();
|
|
647
|
+
private _hasWorkerSupport: boolean = false;
|
|
648
|
+
|
|
649
|
+
public get hasWorkerSupport(): boolean {
|
|
650
|
+
return this._hasWorkerSupport;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
public readonly onTimerCreated = new Signal<(timer: Timer) => void>();
|
|
654
|
+
public readonly onTimerDestroyed = new Signal<(timer: Timer) => void>();
|
|
655
|
+
public readonly onAllTimersPaused = new Signal<() => void>();
|
|
656
|
+
public readonly onAllTimersResumed = new Signal<() => void>();
|
|
657
|
+
|
|
658
|
+
constructor() {
|
|
659
|
+
super('timers');
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
protected getCoreFunctions(): string[] {
|
|
663
|
+
return [
|
|
664
|
+
'createTimer',
|
|
665
|
+
'destroyTimer',
|
|
666
|
+
'pauseAllTimers',
|
|
667
|
+
'resumeAllTimers',
|
|
668
|
+
'resetWorkerTimer',
|
|
669
|
+
'adjustWorkerTimer',
|
|
670
|
+
];
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
protected getCoreSignals(): string[] {
|
|
674
|
+
return ['onTimerCreated', 'onTimerDestroyed', 'onAllTimersPaused', 'onAllTimersResumed'];
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
public postInitialize() {
|
|
678
|
+
// Set up update loop for main thread timers only
|
|
679
|
+
this.app.ticker.add(this.update);
|
|
680
|
+
|
|
681
|
+
// Initialize worker if needed
|
|
682
|
+
this.initWorker();
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
private initWorker(): void {
|
|
686
|
+
if (typeof Worker !== 'undefined') {
|
|
687
|
+
this.worker = createTimerWorker();
|
|
688
|
+
if (this.worker) {
|
|
689
|
+
this._hasWorkerSupport = true;
|
|
690
|
+
this.worker.onmessage = this.handleWorkerMessage;
|
|
691
|
+
} else {
|
|
692
|
+
Logger.warn('Failed to create Web Worker for TimerPlugin, all timers will run on main thread');
|
|
693
|
+
this._hasWorkerSupport = false;
|
|
694
|
+
}
|
|
695
|
+
} else {
|
|
696
|
+
Logger.warn('Web Workers not supported in this environment, all timers will run on main thread');
|
|
697
|
+
this._hasWorkerSupport = false;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
private handleWorkerMessage = (e: MessageEvent<WorkerMessage>): void => {
|
|
702
|
+
const { type, timerId, time, timeAdjustment } = e.data;
|
|
703
|
+
const options = this.timerCallbacks.get(timerId);
|
|
704
|
+
|
|
705
|
+
if (!options) return;
|
|
706
|
+
|
|
707
|
+
switch (type) {
|
|
708
|
+
case 'tick':
|
|
709
|
+
// Directly call onTick from the worker's interval
|
|
710
|
+
options.onTick?.(time);
|
|
711
|
+
break;
|
|
712
|
+
case 'complete':
|
|
713
|
+
options.onComplete?.();
|
|
714
|
+
// Only remove callbacks if not looping
|
|
715
|
+
if (!options.loop) {
|
|
716
|
+
this.timerCallbacks.delete(timerId);
|
|
717
|
+
}
|
|
718
|
+
break;
|
|
719
|
+
case 'adjustTime':
|
|
720
|
+
if (timeAdjustment !== undefined) {
|
|
721
|
+
if (options.duration !== undefined) {
|
|
722
|
+
// For countdown timers, adjust the duration
|
|
723
|
+
options.duration = Math.max(0, options.duration + timeAdjustment);
|
|
724
|
+
}
|
|
725
|
+
// Note: We don't need to handle count-up timers here as they're handled in the worker
|
|
726
|
+
}
|
|
727
|
+
break;
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
|
|
731
|
+
public startWorkerTimer(timerId: string, options: TimerOptions): void {
|
|
732
|
+
if (!this.worker) return;
|
|
733
|
+
|
|
734
|
+
this.timerCallbacks.set(timerId, options);
|
|
735
|
+
this.worker.postMessage({
|
|
736
|
+
type: 'start',
|
|
737
|
+
timerId,
|
|
738
|
+
options: {
|
|
739
|
+
duration: options.duration,
|
|
740
|
+
loop: options.loop,
|
|
741
|
+
workerInterval: options.workerInterval,
|
|
742
|
+
},
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
public stopWorkerTimer(timerId: string): void {
|
|
747
|
+
if (!this.worker) return;
|
|
748
|
+
|
|
749
|
+
this.worker.postMessage({
|
|
750
|
+
type: 'stop',
|
|
751
|
+
timerId,
|
|
752
|
+
});
|
|
753
|
+
this.timerCallbacks.delete(timerId);
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
public resetWorkerTimer(timerId: string): void {
|
|
757
|
+
if (!this.worker) return;
|
|
758
|
+
|
|
759
|
+
this.worker.postMessage({
|
|
760
|
+
type: 'reset',
|
|
761
|
+
timerId,
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
public destroy(): void {
|
|
766
|
+
this.app.ticker.remove(this.update);
|
|
767
|
+
this.worker?.terminate();
|
|
768
|
+
this.worker = null;
|
|
769
|
+
this.timerCallbacks.clear();
|
|
770
|
+
this.mainThreadTimers.clear();
|
|
771
|
+
this.workerTimers.clear();
|
|
772
|
+
super.destroy();
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
private update() {
|
|
776
|
+
// Only update main thread timers
|
|
777
|
+
for (const timer of this.mainThreadTimers) {
|
|
778
|
+
timer.update();
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
public createTimer(options?: TimerOptions): Timer {
|
|
783
|
+
const timer = new Timer(options, this);
|
|
784
|
+
|
|
785
|
+
// Separate management of worker and main thread timers
|
|
786
|
+
if (timer.isWorker()) {
|
|
787
|
+
this.workerTimers.add(timer);
|
|
788
|
+
} else {
|
|
789
|
+
this.mainThreadTimers.add(timer);
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
this.onTimerCreated.emit(timer);
|
|
793
|
+
return timer;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
public destroyTimer(timer: Timer): void {
|
|
797
|
+
const timerSet = timer.isWorker() ? this.workerTimers : this.mainThreadTimers;
|
|
798
|
+
|
|
799
|
+
if (timerSet.has(timer)) {
|
|
800
|
+
timer.destroy();
|
|
801
|
+
timerSet.delete(timer);
|
|
802
|
+
this.onTimerDestroyed.emit(timer);
|
|
803
|
+
|
|
804
|
+
if (timer.isWorker()) {
|
|
805
|
+
this.stopWorkerTimer(timer.getId());
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
public pauseAllTimers(): void {
|
|
811
|
+
// Pause both worker and main thread timers
|
|
812
|
+
for (const timer of [...this.mainThreadTimers, ...this.workerTimers]) {
|
|
813
|
+
timer.pause();
|
|
814
|
+
}
|
|
815
|
+
this.onAllTimersPaused.emit();
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
public resumeAllTimers(): void {
|
|
819
|
+
// Resume both worker and main thread timers
|
|
820
|
+
for (const timer of [...this.mainThreadTimers, ...this.workerTimers]) {
|
|
821
|
+
timer.start();
|
|
822
|
+
}
|
|
823
|
+
this.onAllTimersResumed.emit();
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
public destroyAllTimers(): void {
|
|
827
|
+
for (const timer of [...this.mainThreadTimers, ...this.workerTimers]) {
|
|
828
|
+
this.destroyTimer(timer);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
public adjustWorkerTimer(timerId: string, timeAdjustment: number): void {
|
|
833
|
+
if (!this.worker) return;
|
|
834
|
+
|
|
835
|
+
this.worker.postMessage({
|
|
836
|
+
type: 'adjustTime',
|
|
837
|
+
timerId,
|
|
838
|
+
timeAdjustment,
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
}
|