@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.
Files changed (304) hide show
  1. package/dist/Engine.js +7 -2
  2. package/dist/animation/sequenceResetTypes.d.ts +6 -0
  3. package/dist/animation/types.d.ts +6 -0
  4. package/dist/assetBundle.d.ts +2 -0
  5. package/dist/assetGroupTypes.d.ts +2 -0
  6. package/dist/audioCues.d.ts +4 -0
  7. package/dist/audioTypes.d.ts +13 -0
  8. package/dist/bitmapButtonTypes.d.ts +2 -0
  9. package/dist/bitmapFontTypes.d.ts +3 -0
  10. package/dist/bitmapResourceSlot.d.ts +1 -0
  11. package/dist/camera2d.js +10 -2
  12. package/dist/cameraTypes.d.ts +12 -0
  13. package/dist/contentTypes.d.ts +2 -0
  14. package/dist/createEngineForProfile.js +8 -5
  15. package/dist/fontContentTypes.d.ts +5 -0
  16. package/dist/gameClockTypes.d.ts +6 -0
  17. package/dist/gameRun.d.ts +3 -0
  18. package/dist/gamepadTypes.d.ts +8 -0
  19. package/dist/hoverInputTypes.d.ts +10 -0
  20. package/dist/index.d.ts +5 -2
  21. package/dist/index.js +2 -1
  22. package/dist/inputActions.d.ts +5 -0
  23. package/dist/internal/uiFactoryState.d.ts +4 -0
  24. package/dist/internal/uiFactoryState.js +18 -2
  25. package/dist/keyboardInput.d.ts +1 -0
  26. package/dist/keyboardInput.js +1 -0
  27. package/dist/keyboardInputTypes.d.ts +12 -0
  28. package/dist/kit.d.ts +3 -1
  29. package/dist/kit.js +2 -1
  30. package/dist/manifestResourceState.d.ts +1 -0
  31. package/dist/manifestResourceState.js +1 -0
  32. package/dist/manifestResourceTypes.d.ts +1 -0
  33. package/dist/motion.d.ts +2 -0
  34. package/dist/mouseInputTypes.d.ts +4 -0
  35. package/dist/particleEmitter.js +8 -0
  36. package/dist/particleTypes.d.ts +8 -0
  37. package/dist/physics2d.d.ts +2 -2
  38. package/dist/physics2d.js +1 -1
  39. package/dist/physics2dTypes.d.ts +55 -1
  40. package/dist/physics2dWorld.js +209 -9
  41. package/dist/pointerInput.d.ts +1 -0
  42. package/dist/pointerInput.js +1 -0
  43. package/dist/pointerInputTypes.d.ts +3 -0
  44. package/dist/random.d.ts +1 -0
  45. package/dist/rendering/packSharedDraws2D.js +53 -5
  46. package/dist/rendering/prepareSharedDraws2D.d.ts +2 -0
  47. package/dist/rendering/prepareSharedDraws2D.js +17 -6
  48. package/dist/rendering/sharedColor2D.d.ts +35 -1
  49. package/dist/rendering/sharedColor2D.js +131 -8
  50. package/dist/rendering/sharedEffects2D.js +16 -8
  51. package/dist/rendering/world3d/Animation3D.d.ts +9 -0
  52. package/dist/rendering/world3d/Animation3D.js +4 -0
  53. package/dist/rendering/world3d/AnimationTexture3D.d.ts +6 -0
  54. package/dist/rendering/world3d/AnimationTexture3D.js +2 -0
  55. package/dist/rendering/world3d/Batch3D.d.ts +4 -0
  56. package/dist/rendering/world3d/Batch3D.js +3 -0
  57. package/dist/rendering/world3d/Camera3D.d.ts +5 -0
  58. package/dist/rendering/world3d/Camera3D.js +3 -0
  59. package/dist/rendering/world3d/Character3D.d.ts +4 -0
  60. package/dist/rendering/world3d/Character3D.js +2 -0
  61. package/dist/rendering/world3d/Cloth3D.d.ts +18 -3
  62. package/dist/rendering/world3d/Cloth3D.js +6 -1
  63. package/dist/rendering/world3d/Compression3D.d.ts +1 -0
  64. package/dist/rendering/world3d/Compression3D.js +1 -0
  65. package/dist/rendering/world3d/Curves3D.d.ts +8 -0
  66. package/dist/rendering/world3d/Curves3D.js +5 -0
  67. package/dist/rendering/world3d/Decal3D.d.ts +2 -0
  68. package/dist/rendering/world3d/Decal3D.js +1 -0
  69. package/dist/rendering/world3d/Export3D.d.ts +13 -0
  70. package/dist/rendering/world3d/Export3D.js +263 -0
  71. package/dist/rendering/world3d/Geometry3D.d.ts +11 -1
  72. package/dist/rendering/world3d/Geometry3D.js +10 -1
  73. package/dist/rendering/world3d/GeometryBuilder3D.d.ts +2 -0
  74. package/dist/rendering/world3d/Gizmo3D.d.ts +5 -0
  75. package/dist/rendering/world3d/Gizmo3D.js +2 -0
  76. package/dist/rendering/world3d/Gltf3D.d.ts +6 -0
  77. package/dist/rendering/world3d/Gltf3D.js +25 -5
  78. package/dist/rendering/world3d/GpuParticles3D.d.ts +2 -0
  79. package/dist/rendering/world3d/GpuParticles3D.js +1 -0
  80. package/dist/rendering/world3d/Hdr3D.d.ts +2 -0
  81. package/dist/rendering/world3d/Hdr3D.js +1 -0
  82. package/dist/rendering/world3d/Jelly3D.d.ts +2 -0
  83. package/dist/rendering/world3d/Jelly3D.js +1 -0
  84. package/dist/rendering/world3d/Ktx23D.d.ts +3 -0
  85. package/dist/rendering/world3d/Light3D.d.ts +9 -0
  86. package/dist/rendering/world3d/Light3D.js +4 -0
  87. package/dist/rendering/world3d/Material3D.d.ts +10 -0
  88. package/dist/rendering/world3d/Material3D.js +2 -0
  89. package/dist/rendering/world3d/Mesh3D.d.ts +4 -0
  90. package/dist/rendering/world3d/Mesh3D.js +16 -2
  91. package/dist/rendering/world3d/Meshopt3D.d.ts +3 -0
  92. package/dist/rendering/world3d/Meshopt3D.js +1 -0
  93. package/dist/rendering/world3d/Navigation3D.d.ts +41 -1
  94. package/dist/rendering/world3d/Navigation3D.js +74 -2
  95. package/dist/rendering/world3d/Object3D.d.ts +11 -0
  96. package/dist/rendering/world3d/Object3D.js +10 -0
  97. package/dist/rendering/world3d/Particles3D.d.ts +5 -0
  98. package/dist/rendering/world3d/Particles3D.js +3 -0
  99. package/dist/rendering/world3d/Physics3D.d.ts +14 -0
  100. package/dist/rendering/world3d/Physics3D.js +5 -0
  101. package/dist/rendering/world3d/PhysicsHull3D.d.ts +2 -0
  102. package/dist/rendering/world3d/PhysicsHull3D.js +2 -0
  103. package/dist/rendering/world3d/PhysicsMesh3D.d.ts +2 -0
  104. package/dist/rendering/world3d/PhysicsMesh3D.js +2 -0
  105. package/dist/rendering/world3d/PhysicsRemote3D.d.ts +5 -0
  106. package/dist/rendering/world3d/PhysicsRemote3D.js +2 -0
  107. package/dist/rendering/world3d/Ragdoll3D.d.ts +5 -0
  108. package/dist/rendering/world3d/Ragdoll3D.js +2 -0
  109. package/dist/rendering/world3d/Raycast3D.d.ts +3 -0
  110. package/dist/rendering/world3d/Raycast3D.js +1 -0
  111. package/dist/rendering/world3d/RenderList3D.d.ts +3 -0
  112. package/dist/rendering/world3d/RenderList3D.js +12 -0
  113. package/dist/rendering/world3d/Retarget3D.d.ts +1 -0
  114. package/dist/rendering/world3d/Rig3D.d.ts +57 -0
  115. package/dist/rendering/world3d/Rig3D.js +219 -0
  116. package/dist/rendering/world3d/Sdf3D.d.ts +181 -0
  117. package/dist/rendering/world3d/Sdf3D.js +1136 -0
  118. package/dist/rendering/world3d/SdfLod3D.d.ts +17 -0
  119. package/dist/rendering/world3d/SdfLod3D.js +56 -0
  120. package/dist/rendering/world3d/Serialize3D.d.ts +17 -0
  121. package/dist/rendering/world3d/Serialize3D.js +22 -0
  122. package/dist/rendering/world3d/Simplify3D.d.ts +29 -0
  123. package/dist/rendering/world3d/Simplify3D.js +426 -0
  124. package/dist/rendering/world3d/StateMachine3D.d.ts +9 -0
  125. package/dist/rendering/world3d/StateMachine3D.js +3 -0
  126. package/dist/rendering/world3d/SurfaceMaterial3D.d.ts +26 -0
  127. package/dist/rendering/world3d/SurfaceMaterial3D.js +138 -0
  128. package/dist/rendering/world3d/Terrain3D.d.ts +21 -0
  129. package/dist/rendering/world3d/Terrain3D.js +25 -1
  130. package/dist/rendering/world3d/Text3D.d.ts +5 -0
  131. package/dist/rendering/world3d/Text3D.js +2 -0
  132. package/dist/rendering/world3d/Texture3D.d.ts +16 -1
  133. package/dist/rendering/world3d/Texture3D.js +19 -1
  134. package/dist/rendering/world3d/Trail3D.d.ts +3 -0
  135. package/dist/rendering/world3d/Trail3D.js +2 -0
  136. package/dist/rendering/world3d/Vehicle3D.d.ts +5 -0
  137. package/dist/rendering/world3d/Vehicle3D.js +2 -0
  138. package/dist/rendering/world3d/VolumetricFog3D.d.ts +2 -0
  139. package/dist/rendering/world3d/VolumetricFog3D.js +1 -0
  140. package/dist/rendering/world3d/Water3D.d.ts +2 -0
  141. package/dist/rendering/world3d/Water3D.js +1 -0
  142. package/dist/rendering/world3d/core3D.d.ts +2 -0
  143. package/dist/rendering/world3d/debug3D.d.ts +5 -0
  144. package/dist/rendering/world3d/debug3D.js +5 -0
  145. package/dist/rendering/world3d/geometries3D.d.ts +12 -0
  146. package/dist/rendering/world3d/geometries3D.js +5 -0
  147. package/dist/rendering/world3d/helpers3D.d.ts +2 -0
  148. package/dist/rendering/world3d/helpers3D.js +1 -0
  149. package/dist/rendering/world3d/index.d.ts +12 -0
  150. package/dist/rendering/world3d/index.js +6 -0
  151. package/dist/rendering/world3d/math3D.d.ts +36 -0
  152. package/dist/rendering/world3d/math3D.js +35 -0
  153. package/dist/rendering/world3d/primitives3D.d.ts +7 -0
  154. package/dist/rendering/world3d/primitives3D.js +1 -0
  155. package/dist/saveStore.d.ts +18 -3
  156. package/dist/saveStore.js +23 -4
  157. package/dist/semanticList.d.ts +4 -0
  158. package/dist/semanticList.js +1 -0
  159. package/dist/semanticTree.js +11 -4
  160. package/dist/semanticTypes.d.ts +8 -0
  161. package/dist/sequencePlaybackTypes.d.ts +3 -0
  162. package/dist/text.d.ts +1 -0
  163. package/dist/textTable.d.ts +41 -0
  164. package/dist/textTable.js +114 -0
  165. package/dist/tilemapTypes.d.ts +13 -0
  166. package/dist/timer.d.ts +34 -0
  167. package/dist/timer.js +119 -0
  168. package/dist/tweenTypes.d.ts +4 -0
  169. package/dist/ui/controlKeys.d.ts +4 -0
  170. package/dist/ui/controlKeys.js +1 -0
  171. package/dist/ui/controls.d.ts +6 -0
  172. package/dist/ui/controls.js +2 -0
  173. package/dist/ui/layerTypes.d.ts +7 -0
  174. package/dist/ui/rangeControl.d.ts +3 -0
  175. package/dist/ui/rangeControl.js +1 -0
  176. package/dist/ui/scrollControl.d.ts +12 -0
  177. package/dist/ui/scrollControl.js +5 -1
  178. package/dist/ui/stateControls.d.ts +8 -0
  179. package/dist/ui/stateControls.js +3 -0
  180. package/dist/ui/textEditor.d.ts +1 -0
  181. package/dist/ui/textEditor.js +1 -0
  182. package/dist/ui/textEditorTypes.d.ts +7 -0
  183. package/dist/ui/textFieldControl.d.ts +4 -0
  184. package/dist/ui/textFieldControl.js +1 -0
  185. package/dist/ui/theme.d.ts +5 -0
  186. package/dist/ui/theme.js +1 -0
  187. package/dist/ui/types.d.ts +20 -0
  188. package/dist/ui/uiRoot.js +38 -9
  189. package/dist/ui/uiRootModel.d.ts +3 -1
  190. package/dist/ui/uiRootModel.js +8 -2
  191. package/dist/videoTypes.d.ts +3 -0
  192. package/dist/web/BrowserAssetBundle.d.ts +2 -0
  193. package/dist/web/BrowserAudio.d.ts +34 -1
  194. package/dist/web/BrowserAudio.js +69 -39
  195. package/dist/web/BrowserFrameLoop.d.ts +4 -0
  196. package/dist/web/BrowserGame.d.ts +64 -2
  197. package/dist/web/BrowserGame.js +129 -8
  198. package/dist/web/BrowserGamepadInput.d.ts +3 -0
  199. package/dist/web/BrowserHoverInput.d.ts +1 -0
  200. package/dist/web/BrowserImageTextures.d.ts +6 -0
  201. package/dist/web/BrowserInputActions.d.ts +10 -0
  202. package/dist/web/BrowserInputActions.js +4 -1
  203. package/dist/web/BrowserPlay.d.ts +130 -2
  204. package/dist/web/BrowserPlay.js +366 -19
  205. package/dist/web/BrowserPreferences.d.ts +10 -0
  206. package/dist/web/BrowserPreferences.js +39 -0
  207. package/dist/web/BrowserSemantics.d.ts +2 -0
  208. package/dist/web/BrowserStatsPanel.d.ts +10 -0
  209. package/dist/web/BrowserStatsPanel.js +9 -3
  210. package/dist/web/BrowserStorage.d.ts +2 -0
  211. package/dist/web/BrowserTextEditor.d.ts +3 -0
  212. package/dist/web/BrowserTextInput.d.ts +6 -0
  213. package/dist/web/BrowserTextureProvider.d.ts +6 -0
  214. package/dist/web/BrowserVideo.d.ts +13 -1
  215. package/dist/web/BrowserVideo.js +28 -2
  216. package/dist/web/CanvasKitFontSetProvider.d.ts +3 -0
  217. package/dist/web/CanvasKitParagraphProvider.d.ts +4 -0
  218. package/dist/web/CanvasKitParagraphProvider.js +1 -0
  219. package/dist/web/ManifestByteSource.d.ts +4 -0
  220. package/dist/web/ManifestByteSource.js +1 -0
  221. package/dist/web/ManifestFontContentLoader.d.ts +1 -0
  222. package/dist/web/WebGL2Host.js +64 -25
  223. package/dist/web/WebGPUHost.d.ts +13 -0
  224. package/dist/web/WebGPUHost.js +117 -36
  225. package/dist/web/audio.d.ts +2 -2
  226. package/dist/web/audio.js +1 -1
  227. package/dist/web/editorFonts.d.ts +4 -0
  228. package/dist/web/game.d.ts +1 -1
  229. package/dist/web/imageProjections2D.d.ts +2 -0
  230. package/dist/web/kit.d.ts +1 -0
  231. package/dist/web/kit.js +1 -0
  232. package/dist/web/play.d.ts +6 -1
  233. package/dist/web/play.js +4 -1
  234. package/dist/web/playMusic.d.ts +33 -0
  235. package/dist/web/playMusic.js +194 -0
  236. package/dist/web/playTouch.d.ts +45 -0
  237. package/dist/web/playTouch.js +141 -0
  238. package/dist/web/playWidgets.d.ts +71 -0
  239. package/dist/web/playWidgets.js +431 -0
  240. package/dist/web/prepareSharedSubmission2D.js +9 -3
  241. package/dist/web/resources.d.ts +2 -0
  242. package/dist/web/sharedEffectShaders.d.ts +6 -2
  243. package/dist/web/sharedEffectShaders.js +23 -7
  244. package/dist/web/sharedSubmissionStorage2D.js +1 -1
  245. package/dist/web/sharedWebGL2Options.d.ts +3 -0
  246. package/dist/web/sharedWebGL2Options.js +8 -2
  247. package/dist/web/sharedWebGL2Shaders.d.ts +15 -2
  248. package/dist/web/sharedWebGL2Shaders.js +108 -14
  249. package/dist/web/sharedWebGPUOptions.d.ts +5 -1
  250. package/dist/web/sharedWebGPUOptions.js +6 -2
  251. package/dist/web/video.d.ts +1 -1
  252. package/dist/web/webgl2Native.d.ts +3 -1
  253. package/dist/web/webgl2Native.js +9 -5
  254. package/dist/web/webgl2Types.d.ts +18 -0
  255. package/dist/web/webgpuImageResidency.d.ts +5 -2
  256. package/dist/web/webgpuImageResidency.js +7 -3
  257. package/dist/web/webgpuRetentionPool.d.ts +2 -2
  258. package/dist/web/webgpuRetentionPool.js +2 -1
  259. package/dist/web/webgpuSharedPass.d.ts +1 -1
  260. package/dist/web/webgpuSharedPass.js +87 -5
  261. package/dist/web/webgpuSharedResolvePass.d.ts +1 -1
  262. package/dist/web/webgpuSharedResolvePass.js +9 -4
  263. package/dist/web/world3d/Audio3D.d.ts +18 -1
  264. package/dist/web/world3d/Audio3D.js +62 -3
  265. package/dist/web/world3d/BrowserPlay3D.d.ts +115 -2
  266. package/dist/web/world3d/BrowserPlay3D.js +448 -43
  267. package/dist/web/world3d/FlyControls3D.d.ts +4 -0
  268. package/dist/web/world3d/FlyControls3D.js +2 -0
  269. package/dist/web/world3d/FollowControls3D.d.ts +3 -0
  270. package/dist/web/world3d/FollowControls3D.js +2 -0
  271. package/dist/web/world3d/OrbitControls3D.d.ts +3 -0
  272. package/dist/web/world3d/OrbitControls3D.js +2 -0
  273. package/dist/web/world3d/TransformControls3D.d.ts +5 -2
  274. package/dist/web/world3d/TransformControls3D.js +7 -4
  275. package/dist/web/world3d/WebGL2Renderer3D.d.ts +3 -0
  276. package/dist/web/world3d/WebGL2Renderer3D.js +2 -0
  277. package/dist/web/world3d/WebGPURenderer3D.d.ts +2 -0
  278. package/dist/web/world3d/WebGPURenderer3D.js +1 -0
  279. package/dist/web/world3d/World3DView.d.ts +3 -0
  280. package/dist/web/world3d/World3DView.js +2 -0
  281. package/dist/web/world3d/app3D.d.ts +7 -0
  282. package/dist/web/world3d/app3D.js +1 -0
  283. package/dist/web/world3d/assets3D.d.ts +1 -0
  284. package/dist/web/world3d/atmosphere3D.d.ts +9 -0
  285. package/dist/web/world3d/atmosphere3D.js +19 -4
  286. package/dist/web/world3d/canvasFont3D.d.ts +21 -0
  287. package/dist/web/world3d/canvasFont3D.js +165 -0
  288. package/dist/web/world3d/frame3D.d.ts +2 -0
  289. package/dist/web/world3d/host3D.d.ts +1 -0
  290. package/dist/web/world3d/index.d.ts +4 -2
  291. package/dist/web/world3d/index.js +2 -1
  292. package/dist/web/world3d/loaders3D.d.ts +1 -0
  293. package/dist/web/world3d/markers3D.d.ts +4 -0
  294. package/dist/web/world3d/overlay3D.d.ts +19 -0
  295. package/dist/web/world3d/overlay3D.js +21 -4
  296. package/dist/web/world3d/post3D.d.ts +4 -0
  297. package/dist/web/world3d/post3D.js +3 -0
  298. package/dist/web/world3d/probe3D.d.ts +1 -0
  299. package/dist/web/world3d/stats3D.d.ts +3 -0
  300. package/dist/web/world3d/stats3D.js +1 -0
  301. package/dist/web/world3d/webGL2FrameMetrics3D.d.ts +5 -0
  302. package/dist/web/world3d/webgpu.d.ts +2 -0
  303. package/dist/web/world3d/webgpu.js +1 -0
  304. package/package.json +3 -3
