@egret/engine 0.0.0-stage → 7.0.2
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 +201 -0
- package/NOTICE +21 -0
- package/README.md +101 -2
- package/README.zh-CN.md +102 -0
- package/dist/Engine.d.ts +77 -0
- package/dist/Engine.js +469 -0
- package/dist/animation/index.d.ts +6 -0
- package/dist/animation/index.js +5 -0
- package/dist/animation/sequenceController.d.ts +22 -0
- package/dist/animation/sequenceController.js +618 -0
- package/dist/animation/sequenceCoordinator.d.ts +26 -0
- package/dist/animation/sequenceCoordinator.js +161 -0
- package/dist/animation/sequenceInput.d.ts +25 -0
- package/dist/animation/sequenceInput.js +108 -0
- package/dist/animation/sequenceMath.d.ts +35 -0
- package/dist/animation/sequenceMath.js +164 -0
- package/dist/animation/sequenceResetSlot.d.ts +7 -0
- package/dist/animation/sequenceResetSlot.js +367 -0
- package/dist/animation/sequenceResetTypes.d.ts +48 -0
- package/dist/animation/sequenceResetTypes.js +2 -0
- package/dist/animation/types.d.ts +75 -0
- package/dist/animation/types.js +2 -0
- package/dist/assetBundle.d.ts +54 -0
- package/dist/assetBundle.js +173 -0
- package/dist/assetGroup.d.ts +17 -0
- package/dist/assetGroup.js +332 -0
- package/dist/assetGroupTypes.d.ts +17 -0
- package/dist/assetGroupTypes.js +2 -0
- package/dist/audio.d.ts +4 -0
- package/dist/audio.js +4 -0
- package/dist/audioCues.d.ts +47 -0
- package/dist/audioCues.js +127 -0
- package/dist/audioMixer.d.ts +7 -0
- package/dist/audioMixer.js +785 -0
- package/dist/audioTypes.d.ts +246 -0
- package/dist/audioTypes.js +3 -0
- package/dist/bitmapBindingTicket.d.ts +24 -0
- package/dist/bitmapBindingTicket.js +215 -0
- package/dist/bitmapButton.d.ts +4 -0
- package/dist/bitmapButton.js +407 -0
- package/dist/bitmapButtonTypes.d.ts +31 -0
- package/dist/bitmapButtonTypes.js +2 -0
- package/dist/bitmapFontParse.d.ts +10 -0
- package/dist/bitmapFontParse.js +246 -0
- package/dist/bitmapFontTypes.d.ts +112 -0
- package/dist/bitmapFontTypes.js +2 -0
- package/dist/bitmapResourceSlot.d.ts +26 -0
- package/dist/bitmapResourceSlot.js +340 -0
- package/dist/bitmapText.d.ts +6 -0
- package/dist/bitmapText.js +320 -0
- package/dist/bitmapfont.d.ts +5 -0
- package/dist/bitmapfont.js +5 -0
- package/dist/camera.d.ts +4 -0
- package/dist/camera.js +4 -0
- package/dist/camera2d.d.ts +7 -0
- package/dist/camera2d.js +419 -0
- package/dist/cameraTypes.d.ts +126 -0
- package/dist/cameraTypes.js +2 -0
- package/dist/closeHost.d.ts +4 -0
- package/dist/closeHost.js +66 -0
- package/dist/contentArtifacts.d.ts +12 -0
- package/dist/contentArtifacts.js +153 -0
- package/dist/contentAtlasPages.d.ts +13 -0
- package/dist/contentAtlasPages.js +117 -0
- package/dist/contentLoader.d.ts +6 -0
- package/dist/contentLoader.js +327 -0
- package/dist/contentTypes.d.ts +35 -0
- package/dist/contentTypes.js +2 -0
- package/dist/createEngine.d.ts +7 -0
- package/dist/createEngine.js +25 -0
- package/dist/createEngineForProfile.d.ts +5 -0
- package/dist/createEngineForProfile.js +45 -0
- package/dist/displaySubtreeTicket.d.ts +25 -0
- package/dist/displaySubtreeTicket.js +76 -0
- package/dist/fontContentLoader.d.ts +6 -0
- package/dist/fontContentLoader.js +298 -0
- package/dist/fontContentTypes.d.ts +39 -0
- package/dist/fontContentTypes.js +2 -0
- package/dist/gameClock.d.ts +24 -0
- package/dist/gameClock.js +246 -0
- package/dist/gameClockTypes.d.ts +37 -0
- package/dist/gameClockTypes.js +2 -0
- package/dist/gameRun.d.ts +53 -0
- package/dist/gameRun.js +97 -0
- package/dist/gamepad.d.ts +5 -0
- package/dist/gamepad.js +5 -0
- package/dist/gamepadInput.d.ts +4 -0
- package/dist/gamepadInput.js +281 -0
- package/dist/gamepadKeys.d.ts +4 -0
- package/dist/gamepadKeys.js +205 -0
- package/dist/gamepadTypes.d.ts +142 -0
- package/dist/gamepadTypes.js +3 -0
- package/dist/hover.d.ts +4 -0
- package/dist/hover.js +4 -0
- package/dist/hoverInput.d.ts +8 -0
- package/dist/hoverInput.js +503 -0
- package/dist/hoverInputTypes.d.ts +129 -0
- package/dist/hoverInputTypes.js +2 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +21 -0
- package/dist/input.d.ts +6 -0
- package/dist/input.js +5 -0
- package/dist/inputActions.d.ts +86 -0
- package/dist/inputActions.js +330 -0
- package/dist/internal/contentFactoryState.d.ts +19 -0
- package/dist/internal/contentFactoryState.js +42 -0
- package/dist/internal/mouseInputFactoryState.d.ts +57 -0
- package/dist/internal/mouseInputFactoryState.js +125 -0
- package/dist/internal/sequenceControllerFactoryState.d.ts +42 -0
- package/dist/internal/sequenceControllerFactoryState.js +98 -0
- package/dist/internal/textFieldFactoryState.d.ts +11 -0
- package/dist/internal/textFieldFactoryState.js +32 -0
- package/dist/internal/texturedFrameState.d.ts +4 -0
- package/dist/internal/texturedFrameState.js +12 -0
- package/dist/internal/uiFactoryState.d.ts +68 -0
- package/dist/internal/uiFactoryState.js +173 -0
- package/dist/internal/uiRootState.d.ts +67 -0
- package/dist/internal/uiRootState.js +103 -0
- package/dist/keyboardInput.d.ts +13 -0
- package/dist/keyboardInput.js +579 -0
- package/dist/keyboardInputTypes.d.ts +93 -0
- package/dist/keyboardInputTypes.js +2 -0
- package/dist/kit.d.ts +16 -0
- package/dist/kit.js +10 -0
- package/dist/layout.d.ts +5 -0
- package/dist/layout.js +132 -0
- package/dist/layoutTypes.d.ts +28 -0
- package/dist/layoutTypes.js +2 -0
- package/dist/manifestAssetGroup.d.ts +10 -0
- package/dist/manifestAssetGroup.js +477 -0
- package/dist/manifestResourceState.d.ts +17 -0
- package/dist/manifestResourceState.js +58 -0
- package/dist/manifestResourceTypes.d.ts +26 -0
- package/dist/manifestResourceTypes.js +2 -0
- package/dist/motion.d.ts +35 -0
- package/dist/motion.js +206 -0
- package/dist/mouseInput.d.ts +102 -0
- package/dist/mouseInput.js +562 -0
- package/dist/mouseInputTypes.d.ts +41 -0
- package/dist/mouseInputTypes.js +2 -0
- package/dist/paragraph.d.ts +8 -0
- package/dist/paragraph.js +7 -0
- package/dist/particleEmitter.d.ts +4 -0
- package/dist/particleEmitter.js +300 -0
- package/dist/particleTypes.d.ts +115 -0
- package/dist/particleTypes.js +2 -0
- package/dist/particles.d.ts +4 -0
- package/dist/particles.js +4 -0
- package/dist/physics2d.d.ts +4 -0
- package/dist/physics2d.js +4 -0
- package/dist/physics2dGeometry.d.ts +39 -0
- package/dist/physics2dGeometry.js +230 -0
- package/dist/physics2dTypes.d.ts +221 -0
- package/dist/physics2dTypes.js +2 -0
- package/dist/physics2dWorld.d.ts +4 -0
- package/dist/physics2dWorld.js +823 -0
- package/dist/pointerInput.d.ts +12 -0
- package/dist/pointerInput.js +300 -0
- package/dist/pointerInputTypes.d.ts +41 -0
- package/dist/pointerInputTypes.js +2 -0
- package/dist/random.d.ts +30 -0
- package/dist/random.js +131 -0
- package/dist/rendering/ownedPreparationFailure2D.d.ts +5 -0
- package/dist/rendering/ownedPreparationFailure2D.js +33 -0
- package/dist/rendering/packSharedDraws2D.d.ts +50 -0
- package/dist/rendering/packSharedDraws2D.js +379 -0
- package/dist/rendering/packedOrientation.d.ts +4 -0
- package/dist/rendering/packedOrientation.js +7 -0
- package/dist/rendering/prepareRectangles2D.d.ts +92 -0
- package/dist/rendering/prepareRectangles2D.js +481 -0
- package/dist/rendering/prepareSharedDraws2D.d.ts +90 -0
- package/dist/rendering/prepareSharedDraws2D.js +663 -0
- package/dist/rendering/preparedBatches2D.d.ts +17 -0
- package/dist/rendering/preparedBatches2D.js +30 -0
- package/dist/rendering/preparedSharedBatches2D.d.ts +44 -0
- package/dist/rendering/preparedSharedBatches2D.js +247 -0
- package/dist/rendering/sharedColor2D.d.ts +52 -0
- package/dist/rendering/sharedColor2D.js +191 -0
- package/dist/rendering/sharedEffects2D.d.ts +23 -0
- package/dist/rendering/sharedEffects2D.js +126 -0
- package/dist/rendering/sharedPreparationRetention2D.d.ts +120 -0
- package/dist/rendering/sharedPreparationRetention2D.js +357 -0
- package/dist/rendering/srgbBytes.d.ts +3 -0
- package/dist/rendering/srgbBytes.js +64 -0
- package/dist/rendering/texturedPreparationBudget2D.d.ts +31 -0
- package/dist/rendering/texturedPreparationBudget2D.js +81 -0
- package/dist/rendering/world3d/Animation3D.d.ts +104 -0
- package/dist/rendering/world3d/Animation3D.js +384 -0
- package/dist/rendering/world3d/AnimationTexture3D.d.ts +163 -0
- package/dist/rendering/world3d/AnimationTexture3D.js +603 -0
- package/dist/rendering/world3d/Batch3D.d.ts +75 -0
- package/dist/rendering/world3d/Batch3D.js +332 -0
- package/dist/rendering/world3d/Camera3D.d.ts +62 -0
- package/dist/rendering/world3d/Camera3D.js +132 -0
- package/dist/rendering/world3d/Character3D.d.ts +127 -0
- package/dist/rendering/world3d/Character3D.js +305 -0
- package/dist/rendering/world3d/Cloth3D.d.ts +130 -0
- package/dist/rendering/world3d/Cloth3D.js +503 -0
- package/dist/rendering/world3d/Compression3D.d.ts +22 -0
- package/dist/rendering/world3d/Compression3D.js +703 -0
- package/dist/rendering/world3d/Curves3D.d.ts +119 -0
- package/dist/rendering/world3d/Curves3D.js +460 -0
- package/dist/rendering/world3d/Decal3D.d.ts +43 -0
- package/dist/rendering/world3d/Decal3D.js +242 -0
- package/dist/rendering/world3d/Export3D.d.ts +13 -0
- package/dist/rendering/world3d/Export3D.js +263 -0
- package/dist/rendering/world3d/Geometry3D.d.ts +95 -0
- package/dist/rendering/world3d/Geometry3D.js +335 -0
- package/dist/rendering/world3d/GeometryBuilder3D.d.ts +53 -0
- package/dist/rendering/world3d/GeometryBuilder3D.js +196 -0
- package/dist/rendering/world3d/Gizmo3D.d.ts +80 -0
- package/dist/rendering/world3d/Gizmo3D.js +514 -0
- package/dist/rendering/world3d/Gltf3D.d.ts +73 -0
- package/dist/rendering/world3d/Gltf3D.js +996 -0
- package/dist/rendering/world3d/GpuParticles3D.d.ts +109 -0
- package/dist/rendering/world3d/GpuParticles3D.js +401 -0
- package/dist/rendering/world3d/Hdr3D.d.ts +35 -0
- package/dist/rendering/world3d/Hdr3D.js +191 -0
- package/dist/rendering/world3d/Jelly3D.d.ts +77 -0
- package/dist/rendering/world3d/Jelly3D.js +267 -0
- package/dist/rendering/world3d/Ktx23D.d.ts +30 -0
- package/dist/rendering/world3d/Ktx23D.js +112 -0
- package/dist/rendering/world3d/Light3D.d.ts +84 -0
- package/dist/rendering/world3d/Light3D.js +97 -0
- package/dist/rendering/world3d/Material3D.d.ts +253 -0
- package/dist/rendering/world3d/Material3D.js +269 -0
- package/dist/rendering/world3d/Mesh3D.d.ts +112 -0
- package/dist/rendering/world3d/Mesh3D.js +337 -0
- package/dist/rendering/world3d/Meshopt3D.d.ts +15 -0
- package/dist/rendering/world3d/Meshopt3D.js +276 -0
- package/dist/rendering/world3d/Navigation3D.d.ts +213 -0
- package/dist/rendering/world3d/Navigation3D.js +1043 -0
- package/dist/rendering/world3d/Object3D.d.ts +118 -0
- package/dist/rendering/world3d/Object3D.js +315 -0
- package/dist/rendering/world3d/Particles3D.d.ts +90 -0
- package/dist/rendering/world3d/Particles3D.js +277 -0
- package/dist/rendering/world3d/Physics3D.d.ts +430 -0
- package/dist/rendering/world3d/Physics3D.js +2840 -0
- package/dist/rendering/world3d/PhysicsHull3D.d.ts +37 -0
- package/dist/rendering/world3d/PhysicsHull3D.js +229 -0
- package/dist/rendering/world3d/PhysicsMesh3D.d.ts +41 -0
- package/dist/rendering/world3d/PhysicsMesh3D.js +340 -0
- package/dist/rendering/world3d/PhysicsQueries3D.d.ts +24 -0
- package/dist/rendering/world3d/PhysicsQueries3D.js +323 -0
- package/dist/rendering/world3d/PhysicsRemote3D.d.ts +179 -0
- package/dist/rendering/world3d/PhysicsRemote3D.js +536 -0
- package/dist/rendering/world3d/Ragdoll3D.d.ts +74 -0
- package/dist/rendering/world3d/Ragdoll3D.js +202 -0
- package/dist/rendering/world3d/Raycast3D.d.ts +40 -0
- package/dist/rendering/world3d/Raycast3D.js +247 -0
- package/dist/rendering/world3d/RenderList3D.d.ts +91 -0
- package/dist/rendering/world3d/RenderList3D.js +502 -0
- package/dist/rendering/world3d/Retarget3D.d.ts +21 -0
- package/dist/rendering/world3d/Retarget3D.js +185 -0
- package/dist/rendering/world3d/Rig3D.d.ts +57 -0
- package/dist/rendering/world3d/Rig3D.js +219 -0
- package/dist/rendering/world3d/Sdf3D.d.ts +181 -0
- package/dist/rendering/world3d/Sdf3D.js +1136 -0
- package/dist/rendering/world3d/SdfLod3D.d.ts +17 -0
- package/dist/rendering/world3d/SdfLod3D.js +56 -0
- package/dist/rendering/world3d/Serialize3D.d.ts +66 -0
- package/dist/rendering/world3d/Serialize3D.js +629 -0
- package/dist/rendering/world3d/Simplify3D.d.ts +29 -0
- package/dist/rendering/world3d/Simplify3D.js +426 -0
- package/dist/rendering/world3d/StateMachine3D.d.ts +87 -0
- package/dist/rendering/world3d/StateMachine3D.js +280 -0
- package/dist/rendering/world3d/SurfaceMaterial3D.d.ts +26 -0
- package/dist/rendering/world3d/SurfaceMaterial3D.js +138 -0
- package/dist/rendering/world3d/Terrain3D.d.ts +248 -0
- package/dist/rendering/world3d/Terrain3D.js +827 -0
- package/dist/rendering/world3d/Text3D.d.ts +95 -0
- package/dist/rendering/world3d/Text3D.js +560 -0
- package/dist/rendering/world3d/Texture3D.d.ts +148 -0
- package/dist/rendering/world3d/Texture3D.js +270 -0
- package/dist/rendering/world3d/Trail3D.d.ts +62 -0
- package/dist/rendering/world3d/Trail3D.js +195 -0
- package/dist/rendering/world3d/Vehicle3D.d.ts +102 -0
- package/dist/rendering/world3d/Vehicle3D.js +228 -0
- package/dist/rendering/world3d/VolumetricFog3D.d.ts +57 -0
- package/dist/rendering/world3d/VolumetricFog3D.js +230 -0
- package/dist/rendering/world3d/Water3D.d.ts +165 -0
- package/dist/rendering/world3d/Water3D.js +607 -0
- package/dist/rendering/world3d/core3D.d.ts +36 -0
- package/dist/rendering/world3d/core3D.js +99 -0
- package/dist/rendering/world3d/debug3D.d.ts +69 -0
- package/dist/rendering/world3d/debug3D.js +262 -0
- package/dist/rendering/world3d/decoders3D.d.ts +42 -0
- package/dist/rendering/world3d/decoders3D.js +133 -0
- package/dist/rendering/world3d/geometries3D.d.ts +111 -0
- package/dist/rendering/world3d/geometries3D.js +610 -0
- package/dist/rendering/world3d/helpers3D.d.ts +67 -0
- package/dist/rendering/world3d/helpers3D.js +178 -0
- package/dist/rendering/world3d/index.d.ts +103 -0
- package/dist/rendering/world3d/index.js +62 -0
- package/dist/rendering/world3d/math3D.d.ts +114 -0
- package/dist/rendering/world3d/math3D.js +675 -0
- package/dist/rendering/world3d/primitives3D.d.ts +67 -0
- package/dist/rendering/world3d/primitives3D.js +197 -0
- package/dist/resources.d.ts +8 -0
- package/dist/resources.js +6 -0
- package/dist/saveStore.d.ts +71 -0
- package/dist/saveStore.js +182 -0
- package/dist/semanticList.d.ts +126 -0
- package/dist/semanticList.js +175 -0
- package/dist/semanticTree.d.ts +10 -0
- package/dist/semanticTree.js +539 -0
- package/dist/semanticTypes.d.ts +175 -0
- package/dist/semanticTypes.js +2 -0
- package/dist/semantics.d.ts +6 -0
- package/dist/semantics.js +5 -0
- package/dist/sequencePlayback.d.ts +19 -0
- package/dist/sequencePlayback.js +391 -0
- package/dist/sequencePlaybackTypes.d.ts +24 -0
- package/dist/sequencePlaybackTypes.js +2 -0
- package/dist/sequenceTargetClaims.d.ts +10 -0
- package/dist/sequenceTargetClaims.js +31 -0
- package/dist/srgbBytes.d.ts +3 -0
- package/dist/srgbBytes.js +64 -0
- package/dist/startEngine.d.ts +5 -0
- package/dist/startEngine.js +31 -0
- package/dist/surfaceOwnership.d.ts +3 -0
- package/dist/surfaceOwnership.js +15 -0
- package/dist/text.d.ts +24 -0
- package/dist/text.js +4 -0
- package/dist/textField.d.ts +6 -0
- package/dist/textField.js +6 -0
- package/dist/textTable.d.ts +41 -0
- package/dist/textTable.js +114 -0
- package/dist/tileMapDraw.d.ts +7 -0
- package/dist/tileMapDraw.js +310 -0
- package/dist/tiledImport.d.ts +9 -0
- package/dist/tiledImport.js +357 -0
- package/dist/tilemap.d.ts +5 -0
- package/dist/tilemap.js +5 -0
- package/dist/tilemapTypes.d.ts +182 -0
- package/dist/tilemapTypes.js +2 -0
- package/dist/timer.d.ts +34 -0
- package/dist/timer.js +119 -0
- package/dist/tween.d.ts +15 -0
- package/dist/tween.js +329 -0
- package/dist/tweenTypes.d.ts +31 -0
- package/dist/tweenTypes.js +2 -0
- package/dist/ui/controlKeys.d.ts +113 -0
- package/dist/ui/controlKeys.js +250 -0
- package/dist/ui/controls.d.ts +58 -0
- package/dist/ui/controls.js +290 -0
- package/dist/ui/editing.d.ts +3 -0
- package/dist/ui/editing.js +3 -0
- package/dist/ui/index.d.ts +19 -0
- package/dist/ui/index.js +11 -0
- package/dist/ui/keyboardFocus.d.ts +32 -0
- package/dist/ui/keyboardFocus.js +146 -0
- package/dist/ui/layerTypes.d.ts +98 -0
- package/dist/ui/layerTypes.js +2 -0
- package/dist/ui/layers.d.ts +4 -0
- package/dist/ui/layers.js +586 -0
- package/dist/ui/leafContent.d.ts +21 -0
- package/dist/ui/leafContent.js +136 -0
- package/dist/ui/rangeControl.d.ts +53 -0
- package/dist/ui/rangeControl.js +168 -0
- package/dist/ui/scrollControl.d.ts +84 -0
- package/dist/ui/scrollControl.js +222 -0
- package/dist/ui/stateControls.d.ts +90 -0
- package/dist/ui/stateControls.js +331 -0
- package/dist/ui/textEditor.d.ts +54 -0
- package/dist/ui/textEditor.js +371 -0
- package/dist/ui/textEditorTypes.d.ts +85 -0
- package/dist/ui/textEditorTypes.js +2 -0
- package/dist/ui/textFieldControl.d.ts +100 -0
- package/dist/ui/textFieldControl.js +260 -0
- package/dist/ui/theme.d.ts +64 -0
- package/dist/ui/theme.js +166 -0
- package/dist/ui/types.d.ts +285 -0
- package/dist/ui/types.js +2 -0
- package/dist/ui/uiRoot.d.ts +4 -0
- package/dist/ui/uiRoot.js +1526 -0
- package/dist/ui/uiRootDisplay.d.ts +46 -0
- package/dist/ui/uiRootDisplay.js +148 -0
- package/dist/ui/uiRootModel.d.ts +114 -0
- package/dist/ui/uiRootModel.js +66 -0
- package/dist/ui/virtualList.d.ts +20 -0
- package/dist/ui/virtualList.js +105 -0
- package/dist/video.d.ts +4 -0
- package/dist/video.js +4 -0
- package/dist/videoPlayer.d.ts +4 -0
- package/dist/videoPlayer.js +215 -0
- package/dist/videoTypes.d.ts +77 -0
- package/dist/videoTypes.js +2 -0
- package/dist/web/BrowserAssetBundle.d.ts +41 -0
- package/dist/web/BrowserAssetBundle.js +136 -0
- package/dist/web/BrowserAudio.d.ts +74 -0
- package/dist/web/BrowserAudio.js +503 -0
- package/dist/web/BrowserFrameLoop.d.ts +69 -0
- package/dist/web/BrowserFrameLoop.js +125 -0
- package/dist/web/BrowserGame.d.ts +174 -0
- package/dist/web/BrowserGame.js +473 -0
- package/dist/web/BrowserGamepadInput.d.ts +38 -0
- package/dist/web/BrowserGamepadInput.js +134 -0
- package/dist/web/BrowserHoverInput.d.ts +25 -0
- package/dist/web/BrowserHoverInput.js +266 -0
- package/dist/web/BrowserImageTextures.d.ts +72 -0
- package/dist/web/BrowserImageTextures.js +169 -0
- package/dist/web/BrowserInputActions.d.ts +63 -0
- package/dist/web/BrowserInputActions.js +345 -0
- package/dist/web/BrowserKeyboardInput.d.ts +4 -0
- package/dist/web/BrowserKeyboardInput.js +223 -0
- package/dist/web/BrowserPlay.d.ts +417 -0
- package/dist/web/BrowserPlay.js +1648 -0
- package/dist/web/BrowserPointerInput.d.ts +4 -0
- package/dist/web/BrowserPointerInput.js +511 -0
- package/dist/web/BrowserPreferences.d.ts +10 -0
- package/dist/web/BrowserPreferences.js +39 -0
- package/dist/web/BrowserSemantics.d.ts +36 -0
- package/dist/web/BrowserSemantics.js +418 -0
- package/dist/web/BrowserStatsPanel.d.ts +56 -0
- package/dist/web/BrowserStatsPanel.js +143 -0
- package/dist/web/BrowserStorage.d.ts +35 -0
- package/dist/web/BrowserStorage.js +132 -0
- package/dist/web/BrowserTextEditor.d.ts +52 -0
- package/dist/web/BrowserTextEditor.js +839 -0
- package/dist/web/BrowserTextInput.d.ts +89 -0
- package/dist/web/BrowserTextInput.js +524 -0
- package/dist/web/BrowserTextureProvider.d.ts +58 -0
- package/dist/web/BrowserTextureProvider.js +935 -0
- package/dist/web/BrowserVideo.d.ts +40 -0
- package/dist/web/BrowserVideo.js +237 -0
- package/dist/web/CanvasKitFontSetProvider.d.ts +32 -0
- package/dist/web/CanvasKitFontSetProvider.js +215 -0
- package/dist/web/CanvasKitParagraphProvider.d.ts +173 -0
- package/dist/web/CanvasKitParagraphProvider.js +692 -0
- package/dist/web/CanvasTextRasterProvider.d.ts +4 -0
- package/dist/web/CanvasTextRasterProvider.js +312 -0
- package/dist/web/ManifestByteSource.d.ts +151 -0
- package/dist/web/ManifestByteSource.js +975 -0
- package/dist/web/ManifestFontContentLoader.d.ts +13 -0
- package/dist/web/ManifestFontContentLoader.js +30 -0
- package/dist/web/MouseInput.d.ts +4 -0
- package/dist/web/MouseInput.js +218 -0
- package/dist/web/WebGL2Host.d.ts +5 -0
- package/dist/web/WebGL2Host.js +2711 -0
- package/dist/web/WebGPUHost.d.ts +100 -0
- package/dist/web/WebGPUHost.js +3430 -0
- package/dist/web/audio.d.ts +3 -0
- package/dist/web/audio.js +4 -0
- package/dist/web/canvasKitParagraphGeometry.d.ts +27 -0
- package/dist/web/canvasKitParagraphGeometry.js +83 -0
- package/dist/web/editing.d.ts +5 -0
- package/dist/web/editing.js +4 -0
- package/dist/web/editorFonts.d.ts +54 -0
- package/dist/web/editorFonts.js +297 -0
- package/dist/web/game.d.ts +5 -0
- package/dist/web/game.js +6 -0
- package/dist/web/gamepad.d.ts +3 -0
- package/dist/web/gamepad.js +4 -0
- package/dist/web/hover.d.ts +3 -0
- package/dist/web/hover.js +4 -0
- package/dist/web/image.d.ts +4 -0
- package/dist/web/image.js +4 -0
- package/dist/web/imageProjections2D.d.ts +16 -0
- package/dist/web/imageProjections2D.js +2 -0
- package/dist/web/input.d.ts +6 -0
- package/dist/web/input.js +4 -0
- package/dist/web/keyboard.d.ts +3 -0
- package/dist/web/keyboard.js +3 -0
- package/dist/web/kit.d.ts +11 -0
- package/dist/web/kit.js +8 -0
- package/dist/web/loop.d.ts +3 -0
- package/dist/web/loop.js +4 -0
- package/dist/web/paragraph.d.ts +6 -0
- package/dist/web/paragraph.js +4 -0
- package/dist/web/play.d.ts +10 -0
- package/dist/web/play.js +9 -0
- package/dist/web/playMusic.d.ts +33 -0
- package/dist/web/playMusic.js +194 -0
- package/dist/web/playSfx.d.ts +36 -0
- package/dist/web/playSfx.js +112 -0
- package/dist/web/playTouch.d.ts +45 -0
- package/dist/web/playTouch.js +141 -0
- package/dist/web/playWidgets.d.ts +71 -0
- package/dist/web/playWidgets.js +431 -0
- package/dist/web/pointer.d.ts +3 -0
- package/dist/web/pointer.js +3 -0
- package/dist/web/prepareSharedSubmission2D.d.ts +27 -0
- package/dist/web/prepareSharedSubmission2D.js +63 -0
- package/dist/web/resources.d.ts +29 -0
- package/dist/web/resources.js +96 -0
- package/dist/web/semantics.d.ts +3 -0
- package/dist/web/semantics.js +4 -0
- package/dist/web/sharedDeviceSession.d.ts +64 -0
- package/dist/web/sharedDeviceSession.js +2 -0
- package/dist/web/sharedEffectShaders.d.ts +13 -0
- package/dist/web/sharedEffectShaders.js +181 -0
- package/dist/web/sharedFrameUpload.d.ts +25 -0
- package/dist/web/sharedFrameUpload.js +2 -0
- package/dist/web/sharedHostDeferred.d.ts +7 -0
- package/dist/web/sharedHostDeferred.js +12 -0
- package/dist/web/sharedRetentionLedger.d.ts +85 -0
- package/dist/web/sharedRetentionLedger.js +391 -0
- package/dist/web/sharedSubmissionStorage2D.d.ts +56 -0
- package/dist/web/sharedSubmissionStorage2D.js +73 -0
- package/dist/web/sharedWebGL2Arena.d.ts +40 -0
- package/dist/web/sharedWebGL2Arena.js +77 -0
- package/dist/web/sharedWebGL2Options.d.ts +33 -0
- package/dist/web/sharedWebGL2Options.js +102 -0
- package/dist/web/sharedWebGL2Shaders.d.ts +33 -0
- package/dist/web/sharedWebGL2Shaders.js +408 -0
- package/dist/web/sharedWebGPUOptions.d.ts +41 -0
- package/dist/web/sharedWebGPUOptions.js +130 -0
- package/dist/web/text.d.ts +3 -0
- package/dist/web/text.js +3 -0
- package/dist/web/textInput.d.ts +3 -0
- package/dist/web/textInput.js +3 -0
- package/dist/web/video.d.ts +3 -0
- package/dist/web/video.js +4 -0
- package/dist/web/webgl2.d.ts +7 -0
- package/dist/web/webgl2.js +4 -0
- package/dist/web/webgl2LayerState.d.ts +50 -0
- package/dist/web/webgl2LayerState.js +102 -0
- package/dist/web/webgl2Native.d.ts +72 -0
- package/dist/web/webgl2Native.js +572 -0
- package/dist/web/webgl2Types.d.ts +150 -0
- package/dist/web/webgl2Types.js +2 -0
- package/dist/web/webgpu.d.ts +6 -0
- package/dist/web/webgpu.js +2 -0
- package/dist/web/webgpuBindingCache.d.ts +26 -0
- package/dist/web/webgpuBindingCache.js +223 -0
- package/dist/web/webgpuBufferPool.d.ts +51 -0
- package/dist/web/webgpuBufferPool.js +58 -0
- package/dist/web/webgpuImageResidency.d.ts +56 -0
- package/dist/web/webgpuImageResidency.js +65 -0
- package/dist/web/webgpuLifetime.d.ts +45 -0
- package/dist/web/webgpuLifetime.js +64 -0
- package/dist/web/webgpuRetentionPool.d.ts +66 -0
- package/dist/web/webgpuRetentionPool.js +85 -0
- package/dist/web/webgpuSharedPass.d.ts +7 -0
- package/dist/web/webgpuSharedPass.js +293 -0
- package/dist/web/webgpuSharedResolvePass.d.ts +3 -0
- package/dist/web/webgpuSharedResolvePass.js +34 -0
- package/dist/web/world3d/Audio3D.d.ts +85 -0
- package/dist/web/world3d/Audio3D.js +271 -0
- package/dist/web/world3d/BrowserPlay3D.d.ts +295 -0
- package/dist/web/world3d/BrowserPlay3D.js +1256 -0
- package/dist/web/world3d/FlyControls3D.d.ts +59 -0
- package/dist/web/world3d/FlyControls3D.js +162 -0
- package/dist/web/world3d/FollowControls3D.d.ts +31 -0
- package/dist/web/world3d/FollowControls3D.js +119 -0
- package/dist/web/world3d/OrbitControls3D.d.ts +58 -0
- package/dist/web/world3d/OrbitControls3D.js +189 -0
- package/dist/web/world3d/TransformControls3D.d.ts +37 -0
- package/dist/web/world3d/TransformControls3D.js +128 -0
- package/dist/web/world3d/WebGL2Renderer3D.d.ts +136 -0
- package/dist/web/world3d/WebGL2Renderer3D.js +1175 -0
- package/dist/web/world3d/WebGPURenderer3D.d.ts +112 -0
- package/dist/web/world3d/WebGPURenderer3D.js +1916 -0
- package/dist/web/world3d/World3DView.d.ts +54 -0
- package/dist/web/world3d/World3DView.js +79 -0
- package/dist/web/world3d/app3D.d.ts +143 -0
- package/dist/web/world3d/app3D.js +305 -0
- package/dist/web/world3d/assets3D.d.ts +39 -0
- package/dist/web/world3d/assets3D.js +112 -0
- package/dist/web/world3d/atmosphere3D.d.ts +56 -0
- package/dist/web/world3d/atmosphere3D.js +193 -0
- package/dist/web/world3d/canvasFont3D.d.ts +21 -0
- package/dist/web/world3d/canvasFont3D.js +165 -0
- package/dist/web/world3d/frame3D.d.ts +144 -0
- package/dist/web/world3d/frame3D.js +388 -0
- package/dist/web/world3d/gpuResources3D.d.ts +98 -0
- package/dist/web/world3d/gpuResources3D.js +901 -0
- package/dist/web/world3d/host3D.d.ts +24 -0
- package/dist/web/world3d/host3D.js +61 -0
- package/dist/web/world3d/index.d.ts +40 -0
- package/dist/web/world3d/index.js +24 -0
- package/dist/web/world3d/loaders3D.d.ts +27 -0
- package/dist/web/world3d/loaders3D.js +138 -0
- package/dist/web/world3d/markers3D.d.ts +53 -0
- package/dist/web/world3d/markers3D.js +130 -0
- package/dist/web/world3d/materialWebGL23D.d.ts +34 -0
- package/dist/web/world3d/materialWebGL23D.js +218 -0
- package/dist/web/world3d/overlay3D.d.ts +47 -0
- package/dist/web/world3d/overlay3D.js +187 -0
- package/dist/web/world3d/post3D.d.ts +116 -0
- package/dist/web/world3d/post3D.js +462 -0
- package/dist/web/world3d/postWebGL23D.d.ts +24 -0
- package/dist/web/world3d/postWebGL23D.js +237 -0
- package/dist/web/world3d/postWebGPU3D.d.ts +23 -0
- package/dist/web/world3d/postWebGPU3D.js +255 -0
- package/dist/web/world3d/probe3D.d.ts +15 -0
- package/dist/web/world3d/probe3D.js +66 -0
- package/dist/web/world3d/shaders3D.d.ts +43 -0
- package/dist/web/world3d/shaders3D.js +851 -0
- package/dist/web/world3d/stats3D.d.ts +34 -0
- package/dist/web/world3d/stats3D.js +81 -0
- package/dist/web/world3d/webGL2FrameMetrics3D.d.ts +71 -0
- package/dist/web/world3d/webGL2FrameMetrics3D.js +185 -0
- package/dist/web/world3d/webgpu.d.ts +37 -0
- package/dist/web/world3d/webgpu.js +23 -0
- package/dist/web/world3d/webgpuPacking3D.d.ts +13 -0
- package/dist/web/world3d/webgpuPacking3D.js +85 -0
- package/dist/web/world3d/wgsl3D.d.ts +68 -0
- package/dist/web/world3d/wgsl3D.js +781 -0
- package/package.json +220 -4
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import type { AssetLease, DisplayObject, DiagnosticHandler, Engine, Scope, Stage, SharedFrameOptions2D, Texture } from '@egret/engine';
|
|
2
|
+
import type { TextField } from '@egret/engine/text';
|
|
3
|
+
import type { BrowserFrameLoop } from './loop.js';
|
|
4
|
+
import type { PointerInput } from './pointer.js';
|
|
5
|
+
import type { KeyboardInput } from './keyboard.js';
|
|
6
|
+
import type { createBrowserHoverInput } from './hover.js';
|
|
7
|
+
/** The hover and wheel input of the page, as `createBrowserHoverInput` of `@egret/engine/web/hover` makes it. */
|
|
8
|
+
type BrowserGameHoverInput = ReturnType<typeof createBrowserHoverInput>;
|
|
9
|
+
import type { BrowserStatsPanel } from './BrowserStatsPanel.js';
|
|
10
|
+
/** Which GPU interface a browser game draws with. */
|
|
11
|
+
export type BrowserGameBackend = 'webgpu' | 'webgl2';
|
|
12
|
+
/** How the canvas fills the element it is in: not at all, whole inside it, covering it, or stretched to it. */
|
|
13
|
+
export type BrowserGameFit = 'none' | 'contain' | 'cover' | 'stretch';
|
|
14
|
+
/** A text label to make: its text, font, size and weight, line height, color, locale and direction. */
|
|
15
|
+
export interface BrowserGameLabelOptions {
|
|
16
|
+
readonly text?: string;
|
|
17
|
+
/** A font the page has: a family of the system, or one the page loaded. "sans-serif" unless given. */
|
|
18
|
+
readonly fontFamily?: string;
|
|
19
|
+
/** In stage units: 24 unless given. */
|
|
20
|
+
readonly fontSize?: number;
|
|
21
|
+
readonly fontWeight?: number;
|
|
22
|
+
readonly italic?: boolean;
|
|
23
|
+
/** In stage units: a quarter more than the font size unless given. */
|
|
24
|
+
readonly lineHeight?: number;
|
|
25
|
+
/** 0xffffff unless given. */
|
|
26
|
+
readonly color?: number;
|
|
27
|
+
/** The language of the text, such as "zh" or "en": "en" unless given. */
|
|
28
|
+
readonly locale?: string;
|
|
29
|
+
readonly direction?: 'ltr' | 'rtl';
|
|
30
|
+
}
|
|
31
|
+
/** A label to make: its words and style, and the scope that owns it. */
|
|
32
|
+
export interface BrowserGameLabelCreateOptions extends BrowserGameLabelOptions {
|
|
33
|
+
/**
|
|
34
|
+
* The scope that owns the label's display object. Defaults to `game.scope`. Give the `context.scope` of a UI leaf to
|
|
35
|
+
* use the label as that leaf's content; the label then ends with that scope.
|
|
36
|
+
*/
|
|
37
|
+
readonly scope?: Scope;
|
|
38
|
+
}
|
|
39
|
+
/** A line of text on the stage whose words can be set like a value. */
|
|
40
|
+
export interface BrowserGameLabel {
|
|
41
|
+
/** The text on the stage: place it with `display.x` and `display.y`, add it where it belongs. */
|
|
42
|
+
readonly display: TextField;
|
|
43
|
+
/** Setting it draws the new words when they are ready; until then the old ones stay. */
|
|
44
|
+
text: string;
|
|
45
|
+
/** Settles when the words last set are on the stage, and rejects if they could not be drawn. */
|
|
46
|
+
readonly ready: Promise<void>;
|
|
47
|
+
/** Changes any of the options; what is left out stays. */
|
|
48
|
+
set(options: BrowserGameLabelOptions): void;
|
|
49
|
+
dispose(): void;
|
|
50
|
+
}
|
|
51
|
+
/** A browser game to make: its canvas and size, its backend and colors, its update, its input and stats, and how it fits the page. */
|
|
52
|
+
export interface BrowserGameOptions {
|
|
53
|
+
/** The canvas the game is drawn on. The page gives it its size on the screen. */
|
|
54
|
+
readonly canvas: HTMLCanvasElement;
|
|
55
|
+
/** The size of the stage, in the game's own units, whatever the size of the canvas on the page. */
|
|
56
|
+
readonly width: number;
|
|
57
|
+
readonly height: number;
|
|
58
|
+
/** "auto", unless given: WebGPU where the browser gives an adapter, WebGL2 otherwise. */
|
|
59
|
+
readonly backend?: 'auto' | BrowserGameBackend;
|
|
60
|
+
/** Canvas pixels for each unit of the canvas's own width. The device's ratio unless given, and then never more than 2. */
|
|
61
|
+
readonly pixelRatio?: number;
|
|
62
|
+
/** What a frame is cleared to before the stage is drawn: 0x000000 and 1 unless given. */
|
|
63
|
+
readonly clearColor?: number;
|
|
64
|
+
readonly clearAlpha?: number;
|
|
65
|
+
/**
|
|
66
|
+
* Where translucent draws mix with what is under them: "linear" light unless given, or the stored "srgb"
|
|
67
|
+
* codes, as a 2D canvas and Egret 5 mix them, so a faint white over a dark ground stays faint.
|
|
68
|
+
*/
|
|
69
|
+
readonly blendSpace?: 'linear' | 'srgb';
|
|
70
|
+
/**
|
|
71
|
+
* Whether render effects are drawn: blurs, colour matrices, glows, outlines, and masks of images or of shapes.
|
|
72
|
+
* Off unless given; a frame with an effect is refused without it.
|
|
73
|
+
*/
|
|
74
|
+
readonly effects?: boolean;
|
|
75
|
+
/** One step of the game, called before each frame with the seconds since the step before. */
|
|
76
|
+
readonly update?: (deltaSeconds: number) => void;
|
|
77
|
+
/** Told once of what stopped the game's loop. Without it the failure is thrown where the console shows it. */
|
|
78
|
+
readonly onError?: (error: unknown) => void;
|
|
79
|
+
/** Touch, mouse and pen on display objects, and the keyboard. Both are made unless false is given. */
|
|
80
|
+
readonly pointer?: boolean;
|
|
81
|
+
readonly keyboard?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Hover and the mouse wheel over display objects, as `createBrowserHoverInput` makes them: what a scroll control's
|
|
84
|
+
* `wheel` and a button's hover look need. Made only when true is given; its module is loaded only then.
|
|
85
|
+
*/
|
|
86
|
+
readonly hover?: boolean;
|
|
87
|
+
/** A panel over the canvas with frames a second, what a frame holds and how busy the Host is. Not made unless true is given. */
|
|
88
|
+
readonly stats?: boolean;
|
|
89
|
+
/** "none" unless given. The canvas is sized inside `fitTo`, or its parent element, and again whenever that changes size. */
|
|
90
|
+
readonly fit?: BrowserGameFit;
|
|
91
|
+
readonly fitTo?: HTMLElement;
|
|
92
|
+
/** The loop starts at once unless false is given; then `game.loop.start()` starts it. */
|
|
93
|
+
readonly autoStart?: boolean;
|
|
94
|
+
}
|
|
95
|
+
/** A game in a canvas: its Engine, host and stage, its frame loop and input, and calls that load textures and make labels. */
|
|
96
|
+
export interface BrowserGame {
|
|
97
|
+
readonly backend: BrowserGameBackend;
|
|
98
|
+
readonly engine: Engine;
|
|
99
|
+
/** The Host that draws: its status says what it holds and what last went wrong. It ends with the game. */
|
|
100
|
+
readonly host: {
|
|
101
|
+
getStatus(): {
|
|
102
|
+
readonly pendingFrames: number;
|
|
103
|
+
};
|
|
104
|
+
whenIdle(): Promise<void>;
|
|
105
|
+
};
|
|
106
|
+
/** The stage of the Engine: what is added to it is drawn. */
|
|
107
|
+
readonly stage: Stage;
|
|
108
|
+
/** A scope for what the game creates. It is disposed with the game. */
|
|
109
|
+
readonly scope: Scope;
|
|
110
|
+
/** The frame the loop draws: the stage's size and what it is cleared to. */
|
|
111
|
+
readonly frame: SharedFrameOptions2D;
|
|
112
|
+
readonly loop: BrowserFrameLoop;
|
|
113
|
+
readonly pointer: PointerInput | undefined;
|
|
114
|
+
readonly keyboard: KeyboardInput | undefined;
|
|
115
|
+
/** The hover and wheel input, when `hover: true` was given. */
|
|
116
|
+
readonly hover: BrowserGameHoverInput | undefined;
|
|
117
|
+
readonly stats: BrowserStatsPanel | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* Loads a PNG image from an address and gives the lease of its texture, for `new Bitmap(lease)` or
|
|
120
|
+
* `graphics.beginBitmapFill(lease)`. The lease belongs to the game's scope. The same address loaded twice is one texture.
|
|
121
|
+
*/
|
|
122
|
+
loadTexture(url: string): Promise<AssetLease<Texture>>;
|
|
123
|
+
/**
|
|
124
|
+
* The lease of a texture of pixels painted in code: `width` × `height` pixels of 4 bytes each, red, green, blue and
|
|
125
|
+
* alpha, rows from the top, alpha not multiplied in (as `ImageData` holds them). The bytes are copied, so the array can
|
|
126
|
+
* be changed after. At most 4,096 pixels on an edge and 4,194,304 in all. The lease belongs to the game's scope; each
|
|
127
|
+
* call is a texture of its own, ended with its lease.
|
|
128
|
+
*/
|
|
129
|
+
textureFromPixels(width: number, height: number, pixels: Uint8Array | Uint8ClampedArray): Promise<AssetLease<Texture>>;
|
|
130
|
+
/**
|
|
131
|
+
* The lease of a texture of what a canvas holds now, as `textureFromPixels` of its pixels. A canvas with a 2D context,
|
|
132
|
+
* or none yet, is read with that context; one drawn by WebGL or WebGPU is copied through a 2D canvas first. To scale
|
|
133
|
+
* down a larger picture, or read an image or bitmap, `textureFromCanvas` of `@egret/engine/web/kit` gives a texture.
|
|
134
|
+
*/
|
|
135
|
+
textureFromCanvas(canvas: HTMLCanvasElement | OffscreenCanvas): Promise<AssetLease<Texture>>;
|
|
136
|
+
/** A line of text for the stage. The first call loads the page's text rasterizer. */
|
|
137
|
+
createLabel(options?: BrowserGameLabelCreateOptions): Promise<BrowserGameLabel>;
|
|
138
|
+
/**
|
|
139
|
+
* Stage units in one CSS pixel as the canvas is shown now, the larger of across and down: `44 * game.unitsPerCssPixel`
|
|
140
|
+
* is a touch target a finger can hit. 1 before the canvas is laid out.
|
|
141
|
+
*/
|
|
142
|
+
readonly unitsPerCssPixel: number;
|
|
143
|
+
/**
|
|
144
|
+
* Gives a display object a hit area at least `cssPixels` (44 unless given) square as the canvas is shown now, centred
|
|
145
|
+
* on what it draws and never smaller than it, so a small icon is as easy to press as a finger needs. Call it again
|
|
146
|
+
* after the node, its ancestors or the canvas change transform or size. Returns the area, in the node's own units.
|
|
147
|
+
*/
|
|
148
|
+
padHitArea(node: DisplayObject, cssPixels?: number): {
|
|
149
|
+
readonly x: number;
|
|
150
|
+
readonly y: number;
|
|
151
|
+
readonly width: number;
|
|
152
|
+
readonly height: number;
|
|
153
|
+
};
|
|
154
|
+
/** A place in the page, as a pointer event gives it in `clientX` and `clientY`, as a place on the stage. */
|
|
155
|
+
toStage(clientX: number, clientY: number): {
|
|
156
|
+
x: number;
|
|
157
|
+
y: number;
|
|
158
|
+
};
|
|
159
|
+
/** Stops the loop and ends the input, the scope, the Engine and its Host. */
|
|
160
|
+
dispose(): Promise<void>;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* What a game does with the diagnostics of its Engine. An error the Engine can only report, such as a listener of
|
|
164
|
+
* pointer input that threw, which ends that input, is told as a failure of the loop is: to `onError`, or to the page,
|
|
165
|
+
* where the console shows it. Without this it was told to no one, and the game went on without its input.
|
|
166
|
+
*/
|
|
167
|
+
export declare function gameDiagnostics(onError: ((error: unknown) => void) | undefined): DiagnosticHandler;
|
|
168
|
+
/**
|
|
169
|
+
* Makes a game ready to draw: `await createBrowserGame({ canvas, width, height, update })`, then add display objects
|
|
170
|
+
* to `game.stage`. Everything it makes is what the separate entries make; a game that outgrows it takes them apart.
|
|
171
|
+
*/
|
|
172
|
+
export declare function createBrowserGame(options: BrowserGameOptions): Promise<BrowserGame>;
|
|
173
|
+
export {};
|
|
174
|
+
//# sourceMappingURL=BrowserGame.d.ts.map
|
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// A game in a page from one call: a Host chosen for the browser, an Engine, a scope, pointer and keyboard input and
|
|
3
|
+
// a frame loop, each made the way its own entry makes it, and all of them ended by one dispose.
|
|
4
|
+
import { EgretError } from '@egret/runtime';
|
|
5
|
+
import { createAssetRef, createAssetType, createEngineForProfile, createImageData2D, createTexture, isTexture, SHARED_FRAME_PROFILE_2D } from '@egret/engine';
|
|
6
|
+
import { createBrowserTextureProvider } from './image.js';
|
|
7
|
+
import { createTextField, createTextRasterCache } from '@egret/engine/text';
|
|
8
|
+
import { createBrowserFrameLoop } from './loop.js';
|
|
9
|
+
import { createBrowserPointerInput } from './pointer.js';
|
|
10
|
+
import { createBrowserKeyboardInput } from './keyboard.js';
|
|
11
|
+
import { createBrowserStatsPanel } from './BrowserStatsPanel.js';
|
|
12
|
+
const invalid = () => new EgretError('BROWSER_GAME_OPTIONS_INVALID');
|
|
13
|
+
const whole = (value) => typeof value === 'number' && Number.isSafeInteger(value) && value > 0;
|
|
14
|
+
/** WebGPU where the browser has it and gives an adapter. Asking for an adapter does not touch the canvas, which can hold one kind of context only. */
|
|
15
|
+
async function chooseBackend(asked) {
|
|
16
|
+
if (asked !== 'auto')
|
|
17
|
+
return asked;
|
|
18
|
+
const gpu = globalThis.navigator?.gpu;
|
|
19
|
+
if (gpu === undefined || gpu === null)
|
|
20
|
+
return 'webgl2';
|
|
21
|
+
try {
|
|
22
|
+
return (await gpu.requestAdapter()) ? 'webgpu' : 'webgl2';
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return 'webgl2';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* What a game does with the diagnostics of its Engine. An error the Engine can only report, such as a listener of
|
|
30
|
+
* pointer input that threw, which ends that input, is told as a failure of the loop is: to `onError`, or to the page,
|
|
31
|
+
* where the console shows it. Without this it was told to no one, and the game went on without its input.
|
|
32
|
+
*/
|
|
33
|
+
export function gameDiagnostics(onError) {
|
|
34
|
+
return diagnostic => {
|
|
35
|
+
if (diagnostic.severity !== 'error')
|
|
36
|
+
return;
|
|
37
|
+
const error = diagnostic.cause ?? new EgretError(diagnostic.code);
|
|
38
|
+
if (onError !== undefined) {
|
|
39
|
+
onError(error);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const tell = globalThis.reportError;
|
|
43
|
+
if (typeof tell === 'function')
|
|
44
|
+
tell(error);
|
|
45
|
+
// A page without reportError still shows a promise that nothing handled.
|
|
46
|
+
else
|
|
47
|
+
void Promise.reject(error);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Makes a game ready to draw: `await createBrowserGame({ canvas, width, height, update })`, then add display objects
|
|
52
|
+
* to `game.stage`. Everything it makes is what the separate entries make; a game that outgrows it takes them apart.
|
|
53
|
+
*/
|
|
54
|
+
export async function createBrowserGame(options) {
|
|
55
|
+
if (options === null || typeof options !== 'object')
|
|
56
|
+
throw invalid();
|
|
57
|
+
const { canvas, width, height, update, onError } = options;
|
|
58
|
+
const asked = options.backend ?? 'auto', clearColor = options.clearColor ?? 0, clearAlpha = options.clearAlpha ?? 1, blendSpace = options.blendSpace ?? 'linear', enableEffects = options.effects ?? false;
|
|
59
|
+
const device = Number(globalThis.devicePixelRatio), pixelRatio = options.pixelRatio ?? (device > 0 ? Math.min(device, 2) : 1);
|
|
60
|
+
if (canvas === null ||
|
|
61
|
+
typeof canvas !== 'object' ||
|
|
62
|
+
typeof canvas.getBoundingClientRect !== 'function' ||
|
|
63
|
+
!whole(width) ||
|
|
64
|
+
!whole(height) ||
|
|
65
|
+
(asked !== 'auto' && asked !== 'webgpu' && asked !== 'webgl2') ||
|
|
66
|
+
typeof pixelRatio !== 'number' ||
|
|
67
|
+
!(pixelRatio > 0) ||
|
|
68
|
+
!Number.isFinite(pixelRatio) ||
|
|
69
|
+
!Number.isInteger(clearColor) ||
|
|
70
|
+
clearColor < 0 ||
|
|
71
|
+
clearColor > 0xffffff ||
|
|
72
|
+
typeof clearAlpha !== 'number' ||
|
|
73
|
+
!(clearAlpha >= 0 && clearAlpha <= 1) ||
|
|
74
|
+
(blendSpace !== 'linear' && blendSpace !== 'srgb') ||
|
|
75
|
+
typeof enableEffects !== 'boolean' ||
|
|
76
|
+
(update !== undefined && typeof update !== 'function') ||
|
|
77
|
+
(onError !== undefined && typeof onError !== 'function') ||
|
|
78
|
+
[options.pointer, options.keyboard, options.hover, options.autoStart, options.stats].some(flag => flag !== undefined && typeof flag !== 'boolean') ||
|
|
79
|
+
!['none', 'contain', 'cover', 'stretch'].includes(options.fit ?? 'none') ||
|
|
80
|
+
(options.fitTo !== undefined && (options.fitTo === null || typeof options.fitTo !== 'object')))
|
|
81
|
+
throw invalid();
|
|
82
|
+
const backend = await chooseBackend(asked);
|
|
83
|
+
// Only the chosen backend's module is loaded.
|
|
84
|
+
const host = backend === 'webgpu'
|
|
85
|
+
? (await import('./webgpu.js')).createSharedWebGPUHost({ canvas, pixelRatio, blendSpace, enableEffects })
|
|
86
|
+
: (await import('./webgl2.js')).createSharedWebGL2Host({ canvas, pixelRatio, blendSpace, enableEffects });
|
|
87
|
+
let engine;
|
|
88
|
+
try {
|
|
89
|
+
engine = await createEngineForProfile({ host, onDiagnostic: gameDiagnostics(onError) }, SHARED_FRAME_PROFILE_2D);
|
|
90
|
+
}
|
|
91
|
+
catch (cause) {
|
|
92
|
+
try {
|
|
93
|
+
await host.close();
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
/* The first failure is the one to tell. */
|
|
97
|
+
}
|
|
98
|
+
throw cause;
|
|
99
|
+
}
|
|
100
|
+
let loop, stats, disposal;
|
|
101
|
+
try {
|
|
102
|
+
const scope = engine.createScope(), frame = Object.freeze({ width, height, clearColor, clearAlpha });
|
|
103
|
+
const pointer = options.pointer === false ? undefined : createBrowserPointerInput({ engine, scope, width, height });
|
|
104
|
+
const keyboard = options.keyboard === false ? undefined : createBrowserKeyboardInput({ engine, scope });
|
|
105
|
+
const hover = options.hover === true
|
|
106
|
+
? scope.use((await import('./hover.js')).createBrowserHoverInput({
|
|
107
|
+
engine,
|
|
108
|
+
scope,
|
|
109
|
+
canvas,
|
|
110
|
+
width,
|
|
111
|
+
height,
|
|
112
|
+
...(onError === undefined ? {} : { onError })
|
|
113
|
+
}))
|
|
114
|
+
: undefined;
|
|
115
|
+
const panel = (stats = options.stats === true ? createBrowserStatsPanel({ canvas, label: backend }) : undefined);
|
|
116
|
+
let drawn;
|
|
117
|
+
// With a panel, the loop draws through a step that keeps the frame, and each step tells the panel what the last one did.
|
|
118
|
+
const made = (loop =
|
|
119
|
+
panel === undefined
|
|
120
|
+
? createBrowserFrameLoop({
|
|
121
|
+
engine,
|
|
122
|
+
host,
|
|
123
|
+
frame,
|
|
124
|
+
...(update === undefined ? {} : { update }),
|
|
125
|
+
...(onError === undefined ? {} : { onError })
|
|
126
|
+
})
|
|
127
|
+
: createBrowserFrameLoop({
|
|
128
|
+
engine: {
|
|
129
|
+
clock: engine.clock,
|
|
130
|
+
advanceTime: (seconds) => engine.advanceTime(seconds),
|
|
131
|
+
renderSharedFrame: (given) => (drawn = engine.renderSharedFrame(given))
|
|
132
|
+
},
|
|
133
|
+
host,
|
|
134
|
+
frame,
|
|
135
|
+
...(onError === undefined ? {} : { onError }),
|
|
136
|
+
update(seconds) {
|
|
137
|
+
const now = made.snapshot();
|
|
138
|
+
panel.sample({
|
|
139
|
+
...(drawn === undefined ? {} : { frame: drawn }),
|
|
140
|
+
pendingFrames: host.getStatus().pendingFrames,
|
|
141
|
+
drawCalls: host.getFrameDrawCalls(),
|
|
142
|
+
frames: now.frames,
|
|
143
|
+
skipped: now.skipped
|
|
144
|
+
});
|
|
145
|
+
drawn = undefined;
|
|
146
|
+
update?.(seconds);
|
|
147
|
+
}
|
|
148
|
+
}));
|
|
149
|
+
// Images by address: one asset type whose key is the address, read with the page's own request and decoded as PNG.
|
|
150
|
+
const imageType = createAssetType('egret.browser-game.image', isTexture);
|
|
151
|
+
const images = createBrowserTextureProvider({
|
|
152
|
+
async readBytes(ref, context) {
|
|
153
|
+
const stop = new AbortController(), abort = () => stop.abort();
|
|
154
|
+
if (context.signal.aborted)
|
|
155
|
+
abort();
|
|
156
|
+
else
|
|
157
|
+
context.signal.addEventListener('abort', abort, { once: true });
|
|
158
|
+
try {
|
|
159
|
+
const response = await globalThis.fetch(ref.id, { signal: stop.signal });
|
|
160
|
+
if (!response.ok)
|
|
161
|
+
throw new EgretError('BROWSER_GAME_IMAGE_FAILED', { cause: new Error(response.status + ' ' + ref.id) });
|
|
162
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
163
|
+
}
|
|
164
|
+
finally {
|
|
165
|
+
context.signal.removeEventListener('abort', abort);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
engine.assets.register(imageType, images);
|
|
170
|
+
// Textures painted in code: each call puts its texture under a key of its own, and its lease ends it.
|
|
171
|
+
const paintedType = createAssetType('egret.browser-game.painted', isTexture), painted = new Map();
|
|
172
|
+
let paintedCount = 0;
|
|
173
|
+
engine.assets.register(paintedType, {
|
|
174
|
+
async load(ref) {
|
|
175
|
+
const texture = painted.get(ref.id);
|
|
176
|
+
painted.delete(ref.id);
|
|
177
|
+
if (texture === undefined)
|
|
178
|
+
throw invalid();
|
|
179
|
+
return texture;
|
|
180
|
+
},
|
|
181
|
+
dispose(texture) {
|
|
182
|
+
texture.dispose();
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
const leasePixels = async (width, height, pixels) => {
|
|
186
|
+
if (!whole(width) ||
|
|
187
|
+
!whole(height) ||
|
|
188
|
+
!(pixels instanceof Uint8Array || pixels instanceof Uint8ClampedArray) ||
|
|
189
|
+
pixels.length !== width * height * 4)
|
|
190
|
+
throw invalid();
|
|
191
|
+
let texture;
|
|
192
|
+
try {
|
|
193
|
+
texture = createTexture(createImageData2D({ width, height, pixels: new Uint8Array(pixels) }));
|
|
194
|
+
}
|
|
195
|
+
catch (cause) {
|
|
196
|
+
// Larger than the 2D image limits: 4,096 pixels on an edge, 4,194,304 in all.
|
|
197
|
+
throw new EgretError('BROWSER_GAME_OPTIONS_INVALID', { cause });
|
|
198
|
+
}
|
|
199
|
+
const key = 'painted-' + ++paintedCount;
|
|
200
|
+
painted.set(key, texture);
|
|
201
|
+
try {
|
|
202
|
+
return scope.use(await engine.assets.acquire(createAssetRef(paintedType, key), { signal: scope.signal }));
|
|
203
|
+
}
|
|
204
|
+
finally {
|
|
205
|
+
// Not loaded (the scope ended first): the texture is ended here.
|
|
206
|
+
if (painted.delete(key))
|
|
207
|
+
texture.dispose();
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
// The canvas in its element: sized now and whenever the element changes size. The stage keeps its own units.
|
|
211
|
+
const fit = options.fit ?? 'none', holder = options.fitTo ?? canvas.parentElement;
|
|
212
|
+
let watcher;
|
|
213
|
+
if (fit !== 'none' && holder !== null) {
|
|
214
|
+
const place = () => {
|
|
215
|
+
const box = holder.getBoundingClientRect(), wide = box.width / width, tall = box.height / height;
|
|
216
|
+
const scaleX = fit === 'stretch' ? wide : fit === 'contain' ? Math.min(wide, tall) : Math.max(wide, tall), scaleY = fit === 'stretch' ? tall : scaleX;
|
|
217
|
+
const style = canvas.style;
|
|
218
|
+
style.width = width * scaleX + 'px';
|
|
219
|
+
style.height = height * scaleY + 'px';
|
|
220
|
+
// Centred in its element; with "cover" what does not fit is outside it, for the element to cut off.
|
|
221
|
+
style.marginLeft = (box.width - width * scaleX) / 2 + 'px';
|
|
222
|
+
style.marginTop = (box.height - height * scaleY) / 2 + 'px';
|
|
223
|
+
};
|
|
224
|
+
place();
|
|
225
|
+
watcher = new ResizeObserver(place);
|
|
226
|
+
watcher.observe(holder);
|
|
227
|
+
}
|
|
228
|
+
// Text: one cache for the Engine, made with the page's rasterizer when the first label is asked for.
|
|
229
|
+
let textCache;
|
|
230
|
+
// The text cache takes four drawings at a time and refuses more. Labels wait their turn here instead, two at a
|
|
231
|
+
// time, so a game may make or change any number of them together.
|
|
232
|
+
const LABEL_LANES = 2;
|
|
233
|
+
let labelsDrawing = 0;
|
|
234
|
+
const labelsWaiting = [];
|
|
235
|
+
const enterLabelLane = () => {
|
|
236
|
+
if (labelsDrawing < LABEL_LANES) {
|
|
237
|
+
labelsDrawing++;
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
// The lane is handed over by the label that leaves it, so no newcomer takes it first.
|
|
241
|
+
return new Promise(resolve => labelsWaiting.push(resolve));
|
|
242
|
+
};
|
|
243
|
+
const leaveLabelLane = () => {
|
|
244
|
+
const next = labelsWaiting.shift();
|
|
245
|
+
if (next)
|
|
246
|
+
next();
|
|
247
|
+
else
|
|
248
|
+
labelsDrawing--;
|
|
249
|
+
};
|
|
250
|
+
async function createLabel(options = {}) {
|
|
251
|
+
if (options === null || typeof options !== 'object')
|
|
252
|
+
throw invalid();
|
|
253
|
+
const { scope: owner = scope, ...given } = options;
|
|
254
|
+
if (owner === null || typeof owner !== 'object')
|
|
255
|
+
throw invalid();
|
|
256
|
+
textCache ??= import('./text.js').then(text => createTextRasterCache(engine.assets, { provider: text.createCanvasTextRasterProvider() }));
|
|
257
|
+
const field = createTextField(engine, owner, await textCache);
|
|
258
|
+
let now = {
|
|
259
|
+
text: '',
|
|
260
|
+
fontFamily: 'sans-serif',
|
|
261
|
+
fontSize: 24,
|
|
262
|
+
fontWeight: 400,
|
|
263
|
+
italic: false,
|
|
264
|
+
lineHeight: 0,
|
|
265
|
+
color: 0xffffff,
|
|
266
|
+
locale: 'en',
|
|
267
|
+
direction: 'ltr'
|
|
268
|
+
};
|
|
269
|
+
let ready = Promise.resolve(), asked = 0, drawing = false, running;
|
|
270
|
+
const request = () => field.setRequest({
|
|
271
|
+
text: now.text,
|
|
272
|
+
fontFamily: now.fontFamily,
|
|
273
|
+
fontSize: now.fontSize,
|
|
274
|
+
fontWeight: now.fontWeight,
|
|
275
|
+
fontStyle: now.italic ? 'italic' : 'normal',
|
|
276
|
+
lineHeight: now.lineHeight > 0 ? now.lineHeight : now.fontSize * 1.25,
|
|
277
|
+
locale: now.locale,
|
|
278
|
+
direction: now.direction,
|
|
279
|
+
density: pixelRatio,
|
|
280
|
+
fillColor: now.color
|
|
281
|
+
});
|
|
282
|
+
// Draws the label's newest words. Words changed while it draws are asked for when that drawing is done, never
|
|
283
|
+
// over it, so a label holds one drawing of the text cache at a time however often its words change.
|
|
284
|
+
const draw = async () => {
|
|
285
|
+
try {
|
|
286
|
+
await enterLabelLane();
|
|
287
|
+
try {
|
|
288
|
+
for (let shown = -1; shown !== asked;) {
|
|
289
|
+
if (shown !== -1)
|
|
290
|
+
request();
|
|
291
|
+
shown = asked;
|
|
292
|
+
drawing = true;
|
|
293
|
+
try {
|
|
294
|
+
// The cache frees a drawing's place a few turns after the drawing is handed over. A refusal for
|
|
295
|
+
// want of a place is waited out, without a timer; one that lasts is the label's failure.
|
|
296
|
+
for (let attempt = 0;; attempt++) {
|
|
297
|
+
try {
|
|
298
|
+
await field.prepare();
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
catch (cause) {
|
|
302
|
+
if (!(cause instanceof EgretError) || cause.code !== 'TEXT_CACHE_BUDGET' || attempt >= 400)
|
|
303
|
+
throw cause;
|
|
304
|
+
await Promise.resolve();
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
finally {
|
|
309
|
+
drawing = false;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
finally {
|
|
314
|
+
leaveLabelLane();
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
finally {
|
|
318
|
+
running = undefined;
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
const apply = (next) => {
|
|
322
|
+
if (next === null || typeof next !== 'object')
|
|
323
|
+
throw invalid();
|
|
324
|
+
now = { ...now, ...next };
|
|
325
|
+
// Refused at once when nothing is being drawn; otherwise when its turn comes, through `ready`.
|
|
326
|
+
if (!drawing)
|
|
327
|
+
request();
|
|
328
|
+
asked++;
|
|
329
|
+
running ??= draw();
|
|
330
|
+
// A failure is the label's to tell through `ready`; it is not left unheard.
|
|
331
|
+
running.catch(() => { });
|
|
332
|
+
ready = running;
|
|
333
|
+
};
|
|
334
|
+
apply(given);
|
|
335
|
+
return Object.freeze({
|
|
336
|
+
display: field,
|
|
337
|
+
get text() {
|
|
338
|
+
return now.text;
|
|
339
|
+
},
|
|
340
|
+
set text(value) {
|
|
341
|
+
if (value !== now.text)
|
|
342
|
+
apply({ text: value });
|
|
343
|
+
},
|
|
344
|
+
get ready() {
|
|
345
|
+
return ready;
|
|
346
|
+
},
|
|
347
|
+
set: apply,
|
|
348
|
+
dispose() {
|
|
349
|
+
field.dispose();
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
const game = Object.freeze({
|
|
354
|
+
backend,
|
|
355
|
+
engine,
|
|
356
|
+
host,
|
|
357
|
+
stage: engine.stage,
|
|
358
|
+
scope,
|
|
359
|
+
frame,
|
|
360
|
+
loop: made,
|
|
361
|
+
pointer,
|
|
362
|
+
keyboard,
|
|
363
|
+
hover,
|
|
364
|
+
stats: panel,
|
|
365
|
+
createLabel,
|
|
366
|
+
async loadTexture(url) {
|
|
367
|
+
if (typeof url !== 'string' || url === '')
|
|
368
|
+
throw invalid();
|
|
369
|
+
return scope.use(await engine.assets.acquire(createAssetRef(imageType, url), { signal: scope.signal }));
|
|
370
|
+
},
|
|
371
|
+
textureFromPixels: leasePixels,
|
|
372
|
+
async textureFromCanvas(source) {
|
|
373
|
+
if (source === null || typeof source !== 'object' || typeof source.getContext !== 'function')
|
|
374
|
+
throw invalid();
|
|
375
|
+
const { width, height } = source;
|
|
376
|
+
if (!whole(width) || !whole(height))
|
|
377
|
+
throw invalid();
|
|
378
|
+
let context = source.getContext('2d');
|
|
379
|
+
if (context === null) {
|
|
380
|
+
// A canvas of another kind of context: drawn onto a 2D canvas of its size, and read there.
|
|
381
|
+
const copy = typeof OffscreenCanvas === 'function'
|
|
382
|
+
? new OffscreenCanvas(width, height)
|
|
383
|
+
: Object.assign(document.createElement('canvas'), { width, height });
|
|
384
|
+
context = copy.getContext('2d');
|
|
385
|
+
if (context === null)
|
|
386
|
+
throw invalid();
|
|
387
|
+
context.drawImage(source, 0, 0);
|
|
388
|
+
}
|
|
389
|
+
return leasePixels(width, height, context.getImageData(0, 0, width, height).data);
|
|
390
|
+
},
|
|
391
|
+
padHitArea(node, cssPixels = 44) {
|
|
392
|
+
if (node === null ||
|
|
393
|
+
typeof node !== 'object' ||
|
|
394
|
+
typeof node.getBounds !== 'function' ||
|
|
395
|
+
!(typeof cssPixels === 'number' && cssPixels >= 0 && Number.isFinite(cssPixels)))
|
|
396
|
+
throw invalid();
|
|
397
|
+
const drawn = node.getBounds(), box = canvas.getBoundingClientRect();
|
|
398
|
+
const laidOut = box.width > 0 && box.height > 0;
|
|
399
|
+
const halfX = (cssPixels / 2) * (laidOut ? width / box.width : 1);
|
|
400
|
+
const halfY = (cssPixels / 2) * (laidOut ? height / box.height : 1);
|
|
401
|
+
let wide = drawn.width, tall = drawn.height;
|
|
402
|
+
if (cssPixels > 0) {
|
|
403
|
+
const cx = drawn.x + drawn.width / 2, cy = drawn.y + drawn.height / 2;
|
|
404
|
+
const center = node.localToGlobal(cx, cy);
|
|
405
|
+
try {
|
|
406
|
+
// Opposite corners are symmetric. Two adjacent corners give the local extents of the entire CSS square.
|
|
407
|
+
const top = node.globalToLocal(center.x + halfX, center.y - halfY);
|
|
408
|
+
const bottom = node.globalToLocal(center.x + halfX, center.y + halfY);
|
|
409
|
+
wide = Math.max(wide, 2 * Math.abs(top.x - cx), 2 * Math.abs(bottom.x - cx));
|
|
410
|
+
tall = Math.max(tall, 2 * Math.abs(top.y - cy), 2 * Math.abs(bottom.y - cy));
|
|
411
|
+
}
|
|
412
|
+
catch (cause) {
|
|
413
|
+
if (!(cause instanceof EgretError) || cause.code !== 'COORDINATE_TRANSFORM_SINGULAR')
|
|
414
|
+
throw cause;
|
|
415
|
+
// A collapsed node cannot receive a two-dimensional hit. Keep a finite area until it is laid out again.
|
|
416
|
+
const perCss = laidOut ? Math.max(width / box.width, height / box.height) : 1;
|
|
417
|
+
wide = Math.max(wide, (cssPixels * perCss) / (Math.abs(node.scaleX) || 1));
|
|
418
|
+
tall = Math.max(tall, (cssPixels * perCss) / (Math.abs(node.scaleY) || 1));
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
const area = Object.freeze({
|
|
422
|
+
x: drawn.x - (wide - drawn.width) / 2,
|
|
423
|
+
y: drawn.y - (tall - drawn.height) / 2,
|
|
424
|
+
width: wide,
|
|
425
|
+
height: tall
|
|
426
|
+
});
|
|
427
|
+
node.hitArea = area;
|
|
428
|
+
return area;
|
|
429
|
+
},
|
|
430
|
+
get unitsPerCssPixel() {
|
|
431
|
+
const box = canvas.getBoundingClientRect();
|
|
432
|
+
// Before the page lays the canvas out, one unit is one pixel.
|
|
433
|
+
return box.width > 0 && box.height > 0 ? Math.max(width / box.width, height / box.height) : 1;
|
|
434
|
+
},
|
|
435
|
+
toStage(clientX, clientY) {
|
|
436
|
+
const box = canvas.getBoundingClientRect();
|
|
437
|
+
return { x: ((clientX - box.left) * width) / box.width, y: ((clientY - box.top) * height) / box.height };
|
|
438
|
+
},
|
|
439
|
+
dispose() {
|
|
440
|
+
// The scope ends the input it was given; the Engine ends its scopes and its Host.
|
|
441
|
+
return (disposal ??= (async () => {
|
|
442
|
+
made.dispose();
|
|
443
|
+
panel?.dispose();
|
|
444
|
+
watcher?.disconnect();
|
|
445
|
+
// The scope ends the labels; then the cache they were drawn from can end, before the Engine does.
|
|
446
|
+
scope.dispose();
|
|
447
|
+
if (textCache !== undefined) {
|
|
448
|
+
const cache = await textCache.catch(() => undefined);
|
|
449
|
+
cache?.dispose();
|
|
450
|
+
await cache?.whenIdle();
|
|
451
|
+
}
|
|
452
|
+
await engine.dispose();
|
|
453
|
+
await images.close();
|
|
454
|
+
})());
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
if (options.autoStart !== false)
|
|
458
|
+
made.start();
|
|
459
|
+
return game;
|
|
460
|
+
}
|
|
461
|
+
catch (cause) {
|
|
462
|
+
loop?.dispose();
|
|
463
|
+
stats?.dispose();
|
|
464
|
+
try {
|
|
465
|
+
await engine.dispose();
|
|
466
|
+
}
|
|
467
|
+
catch {
|
|
468
|
+
/* The first failure is the one to tell. */
|
|
469
|
+
}
|
|
470
|
+
throw cause;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
//# sourceMappingURL=BrowserGame.js.map
|