@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
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Music made in code, for a game that has no music files. A piece is a few bars in a mood, written once from a seed
|
|
3
|
+
// as four parts of the same length: a pad of held chords, a bass, drums and a tune. Played together and looped, the
|
|
4
|
+
// parts stay in time; a game brings them in and out by how intense the moment is. Nothing here needs a page.
|
|
5
|
+
/** The moods play music can be made in. */
|
|
6
|
+
export const MUSIC_MOODS = Object.freeze(['calm', 'mystery', 'tense', 'battle', 'triumph']);
|
|
7
|
+
/** The parts of a piece, from the quietest moment to the most intense. */
|
|
8
|
+
export const MUSIC_PARTS = Object.freeze(['pad', 'bass', 'drums', 'tune']);
|
|
9
|
+
const MINOR = [0, 2, 3, 5, 7, 8, 10], MAJOR = [0, 2, 4, 5, 7, 9, 11], DORIAN = [0, 2, 3, 5, 7, 9, 10];
|
|
10
|
+
const MOODS = Object.freeze({
|
|
11
|
+
calm: {
|
|
12
|
+
tempo: 84,
|
|
13
|
+
root: 41,
|
|
14
|
+
scale: MAJOR,
|
|
15
|
+
chords: [0, 5, 3, 4, 0, 5, 3, 4],
|
|
16
|
+
pad: 'triangle',
|
|
17
|
+
drums: 'h.......h.......',
|
|
18
|
+
tune: { notes: 4, leap: 2, wave: 'triangle' },
|
|
19
|
+
bass: 'whole'
|
|
20
|
+
},
|
|
21
|
+
mystery: {
|
|
22
|
+
tempo: 72,
|
|
23
|
+
root: 38,
|
|
24
|
+
scale: DORIAN,
|
|
25
|
+
chords: [0, 6, 0, 3, 0, 6, 5, 4],
|
|
26
|
+
pad: 'sine',
|
|
27
|
+
drums: '....h.......h...',
|
|
28
|
+
tune: { notes: 3, leap: 3, wave: 'sine' },
|
|
29
|
+
bass: 'pulse'
|
|
30
|
+
},
|
|
31
|
+
tense: {
|
|
32
|
+
tempo: 108,
|
|
33
|
+
root: 40,
|
|
34
|
+
scale: MINOR,
|
|
35
|
+
chords: [0, 0, 5, 4, 0, 0, 5, 6],
|
|
36
|
+
pad: 'saw',
|
|
37
|
+
drums: 'k...h...k.k.h...',
|
|
38
|
+
tune: { notes: 4, leap: 2, wave: 'square' },
|
|
39
|
+
bass: 'pulse'
|
|
40
|
+
},
|
|
41
|
+
battle: {
|
|
42
|
+
tempo: 140,
|
|
43
|
+
root: 38,
|
|
44
|
+
scale: MINOR,
|
|
45
|
+
chords: [0, 5, 6, 4, 0, 5, 3, 4],
|
|
46
|
+
pad: 'saw',
|
|
47
|
+
drums: 'k.h.s.h.k.k.s.hh',
|
|
48
|
+
tune: { notes: 8, leap: 3, wave: 'square' },
|
|
49
|
+
bass: 'eighths'
|
|
50
|
+
},
|
|
51
|
+
triumph: {
|
|
52
|
+
tempo: 120,
|
|
53
|
+
root: 43,
|
|
54
|
+
scale: MAJOR,
|
|
55
|
+
chords: [0, 3, 4, 0, 5, 3, 4, 4],
|
|
56
|
+
pad: 'saw',
|
|
57
|
+
drums: 'k...s...k.k.s...',
|
|
58
|
+
tune: { notes: 4, leap: 2, wave: 'square' },
|
|
59
|
+
bass: 'eighths'
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const hertz = (midi) => 440 * 2 ** ((midi - 69) / 12);
|
|
63
|
+
/** A small seeded generator, so a seed writes the same piece in every engine. */
|
|
64
|
+
function generator(seed) {
|
|
65
|
+
let h = 2166136261 >>> 0;
|
|
66
|
+
for (const character of String(seed ?? 'egret'))
|
|
67
|
+
h = Math.imul(h ^ character.charCodeAt(0), 16777619) >>> 0;
|
|
68
|
+
return () => {
|
|
69
|
+
h = (h + 0x6d2b79f5) >>> 0;
|
|
70
|
+
let t = h;
|
|
71
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
72
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
73
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const waveAt = (wave, phase) => {
|
|
77
|
+
const p = phase - Math.floor(phase);
|
|
78
|
+
if (wave === 'sine')
|
|
79
|
+
return Math.sin(2 * Math.PI * p);
|
|
80
|
+
if (wave === 'square')
|
|
81
|
+
return p < 0.5 ? 1 : -1;
|
|
82
|
+
if (wave === 'saw')
|
|
83
|
+
return 2 * p - 1;
|
|
84
|
+
return 1 - 4 * Math.abs(p - 0.5);
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Adds one note to a part. A note that runs past the end of the piece continues at its start, so the part joins
|
|
88
|
+
* itself. `attack` and `release` are in seconds; `bright` softens a bright wave with a simple low pass.
|
|
89
|
+
*/
|
|
90
|
+
function note(out, rate, start, seconds, midi, wave, volume, attack, release, bright = 1) {
|
|
91
|
+
const frequency = hertz(midi), length = Math.round((seconds + release) * rate), first = Math.round(start * rate), held = seconds * rate, smoothing = Math.min(1, bright);
|
|
92
|
+
let filtered = 0;
|
|
93
|
+
for (let i = 0; i < length; i++) {
|
|
94
|
+
const t = i / rate;
|
|
95
|
+
let envelope = Math.min(1, t / Math.max(attack, 1e-3));
|
|
96
|
+
if (i > held)
|
|
97
|
+
envelope *= Math.max(0, 1 - (i - held) / Math.max(release * rate, 1));
|
|
98
|
+
const raw = waveAt(wave, frequency * t);
|
|
99
|
+
filtered += (raw - filtered) * smoothing;
|
|
100
|
+
out[(first + i) % out.length] += filtered * envelope * volume;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function noiseHit(out, rate, start, seconds, volume, random, tone = 0) {
|
|
104
|
+
const length = Math.round(seconds * rate), first = Math.round(start * rate);
|
|
105
|
+
for (let i = 0; i < length; i++) {
|
|
106
|
+
const t = i / rate, envelope = Math.exp((-t / seconds) * 5), body = tone > 0 ? Math.sin(2 * Math.PI * tone * t * (1 - t / (seconds * 2))) : 0;
|
|
107
|
+
out[(first + i) % out.length] += ((random() * 2 - 1) * (tone > 0 ? 0.35 : 1) + body) * envelope * volume;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/** Brings a part to a peak of `peak`, so parts of different density are heard alike. */
|
|
111
|
+
function level(part, peak) {
|
|
112
|
+
let most = 0;
|
|
113
|
+
for (let i = 0; i < part.length; i++)
|
|
114
|
+
most = Math.max(most, Math.abs(part[i]));
|
|
115
|
+
if (most > 0)
|
|
116
|
+
for (let i = 0; i < part.length; i++)
|
|
117
|
+
part[i] *= peak / most;
|
|
118
|
+
return part;
|
|
119
|
+
}
|
|
120
|
+
/** Writes a piece. Every call with the same options gives the same samples. */
|
|
121
|
+
export function composeMusic(options = {}, rate = 22050) {
|
|
122
|
+
const mood = options.mood ?? 'calm';
|
|
123
|
+
const shape = MOODS[mood];
|
|
124
|
+
if (shape === undefined)
|
|
125
|
+
throw new TypeError('the mood of music is one of: ' + MUSIC_MOODS.join(', '));
|
|
126
|
+
const tempo = typeof options.tempo === 'number' && Number.isFinite(options.tempo)
|
|
127
|
+
? Math.max(50, Math.min(200, options.tempo))
|
|
128
|
+
: shape.tempo;
|
|
129
|
+
const bars = options.bars === 4 ? 4 : 8;
|
|
130
|
+
if (!Number.isSafeInteger(rate) || rate < 8000 || rate > 96000)
|
|
131
|
+
throw new RangeError('a rate of 8000 to 96000');
|
|
132
|
+
const random = generator(options.seed), beat = 60 / tempo, bar = 4 * beat, seconds = bars * bar, length = Math.round(seconds * rate);
|
|
133
|
+
const parts = {
|
|
134
|
+
pad: new Float32Array(length),
|
|
135
|
+
bass: new Float32Array(length),
|
|
136
|
+
drums: new Float32Array(length),
|
|
137
|
+
tune: new Float32Array(length)
|
|
138
|
+
};
|
|
139
|
+
const degree = (index) => {
|
|
140
|
+
const octave = Math.floor(index / shape.scale.length), step = ((index % shape.scale.length) + shape.scale.length) % shape.scale.length;
|
|
141
|
+
return shape.root + 12 * octave + shape.scale[step];
|
|
142
|
+
};
|
|
143
|
+
// A tune walks the scale over the chord of each bar, starting on a note of the chord.
|
|
144
|
+
let walk = 14;
|
|
145
|
+
for (let b = 0; b < bars; b++) {
|
|
146
|
+
const chord = shape.chords[b % shape.chords.length], at = b * bar;
|
|
147
|
+
// Pad: the three notes of the chord an octave and more above the bass, held the whole bar.
|
|
148
|
+
for (const third of [0, 2, 4])
|
|
149
|
+
note(parts.pad, rate, at, bar * 0.98, degree(chord + third) + 12, shape.pad, 0.3, 0.25, 0.4, 0.08);
|
|
150
|
+
// Bass: the root of the chord.
|
|
151
|
+
const low = degree(chord);
|
|
152
|
+
if (shape.bass === 'whole')
|
|
153
|
+
note(parts.bass, rate, at, bar * 0.9, low, 'triangle', 0.8, 0.02, 0.2, 0.5);
|
|
154
|
+
else
|
|
155
|
+
for (let step = 0; step < (shape.bass === 'eighths' ? 8 : 4); step++) {
|
|
156
|
+
const each = shape.bass === 'eighths' ? beat / 2 : beat;
|
|
157
|
+
note(parts.bass, rate, at + step * each, each * 0.7, low + (step % 4 === 3 ? 7 : 0), 'saw', 0.7, 0.005, 0.05, 0.2);
|
|
158
|
+
}
|
|
159
|
+
// Drums.
|
|
160
|
+
for (let step = 0; step < 16; step++) {
|
|
161
|
+
const when = at + (step * beat) / 4, hit = shape.drums[step];
|
|
162
|
+
if (hit === 'k')
|
|
163
|
+
noiseHit(parts.drums, rate, when, 0.18, 0.9, random, 55);
|
|
164
|
+
else if (hit === 's')
|
|
165
|
+
noiseHit(parts.drums, rate, when, 0.14, 0.6, random, 180);
|
|
166
|
+
else if (hit === 'h')
|
|
167
|
+
noiseHit(parts.drums, rate, when, 0.04, 0.25, random);
|
|
168
|
+
}
|
|
169
|
+
// Tune.
|
|
170
|
+
const notes = shape.tune.notes, each = bar / notes;
|
|
171
|
+
walk = chord + 14 + Math.round(random() * 2) * 2 - 2 + (walk > chord + 18 ? -2 : 0);
|
|
172
|
+
for (let n = 0; n < notes; n++) {
|
|
173
|
+
if (n > 0)
|
|
174
|
+
walk += Math.round((random() * 2 - 1) * shape.tune.leap);
|
|
175
|
+
walk = Math.max(chord + 9, Math.min(chord + 21, walk));
|
|
176
|
+
// A rest now and then lets the tune breathe.
|
|
177
|
+
if (n > 0 && random() < 0.18)
|
|
178
|
+
continue;
|
|
179
|
+
note(parts.tune, rate, at + n * each, each * 0.8, degree(walk), shape.tune.wave, 0.5, 0.01, each * 0.3, 0.25);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
level(parts.pad, 0.5);
|
|
183
|
+
level(parts.bass, 0.6);
|
|
184
|
+
level(parts.drums, 0.6);
|
|
185
|
+
level(parts.tune, 0.45);
|
|
186
|
+
return Object.freeze({ mood, tempo, bars, rate, seconds: length / rate, parts: Object.freeze(parts) });
|
|
187
|
+
}
|
|
188
|
+
/** How loud each part is at an intensity from 0 to 1: the pad always, then the bass, the drums and the tune. */
|
|
189
|
+
export function musicMix(intensity) {
|
|
190
|
+
const x = Math.max(0, Math.min(1, Number.isFinite(intensity) ? intensity : 0));
|
|
191
|
+
const ramp = (from) => Math.max(0, Math.min(1, (x - from) / 0.2));
|
|
192
|
+
return { pad: 1, bass: ramp(0.15), drums: ramp(0.45), tune: ramp(0.7) };
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=playMusic.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Sprite } from '@egret/engine';
|
|
2
|
+
import type { PlayGame } from './BrowserPlay.js';
|
|
3
|
+
/** A touch stick to show: where, how large, and whether it shows without touch. */
|
|
4
|
+
export interface PlayStickOptions {
|
|
5
|
+
/** The middle of the stick. Near the bottom left of the stage unless given. */
|
|
6
|
+
readonly x?: number;
|
|
7
|
+
readonly y?: number;
|
|
8
|
+
/** How far the knob moves; 48 unless given. */
|
|
9
|
+
readonly radius?: number;
|
|
10
|
+
/** Shown before any finger has touched the stage. */
|
|
11
|
+
readonly always?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** A touch button to show: where, the key it presses, how large, its color, and whether it shows without touch. */
|
|
14
|
+
export interface PlayTouchButtonOptions {
|
|
15
|
+
readonly x: number;
|
|
16
|
+
readonly y: number;
|
|
17
|
+
/** The key it holds while a finger is on it: `'space'` unless given. Any name `keys.down` takes. */
|
|
18
|
+
readonly key?: string;
|
|
19
|
+
readonly radius?: number;
|
|
20
|
+
readonly color?: number;
|
|
21
|
+
readonly always?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/** What the controls tell the game: keys held and let go, and where the stick is. */
|
|
24
|
+
export interface PlayTouchPort {
|
|
25
|
+
hold(key: string): void;
|
|
26
|
+
letGo(key: string): void;
|
|
27
|
+
stick(x: number, y: number): void;
|
|
28
|
+
/** A stage place for a place of the page. */
|
|
29
|
+
toStage(clientX: number, clientY: number): {
|
|
30
|
+
x: number;
|
|
31
|
+
y: number;
|
|
32
|
+
};
|
|
33
|
+
/** The layer the controls are drawn on: over the ui, so a box of words does not hide them. */
|
|
34
|
+
readonly layer: Sprite;
|
|
35
|
+
}
|
|
36
|
+
/** The controls of one game. `claim` is asked first for each press: a press it takes is not the game's pointer. */
|
|
37
|
+
export declare function createPlayTouch(game: PlayGame, port: PlayTouchPort): {
|
|
38
|
+
stick(options?: PlayStickOptions): Sprite;
|
|
39
|
+
button(words: string, options: PlayTouchButtonOptions): Sprite;
|
|
40
|
+
claim(event: PointerEvent): boolean;
|
|
41
|
+
move(event: PointerEvent): void;
|
|
42
|
+
end(event: PointerEvent): boolean;
|
|
43
|
+
reset(): void;
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=playTouch.d.ts.map
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Controls on the glass for a game played by keys: a stick that counts in `keys.axis()`, and buttons that hold keys.
|
|
3
|
+
// A game written for the keyboard is played on a phone by adding them. They are drawn over the ui layer once a finger
|
|
4
|
+
// has touched the stage, or at once with `always`. Each finger keeps the control it started on until it lifts.
|
|
5
|
+
import { Sprite } from '@egret/engine';
|
|
6
|
+
/** The controls of one game. `claim` is asked first for each press: a press it takes is not the game's pointer. */
|
|
7
|
+
export function createPlayTouch(game, port) {
|
|
8
|
+
let controls = [];
|
|
9
|
+
let seen = false;
|
|
10
|
+
const finite = (value) => typeof value === 'number' && Number.isFinite(value);
|
|
11
|
+
const show = () => {
|
|
12
|
+
for (const control of controls)
|
|
13
|
+
control.node.visible = seen || control.always;
|
|
14
|
+
};
|
|
15
|
+
const touch = {
|
|
16
|
+
stick(o = {}) {
|
|
17
|
+
const reach = finite(o?.radius) && o.radius > 0 ? o.radius : 48, x = finite(o?.x) ? o.x : reach + 28, y = finite(o?.y) ? o.y : game.height - reach - 28;
|
|
18
|
+
const node = game.sprite(g => {
|
|
19
|
+
g.beginFill(0xffffff, 0.12).drawCircle(0, 0, reach).endFill();
|
|
20
|
+
g.lineStyle(2, 0xffffff, 0.3).drawCircle(0, 0, reach);
|
|
21
|
+
}, port.layer);
|
|
22
|
+
node.x = x;
|
|
23
|
+
node.y = y;
|
|
24
|
+
const knob = game.sprite(g => g
|
|
25
|
+
.beginFill(0xffffff, 0.45)
|
|
26
|
+
.drawCircle(0, 0, reach * 0.42)
|
|
27
|
+
.endFill(), node);
|
|
28
|
+
const place = (px, py) => {
|
|
29
|
+
let dx = px - x, dy = py - y;
|
|
30
|
+
const length = Math.hypot(dx, dy);
|
|
31
|
+
if (length > reach) {
|
|
32
|
+
dx = (dx / length) * reach;
|
|
33
|
+
dy = (dy / length) * reach;
|
|
34
|
+
}
|
|
35
|
+
knob.x = dx;
|
|
36
|
+
knob.y = dy;
|
|
37
|
+
port.stick(dx / reach, dy / reach);
|
|
38
|
+
};
|
|
39
|
+
controls.push({
|
|
40
|
+
node,
|
|
41
|
+
always: o?.always === true,
|
|
42
|
+
x,
|
|
43
|
+
y,
|
|
44
|
+
// A finger a little outside the ring still takes the stick.
|
|
45
|
+
reach: reach * 1.4,
|
|
46
|
+
owner: undefined,
|
|
47
|
+
press: place,
|
|
48
|
+
drag: place,
|
|
49
|
+
release() {
|
|
50
|
+
knob.x = knob.y = 0;
|
|
51
|
+
port.stick(0, 0);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
show();
|
|
55
|
+
return node;
|
|
56
|
+
},
|
|
57
|
+
button(words, o) {
|
|
58
|
+
if (o === null || typeof o !== 'object' || !finite(o.x) || !finite(o.y))
|
|
59
|
+
throw new TypeError('a touch button takes its words and { x, y }');
|
|
60
|
+
const r = finite(o.radius) && o.radius > 0 ? o.radius : 32, key = typeof o.key === 'string' && o.key !== '' ? o.key : 'space', color = Number.isInteger(o.color) && o.color >= 0 && o.color <= 0xffffff ? o.color : 0xffffff;
|
|
61
|
+
const draw = (down) => {
|
|
62
|
+
node.graphics
|
|
63
|
+
.clear()
|
|
64
|
+
.beginFill(color, down ? 0.5 : 0.2)
|
|
65
|
+
.drawCircle(0, 0, r)
|
|
66
|
+
.endFill()
|
|
67
|
+
.lineStyle(2, color, 0.5)
|
|
68
|
+
.drawCircle(0, 0, r);
|
|
69
|
+
};
|
|
70
|
+
const node = game.sprite(undefined, port.layer);
|
|
71
|
+
node.x = o.x;
|
|
72
|
+
node.y = o.y;
|
|
73
|
+
draw(false);
|
|
74
|
+
game.text(String(words), { size: Math.round(r * 0.6), align: 'center', baseline: 'middle', layer: node });
|
|
75
|
+
controls.push({
|
|
76
|
+
node,
|
|
77
|
+
always: o.always === true,
|
|
78
|
+
x: o.x,
|
|
79
|
+
y: o.y,
|
|
80
|
+
reach: r * 1.2,
|
|
81
|
+
owner: undefined,
|
|
82
|
+
press() {
|
|
83
|
+
draw(true);
|
|
84
|
+
port.hold(key);
|
|
85
|
+
},
|
|
86
|
+
drag() { },
|
|
87
|
+
release() {
|
|
88
|
+
draw(false);
|
|
89
|
+
port.letGo(key);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
show();
|
|
93
|
+
return node;
|
|
94
|
+
},
|
|
95
|
+
claim(event) {
|
|
96
|
+
if (event.pointerType !== 'touch')
|
|
97
|
+
return false;
|
|
98
|
+
if (!seen) {
|
|
99
|
+
seen = true;
|
|
100
|
+
show();
|
|
101
|
+
}
|
|
102
|
+
const at = port.toStage(event.clientX, event.clientY);
|
|
103
|
+
controls = controls.filter(control => !control.node.isDisposed);
|
|
104
|
+
for (const control of controls) {
|
|
105
|
+
if (control.owner !== undefined || !control.node.visible)
|
|
106
|
+
continue;
|
|
107
|
+
if (Math.hypot(at.x - control.x, at.y - control.y) > control.reach)
|
|
108
|
+
continue;
|
|
109
|
+
control.owner = event.pointerId;
|
|
110
|
+
control.press(at.x, at.y);
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
},
|
|
115
|
+
move(event) {
|
|
116
|
+
for (const control of controls)
|
|
117
|
+
if (control.owner === event.pointerId) {
|
|
118
|
+
const at = port.toStage(event.clientX, event.clientY);
|
|
119
|
+
control.drag(at.x, at.y);
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
end(event) {
|
|
123
|
+
let owned = false;
|
|
124
|
+
for (const control of controls)
|
|
125
|
+
if (control.owner === event.pointerId) {
|
|
126
|
+
control.owner = undefined;
|
|
127
|
+
control.release();
|
|
128
|
+
owned = true;
|
|
129
|
+
}
|
|
130
|
+
return owned;
|
|
131
|
+
},
|
|
132
|
+
reset() {
|
|
133
|
+
for (const control of controls)
|
|
134
|
+
if (control.owner !== undefined && !control.node.isDisposed)
|
|
135
|
+
control.release();
|
|
136
|
+
controls = [];
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
return touch;
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=playTouch.js.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Sprite } from '@egret/engine';
|
|
2
|
+
import type { PlayGame } from './BrowserPlay.js';
|
|
3
|
+
/** A bar to show, as for health: where and how large, its value and maximum, its colors and layer. */
|
|
4
|
+
export interface PlayBarOptions {
|
|
5
|
+
readonly x: number;
|
|
6
|
+
readonly y: number;
|
|
7
|
+
/** 120 by 12 unless given. `x` and `y` are its left and its top. */
|
|
8
|
+
readonly width?: number;
|
|
9
|
+
readonly height?: number;
|
|
10
|
+
/** How full it is: `value` out of `max`. 1 of 1 unless given. */
|
|
11
|
+
readonly value?: number;
|
|
12
|
+
readonly max?: number;
|
|
13
|
+
readonly color?: number;
|
|
14
|
+
/** The colour of the empty part. */
|
|
15
|
+
readonly back?: number;
|
|
16
|
+
readonly layer?: Sprite;
|
|
17
|
+
}
|
|
18
|
+
/** A bar of health, time or power. Setting `value` slides it there; a fall leaves a pale trail that catches up. */
|
|
19
|
+
export declare class PlayBar extends Sprite {
|
|
20
|
+
#private;
|
|
21
|
+
constructor(width: number, height: number, value: number, max: number, color: number, back: number);
|
|
22
|
+
get value(): number;
|
|
23
|
+
set value(next: number);
|
|
24
|
+
get max(): number;
|
|
25
|
+
set max(next: number);
|
|
26
|
+
get color(): number;
|
|
27
|
+
set color(next: number);
|
|
28
|
+
/** Moves what is shown towards the value, by the seconds since the last step. */
|
|
29
|
+
step(seconds: number): void;
|
|
30
|
+
draw(): void;
|
|
31
|
+
}
|
|
32
|
+
/** A line of dialogue: who says it, the choices offered, its color and how fast it types. */
|
|
33
|
+
export interface PlaySayOptions {
|
|
34
|
+
/** The name shown above the words. */
|
|
35
|
+
readonly who?: string;
|
|
36
|
+
/** Answers to choose from. `say` then gives the index of the one chosen. */
|
|
37
|
+
readonly choices?: readonly string[];
|
|
38
|
+
/** The colour of the name and of the chosen answer. */
|
|
39
|
+
readonly color?: number;
|
|
40
|
+
/** Letters a second as the words appear; 0 shows them at once. 40 unless given. */
|
|
41
|
+
readonly speed?: number;
|
|
42
|
+
}
|
|
43
|
+
/** A menu to show: its title, where it goes, how wide and its color. */
|
|
44
|
+
export interface PlayMenuOptions {
|
|
45
|
+
readonly title?: string;
|
|
46
|
+
/** The middle of the menu. The middle of the stage unless given. */
|
|
47
|
+
readonly x?: number;
|
|
48
|
+
readonly y?: number;
|
|
49
|
+
readonly width?: number;
|
|
50
|
+
/** The colour of the chosen item. */
|
|
51
|
+
readonly color?: number;
|
|
52
|
+
}
|
|
53
|
+
/** A toast to show: how long and in what color. */
|
|
54
|
+
export interface PlayToastOptions {
|
|
55
|
+
readonly seconds?: number;
|
|
56
|
+
readonly color?: number;
|
|
57
|
+
}
|
|
58
|
+
/** Breaks words into lines no wider than `units`: at a space where there is one, between any two wide characters. */
|
|
59
|
+
export declare function wrapPlayWords(words: string, units: number): string[];
|
|
60
|
+
/** The widgets of one game. `tick` is called once a step, also while the game is paused, with seconds of the wall. */
|
|
61
|
+
export declare function createPlayWidgets(game: PlayGame, wake?: () => void): {
|
|
62
|
+
bar(options: PlayBarOptions): PlayBar;
|
|
63
|
+
toast(words: string, options?: PlayToastOptions): void;
|
|
64
|
+
say(words: string, options?: PlaySayOptions): Promise<number | undefined>;
|
|
65
|
+
sayPage(words: string, options?: PlaySayOptions): Promise<number | undefined>;
|
|
66
|
+
menu(items: readonly string[], options?: PlayMenuOptions): Promise<number>;
|
|
67
|
+
readonly asking: boolean;
|
|
68
|
+
tick(seconds: number): void;
|
|
69
|
+
reset(): void;
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=playWidgets.d.ts.map
|