@@ -5,13 +5,17 @@
5
5
  // shake, a flash and a hit stop. Everything is built from the public entries, which stay there for a game that
6
6
  // outgrows this one.
7
7
  import { EgretError } from '@egret/runtime';
8
- import { Sprite, animate } from '@egret/engine';
8
+ import { Bitmap, Sprite, animate, createSharedMaterial2D } from '@egret/engine';
9
9
  import { createRandom, encodeWav } from '@egret/engine/kit';
10
10
  import { createBrowserAudio } from './audio.js';
11
11
  import { createBrowserGamepadInput } from './gamepad.js';
12
12
  import { createBrowserGame } from './game.js';
13
13
  import { createBrowserFrameLoop } from './loop.js';
14
14
  import { SFX_PRESETS, isSfxRecipe, synthesizeSfx } from './playSfx.js';
15
+ import { createPlayWidgets } from './playWidgets.js';
16
+ import { prefersReducedMotion, watchReducedMotion } from './BrowserPreferences.js';
17
+ import { createPlayTouch } from './playTouch.js';
18
+ import { MUSIC_MOODS, MUSIC_PARTS, composeMusic, musicMix } from './playMusic.js';
15
19
  /** A line of text: a sprite to place, fade, tween and remove like any other, with words that can be changed. */
