@egret/engine 7.0.1-rc.3 → 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/dist/Engine.js +7 -2
- package/dist/animation/sequenceResetTypes.d.ts +6 -0
- package/dist/animation/types.d.ts +6 -0
- package/dist/assetBundle.d.ts +2 -0
- package/dist/assetGroupTypes.d.ts +2 -0
- package/dist/audioCues.d.ts +4 -0
- package/dist/audioTypes.d.ts +13 -0
- package/dist/bitmapButtonTypes.d.ts +2 -0
- package/dist/bitmapFontTypes.d.ts +3 -0
- package/dist/bitmapResourceSlot.d.ts +1 -0
- package/dist/camera2d.js +10 -2
- package/dist/cameraTypes.d.ts +12 -0
- package/dist/contentTypes.d.ts +2 -0
- package/dist/createEngineForProfile.js +8 -5
- package/dist/fontContentTypes.d.ts +5 -0
- package/dist/gameClockTypes.d.ts +6 -0
- package/dist/gameRun.d.ts +3 -0
- package/dist/gamepadTypes.d.ts +8 -0
- package/dist/hoverInputTypes.d.ts +10 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +2 -1
- package/dist/inputActions.d.ts +5 -0
- package/dist/internal/uiFactoryState.d.ts +4 -0
- package/dist/internal/uiFactoryState.js +18 -2
- package/dist/keyboardInput.d.ts +1 -0
- package/dist/keyboardInput.js +1 -0
- package/dist/keyboardInputTypes.d.ts +12 -0
- package/dist/kit.d.ts +3 -1
- package/dist/kit.js +2 -1
- package/dist/manifestResourceState.d.ts +1 -0
- package/dist/manifestResourceState.js +1 -0
- package/dist/manifestResourceTypes.d.ts +1 -0
- package/dist/motion.d.ts +2 -0
- package/dist/mouseInputTypes.d.ts +4 -0
- package/dist/particleEmitter.js +8 -0
- package/dist/particleTypes.d.ts +8 -0
- package/dist/physics2d.d.ts +2 -2
- package/dist/physics2d.js +1 -1
- package/dist/physics2dTypes.d.ts +55 -1
- package/dist/physics2dWorld.js +209 -9
- package/dist/pointerInput.d.ts +1 -0
- package/dist/pointerInput.js +1 -0
- package/dist/pointerInputTypes.d.ts +3 -0
- package/dist/random.d.ts +1 -0
- package/dist/rendering/packSharedDraws2D.js +53 -5
- package/dist/rendering/prepareSharedDraws2D.d.ts +2 -0
- package/dist/rendering/prepareSharedDraws2D.js +17 -6
- package/dist/rendering/sharedColor2D.d.ts +35 -1
- package/dist/rendering/sharedColor2D.js +131 -8
- package/dist/rendering/sharedEffects2D.js +16 -8
- package/dist/rendering/world3d/Animation3D.d.ts +9 -0
- package/dist/rendering/world3d/Animation3D.js +4 -0
- package/dist/rendering/world3d/AnimationTexture3D.d.ts +6 -0
- package/dist/rendering/world3d/AnimationTexture3D.js +2 -0
- package/dist/rendering/world3d/Batch3D.d.ts +4 -0
- package/dist/rendering/world3d/Batch3D.js +3 -0
- package/dist/rendering/world3d/Camera3D.d.ts +5 -0
- package/dist/rendering/world3d/Camera3D.js +3 -0
- package/dist/rendering/world3d/Character3D.d.ts +4 -0
- package/dist/rendering/world3d/Character3D.js +2 -0
- package/dist/rendering/world3d/Cloth3D.d.ts +18 -3
- package/dist/rendering/world3d/Cloth3D.js +6 -1
- package/dist/rendering/world3d/Compression3D.d.ts +1 -0
- package/dist/rendering/world3d/Compression3D.js +1 -0
- package/dist/rendering/world3d/Curves3D.d.ts +8 -0
- package/dist/rendering/world3d/Curves3D.js +5 -0
- package/dist/rendering/world3d/Decal3D.d.ts +2 -0
- package/dist/rendering/world3d/Decal3D.js +1 -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 +11 -1
- package/dist/rendering/world3d/Geometry3D.js +10 -1
- package/dist/rendering/world3d/GeometryBuilder3D.d.ts +2 -0
- package/dist/rendering/world3d/Gizmo3D.d.ts +5 -0
- package/dist/rendering/world3d/Gizmo3D.js +2 -0
- package/dist/rendering/world3d/Gltf3D.d.ts +6 -0
- package/dist/rendering/world3d/Gltf3D.js +25 -5
- package/dist/rendering/world3d/GpuParticles3D.d.ts +2 -0
- package/dist/rendering/world3d/GpuParticles3D.js +1 -0
- package/dist/rendering/world3d/Hdr3D.d.ts +2 -0
- package/dist/rendering/world3d/Hdr3D.js +1 -0
- package/dist/rendering/world3d/Jelly3D.d.ts +2 -0
- package/dist/rendering/world3d/Jelly3D.js +1 -0
- package/dist/rendering/world3d/Ktx23D.d.ts +3 -0
- package/dist/rendering/world3d/Light3D.d.ts +9 -0
- package/dist/rendering/world3d/Light3D.js +4 -0
- package/dist/rendering/world3d/Material3D.d.ts +10 -0
- package/dist/rendering/world3d/Material3D.js +2 -0
- package/dist/rendering/world3d/Mesh3D.d.ts +4 -0
- package/dist/rendering/world3d/Mesh3D.js +16 -2
- package/dist/rendering/world3d/Meshopt3D.d.ts +3 -0
- package/dist/rendering/world3d/Meshopt3D.js +1 -0
- package/dist/rendering/world3d/Navigation3D.d.ts +41 -1
- package/dist/rendering/world3d/Navigation3D.js +74 -2
- package/dist/rendering/world3d/Object3D.d.ts +11 -0
- package/dist/rendering/world3d/Object3D.js +10 -0
- package/dist/rendering/world3d/Particles3D.d.ts +5 -0
- package/dist/rendering/world3d/Particles3D.js +3 -0
- package/dist/rendering/world3d/Physics3D.d.ts +14 -0
- package/dist/rendering/world3d/Physics3D.js +5 -0
- package/dist/rendering/world3d/PhysicsHull3D.d.ts +2 -0
- package/dist/rendering/world3d/PhysicsHull3D.js +2 -0
- package/dist/rendering/world3d/PhysicsMesh3D.d.ts +2 -0
- package/dist/rendering/world3d/PhysicsMesh3D.js +2 -0
- package/dist/rendering/world3d/PhysicsRemote3D.d.ts +5 -0
- package/dist/rendering/world3d/PhysicsRemote3D.js +2 -0
- package/dist/rendering/world3d/Ragdoll3D.d.ts +5 -0
- package/dist/rendering/world3d/Ragdoll3D.js +2 -0
- package/dist/rendering/world3d/Raycast3D.d.ts +3 -0
- package/dist/rendering/world3d/Raycast3D.js +1 -0
- package/dist/rendering/world3d/RenderList3D.d.ts +3 -0
- package/dist/rendering/world3d/RenderList3D.js +12 -0
- package/dist/rendering/world3d/Retarget3D.d.ts +1 -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 +17 -0
- package/dist/rendering/world3d/Serialize3D.js +22 -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 +9 -0
- package/dist/rendering/world3d/StateMachine3D.js +3 -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 +21 -0
- package/dist/rendering/world3d/Terrain3D.js +25 -1
- package/dist/rendering/world3d/Text3D.d.ts +5 -0
- package/dist/rendering/world3d/Text3D.js +2 -0
- package/dist/rendering/world3d/Texture3D.d.ts +16 -1
- package/dist/rendering/world3d/Texture3D.js +19 -1
- package/dist/rendering/world3d/Trail3D.d.ts +3 -0
- package/dist/rendering/world3d/Trail3D.js +2 -0
- package/dist/rendering/world3d/Vehicle3D.d.ts +5 -0
- package/dist/rendering/world3d/Vehicle3D.js +2 -0
- package/dist/rendering/world3d/VolumetricFog3D.d.ts +2 -0
- package/dist/rendering/world3d/VolumetricFog3D.js +1 -0
- package/dist/rendering/world3d/Water3D.d.ts +2 -0
- package/dist/rendering/world3d/Water3D.js +1 -0
- package/dist/rendering/world3d/core3D.d.ts +2 -0
- package/dist/rendering/world3d/debug3D.d.ts +5 -0
- package/dist/rendering/world3d/debug3D.js +5 -0
- package/dist/rendering/world3d/geometries3D.d.ts +12 -0
- package/dist/rendering/world3d/geometries3D.js +5 -0
- package/dist/rendering/world3d/helpers3D.d.ts +2 -0
- package/dist/rendering/world3d/helpers3D.js +1 -0
- package/dist/rendering/world3d/index.d.ts +12 -0
- package/dist/rendering/world3d/index.js +6 -0
- package/dist/rendering/world3d/math3D.d.ts +36 -0
- package/dist/rendering/world3d/math3D.js +35 -0
- package/dist/rendering/world3d/primitives3D.d.ts +7 -0
- package/dist/rendering/world3d/primitives3D.js +1 -0
- package/dist/saveStore.d.ts +18 -3
- package/dist/saveStore.js +23 -4
- package/dist/semanticList.d.ts +4 -0
- package/dist/semanticList.js +1 -0
- package/dist/semanticTree.js +11 -4
- package/dist/semanticTypes.d.ts +8 -0
- package/dist/sequencePlaybackTypes.d.ts +3 -0
- package/dist/text.d.ts +1 -0
- package/dist/textTable.d.ts +41 -0
- package/dist/textTable.js +114 -0
- package/dist/tilemapTypes.d.ts +13 -0
- package/dist/timer.d.ts +34 -0
- package/dist/timer.js +119 -0
- package/dist/tweenTypes.d.ts +4 -0
- package/dist/ui/controlKeys.d.ts +4 -0
- package/dist/ui/controlKeys.js +1 -0
- package/dist/ui/controls.d.ts +6 -0
- package/dist/ui/controls.js +2 -0
- package/dist/ui/layerTypes.d.ts +7 -0
- package/dist/ui/rangeControl.d.ts +3 -0
- package/dist/ui/rangeControl.js +1 -0
- package/dist/ui/scrollControl.d.ts +12 -0
- package/dist/ui/scrollControl.js +5 -1
- package/dist/ui/stateControls.d.ts +8 -0
- package/dist/ui/stateControls.js +3 -0
- package/dist/ui/textEditor.d.ts +1 -0
- package/dist/ui/textEditor.js +1 -0
- package/dist/ui/textEditorTypes.d.ts +7 -0
- package/dist/ui/textFieldControl.d.ts +4 -0
- package/dist/ui/textFieldControl.js +1 -0
- package/dist/ui/theme.d.ts +5 -0
- package/dist/ui/theme.js +1 -0
- package/dist/ui/types.d.ts +20 -0
- package/dist/ui/uiRoot.js +38 -9
- package/dist/ui/uiRootModel.d.ts +3 -1
- package/dist/ui/uiRootModel.js +8 -2
- package/dist/videoTypes.d.ts +3 -0
- package/dist/web/BrowserAssetBundle.d.ts +2 -0
- package/dist/web/BrowserAudio.d.ts +34 -1
- package/dist/web/BrowserAudio.js +69 -39
- package/dist/web/BrowserFrameLoop.d.ts +4 -0
- package/dist/web/BrowserGame.d.ts +64 -2
- package/dist/web/BrowserGame.js +129 -8
- package/dist/web/BrowserGamepadInput.d.ts +3 -0
- package/dist/web/BrowserHoverInput.d.ts +1 -0
- package/dist/web/BrowserImageTextures.d.ts +6 -0
- package/dist/web/BrowserInputActions.d.ts +10 -0
- package/dist/web/BrowserInputActions.js +4 -1
- package/dist/web/BrowserPlay.d.ts +130 -2
- package/dist/web/BrowserPlay.js +366 -19
- package/dist/web/BrowserPreferences.d.ts +10 -0
- package/dist/web/BrowserPreferences.js +39 -0
- package/dist/web/BrowserSemantics.d.ts +2 -0
- package/dist/web/BrowserStatsPanel.d.ts +10 -0
- package/dist/web/BrowserStatsPanel.js +9 -3
- package/dist/web/BrowserStorage.d.ts +2 -0
- package/dist/web/BrowserTextEditor.d.ts +3 -0
- package/dist/web/BrowserTextInput.d.ts +6 -0
- package/dist/web/BrowserTextureProvider.d.ts +6 -0
- package/dist/web/BrowserVideo.d.ts +13 -1
- package/dist/web/BrowserVideo.js +28 -2
- package/dist/web/CanvasKitFontSetProvider.d.ts +3 -0
- package/dist/web/CanvasKitParagraphProvider.d.ts +4 -0
- package/dist/web/CanvasKitParagraphProvider.js +1 -0
- package/dist/web/ManifestByteSource.d.ts +4 -0
- package/dist/web/ManifestByteSource.js +1 -0
- package/dist/web/ManifestFontContentLoader.d.ts +1 -0
- package/dist/web/WebGL2Host.js +64 -25
- package/dist/web/WebGPUHost.d.ts +13 -0
- package/dist/web/WebGPUHost.js +117 -36
- package/dist/web/audio.d.ts +2 -2
- package/dist/web/audio.js +1 -1
- package/dist/web/editorFonts.d.ts +4 -0
- package/dist/web/game.d.ts +1 -1
- package/dist/web/imageProjections2D.d.ts +2 -0
- package/dist/web/kit.d.ts +1 -0
- package/dist/web/kit.js +1 -0
- package/dist/web/play.d.ts +6 -1
- package/dist/web/play.js +4 -1
- package/dist/web/playMusic.d.ts +33 -0
- package/dist/web/playMusic.js +194 -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/prepareSharedSubmission2D.js +9 -3
- package/dist/web/resources.d.ts +2 -0
- package/dist/web/sharedEffectShaders.d.ts +6 -2
- package/dist/web/sharedEffectShaders.js +23 -7
- package/dist/web/sharedSubmissionStorage2D.js +1 -1
- package/dist/web/sharedWebGL2Options.d.ts +3 -0
- package/dist/web/sharedWebGL2Options.js +8 -2
- package/dist/web/sharedWebGL2Shaders.d.ts +15 -2
- package/dist/web/sharedWebGL2Shaders.js +108 -14
- package/dist/web/sharedWebGPUOptions.d.ts +5 -1
- package/dist/web/sharedWebGPUOptions.js +6 -2
- package/dist/web/video.d.ts +1 -1
- package/dist/web/webgl2Native.d.ts +3 -1
- package/dist/web/webgl2Native.js +9 -5
- package/dist/web/webgl2Types.d.ts +18 -0
- package/dist/web/webgpuImageResidency.d.ts +5 -2
- package/dist/web/webgpuImageResidency.js +7 -3
- package/dist/web/webgpuRetentionPool.d.ts +2 -2
- package/dist/web/webgpuRetentionPool.js +2 -1
- package/dist/web/webgpuSharedPass.d.ts +1 -1
- package/dist/web/webgpuSharedPass.js +87 -5
- package/dist/web/webgpuSharedResolvePass.d.ts +1 -1
- package/dist/web/webgpuSharedResolvePass.js +9 -4
- package/dist/web/world3d/Audio3D.d.ts +18 -1
- package/dist/web/world3d/Audio3D.js +62 -3
- package/dist/web/world3d/BrowserPlay3D.d.ts +115 -2
- package/dist/web/world3d/BrowserPlay3D.js +448 -43
- package/dist/web/world3d/FlyControls3D.d.ts +4 -0
- package/dist/web/world3d/FlyControls3D.js +2 -0
- package/dist/web/world3d/FollowControls3D.d.ts +3 -0
- package/dist/web/world3d/FollowControls3D.js +2 -0
- package/dist/web/world3d/OrbitControls3D.d.ts +3 -0
- package/dist/web/world3d/OrbitControls3D.js +2 -0
- package/dist/web/world3d/TransformControls3D.d.ts +5 -2
- package/dist/web/world3d/TransformControls3D.js +7 -4
- package/dist/web/world3d/WebGL2Renderer3D.d.ts +3 -0
- package/dist/web/world3d/WebGL2Renderer3D.js +2 -0
- package/dist/web/world3d/WebGPURenderer3D.d.ts +2 -0
- package/dist/web/world3d/WebGPURenderer3D.js +1 -0
- package/dist/web/world3d/World3DView.d.ts +3 -0
- package/dist/web/world3d/World3DView.js +2 -0
- package/dist/web/world3d/app3D.d.ts +7 -0
- package/dist/web/world3d/app3D.js +1 -0
- package/dist/web/world3d/assets3D.d.ts +1 -0
- package/dist/web/world3d/atmosphere3D.d.ts +9 -0
- package/dist/web/world3d/atmosphere3D.js +19 -4
- package/dist/web/world3d/canvasFont3D.d.ts +21 -0
- package/dist/web/world3d/canvasFont3D.js +165 -0
- package/dist/web/world3d/frame3D.d.ts +2 -0
- package/dist/web/world3d/host3D.d.ts +1 -0
- package/dist/web/world3d/index.d.ts +4 -2
- package/dist/web/world3d/index.js +2 -1
- package/dist/web/world3d/loaders3D.d.ts +1 -0
- package/dist/web/world3d/markers3D.d.ts +4 -0
- package/dist/web/world3d/overlay3D.d.ts +19 -0
- package/dist/web/world3d/overlay3D.js +21 -4
- package/dist/web/world3d/post3D.d.ts +4 -0
- package/dist/web/world3d/post3D.js +3 -0
- package/dist/web/world3d/probe3D.d.ts +1 -0
- package/dist/web/world3d/stats3D.d.ts +3 -0
- package/dist/web/world3d/stats3D.js +1 -0
- package/dist/web/world3d/webGL2FrameMetrics3D.d.ts +5 -0
- package/dist/web/world3d/webgpu.d.ts +2 -0
- package/dist/web/world3d/webgpu.js +1 -0
- package/package.json +3 -3
package/dist/web/BrowserGame.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
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
3
|
// a frame loop, each made the way its own entry makes it, and all of them ended by one dispose.
|
|
4
4
|
import { EgretError } from '@egret/runtime';
|
|
5
|
-
import { createAssetRef, createAssetType, createEngineForProfile, isTexture, SHARED_FRAME_PROFILE_2D } from '@egret/engine';
|
|
5
|
+
import { createAssetRef, createAssetType, createEngineForProfile, createImageData2D, createTexture, isTexture, SHARED_FRAME_PROFILE_2D } from '@egret/engine';
|
|
6
6
|
import { createBrowserTextureProvider } from './image.js';
|
|
7
7
|
import { createTextField, createTextRasterCache } from '@egret/engine/text';
|
|
8
8
|
import { createBrowserFrameLoop } from './loop.js';
|
|
@@ -55,7 +55,7 @@ export async function createBrowserGame(options) {
|
|
|
55
55
|
if (options === null || typeof options !== 'object')
|
|
56
56
|
throw invalid();
|
|
57
57
|
const { canvas, width, height, update, onError } = options;
|
|
58
|
-
const asked = options.backend ?? 'auto', clearColor = options.clearColor ?? 0, clearAlpha = options.clearAlpha ?? 1;
|
|
58
|
+
const asked = options.backend ?? 'auto', clearColor = options.clearColor ?? 0, clearAlpha = options.clearAlpha ?? 1, blendSpace = options.blendSpace ?? 'linear', enableEffects = options.effects ?? false;
|
|
59
59
|
const device = Number(globalThis.devicePixelRatio), pixelRatio = options.pixelRatio ?? (device > 0 ? Math.min(device, 2) : 1);
|
|
60
60
|
if (canvas === null ||
|
|
61
61
|
typeof canvas !== 'object' ||
|
|
@@ -71,17 +71,19 @@ export async function createBrowserGame(options) {
|
|
|
71
71
|
clearColor > 0xffffff ||
|
|
72
72
|
typeof clearAlpha !== 'number' ||
|
|
73
73
|
!(clearAlpha >= 0 && clearAlpha <= 1) ||
|
|
74
|
+
(blendSpace !== 'linear' && blendSpace !== 'srgb') ||
|
|
75
|
+
typeof enableEffects !== 'boolean' ||
|
|
74
76
|
(update !== undefined && typeof update !== 'function') ||
|
|
75
77
|
(onError !== undefined && typeof onError !== 'function') ||
|
|
76
|
-
[options.pointer, options.keyboard, options.autoStart, options.stats].some(flag => flag !== undefined && typeof flag !== 'boolean') ||
|
|
78
|
+
[options.pointer, options.keyboard, options.hover, options.autoStart, options.stats].some(flag => flag !== undefined && typeof flag !== 'boolean') ||
|
|
77
79
|
!['none', 'contain', 'cover', 'stretch'].includes(options.fit ?? 'none') ||
|
|
78
80
|
(options.fitTo !== undefined && (options.fitTo === null || typeof options.fitTo !== 'object')))
|
|
79
81
|
throw invalid();
|
|
80
82
|
const backend = await chooseBackend(asked);
|
|
81
83
|
// Only the chosen backend's module is loaded.
|
|
82
84
|
const host = backend === 'webgpu'
|
|
83
|
-
? (await import('./webgpu.js')).createSharedWebGPUHost({ canvas, pixelRatio })
|
|
84
|
-
: (await import('./webgl2.js')).createSharedWebGL2Host({ canvas, pixelRatio });
|
|
85
|
+
? (await import('./webgpu.js')).createSharedWebGPUHost({ canvas, pixelRatio, blendSpace, enableEffects })
|
|
86
|
+
: (await import('./webgl2.js')).createSharedWebGL2Host({ canvas, pixelRatio, blendSpace, enableEffects });
|
|
85
87
|
let engine;
|
|
86
88
|
try {
|
|
87
89
|
engine = await createEngineForProfile({ host, onDiagnostic: gameDiagnostics(onError) }, SHARED_FRAME_PROFILE_2D);
|
|
@@ -100,6 +102,16 @@ export async function createBrowserGame(options) {
|
|
|
100
102
|
const scope = engine.createScope(), frame = Object.freeze({ width, height, clearColor, clearAlpha });
|
|
101
103
|
const pointer = options.pointer === false ? undefined : createBrowserPointerInput({ engine, scope, width, height });
|
|
102
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;
|
|
103
115
|
const panel = (stats = options.stats === true ? createBrowserStatsPanel({ canvas, label: backend }) : undefined);
|
|
104
116
|
let drawn;
|
|
105
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.
|
|
@@ -126,6 +138,7 @@ export async function createBrowserGame(options) {
|
|
|
126
138
|
panel.sample({
|
|
127
139
|
...(drawn === undefined ? {} : { frame: drawn }),
|
|
128
140
|
pendingFrames: host.getStatus().pendingFrames,
|
|
141
|
+
drawCalls: host.getFrameDrawCalls(),
|
|
129
142
|
frames: now.frames,
|
|
130
143
|
skipped: now.skipped
|
|
131
144
|
});
|
|
@@ -154,6 +167,46 @@ export async function createBrowserGame(options) {
|
|
|
154
167
|
}
|
|
155
168
|
});
|
|
156
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
|
+
};
|
|
157
210
|
// The canvas in its element: sized now and whenever the element changes size. The stage keeps its own units.
|
|
158
211
|
const fit = options.fit ?? 'none', holder = options.fitTo ?? canvas.parentElement;
|
|
159
212
|
let watcher;
|
|
@@ -194,11 +247,14 @@ export async function createBrowserGame(options) {
|
|
|
194
247
|
else
|
|
195
248
|
labelsDrawing--;
|
|
196
249
|
};
|
|
197
|
-
async function createLabel(
|
|
198
|
-
if (
|
|
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')
|
|
199
255
|
throw invalid();
|
|
200
256
|
textCache ??= import('./text.js').then(text => createTextRasterCache(engine.assets, { provider: text.createCanvasTextRasterProvider() }));
|
|
201
|
-
const field = createTextField(engine,
|
|
257
|
+
const field = createTextField(engine, owner, await textCache);
|
|
202
258
|
let now = {
|
|
203
259
|
text: '',
|
|
204
260
|
fontFamily: 'sans-serif',
|
|
@@ -304,6 +360,7 @@ export async function createBrowserGame(options) {
|
|
|
304
360
|
loop: made,
|
|
305
361
|
pointer,
|
|
306
362
|
keyboard,
|
|
363
|
+
hover,
|
|
307
364
|
stats: panel,
|
|
308
365
|
createLabel,
|
|
309
366
|
async loadTexture(url) {
|
|
@@ -311,6 +368,70 @@ export async function createBrowserGame(options) {
|
|
|
311
368
|
throw invalid();
|
|
312
369
|
return scope.use(await engine.assets.acquire(createAssetRef(imageType, url), { signal: scope.signal }));
|
|
313
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
|
+
},
|
|
314
435
|
toStage(clientX, clientY) {
|
|
315
436
|
const box = canvas.getBoundingClientRect();
|
|
316
437
|
return { x: ((clientX - box.left) * width) / box.width, y: ((clientY - box.top) * height) / box.height };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { GamepadInput, GamepadInputOptions } from '@egret/engine/input/gamepad';
|
|
2
|
+
/** Browser gamepad input to make: what is called on an error. */
|
|
2
3
|
export interface BrowserGamepadInputOptions extends GamepadInputOptions {
|
|
3
4
|
/**
|
|
4
5
|
* Told what failed where nothing could be returned: in a listener of the page, or when a pad
|
|
@@ -6,6 +7,7 @@ export interface BrowserGamepadInputOptions extends GamepadInputOptions {
|
|
|
6
7
|
*/
|
|
7
8
|
readonly onError?: (cause: unknown) => void;
|
|
8
9
|
}
|
|
10
|
+
/** A rumble to play: how long, and how strong its weak and strong motors run. */
|
|
9
11
|
export interface GamepadRumble {
|
|
10
12
|
/** Milliseconds, up to 5000. Defaults to 200. */
|
|
11
13
|
readonly duration?: number;
|
|
@@ -14,6 +16,7 @@ export interface GamepadRumble {
|
|
|
14
16
|
/** The heavy, slow motor, 0 to 1. Defaults to 0.5. */
|
|
15
17
|
readonly strong?: number;
|
|
16
18
|
}
|
|
19
|
+
/** Gamepads read from the browser: poll them each frame, and make one rumble. */
|
|
17
20
|
export interface BrowserGamepadInput {
|
|
18
21
|
readonly input: GamepadInput;
|
|
19
22
|
/**
|
|
@@ -4,6 +4,7 @@ import type { HoverInput, HoverInputOptions } from '@egret/engine/input/hover';
|
|
|
4
4
|
* (the canvas owns the wheel), or always (the listener is passive and cannot hold the page).
|
|
5
5
|
*/
|
|
6
6
|
export type WheelPagePolicy = 'unconsumed' | 'never' | 'always';
|
|
7
|
+
/** Browser hover input to make: its canvas, how far a page of wheel scrolls, and what is called on an error. */
|
|
7
8
|
export interface BrowserHoverInputOptions extends HoverInputOptions {
|
|
8
9
|
/** The canvas the Engine draws on. Its CSS rectangle is mapped to the logical width and height. */
|
|
9
10
|
readonly canvas: HTMLCanvasElement;
|
|
@@ -6,12 +6,14 @@ export type BrowserImageSource = HTMLCanvasElement | OffscreenCanvas | HTMLImage
|
|
|
6
6
|
};
|
|
7
7
|
/** The picture formats the browser route recognises by their first bytes. */
|
|
8
8
|
export type BrowserImageFormat = 'png' | 'jpeg' | 'webp' | 'gif' | 'avif';
|
|
9
|
+
/** How the browser makes a canvas and decodes an image, for image textures. */
|
|
9
10
|
export interface BrowserImagePorts {
|
|
10
11
|
/** A fresh canvas of the given size with a 2D context that can be read back. */
|
|
11
12
|
readonly createCanvas: (width: number, height: number) => BrowserImageCanvas;
|
|
12
13
|
/** Decodes encoded bytes into something a 2D context can draw. */
|
|
13
14
|
readonly decode: (bytes: Uint8Array<ArrayBuffer>, type: string) => Promise<BrowserDecodedImage>;
|
|
14
15
|
}
|
|
16
|
+
/** A canvas to draw a decoded image into. */
|
|
15
17
|
export interface BrowserImageCanvas {
|
|
16
18
|
width: number;
|
|
17
19
|
height: number;
|
|
@@ -19,12 +21,14 @@ export interface BrowserImageCanvas {
|
|
|
19
21
|
willReadFrequently?: boolean;
|
|
20
22
|
}): BrowserImageContext | null;
|
|
21
23
|
}
|
|
24
|
+
/** The drawing context of such a canvas: draw an image and read its pixels. */
|
|
22
25
|
export interface BrowserImageContext {
|
|
23
26
|
drawImage(source: unknown, x: number, y: number, width: number, height: number): void;
|
|
24
27
|
getImageData(x: number, y: number, width: number, height: number): {
|
|
25
28
|
readonly data: Uint8ClampedArray;
|
|
26
29
|
};
|
|
27
30
|
}
|
|
31
|
+
/** A decoded image: its source, size, and a call that releases it. */
|
|
28
32
|
export interface BrowserDecodedImage {
|
|
29
33
|
readonly source: unknown;
|
|
30
34
|
readonly width: number;
|
|
@@ -32,6 +36,7 @@ export interface BrowserDecodedImage {
|
|
|
32
36
|
/** Frees what decoding held; called once the pixels are read. */
|
|
33
37
|
readonly release?: () => void;
|
|
34
38
|
}
|
|
39
|
+
/** How images are decoded: the largest size accepted, and the ports used. */
|
|
35
40
|
export interface BrowserImageOptions {
|
|
36
41
|
/** Largest area kept, in pixels; larger pictures are scaled down. At most the 2D image limit. */
|
|
37
42
|
readonly maxPixels?: number;
|
|
@@ -40,6 +45,7 @@ export interface BrowserImageOptions {
|
|
|
40
45
|
/** Replaces the browser operations, for tests or other hosts. */
|
|
41
46
|
readonly ports?: BrowserImagePorts;
|
|
42
47
|
}
|
|
48
|
+
/** Where an image texture provider reads the bytes of each image from. */
|
|
43
49
|
export interface BrowserImageTextureProviderOptions extends BrowserImageOptions {
|
|
44
50
|
/** Reads the encoded bytes a reference names. */
|
|
45
51
|
readonly readBytes: (ref: AssetRef<Texture>, context: AssetLoadContext) => Promise<Uint8Array<ArrayBuffer>>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { InputActions } from '@egret/engine/kit';
|
|
2
|
+
/** Where input actions read the browser: which element takes keys and pointers, whether gamepads count, and which keys pass through. */
|
|
2
3
|
export interface BrowserInputActionsOptions {
|
|
3
4
|
/** Where keys are listened for; the window by default. */
|
|
4
5
|
readonly keyTarget?: EventTarget;
|
|
@@ -10,7 +11,14 @@ export interface BrowserInputActionsOptions {
|
|
|
10
11
|
readonly preventDefault?: boolean;
|
|
11
12
|
/** Keys that are passed on even when bound, such as F5 or F12. */
|
|
12
13
|
readonly passKeys?: readonly string[];
|
|
14
|
+
/**
|
|
15
|
+
* Leave alone a key something before has already acted on, which says so by `preventDefault`. The game's keyboard input
|
|
16
|
+
* does this for a key a focused control took — Space on a focused button, the arrows on a focused slider — so with
|
|
17
|
+
* `true` that key does not also press an action. Off by default.
|
|
18
|
+
*/
|
|
19
|
+
readonly skipPrevented?: boolean;
|
|
13
20
|
}
|
|
21
|
+
/** Input actions driven by the browser's keys, pointers and gamepads: poll them each frame. */
|
|
14
22
|
export interface BrowserInputActions {
|
|
15
23
|
/** Reads the gamepads; call once a frame before the game reads its actions. */
|
|
16
24
|
poll(): void;
|
|
@@ -18,6 +26,7 @@ export interface BrowserInputActions {
|
|
|
18
26
|
}
|
|
19
27
|
/** Listens to the page for the controls of `actions`. */
|
|
20
28
|
export declare function bindBrowserInputActions(actions: InputActions, options?: BrowserInputActionsOptions): BrowserInputActions;
|
|
29
|
+
/** A touch stick to put on the page: its binding, radius, the zone it appears in and its class. */
|
|
21
30
|
export interface TouchStickOptions {
|
|
22
31
|
/** The binding the stick drives; `Touch:stick` by default. Put it in a vector action's `sticks`. */
|
|
23
32
|
readonly binding?: string;
|
|
@@ -28,6 +37,7 @@ export interface TouchStickOptions {
|
|
|
28
37
|
/** Class names of the base and the knob, which the stick creates inside the element. */
|
|
29
38
|
readonly className?: string;
|
|
30
39
|
}
|
|
40
|
+
/** Touch controls on the page: their elements; dispose of them to take them off. */
|
|
31
41
|
export interface TouchControl {
|
|
32
42
|
/** The elements the control made, to style. */
|
|
33
43
|
readonly elements: readonly HTMLElement[];
|
|
@@ -52,6 +52,9 @@ export function bindBrowserInputActions(actions, options = {}) {
|
|
|
52
52
|
throw new EgretError('INPUT_ACTIONS_INVALID');
|
|
53
53
|
const prevent = options.preventDefault ?? true;
|
|
54
54
|
const pass = new Set(options.passKeys ?? ['F5', 'F11', 'F12']);
|
|
55
|
+
const skipPrevented = options.skipPrevented ?? false;
|
|
56
|
+
if (typeof skipPrevented !== 'boolean')
|
|
57
|
+
throw new EgretError('INPUT_ACTIONS_INVALID');
|
|
55
58
|
const removers = [];
|
|
56
59
|
const listen = (target, type, handler, opts) => {
|
|
57
60
|
target.addEventListener(type, handler, opts);
|
|
@@ -64,7 +67,7 @@ export function bindBrowserInputActions(actions, options = {}) {
|
|
|
64
67
|
};
|
|
65
68
|
listen(keyTarget, 'keydown', event => {
|
|
66
69
|
const e = event;
|
|
67
|
-
if (typing(e) || !e.code)
|
|
70
|
+
if (typing(e) || !e.code || (skipPrevented && e.defaultPrevented))
|
|
68
71
|
return;
|
|
69
72
|
const binding = 'Key:' + e.code;
|
|
70
73
|
if (prevent && !pass.has(e.code) && bound(actions, binding))
|
|
@@ -3,6 +3,10 @@ import type { DisplayObject, Engine, Graphics, Motion, Scope } from '@egret/engi
|
|
|
3
3
|
import type { Random } from '@egret/engine/kit';
|
|
4
4
|
import type { BrowserGame, BrowserGameBackend } from './game.js';
|
|
5
5
|
import type { SfxRecipe } from './playSfx.js';
|
|
6
|
+
import type { PlayStickOptions, PlayTouchButtonOptions } from './playTouch.js';
|
|
7
|
+
import type { MusicOptions, MusicMood } from './playMusic.js';
|
|
8
|
+
import type { PlayBar, PlayBarOptions, PlayMenuOptions, PlaySayOptions, PlayToastOptions } from './playWidgets.js';
|
|
9
|
+
/** A whole small game to start: its size and background, where it goes on the page, its setup and update, its seed, backend and save key. */
|
|
6
10
|
export interface PlayOptions {
|
|
7
11
|
/** The size of the stage, in the game's own units: whole numbers above 0. The canvas is scaled to fit. */
|
|
8
12
|
readonly width: number;
|
|
@@ -15,6 +19,8 @@ export interface PlayOptions {
|
|
|
15
19
|
readonly parent?: HTMLElement;
|
|
16
20
|
/** A canvas of the page to draw on, as it is placed there. Without it one is made and fitted. */
|
|
17
21
|
readonly canvas?: HTMLCanvasElement;
|
|
22
|
+
/** Set false for a silent game or an application-owned mixer. Skips the built-in context and sound preparation. */
|
|
23
|
+
readonly audio?: boolean;
|
|
18
24
|
/** Builds the game. Updates begin when it has returned, or when the promise it returns has resolved. */
|
|
19
25
|
readonly setup?: (game: PlayGame) => void | Promise<void>;
|
|
20
26
|
/** One step of the game, with the seconds since the step before. */
|
|
@@ -25,9 +31,21 @@ export interface PlayOptions {
|
|
|
25
31
|
readonly seed?: number | string;
|
|
26
32
|
/** `'auto'` unless given. */
|
|
27
33
|
readonly backend?: 'auto' | BrowserGameBackend;
|
|
34
|
+
/**
|
|
35
|
+
* How translucent things mix with what is under them. `'srgb'` unless given: as a 2D canvas and Egret 5 mix
|
|
36
|
+
* them, so a white at 10% over a dark ground is a faint white. `'linear'` mixes light as it is, as the engine
|
|
37
|
+
* does by default; translucent light colours then look stronger.
|
|
38
|
+
*/
|
|
39
|
+
readonly blendSpace?: 'linear' | 'srgb';
|
|
28
40
|
/** Under what name `game.save` keeps its values in the page's storage. The page's path unless given. */
|
|
29
41
|
readonly saveKey?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Less motion for a player who asks for it: shakes are left out and flashes are faint. The system's
|
|
44
|
+
* `prefers-reduced-motion` unless given, followed as the player changes it; `game.reducedMotion` changes it later.
|
|
45
|
+
*/
|
|
46
|
+
readonly reducedMotion?: boolean;
|
|
30
47
|
}
|
|
48
|
+
/** Text to show: where, how large, its color and alignment, whether bold, its layer, baseline and locale. */
|
|
31
49
|
export interface PlayTextOptions {
|
|
32
50
|
readonly x?: number;
|
|
33
51
|
readonly y?: number;
|
|
@@ -65,6 +83,43 @@ export declare class PlayText extends Sprite {
|
|
|
65
83
|
get size(): number;
|
|
66
84
|
set size(value: number);
|
|
67
85
|
}
|
|
86
|
+
/** A map of tiles to make: the size of a tile, where its top left corner is, its colours, which characters are solid, and its layer. */
|
|
87
|
+
export interface PlayTilesOptions {
|
|
88
|
+
/** The width and height of one tile; 32 unless given. */
|
|
89
|
+
readonly size?: number;
|
|
90
|
+
readonly x?: number;
|
|
91
|
+
readonly y?: number;
|
|
92
|
+
/** The colour of each character's tiles; `#` is grey and the rest are not drawn unless given. */
|
|
93
|
+
readonly colors?: Readonly<Record<string, number>>;
|
|
94
|
+
/** The characters that are solid; `'#'` unless given. */
|
|
95
|
+
readonly solid?: string;
|
|
96
|
+
readonly layer?: Sprite;
|
|
97
|
+
}
|
|
98
|
+
/** A map of tiles: read and change its cells, and push a sprite out of its solid ones. */
|
|
99
|
+
export interface PlayTiles {
|
|
100
|
+
/** The sprite the tiles are drawn in. */
|
|
101
|
+
readonly sprite: Sprite;
|
|
102
|
+
readonly columns: number;
|
|
103
|
+
readonly rows: number;
|
|
104
|
+
readonly size: number;
|
|
105
|
+
/** The character of a cell, or `''` outside the map. */
|
|
106
|
+
at(column: number, row: number): string;
|
|
107
|
+
/** Changes the character of a cell and draws the map again. */
|
|
108
|
+
set(column: number, row: number, character: string): void;
|
|
109
|
+
/** The cell under a point of the layer the map is in: `{ column, row }`. */
|
|
110
|
+
cellAt(x: number, y: number): {
|
|
111
|
+
column: number;
|
|
112
|
+
row: number;
|
|
113
|
+
};
|
|
114
|
+
/** Whether a point of the layer the map is in is on a solid tile. */
|
|
115
|
+
solidAt(x: number, y: number): boolean;
|
|
116
|
+
/** How far to move `a` out of the solid tiles it overlaps, `{ x, y }`, or `undefined` when it overlaps none. */
|
|
117
|
+
pushOut(a: DisplayObject): {
|
|
118
|
+
x: number;
|
|
119
|
+
y: number;
|
|
120
|
+
} | undefined;
|
|
121
|
+
}
|
|
122
|
+
/** The keyboard of a play game: what is held, pressed and released, and axes from the arrow and WASD keys. */
|
|
68
123
|
export interface PlayKeys {
|
|
69
124
|
/** Whether any of the keys is held. A key is `'left'`, `'right'`, `'up'`, `'down'`, `'space'`, `'enter'`, `'escape'`, `'shift'`, a letter, a digit, or a `KeyboardEvent.code`. */
|
|
70
125
|
down(...keys: string[]): boolean;
|
|
@@ -86,6 +141,7 @@ export interface PlayKeys {
|
|
|
86
141
|
y: number;
|
|
87
142
|
};
|
|
88
143
|
}
|
|
144
|
+
/** The pointer of a play game: where it is, what it pressed, swipes, wheel and pointer lock. */
|
|
89
145
|
export interface PlayPointer {
|
|
90
146
|
/** Where the mouse, pen or finger is, on the stage. It follows the mouse whether or not a button is held. */
|
|
91
147
|
readonly x: number;
|
|
@@ -122,6 +178,16 @@ export type PlayMotion<T extends object> = Motion<T> & {
|
|
|
122
178
|
/** Resolves when the motion has finished or been stopped: `await game.tween(s).to({ x: 9 }, 0.2).done`. */
|
|
123
179
|
readonly done: Promise<void>;
|
|
124
180
|
};
|
|
181
|
+
/** An image to show: where, how large, whether smoothed, and its layer. */
|
|
182
|
+
export interface PlayImageOptions {
|
|
183
|
+
readonly x?: number;
|
|
184
|
+
readonly y?: number;
|
|
185
|
+
readonly width?: number;
|
|
186
|
+
readonly height?: number;
|
|
187
|
+
readonly smooth?: boolean;
|
|
188
|
+
readonly layer?: 'ui' | 'world' | Sprite;
|
|
189
|
+
}
|
|
190
|
+
/** A button to show: where, how large, its colors, text size and layer. */
|
|
125
191
|
export interface PlayButtonOptions {
|
|
126
192
|
readonly x: number;
|
|
127
193
|
readonly y: number;
|
|
@@ -151,6 +217,26 @@ export interface PlayLoop {
|
|
|
151
217
|
stop(seconds?: number): void;
|
|
152
218
|
readonly stopped: boolean;
|
|
153
219
|
}
|
|
220
|
+
/** The music of a play game: play or stop it, and set its intensity, volume and mood. */
|
|
221
|
+
export interface PlayMusic {
|
|
222
|
+
/**
|
|
223
|
+
* Writes a piece in a mood (`'calm'`, `'mystery'`, `'tense'`, `'battle'` or `'triumph'`), or from
|
|
224
|
+
* `{ mood, seed, tempo, bars }`, and loops it; a piece already playing fades out. It is heard once the page has had
|
|
225
|
+
* its first key or click. A restart stops it.
|
|
226
|
+
*/
|
|
227
|
+
play(mood?: MusicMood | MusicOptions): Promise<void>;
|
|
228
|
+
/** Fades the music out over `seconds`, 1 unless given. */
|
|
229
|
+
stop(seconds?: number): void;
|
|
230
|
+
/**
|
|
231
|
+
* 0 to 1, 0.5 unless set: how much of the piece plays. The pad of held chords always; the bass from about 0.2, the
|
|
232
|
+
* drums from about 0.5, the tune from about 0.75. A change is heard over a second or so.
|
|
233
|
+
*/
|
|
234
|
+
intensity: number;
|
|
235
|
+
/** 0 to 1, 0.6 unless set; the volume and the mute of the sound effects apply too. */
|
|
236
|
+
volume: number;
|
|
237
|
+
readonly mood: MusicMood | undefined;
|
|
238
|
+
}
|
|
239
|
+
/** The sound effects of a play game: play or loop one by name, define new ones, and set the volume. */
|
|
154
240
|
export interface PlaySfx {
|
|
155
241
|
/** Plays an effect by name: one of `names`. `pitch` is 1 as written, 2 an octave up. */
|
|
156
242
|
play(name: string, options?: {
|
|
@@ -176,6 +262,7 @@ export interface PlaySfx {
|
|
|
176
262
|
volume: number;
|
|
177
263
|
muted: boolean;
|
|
178
264
|
}
|
|
265
|
+
/** A burst of particles: its color and count, how fast and how long they fly, their size and gravity. */
|
|
179
266
|
export interface PlayBurstOptions {
|
|
180
267
|
readonly color?: number;
|
|
181
268
|
/** How many pieces; 12 unless given. */
|
|
@@ -195,6 +282,7 @@ export interface PlayBurstOptions {
|
|
|
195
282
|
* When it is a promise, as an `async` function returns, its failure is told as the function's own would be.
|
|
196
283
|
*/
|
|
197
284
|
export declare function tapListener(callback: () => unknown, fail: (cause: unknown) => void): () => void;
|
|
285
|
+
/** Everything a small game is given: its world, UI and view, keys and pointer, sound and random numbers, and calls that make, move, test and time things. */
|
|
198
286
|
export interface PlayGame {
|
|
199
287
|
readonly width: number;
|
|
200
288
|
readonly height: number;
|
|
@@ -248,6 +336,13 @@ export interface PlayGame {
|
|
|
248
336
|
} | undefined;
|
|
249
337
|
/** Whether the middles of what two sprites draw are within `distance` of each other: a test of circles. */
|
|
250
338
|
near(a: DisplayObject, b: DisplayObject, distance: number): boolean;
|
|
339
|
+
/**
|
|
340
|
+
* A map of tiles from rows of characters, drawn as one sprite: `game.tiles(['#####', '#...#', '#####'], { size: 32 })`.
|
|
341
|
+
* `#` is solid unless `solid` says which characters are; `colors` gives each character its colour.
|
|
342
|
+
*/
|
|
343
|
+
tiles(rows: readonly string[], options?: PlayTilesOptions): PlayTiles;
|
|
344
|
+
/** The colour a fraction `t` of the way from `a` to `b`, both `0xRRGGBB`: `game.mix(0x000000, 0xffffff, 0.5)`. */
|
|
345
|
+
mix(a: number, b: number, t: number): number;
|
|
251
346
|
/** Moves numbers of an object over time: `game.tween(s).to({ x: 100, alpha: 0 }, 0.3, 'quadOut')`. It starts by itself. */
|
|
252
347
|
tween<T extends object>(target: T): PlayMotion<T>;
|
|
253
348
|
/** Calls a function once, after seconds of play. The function returned calls it off. */
|
|
@@ -256,9 +351,11 @@ export interface PlayGame {
|
|
|
256
351
|
wait(seconds: number): Promise<void>;
|
|
257
352
|
/** Calls a function again and again, seconds of play apart. The function returned ends it. */
|
|
258
353
|
every(seconds: number, callback: () => void): () => void;
|
|
259
|
-
/**
|
|
354
|
+
/** Whether shakes are left out and flashes faint, for a player who asks for less motion. A settings menu may change it. */
|
|
355
|
+
reducedMotion: boolean;
|
|
356
|
+
/** Shakes the world by up to `amount` units for `seconds`. Nothing while `reducedMotion` is on. */
|
|
260
357
|
shake(amount?: number, seconds?: number): void;
|
|
261
|
-
/** Covers the stage with a colour that fades away over `seconds
|
|
358
|
+
/** Covers the stage with a colour that fades away over `seconds`; faintly while `reducedMotion` is on. */
|
|
262
359
|
flash(color?: number, seconds?: number): void;
|
|
263
360
|
/** Stops play for a moment, as a hard hit does: no updates and no timers for `seconds`. */
|
|
264
361
|
hitStop(seconds?: number): void;
|
|
@@ -276,6 +373,37 @@ export interface PlayGame {
|
|
|
276
373
|
* off, and `setup` runs again. Concurrent requests share one promise. Updates resume on success; a failed setup can be retried.
|
|
277
374
|
*/
|
|
278
375
|
restart(): Promise<void>;
|
|
376
|
+
/**
|
|
377
|
+
* A picture from an address (a PNG beside the page, say), its middle at `x`, `y`, scaled to `width` and `height`.
|
|
378
|
+
* Given one of the two, it keeps its shape; given neither, its own size. It is smooth, and drawn from its smaller
|
|
379
|
+
* copies when small, unless `smooth: false`, which keeps every texel sharp, for pixel art. It goes on the world
|
|
380
|
+
* layer unless given another, and is a sprite to move, turn, fade and remove.
|
|
381
|
+
*/
|
|
382
|
+
image(url: string, options?: PlayImageOptions): Promise<Sprite>;
|
|
383
|
+
/** A bar of health, time or power, on the ui layer unless given another; set its `value` and it slides there. */
|
|
384
|
+
bar(options: PlayBarOptions): PlayBar;
|
|
385
|
+
/** A short notice at the top of the stage that fades after `seconds`; several stack. */
|
|
386
|
+
toast(words: string, options?: PlayToastOptions): void;
|
|
387
|
+
/**
|
|
388
|
+
* A box of words at the bottom of the stage, shown letter by letter, with a name above it when `who` is given. A
|
|
389
|
+
* press of Space, Enter or Z or a tap shows the rest, and another closes it. With `choices` it gives the index of
|
|
390
|
+
* the answer chosen by the arrows and Enter or by a tap; without, it gives undefined. Boxes asked for while one is
|
|
391
|
+
* open wait their turn. A restart closes it, and the promise is then not answered.
|
|
392
|
+
*/
|
|
393
|
+
say(words: string, options?: PlaySayOptions): Promise<number | undefined>;
|
|
394
|
+
/** A list to choose from in the middle of the stage, with a title when given; it gives the index chosen. */
|
|
395
|
+
menu(items: readonly string[], options?: PlayMenuOptions): Promise<number>;
|
|
396
|
+
/** Whether a box of words or a menu is open: an update can then leave the game alone. */
|
|
397
|
+
readonly asking: boolean;
|
|
398
|
+
/**
|
|
399
|
+
* A stick on the glass, near the bottom left unless placed, that counts in `keys.axis()`. It is shown once a finger
|
|
400
|
+
* has touched the stage, or at once with `always`.
|
|
401
|
+
*/
|
|
402
|
+
touchStick(options?: PlayStickOptions): Sprite;
|
|
403
|
+
/** A round button on the glass that holds a key while a finger is on it: `keys.down('space')` sees it. */
|
|
404
|
+
touchButton(words: string, options: PlayTouchButtonOptions): Sprite;
|
|
405
|
+
/** Music made in code, in a mood, whose parts come in as `intensity` rises. */
|
|
406
|
+
readonly music: PlayMusic;
|
|
279
407
|
/** The game `play` is built on: its Engine, scope, loop and input, for what this entry does not cover. */
|
|
280
408
|
readonly browser: BrowserGame;
|
|
281
409
|
readonly engine: Engine;
|