16
20
  export class PlayText extends Sprite {
17
21
  #text;
@@ -92,7 +96,26 @@ const KEY_NAMES = {
92
96
  };
93
97
  /** Keys a game uses that would otherwise scroll or move about the page. */
94
98
  const KEPT_FROM_PAGE = new Set(['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Space', 'Tab']);
99
+ /** The buttons of a pad a key name may be, as `'pad:a'`: the standard layout, by where each button is. */
100
+ const PAD_BUTTONS = Object.freeze([
101
+ 'a',
102
+ 'b',
103
+ 'x',
104
+ 'y',
105
+ 'l1',
106
+ 'r1',
107
+ 'l2',
108
+ 'r2',
109
+ 'select',
110
+ 'start',
111
+ 'up',
112
+ 'down',
113
+ 'left',
114
+ 'right'
115
+ ]);
95
116
  function codeOf(key) {
117
+ if (/^pad:/i.test(key))
118
+ return 'Pad:' + key.slice(4).toLowerCase();
96
119
  const named = KEY_NAMES[key.toLowerCase()];
97
120
  if (named !== undefined)
98
121
  return named;
@@ -103,6 +126,8 @@ function codeOf(key) {
103
126
  return key;
104
127
  }
105
128
  const SWIPE = 24;
129
+ // A picture is smooth, and read from its smaller copies when drawn small; or sharp, every texel kept.
130
+ const SMOOTH = createSharedMaterial2D({ filter: 'linear', mipmapFilter: 'linear' }), SHARP = createSharedMaterial2D({});
106
131
  const PIECES = 256;
107
132
  /** A loop of `sfx.loop`. Its voice starts once its sound is made, which is at once for the effects every game has. */
108
133
  class PlayingLoop {
@@ -116,11 +141,14 @@ class PlayingLoop {
116
141
  this.#volume = Math.max(0, Math.min(1, volume));
117
142
  this.#pitch = Math.max(0.25, Math.min(4, pitch));
118
143
  this.#pan = Math.max(-1, Math.min(1, pan));
119
- const made = sound();
120
- if (made === undefined)
144
+ if (mixer === undefined) {
145
+ this.#stopped = true;
146
+ return;
147
+ }
148
+ if (sound === undefined)
121
149
  return;
122
150
  try {
123
- this.#voice = mixer.play(made, {
151
+ this.#voice = mixer.play(sound, {
124
152
  loop: true,
125
153
  volume: 0,
126
154
  rate: this.#pitch,
@@ -225,6 +253,19 @@ export async function play(options) {
225
253
  throw invalid('update is a function');
226
254
  if (onError !== undefined && typeof onError !== 'function')
227
255
  throw invalid('onError is a function');
256
+ if (options.audio !== undefined && typeof options.audio !== 'boolean')
257
+ throw invalid('audio is true or false');
258
+ if (options.reducedMotion !== undefined && typeof options.reducedMotion !== 'boolean')
259
+ throw invalid('reducedMotion is true or false');
260
+ // Given, it is the game's; not given, it follows the system's setting.
261
+ let reduced = options.reducedMotion ?? prefersReducedMotion(), followSystem = options.reducedMotion === undefined;
262
+ const unwatchMotion = watchReducedMotion(next => {
263
+ if (followSystem)
264
+ reduced = next;
265
+ });
266
+ const blendSpace = options.blendSpace ?? 'srgb';
267
+ if (blendSpace !== 'linear' && blendSpace !== 'srgb')
268
+ throw invalid("blendSpace is 'srgb' or 'linear'");
228
269
  const page = options.canvas?.ownerDocument ?? options.parent?.ownerDocument ?? globalThis.document;
229
270
  if (page === undefined)
230
271
  throw invalid('play needs a page');
@@ -253,6 +294,9 @@ export async function play(options) {
253
294
  height,
254
295
  clearColor: options.transparent === true ? 0 : background,
255
296
  ...(options.transparent === true ? { clearAlpha: 0 } : {}),
297
+ blendSpace,
298
+ // Masks, glows, outlines, blurs and colour matrices are drawn, as Egret 5 code expects of them.
299
+ effects: true,
256
300
  autoStart: false,
257
301
  keyboard: false,
258
302
  ...(holder === undefined ? {} : { fit: 'contain', fitTo: holder }),
@@ -318,7 +362,7 @@ export async function play(options) {
318
362
  }
319
363
  });
320
364
  const layer = () => stage.addChild(scope.use(new Sprite()));
321
- const world = layer(), effects = layer(), ui = layer(), cover = layer();
365
+ const world = layer(), effects = layer(), ui = layer(), glass = layer(), cover = layer();
322
366
  const view = { x: 0, y: 0 };
323
367
  const random = createRandom(options.seed ?? Date.now() + ':' + Math.random());
324
368
  // Keys: a set of what is held, and what changed since the last update.
@@ -371,16 +415,41 @@ export async function play(options) {
371
415
  return { x: 0, y: 0 };
372
416
  }
373
417
  };
418
+ // The buttons of the first pad count as keys named `pad:a` and so on: held, pressed and let go as keys are.
419
+ const pollPadButtons = () => {
420
+ const pad = pads?.input.pads[0];
421
+ for (const name of PAD_BUTTONS) {
422
+ let down = false;
423
+ try {
424
+ down = pad !== undefined && pad.standard && pad.pressed(name);
425
+ }
426
+ catch {
427
+ down = false;
428
+ }
429
+ const code = 'Pad:' + name;
430
+ if (down && !held.has(code)) {
431
+ held.add(code);
432
+ wentDown.add(code);
433
+ }
434
+ else if (!down && held.has(code) && !touchHeld.has(code)) {
435
+ held.delete(code);
436
+ cameUp.add(code);
437
+ }
438
+ }
439
+ };
440
+ // Keys a finger holds through a button on the glass, and where a stick on the glass is.
441
+ const touchHeld = new Set(), touchStick = { x: 0, y: 0 };
374
442
  const keys = {
375
443
  down: (...names) => any(held, names),
376
444
  pressed: (...names) => any(wentDown, names),
377
445
  released: (...names) => any(cameUp, names),
378
446
  axis() {
379
- let x = (any(held, ['right', 'd']) ? 1 : 0) - (any(held, ['left', 'a']) ? 1 : 0), y = (any(held, ['down', 's']) ? 1 : 0) - (any(held, ['up', 'w']) ? 1 : 0);
447
+ let x = (any(held, ['right', 'd', 'pad:right']) ? 1 : 0) - (any(held, ['left', 'a', 'pad:left']) ? 1 : 0), y = (any(held, ['down', 's', 'pad:down']) ? 1 : 0) - (any(held, ['up', 'w', 'pad:up']) ? 1 : 0);
380
448
  const length = x !== 0 && y !== 0 ? Math.SQRT1_2 : 1;
381
449
  x *= length;
382
450
  y *= length;
383
- const pushed = stick('left');
451
+ // A stick on the glass, then the pad's left stick, when no key is held.
452
+ const pushed = touchStick.x !== 0 || touchStick.y !== 0 ? touchStick : stick('left');
384
453
  if (x === 0 && y === 0 && (pushed.x !== 0 || pushed.y !== 0)) {
385
454
  const reach = Math.hypot(pushed.x, pushed.y);
386
455
  return reach > 1 ? { x: pushed.x / reach, y: pushed.y / reach } : pushed;
@@ -407,6 +476,7 @@ export async function play(options) {
407
476
  // This convenience view follows one drag; the shared UI router still receives every contact.
408
477
  let pointerOwner;
409
478
  const moved = (event) => {
479
+ touch.move(event);
410
480
  if (pointerOwner !== undefined
411
481
  ? event.pointerId !== pointerOwner
412
482
  : event.pointerType === 'touch' || event.buttons !== 0)
@@ -437,6 +507,11 @@ export async function play(options) {
437
507
  // that places something wherever the stage is pressed would place it under its own buttons.
438
508
  let tappable = [];
439
509
  const pointerDown = (event) => {
510
+ // A finger on a stick or a button on the glass is that control's, and not the game's pointer.
511
+ if (touch.claim(event)) {
512
+ event.preventDefault();
513
+ return;
514
+ }
440
515
  if (pointerOwner !== undefined)
441
516
  return;
442
517
  pointerOwner = event.pointerId;
@@ -449,6 +524,8 @@ export async function play(options) {
449
524
  win.focus?.();
450
525
  };
451
526
  const pointerUp = (event) => {
527
+ if (touch.end(event))
528
+ return;
452
529
  if (event.pointerId !== pointerOwner)
453
530
  return;
454
531
  pointerOwner = undefined;
@@ -459,6 +536,8 @@ export async function play(options) {
459
536
  point.swipe = Math.abs(dx) > Math.abs(dy) ? (dx > 0 ? 'right' : 'left') : dy > 0 ? 'down' : 'up';
460
537
  };
461
538
  const pointerCancel = (event) => {
539
+ if (touch.end(event))
540
+ return;
462
541
  if (event.pointerId === pointerOwner)
463
542
  pointerOwner = undefined;
464
543
  };
@@ -532,13 +611,15 @@ export async function play(options) {
532
611
  ];
533
612
  for (const [target, type, listener] of listening)
534
613
  target.addEventListener(type, listener, { passive: false });
535
- // Sound: every effect is made and decoded before the game is set up, so the first one plays at once.
536
- const audio = scope.use(createBrowserAudio({ limiter: true }));
614
+ // Only the built-in mixer belongs to this game. Opting out also skips its browser gesture listeners.
615
+ const mixer = options.audio === false ? undefined : scope.use(createBrowserAudio({ limiter: true })).mixer;
537
616
  const sounds = new Map();
538
617
  const RATE = 22050;
539
618
  const make = async (name, recipe) => {
619
+ if (mixer === undefined)
620
+ return;
540
621
  try {
541
- sounds.set(name, await audio.mixer.decode(encodeWav([synthesizeSfx(recipe, RATE)], RATE)));
622
+ sounds.set(name, await mixer.decode(encodeWav([synthesizeSfx(recipe, RATE)], RATE)));
542
623
  }
543
624
  catch {
544
625
  // A page without sound still plays the game.
@@ -559,11 +640,11 @@ export async function play(options) {
559
640
  cause: new Error(`"${String(name)}" is not one of: ${[...names].join(', ')}`)
560
641
  });
561
642
  const sound = sounds.get(name);
562
- if (sound === undefined || muted)
643
+ if (mixer === undefined || sound === undefined || muted)
563
644
  return;
564
645
  const loud = Math.max(0, Math.min(1, (finite(given.volume) ? given.volume : 1) * volume)), rate = Math.max(0.25, Math.min(4, finite(given.pitch) ? given.pitch : 1)), pan = Math.max(-1, Math.min(1, finite(given.pan) ? given.pan : 0));
565
646
  try {
566
- audio.mixer.play(sound, { volume: loud, rate, pan, maxInstances: 6 });
647
+ mixer.play(sound, { volume: loud, rate, pan, maxInstances: 6 });
567
648
  }
568
649
  catch {
569
650
  // Sound never stops a game.
@@ -574,7 +655,9 @@ export async function play(options) {
574
655
  throw new EgretError('PLAY_SFX_UNKNOWN', {
575
656
  cause: new Error(`"${String(name)}" is not one of: ${[...names].join(', ')}`)
576
657
  });
577
- const made = new PlayingLoop(() => sounds.get(name), audio.mixer, finite(given.volume) ? given.volume : 1, finite(given.pitch) ? given.pitch : 1, finite(given.pan) ? given.pan : 0, finite(given.fadeIn) ? given.fadeIn : 0);
658
+ const made = new PlayingLoop(sounds.get(name), mixer, finite(given.volume) ? given.volume : 1, finite(given.pitch) ? given.pitch : 1, finite(given.pan) ? given.pan : 0, finite(given.fadeIn) ? given.fadeIn : 0);
659
+ if (mixer === undefined)
660
+ return made;
578
661
  loops.add(made);
579
662
  made.heard(muted ? 0 : volume);
580
663
  return made;
@@ -606,6 +689,83 @@ export async function play(options) {
606
689
  each.heard(muted ? 0 : volume);
607
690
  }
608
691
  };
692
+ // Music: the parts of one piece looped together, each a loop whose loudness follows the intensity.
693
+ let musicParts = [], musicIntensity = 0.5, musicVolume = 0.6, musicMood, musicTicket = 0;
694
+ const musicTick = (seconds) => {
695
+ if (musicParts.length === 0)
696
+ return;
697
+ const mix = musicMix(musicIntensity), rate = Math.min(1, seconds / 1.5);
698
+ for (const entry of musicParts) {
699
+ const wanted = musicVolume * mix[entry.part];
700
+ if (Math.abs(wanted - entry.level) < 1e-3)
701
+ continue;
702
+ entry.level += (wanted - entry.level) * rate;
703
+ entry.loop.volume = entry.level;
704
+ }
705
+ };
706
+ const endMusic = (seconds) => {
707
+ musicTicket++;
708
+ for (const { loop } of musicParts)
709
+ loop.stop(seconds);
710
+ musicParts = [];
711
+ musicMood = undefined;
712
+ };
713
+ const music = {
714
+ async play(given = 'calm') {
715
+ const chosen = typeof given === 'string' ? { mood: given } : (given ?? {});
716
+ if (chosen === null || typeof chosen !== 'object')
717
+ throw invalid('music.play takes a mood or { mood, seed, tempo, bars }');
718
+ if (mixer === undefined) {
719
+ if (!MUSIC_MOODS.includes(chosen.mood ?? 'calm'))
720
+ throw invalid('the mood of music is one of: ' + MUSIC_MOODS.join(', '));
721
+ return;
722
+ }
723
+ let piece;
724
+ try {
725
+ piece = composeMusic(chosen, RATE);
726
+ }
727
+ catch (cause) {
728
+ throw invalid(cause instanceof Error ? cause.message : 'music.play takes a mood');
729
+ }
730
+ const ticket = ++musicTicket;
731
+ const made = await Promise.all(MUSIC_PARTS.map(part => mixer.decode(encodeWav([piece.parts[part]], piece.rate)).catch(() => undefined)));
732
+ // A newer piece, a stop or the end of the game came while this one was being made.
733
+ if (ticket !== musicTicket || disposed)
734
+ return;
735
+ for (const { loop } of musicParts)
736
+ loop.stop(1.2);
737
+ const mix = musicMix(musicIntensity);
738
+ musicParts = MUSIC_PARTS.map((part, index) => {
739
+ const level = musicVolume * mix[part], loop = new PlayingLoop(made[index], mixer, level, 1, 0, 1.2);
740
+ loops.add(loop);
741
+ loop.heard(muted ? 0 : volume);
742
+ if (paused)
743
+ loop.hold(true);
744
+ return { part, loop, level };
745
+ });
746
+ musicMood = piece.mood;
747
+ },
748
+ stop(seconds = 1) {
749
+ endMusic(finite(seconds) && seconds >= 0 ? seconds : 1);
750
+ },
751
+ get intensity() {
752
+ return musicIntensity;
753
+ },
754
+ set intensity(value) {
755
+ if (finite(value))
756
+ musicIntensity = Math.max(0, Math.min(1, value));
757
+ },
758
+ get volume() {
759
+ return musicVolume;
760
+ },
761
+ set volume(value) {
762
+ if (finite(value))
763
+ musicVolume = Math.max(0, Math.min(1, value));
764
+ },
765
+ get mood() {
766
+ return musicMood;
767
+ }
768
+ };
609
769
  let timers = [];
610
770
  const timer = (seconds, callback, repeat) => {
611
771
  if (!finite(seconds) || seconds < 0 || typeof callback !== 'function')
@@ -777,6 +937,7 @@ export async function play(options) {
777
937
  }
778
938
  try {
779
939
  pads?.poll();
940
+ pollPadButtons();
780
941
  }
781
942
  catch {
782
943
  // A pad that cannot be read is not there.
@@ -788,6 +949,11 @@ export async function play(options) {
788
949
  stopped <= 0 &&
789
950
  version === generation &&
790
951
  playLoop.state === 'running';
952
+ // Bars, boxes of words and menus answer while the game is paused, as buttons do, and while `setup` awaits one.
953
+ if (!disposed && playLoop.state === 'running') {
954
+ widgets.tick(real);
955
+ musicTick(real);
956
+ }
791
957
  if (api === undefined || paused || disposed || playLoop.state !== 'running') {
792
958
  endFrame();
793
959
  return;
@@ -876,7 +1042,7 @@ export async function play(options) {
876
1042
  world.y = effects.y = dy - view.y;
877
1043
  if (flashLeft > 0) {
878
1044
  flashLeft -= real;
879
- cover.alpha = Math.max(0, flashLeft / flashSpan) * 0.85;
1045
+ cover.alpha = Math.max(0, flashLeft / flashSpan) * (reduced ? 0.3 : 0.85);
880
1046
  if (flashLeft <= 0)
881
1047
  cover.visible = false;
882
1048
  }
@@ -893,10 +1059,15 @@ export async function play(options) {
893
1059
  const kept = new Map();
894
1060
  const saveKey = (key) => 'egret.play:' + (options.saveKey ?? win.location?.pathname ?? '') + ':' + key;
895
1061
  function resetRound() {
1062
+ endMusic(0.3);
1063
+ widgets.reset();
1064
+ touch.reset();
1065
+ touchHeld.clear();
1066
+ touchStick.x = touchStick.y = 0;
896
1067
  timers = [];
897
1068
  stopLoops();
898
1069
  stopMotions();
899
- for (const made of [world, ui])
1070
+ for (const made of [world, ui, glass])
900
1071
  while (made.numChildren > 0)
901
1072
  game.remove(made.getChildAt(0));
902
1073
  endRemoved();
@@ -1125,6 +1296,107 @@ export async function play(options) {
1125
1296
  const dx = (first.left + first.right - second.left - second.right) / 2, dy = (first.top + first.bottom - second.top - second.bottom) / 2;
1126
1297
  return dx * dx + dy * dy <= distance * distance;
1127
1298
  },
1299
+ tiles(rows, o = {}) {
1300
+ if (!Array.isArray(rows) || rows.length === 0 || rows.some(row => typeof row !== 'string'))
1301
+ throw invalid('tiles takes rows of characters');
1302
+ const size = finite(o?.size) && o.size > 0 ? o.size : 32, solid = typeof o?.solid === 'string' ? o.solid : '#', colors = { '#': 0x6b7280, ...(o?.colors ?? {}) }, cells = rows.map(row => [...row]), columns = Math.max(...cells.map(row => row.length)), node = game.sprite(undefined, o?.layer ?? world);
1303
+ node.x = finite(o?.x) ? o.x : 0;
1304
+ node.y = finite(o?.y) ? o.y : 0;
1305
+ const draw = () => {
1306
+ const g = node.graphics.clear();
1307
+ // An empty fill over the whole map keeps its bounds those of the map.
1308
+ g.beginFill(0, 0)
1309
+ .drawRect(0, 0, columns * size, cells.length * size)
1310
+ .endFill();
1311
+ for (let row = 0; row < cells.length; row++)
1312
+ for (let column = 0; column < cells[row].length; column++) {
1313
+ const color = colors[cells[row][column]];
1314
+ if (colour(color))
1315
+ g.beginFill(color)
1316
+ .drawRect(column * size, row * size, size, size)
1317
+ .endFill();
1318
+ }
1319
+ };
1320
+ draw();
1321
+ const at = (column, row) => cells[row]?.[column] ?? '';
1322
+ const cellAt = (x, y) => ({
1323
+ column: Math.floor((x - node.x) / size),
1324
+ row: Math.floor((y - node.y) / size)
1325
+ });
1326
+ const corner = (column, row) => node.localToGlobal(column * size, row * size);
1327
+ return {
1328
+ sprite: node,
1329
+ columns,
1330
+ rows: cells.length,
1331
+ size,
1332
+ at,
1333
+ set(column, row, character) {
1334
+ if (cells[row] === undefined || column < 0 || column >= columns || typeof character !== 'string')
1335
+ return;
1336
+ cells[row][column] = character.slice(0, 1) || ' ';
1337
+ draw();
1338
+ },
1339
+ cellAt,
1340
+ solidAt(x, y) {
1341
+ const cell = cellAt(x, y);
1342
+ return solid.includes(at(cell.column, cell.row) || '\u0000');
1343
+ },
1344
+ pushOut(a) {
1345
+ if (!seen(a) || !seen(node))
1346
+ return undefined;
1347
+ const first = boxOf(a);
1348
+ if (first === undefined)
1349
+ return undefined;
1350
+ const origin = corner(0, 0), far = corner(1, 1), unitX = far.x - origin.x, unitY = far.y - origin.y;
1351
+ if (!(unitX > 0) || !(unitY > 0))
1352
+ return undefined;
1353
+ let moveX = 0, moveY = 0;
1354
+ // Out of the most overlapped solid tile first, then of what still overlaps, a few times at most.
1355
+ for (let round = 0; round < 4; round++) {
1356
+ const box = {
1357
+ left: first.left + moveX,
1358
+ right: first.right + moveX,
1359
+ top: first.top + moveY,
1360
+ bottom: first.bottom + moveY
1361
+ };
1362
+ let best, most = 0;
1363
+ const c0 = Math.floor((box.left - origin.x) / unitX), c1 = Math.floor((box.right - origin.x) / unitX), r0 = Math.floor((box.top - origin.y) / unitY), r1 = Math.floor((box.bottom - origin.y) / unitY);
1364
+ for (let row = Math.max(0, r0); row <= Math.min(cells.length - 1, r1); row++)
1365
+ for (let column = Math.max(0, c0); column <= Math.min(columns - 1, c1); column++) {
1366
+ if (!solid.includes(at(column, row) || '\u0000'))
1367
+ continue;
1368
+ const cell = {
1369
+ left: origin.x + column * unitX,
1370
+ right: origin.x + (column + 1) * unitX,
1371
+ top: origin.y + row * unitY,
1372
+ bottom: origin.y + (row + 1) * unitY
1373
+ };
1374
+ if (!meet(box, cell, 0))
1375
+ continue;
1376
+ const area = (Math.min(box.right, cell.right) - Math.max(box.left, cell.left)) *
1377
+ (Math.min(box.bottom, cell.bottom) - Math.max(box.top, cell.top));
1378
+ if (area <= most)
1379
+ continue;
1380
+ most = area;
1381
+ const left = cell.left - box.right, right = cell.right - box.left, up = cell.top - box.bottom, down = cell.bottom - box.top;
1382
+ const x = -left < right ? left : right, y = -up < down ? up : down;
1383
+ best = Math.abs(x) < Math.abs(y) ? { x, y: 0 } : { x: 0, y };
1384
+ }
1385
+ if (best === undefined)
1386
+ break;
1387
+ moveX += best.x;
1388
+ moveY += best.y;
1389
+ }
1390
+ return moveX === 0 && moveY === 0 ? undefined : { x: moveX, y: moveY };
1391
+ }
1392
+ };
1393
+ },
1394
+ mix(a, b, t) {
1395
+ if (!colour(a) || !colour(b) || !finite(t))
1396
+ throw invalid('mix takes two colours 0xRRGGBB and a number');
1397
+ const k = Math.min(1, Math.max(0, t)), part = (shift) => Math.round(((a >> shift) & 255) + (((b >> shift) & 255) - ((a >> shift) & 255)) * k) << shift;
1398
+ return part(16) | part(8) | part(0);
1399
+ },
1128
1400
  tween(target) {
1129
1401
  const motion = animate(engine, scope, target);
1130
1402
  let settle;
@@ -1143,8 +1415,19 @@ export async function play(options) {
1143
1415
  },
1144
1416
  after: (seconds, callback) => timer(seconds, callback, false),
1145
1417
  every: (seconds, callback) => timer(seconds, callback, true),
1418
+ get reducedMotion() {
1419
+ return reduced;
1420
+ },
1421
+ set reducedMotion(value) {
1422
+ if (typeof value !== 'boolean')
1423
+ throw invalid('reducedMotion is true or false');
1424
+ reduced = value;
1425
+ followSystem = false;
1426
+ if (value)
1427
+ shakeLeft = 0;
1428
+ },
1146
1429
  shake(amount = 6, seconds = 0.25) {
1147
- if (!finite(amount) || !finite(seconds) || amount <= 0 || seconds <= 0)
1430
+ if (reduced || !finite(amount) || !finite(seconds) || amount <= 0 || seconds <= 0)
1148
1431
  return;
1149
1432
  shakeAmount = Math.max(shakeLeft > 0 ? shakeAmount : 0, Math.min(amount, Math.max(width, height)));
1150
1433
  shakeLeft = shakeSpan = Math.min(seconds, 5);
@@ -1154,7 +1437,7 @@ export async function play(options) {
1154
1437
  return;
1155
1438
  cover.graphics.clear().beginFill(color).drawRect(0, 0, width, height).endFill();
1156
1439
  cover.visible = true;
1157
- cover.alpha = 0.85;
1440
+ cover.alpha = reduced ? 0.3 : 0.85;
1158
1441
  flashLeft = flashSpan = Math.min(seconds, 5);
1159
1442
  },
1160
1443
  hitStop(seconds = 0.06) {
@@ -1250,6 +1533,39 @@ export async function play(options) {
1250
1533
  restart() {
1251
1534
  return disposed ? Promise.resolve() : runSetup(true);
1252
1535
  },
1536
+ async image(url, o = {}) {
1537
+ if (typeof url !== 'string' || url === '')
1538
+ throw invalid('image takes the address of a picture');
1539
+ if (o === null || typeof o !== 'object')
1540
+ throw invalid('the options of an image are an object');
1541
+ const into = o.layer === undefined || o.layer === 'world' ? world : o.layer === 'ui' ? ui : o.layer;
1542
+ if (!(into instanceof Sprite) || into.isDisposed)
1543
+ throw invalid("layer is 'ui', 'world' or a sprite");
1544
+ const lease = await browser.loadTexture(url);
1545
+ const holder = scope.use(new Sprite()), picture = scope.use(new Bitmap(lease));
1546
+ picture.sharedMaterial = o.smooth === false ? SHARP : SMOOTH;
1547
+ const own = { width: picture.width, height: picture.height }, w = finite(o.width) && o.width > 0 ? o.width : undefined, h = finite(o.height) && o.height > 0 ? o.height : undefined;
1548
+ const sx = w !== undefined ? w / own.width : h !== undefined ? h / own.height : 1, sy = h !== undefined ? h / own.height : sx;
1549
+ picture.scaleX = sx;
1550
+ picture.scaleY = sy;
1551
+ picture.x = (-own.width * sx) / 2;
1552
+ picture.y = (-own.height * sy) / 2;
1553
+ holder.addChild(picture);
1554
+ holder.x = finite(o.x) ? o.x : 0;
1555
+ holder.y = finite(o.y) ? o.y : 0;
1556
+ into.addChild(holder);
1557
+ return holder;
1558
+ },
1559
+ bar: options => widgets.bar(options),
1560
+ toast: (words, options) => widgets.toast(words, options),
1561
+ say: (words, options) => widgets.say(words, options),
1562
+ menu: (items, options) => widgets.menu(items, options),
1563
+ get asking() {
1564
+ return widgets.asking;
1565
+ },
1566
+ touchStick: options => touch.stick(options),
1567
+ touchButton: (words, options) => touch.button(words, options),
1568
+ music,
1253
1569
  browser,
1254
1570
  engine,
1255
1571
  scope,
@@ -1261,6 +1577,7 @@ export async function play(options) {
1261
1577
  disposal = close.promise;
1262
1578
  disposed = true;
1263
1579
  api = undefined;
1580
+ unwatchMotion();
1264
1581
  // Caller-controlled loading can outlive the game. Release its waiters now;
1265
1582
  // late completion cannot re-enable updates or restart the closed loop.
1266
1583
  setupRequest?.reject(new EgretError('SCOPE_CLOSED'));
@@ -1280,12 +1597,42 @@ export async function play(options) {
1280
1597
  }
1281
1598
  };
1282
1599
  cover.visible = false;
1600
+ // A menu or a box of words that the first `setup` awaits starts the frames, so it is seen and answered. Otherwise
1601
+ // they start when `setup` has finished, as they always have. The game's own steps, timers and tweens begin then.
1602
+ const widgets = createPlayWidgets(game, () => {
1603
+ if (!disposed && browser.loop.state === 'idle')
1604
+ browser.loop.start();
1605
+ });
1606
+ const touch = createPlayTouch(game, {
1607
+ hold(key) {
1608
+ const code = codeOf(key);
1609
+ touchHeld.add(code);
1610
+ if (!held.has(code)) {
1611
+ held.add(code);
1612
+ wentDown.add(code);
1613
+ }
1614
+ },
1615
+ letGo(key) {
1616
+ const code = codeOf(key);
1617
+ touchHeld.delete(code);
1618
+ if (held.delete(code))
1619
+ cameUp.add(code);
1620
+ },
1621
+ stick(x, y) {
1622
+ touchStick.x = x;
1623
+ touchStick.y = y;
1624
+ },
1625
+ toStage: (x, y) => browser.toStage(x, y),
1626
+ layer: glass
1627
+ });
1283
1628
  try {
1284
- await Promise.all(Object.entries(SFX_PRESETS).map(([name, recipe]) => make(name, recipe)));
1629
+ if (mixer !== undefined)
1630
+ await Promise.all(Object.entries(SFX_PRESETS).map(([name, recipe]) => make(name, recipe)));
1285
1631
  await runSetup(false);
1286
1632
  if (disposed)
1287
1633
  throw new EgretError('SCOPE_CLOSED');
1288
- browser.loop.start();
1634
+ if (browser.loop.state === 'idle')
1635
+ browser.loop.start();
1289
1636
  }
1290
1637
  catch (cause) {
1291
1638
  try {
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Whether the player has asked the system for less motion (`prefers-reduced-motion: reduce`): then leave out shakes,
3
+ * flashes, parallax and large moves that are only for show. False where the page cannot tell.
4
+ */
5
+ export declare function prefersReducedMotion(): boolean;
6
+ /** Calls `listener` with the new answer whenever the player changes it. The function returned stops it. */
7
+ export declare function watchReducedMotion(listener: (reduced: boolean) => void): () => void;
8
+ /** The languages the player's browser asks for, most wanted first, such as `['zh-CN', 'en']`; empty where unknown. */
9
+ export declare function browserLanguages(): readonly string[];
10
+ //# sourceMappingURL=BrowserPreferences.d.ts.map
@@ -0,0 +1,39 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // What the player has asked of every page: less motion, and which languages. Read once, or watched as it changes.
3
+ function query() {
4
+ const page = globalThis;
5
+ try {
6
+ return typeof page.matchMedia === 'function' ? page.matchMedia('(prefers-reduced-motion: reduce)') : undefined;
7
+ }
8
+ catch {
9
+ return undefined;
10
+ }
11
+ }
12
+ /**
13
+ * Whether the player has asked the system for less motion (`prefers-reduced-motion: reduce`): then leave out shakes,
14
+ * flashes, parallax and large moves that are only for show. False where the page cannot tell.
15
+ */
16
+ export function prefersReducedMotion() {
17
+ return query()?.matches === true;
18
+ }
19
+ /** Calls `listener` with the new answer whenever the player changes it. The function returned stops it. */
20
+ export function watchReducedMotion(listener) {
21
+ if (typeof listener !== 'function')
22
+ throw new TypeError('watchReducedMotion needs a function');
23
+ const list = query();
24
+ if (list === undefined || typeof list.addEventListener !== 'function')
25
+ return () => { };
26
+ const changed = (event) => listener(event.matches);
27
+ list.addEventListener('change', changed);
28
+ return () => list.removeEventListener('change', changed);
29
+ }
30
+ /** The languages the player's browser asks for, most wanted first, such as `['zh-CN', 'en']`; empty where unknown. */
31
+ export function browserLanguages() {
32
+ const nav = globalThis.navigator;
33
+ if (nav === undefined)
34
+ return [];
35
+ if (Array.isArray(nav.languages) && nav.languages.length > 0)
36
+ return Object.freeze([...nav.languages]);
37
+ return typeof nav.language === 'string' ? Object.freeze([nav.language]) : [];
38
+ }
39
+ //# sourceMappingURL=BrowserPreferences.js.map
@@ -1,4 +1,5 @@
1
1
  import type { UiSemantics } from '@egret/engine/ui/semantics';
2
+ /** Browser semantics to make: the semantic tree, the canvas and its size, its label, and what is called on an error. */
2
3
  export interface BrowserSemanticsOptions {
3
4
  readonly semantics: UiSemantics;
4
5
  /** The canvas the Engine draws on. Its CSS rectangle is mapped to the logical width and height. */
@@ -14,6 +15,7 @@ export interface BrowserSemanticsOptions {
14
15
  */
15
16
  readonly onError?: (cause: unknown) => void;
16
17
  }
18
+ /** The semantic tree projected as elements over the canvas, for screen readers: sync it after the tree changes. */
17
19
  export interface BrowserSemantics {
18
20
  readonly state: 'active' | 'closed';
19
21
  /** The element that holds the projection. It is invisible and takes no pointer. */