@auraindustry/aurajs 0.0.6 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +103 -7
- package/benchmarks/perf-thresholds.json +54 -0
- package/package.json +4 -7
- package/src/asset-pack.mjs +5 -1
- package/src/authored-project.mjs +1449 -0
- package/src/authored-runtime.mjs +2016 -0
- package/src/authoring/avatar-animation-graph.mjs +648 -0
- package/src/bin-integrity.mjs +272 -0
- package/src/build-contract/assets.mjs +130 -0
- package/src/build-contract/capabilities.mjs +116 -0
- package/src/build-contract/constants.mjs +6 -0
- package/src/build-contract/helpers.mjs +44 -0
- package/src/build-contract/web-templates.mjs +5993 -0
- package/src/build-contract.mjs +27 -2910
- package/src/bundler.mjs +188 -55
- package/src/cli.mjs +4825 -1512
- package/src/commands/project-authoring.mjs +434 -0
- package/src/config.mjs +27 -0
- package/src/conformance/cases/app-and-ui-runtime-cases.mjs +3309 -0
- package/src/conformance/cases/core-runtime-cases.mjs +1431 -0
- package/src/conformance/cases/index.mjs +11 -0
- package/src/conformance/cases/scene3d-and-media-cases.mjs +2094 -0
- package/src/conformance/cases/systems-and-gameplay-cases.mjs +1776 -0
- package/src/conformance/shared.mjs +27 -0
- package/src/conformance-runner.mjs +25 -13
- package/src/conformance.mjs +619 -4020
- package/src/cutscene.mjs +362 -5
- package/src/dev-cli-action.mjs +249 -0
- package/src/dev-cli-inspect.mjs +92 -0
- package/src/dev-cli-state.mjs +80 -0
- package/src/external-asset-cache.mjs +587 -0
- package/src/external-asset-policy.mjs +217 -0
- package/src/external-package-surface.mjs +206 -0
- package/src/game-action-runtime.mjs +869 -0
- package/src/game-state-runtime.mjs +206 -6
- package/src/headless-action.mjs +186 -0
- package/src/headless-test/runtime-animation.mjs +1173 -0
- package/src/headless-test/runtime-coordinator.mjs +1514 -0
- package/src/headless-test/runtime-primitives.mjs +320 -0
- package/src/headless-test/runtime-world.mjs +2253 -0
- package/src/headless-test.mjs +392 -4298
- package/src/host-binary.mjs +342 -14
- package/src/icon-discovery.mjs +64 -0
- package/src/make-catalog.mjs +109 -0
- package/src/make.mjs +197 -0
- package/src/package-integrity.mjs +586 -0
- package/src/perf-benchmark.mjs +353 -0
- package/src/postinstall.mjs +5 -5
- package/src/prefabs/index.mjs +34 -0
- package/src/prefabs/scene-serialization.mjs +184 -0
- package/src/project-importer.mjs +620 -0
- package/src/project-registry.mjs +24 -0
- package/src/publish-command.mjs +195 -0
- package/src/publish-env-example.mjs +83 -0
- package/src/publish-validation.mjs +708 -0
- package/src/retro/assets/compile.mjs +232 -0
- package/src/retro/backend-gba/authoring.mjs +1029 -0
- package/src/retro/backend-gba/rom.mjs +363 -0
- package/src/retro/backend-gbc/rom.mjs +85 -0
- package/src/retro/build.mjs +278 -0
- package/src/retro/cli/commands.mjs +292 -0
- package/src/retro/cli/templates.mjs +84 -0
- package/src/retro/diagnostics/catalog.mjs +110 -0
- package/src/retro/diagnostics/emit.mjs +72 -0
- package/src/retro/emulator/case-overlay.mjs +64 -0
- package/src/retro/emulator/discovery.mjs +158 -0
- package/src/retro/emulator/macos-case-overlay.swift +220 -0
- package/src/retro/emulator/profiles.mjs +146 -0
- package/src/retro/emulator/runner.mjs +289 -0
- package/src/retro/frontend/load-project.mjs +98 -0
- package/src/retro/index.mjs +30 -0
- package/src/retro/ir/build-ir.mjs +108 -0
- package/src/retro/runtime-gba/contract.mjs +151 -0
- package/src/retro/runtime-gbc/contract.mjs +117 -0
- package/src/retro/shared/span.mjs +26 -0
- package/src/retro/shared/targets.mjs +64 -0
- package/src/retro/validator/check-project.mjs +114 -0
- package/src/runtime-hotspot-audit.mjs +707 -0
- package/src/scaffold/config.mjs +1000 -0
- package/src/scaffold/fs.mjs +56 -0
- package/src/scaffold/layout.mjs +318 -0
- package/src/scaffold/project-docs.mjs +438 -0
- package/src/scaffold.mjs +93 -596
- package/src/scene-composition/index.mjs +326 -0
- package/src/scene-composition/runtime.mjs +751 -0
- package/src/self-hosted-assets.mjs +604 -0
- package/src/session-client.mjs +750 -0
- package/src/session-native-launcher.mjs +74 -0
- package/src/session-protocol.mjs +75 -0
- package/src/session-runtime.mjs +321 -0
- package/src/session-server.mjs +360 -0
- package/src/shader-kits/index.mjs +773 -0
- package/src/starter-content-registry.mjs +292 -0
- package/src/state-artifacts.mjs +662 -24
- package/src/state-dev-reload.mjs +99 -2
- package/src/terminal-ui.mjs +245 -0
- package/src/web-conformance.mjs +219 -0
- package/templates/create/2d/config/gameplay/shooter.config.js +26 -0
- package/templates/create/2d/content/gameplay/waves.json +26 -0
- package/templates/create/2d/content/registries/.gitkeep +1 -0
- package/templates/create/2d/docs/design/.gitkeep +1 -0
- package/templates/create/2d/docs/design/loop.md +5 -0
- package/templates/create/2d/prefabs/enemies.prefab.js +90 -0
- package/templates/create/2d/prefabs/enemy-basic.prefab.js +18 -0
- package/templates/create/2d/prefabs/player.prefab.js +36 -0
- package/templates/create/2d/prefabs/projectiles.prefab.js +35 -0
- package/templates/create/2d/scenes/boot.scene.js +12 -0
- package/templates/create/2d/scenes/gameplay.scene.js +230 -0
- package/templates/create/2d/scenes/menu.scene.js +9 -0
- package/templates/create/2d/src/main.js +6 -185
- package/templates/create/2d/src/runtime/app.js +49 -0
- package/templates/create/2d/src/runtime/capabilities.js +35 -0
- package/templates/create/2d/ui/hud.screen.js +40 -0
- package/templates/create/2d/ui/pause.screen.js +149 -0
- package/templates/create/2d/ui/settings.screen.js +347 -0
- package/templates/create/2d/ui/title.screen.js +13 -0
- package/templates/create/2d-adventure/aura.config.json +28 -0
- package/templates/create/2d-adventure/config/gameplay/adventure.config.js +14 -0
- package/templates/create/2d-adventure/content/gameplay/world.js +46 -0
- package/templates/create/2d-adventure/content/registries/.gitkeep +1 -0
- package/templates/create/2d-adventure/docs/design/loop.md +5 -0
- package/templates/create/2d-adventure/prefabs/player.prefab.js +54 -0
- package/templates/create/2d-adventure/prefabs/relic.prefab.js +38 -0
- package/templates/create/2d-adventure/prefabs/world.prefab.js +125 -0
- package/templates/create/2d-adventure/scenes/gameplay.scene.js +256 -0
- package/templates/create/2d-adventure/src/runtime/capabilities.js +34 -0
- package/templates/create/2d-adventure/ui/hud.screen.js +60 -0
- package/templates/create/2d-survivor/config/gameplay/survivor.config.js +33 -0
- package/templates/create/2d-survivor/content/gameplay/spawn-zones.json +29 -0
- package/templates/create/2d-survivor/content/registries/.gitkeep +1 -0
- package/templates/create/2d-survivor/docs/design/.gitkeep +1 -0
- package/templates/create/2d-survivor/docs/design/loop.md +5 -0
- package/templates/create/2d-survivor/prefabs/enemies.prefab.js +178 -0
- package/templates/create/2d-survivor/prefabs/enemy-swarm.prefab.js +18 -0
- package/templates/create/2d-survivor/prefabs/player.prefab.js +42 -0
- package/templates/create/2d-survivor/prefabs/projectiles.prefab.js +56 -0
- package/templates/create/2d-survivor/scenes/boot.scene.js +12 -0
- package/templates/create/2d-survivor/scenes/gameplay.scene.js +314 -0
- package/templates/create/2d-survivor/scenes/menu.scene.js +9 -0
- package/templates/create/2d-survivor/src/main.js +5 -332
- package/templates/create/2d-survivor/src/runtime/app.js +49 -0
- package/templates/create/2d-survivor/src/runtime/capabilities.js +35 -0
- package/templates/create/2d-survivor/ui/hud.screen.js +45 -0
- package/templates/create/2d-survivor/ui/title.screen.js +13 -0
- package/templates/create/3d/assets/models/starter-avatar.gltf +184 -0
- package/templates/create/3d/config/gameplay/.gitkeep +1 -0
- package/templates/create/3d/content/gameplay/checkpoints.json +33 -0
- package/templates/create/3d/content/gameplay/course.js +40 -0
- package/templates/create/3d/content/registries/.gitkeep +1 -0
- package/templates/create/3d/docs/design/.gitkeep +1 -0
- package/templates/create/3d/docs/design/loop.md +5 -0
- package/templates/create/3d/prefabs/checkpoint.prefab.js +15 -0
- package/templates/create/3d/prefabs/player.prefab.js +204 -0
- package/templates/create/3d/prefabs/world.prefab.js +112 -0
- package/templates/create/3d/scenes/boot.scene.js +12 -0
- package/templates/create/3d/scenes/checkpoint.scene.js +9 -0
- package/templates/create/3d/scenes/gameplay.scene.js +292 -0
- package/templates/create/3d/src/main.js +6 -295
- package/templates/create/3d/src/runtime/app.js +49 -0
- package/templates/create/3d/src/runtime/capabilities.js +53 -0
- package/templates/create/3d/src/runtime/materials.js +34 -0
- package/templates/create/3d/src/runtime/state.js +39 -0
- package/templates/create/3d/ui/hud.screen.js +75 -0
- package/templates/create/3d/ui/pause.screen.js +166 -0
- package/templates/create/3d/ui/settings.screen.js +387 -0
- package/templates/create/3d-adventure/assets/models/starter-avatar.gltf +184 -0
- package/templates/create/3d-adventure/aura.config.json +28 -0
- package/templates/create/3d-adventure/config/gameplay/adventure.config.js +9 -0
- package/templates/create/3d-adventure/content/gameplay/course.js +62 -0
- package/templates/create/3d-adventure/content/registries/.gitkeep +1 -0
- package/templates/create/3d-adventure/docs/design/loop.md +5 -0
- package/templates/create/3d-adventure/prefabs/player.prefab.js +168 -0
- package/templates/create/3d-adventure/prefabs/relic.prefab.js +35 -0
- package/templates/create/3d-adventure/prefabs/world.prefab.js +119 -0
- package/templates/create/3d-adventure/scenes/gameplay.scene.js +358 -0
- package/templates/create/3d-adventure/src/runtime/capabilities.js +56 -0
- package/templates/create/3d-adventure/src/runtime/materials.js +39 -0
- package/templates/create/3d-adventure/src/runtime/state.js +31 -0
- package/templates/create/3d-adventure/ui/hud.screen.js +70 -0
- package/templates/create/3d-adventure/ui/pause.screen.js +437 -0
- package/templates/create/3d-collectathon/assets/models/starter-avatar.gltf +184 -0
- package/templates/create/3d-collectathon/config/gameplay/.gitkeep +1 -0
- package/templates/create/3d-collectathon/content/gameplay/collectibles.json +26 -0
- package/templates/create/3d-collectathon/content/gameplay/course.js +46 -0
- package/templates/create/3d-collectathon/content/registries/.gitkeep +1 -0
- package/templates/create/3d-collectathon/docs/design/.gitkeep +1 -0
- package/templates/create/3d-collectathon/docs/design/loop.md +5 -0
- package/templates/create/3d-collectathon/prefabs/collectible.prefab.js +15 -0
- package/templates/create/3d-collectathon/prefabs/player.prefab.js +207 -0
- package/templates/create/3d-collectathon/prefabs/world.prefab.js +112 -0
- package/templates/create/3d-collectathon/scenes/boot.scene.js +12 -0
- package/templates/create/3d-collectathon/scenes/checkpoint.scene.js +9 -0
- package/templates/create/3d-collectathon/scenes/gameplay.scene.js +200 -0
- package/templates/create/3d-collectathon/src/main.js +5 -355
- package/templates/create/3d-collectathon/src/runtime/app.js +49 -0
- package/templates/create/3d-collectathon/src/runtime/capabilities.js +53 -0
- package/templates/create/3d-collectathon/src/runtime/materials.js +34 -0
- package/templates/create/3d-collectathon/src/runtime/state.js +27 -0
- package/templates/create/3d-collectathon/ui/hud.screen.js +66 -0
- package/templates/create/3d-collectathon/ui/pause.screen.js +13 -0
- package/templates/create/blank/config/gameplay/.gitkeep +1 -0
- package/templates/create/blank/content/gameplay/.gitkeep +1 -0
- package/templates/create/blank/content/registries/.gitkeep +1 -0
- package/templates/create/blank/docs/design/.gitkeep +1 -0
- package/templates/create/blank/docs/design/loop.md +5 -0
- package/templates/create/blank/prefabs/.gitkeep +1 -0
- package/templates/create/blank/scenes/.gitkeep +1 -0
- package/templates/create/blank/src/runtime/.gitkeep +1 -0
- package/templates/create/blank/ui/.gitkeep +1 -0
- package/templates/create/deckbuilder-2d/assets/audio/.gitkeep +1 -0
- package/templates/create/deckbuilder-2d/assets/fonts/.gitkeep +1 -0
- package/templates/create/deckbuilder-2d/assets/sprites/.gitkeep +1 -0
- package/templates/create/deckbuilder-2d/assets/starter/README.md +11 -0
- package/templates/create/deckbuilder-2d/assets/ui/.gitkeep +1 -0
- package/templates/create/deckbuilder-2d/aura.config.json +28 -0
- package/templates/create/deckbuilder-2d/config/gameplay/deckbuilder.config.js +26 -0
- package/templates/create/deckbuilder-2d/content/cards/guard.card.js +19 -0
- package/templates/create/deckbuilder-2d/content/cards/spark.card.js +20 -0
- package/templates/create/deckbuilder-2d/content/cards/starter.deck.js +69 -0
- package/templates/create/deckbuilder-2d/content/cards/strike.card.js +19 -0
- package/templates/create/deckbuilder-2d/content/cards/survey.card.js +20 -0
- package/templates/create/deckbuilder-2d/content/encounters/training-battle.encounter.js +14 -0
- package/templates/create/deckbuilder-2d/content/encounters/training-battle.js +65 -0
- package/templates/create/deckbuilder-2d/content/enemies/training-automaton.enemy.js +48 -0
- package/templates/create/deckbuilder-2d/content/gameplay/.gitkeep +1 -0
- package/templates/create/deckbuilder-2d/content/registries/cards.registry.js +26 -0
- package/templates/create/deckbuilder-2d/content/registries/encounters.registry.js +20 -0
- package/templates/create/deckbuilder-2d/content/registries/enemies.registry.js +20 -0
- package/templates/create/deckbuilder-2d/content/registries/relics.registry.js +20 -0
- package/templates/create/deckbuilder-2d/content/relics/ember-charm.relic.js +18 -0
- package/templates/create/deckbuilder-2d/docs/design/loop.md +12 -0
- package/templates/create/deckbuilder-2d/prefabs/.gitkeep +1 -0
- package/templates/create/deckbuilder-2d/scenes/boot.scene.js +84 -0
- package/templates/create/deckbuilder-2d/scenes/gameplay.scene.js +641 -0
- package/templates/create/deckbuilder-2d/src/components/.gitkeep +1 -0
- package/templates/create/deckbuilder-2d/src/main.js +17 -0
- package/templates/create/deckbuilder-2d/src/runtime/capabilities.js +22 -0
- package/templates/create/deckbuilder-2d/src/shared/.gitkeep +1 -0
- package/templates/create/deckbuilder-2d/src/systems/.gitkeep +1 -0
- package/templates/create/deckbuilder-2d/tests/smoke/.gitkeep +1 -0
- package/templates/create/deckbuilder-2d/ui/hud.screen.js +80 -0
- package/templates/create/deckbuilder-2d/ui/pause.screen.js +146 -0
- package/templates/create/deckbuilder-2d/ui/settings.screen.js +342 -0
- package/templates/create/local-multiplayer/aura.config.json +40 -0
- package/templates/create/local-multiplayer/config/gameplay/local-multiplayer.config.js +26 -0
- package/templates/create/local-multiplayer/content/gameplay/room-layout.js +13 -0
- package/templates/create/local-multiplayer/content/registries/.gitkeep +1 -0
- package/templates/create/local-multiplayer/docs/design/loop.md +14 -0
- package/templates/create/local-multiplayer/prefabs/player.prefab.js +99 -0
- package/templates/create/local-multiplayer/scenes/boot.scene.js +12 -0
- package/templates/create/local-multiplayer/scenes/gameplay.scene.js +443 -0
- package/templates/create/local-multiplayer/src/main.js +17 -0
- package/templates/create/local-multiplayer/src/runtime/capabilities.js +28 -0
- package/templates/create/local-multiplayer/ui/hud.screen.js +60 -0
- package/templates/create/shared/src/runtime/project-inspector.js +105 -0
- package/templates/create/shared/src/runtime/scene-flow.js +290 -0
- package/templates/create/shared/src/runtime/screen-shell.js +222 -0
- package/templates/create/shared/src/runtime/ui-forms.js +209 -0
- package/templates/create/shared/src/runtime/ui-settings.js +237 -0
- package/templates/create/shared/src/runtime/ui-theme.js +352 -0
- package/templates/create/shared/src/starter-utils/adventure-objectives.js +102 -0
- package/templates/create/shared/src/starter-utils/animation-2d.js +337 -0
- package/templates/create/shared/src/starter-utils/avatar-3d.js +404 -0
- package/templates/create/shared/src/starter-utils/combat-feedback-2d.js +320 -0
- package/templates/create/shared/src/starter-utils/core.js +39 -3
- package/templates/create/shared/src/starter-utils/index.js +8 -2
- package/templates/create/shared/src/starter-utils/platformer-3d.js +34 -3
- package/templates/create/shared/src/starter-utils/triggers.js +662 -0
- package/templates/create/shared/src/starter-utils/tween-2d.js +615 -0
- package/templates/create/video-cutscene/assets/video/.gitkeep +0 -0
- package/templates/create/video-cutscene/aura.config.json +28 -0
- package/templates/create/video-cutscene/config/gameplay/.gitkeep +0 -0
- package/templates/create/video-cutscene/content/gameplay/.gitkeep +0 -0
- package/templates/create/video-cutscene/content/registries/.gitkeep +0 -0
- package/templates/create/video-cutscene/docs/design/loop.md +22 -0
- package/templates/create/video-cutscene/prefabs/.gitkeep +0 -0
- package/templates/create/video-cutscene/scenes/boot.scene.js +11 -0
- package/templates/create/video-cutscene/scenes/cutscene.scene.js +113 -0
- package/templates/create/video-cutscene/scenes/gameplay.scene.js +50 -0
- package/templates/create/video-cutscene/src/main.js +17 -0
- package/templates/create/video-cutscene/src/runtime/app.js +52 -0
- package/templates/create/video-cutscene/src/runtime/capabilities.js +35 -0
- package/templates/create/video-cutscene/src/runtime/state.js +13 -0
- package/templates/create/video-cutscene/ui/.gitkeep +0 -0
- package/templates/create-bin/play.js +1187 -0
- package/templates/make/README.md +46 -0
- package/templates/make/catalog.json +51 -0
- package/templates/make/component/files/{{MAKE_NAME}}.component.js +20 -0
- package/templates/make/component/manifest.json +9 -0
- package/templates/make/data/files/{{MAKE_NAME}}.json +14 -0
- package/templates/make/data/manifest.json +9 -0
- package/templates/make/material/files/{{MAKE_NAME}}.material.json +17 -0
- package/templates/make/material/manifest.json +9 -0
- package/templates/make/prefab/files/{{MAKE_NAME}}.prefab.js +20 -0
- package/templates/make/prefab/manifest.json +9 -0
- package/templates/make/scene/files/{{MAKE_NAME}}.scene.js +31 -0
- package/templates/make/scene/manifest.json +9 -0
- package/templates/make/shader/files/{{MAKE_NAME}}.shader.js +23 -0
- package/templates/make/shader/manifest.json +9 -0
- package/templates/make/system/files/{{MAKE_NAME}}.system.js +15 -0
- package/templates/make/system/manifest.json +9 -0
- package/templates/make/ui-screen/files/{{MAKE_NAME}}.screen.js +16 -0
- package/templates/make/ui-screen/files/{{MAKE_NAME}}.screen.json +23 -0
- package/templates/make/ui-screen/manifest.json +10 -0
- package/templates/make-starters/deckbuilder-2d/card/files/{{MAKE_NAME}}.card.js +22 -0
- package/templates/make-starters/deckbuilder-2d/card/manifest.json +9 -0
- package/templates/make-starters/deckbuilder-2d/catalog.json +34 -0
- package/templates/make-starters/deckbuilder-2d/encounter/files/{{MAKE_NAME}}.encounter.js +18 -0
- package/templates/make-starters/deckbuilder-2d/encounter/manifest.json +9 -0
- package/templates/make-starters/deckbuilder-2d/enemy/files/{{MAKE_NAME}}.enemy.js +28 -0
- package/templates/make-starters/deckbuilder-2d/enemy/manifest.json +9 -0
- package/templates/make-starters/deckbuilder-2d/relic/files/{{MAKE_NAME}}.relic.js +23 -0
- package/templates/make-starters/deckbuilder-2d/relic/manifest.json +9 -0
- package/templates/retro/platformer/README.md +10 -0
- package/templates/retro/platformer/assets/retro/assets.json +91 -0
- package/templates/retro/platformer/aura.config.json +7 -0
- package/templates/retro/platformer/package.json +5 -0
- package/templates/retro/platformer/src/main.js +40 -0
- package/templates/retro/puzzle-grid/README.md +10 -0
- package/templates/retro/puzzle-grid/assets/retro/assets.json +90 -0
- package/templates/retro/puzzle-grid/aura.config.json +7 -0
- package/templates/retro/puzzle-grid/package.json +5 -0
- package/templates/retro/puzzle-grid/src/main.js +29 -0
- package/templates/retro/tactics-grid/README.md +10 -0
- package/templates/retro/tactics-grid/assets/retro/assets.json +90 -0
- package/templates/retro/tactics-grid/aura.config.json +7 -0
- package/templates/retro/tactics-grid/package.json +5 -0
- package/templates/retro/tactics-grid/src/main.js +35 -0
- package/templates/retro/topdown-adventure/README.md +10 -0
- package/templates/retro/topdown-adventure/assets/retro/assets.json +95 -0
- package/templates/retro/topdown-adventure/aura.config.json +7 -0
- package/templates/retro/topdown-adventure/package.json +5 -0
- package/templates/retro/topdown-adventure/src/main.js +29 -0
- package/templates/skills/aurajs/SKILL.md +61 -5
|
@@ -0,0 +1,648 @@
|
|
|
1
|
+
const DEFAULT_AVATAR_LOCOMOTION_KEYS = Object.freeze([
|
|
2
|
+
'idle',
|
|
3
|
+
'walk',
|
|
4
|
+
'run',
|
|
5
|
+
'jump',
|
|
6
|
+
'fall',
|
|
7
|
+
'land',
|
|
8
|
+
]);
|
|
9
|
+
|
|
10
|
+
const DEFAULT_AVATAR_ACTION_KEYS = Object.freeze([
|
|
11
|
+
'attack',
|
|
12
|
+
'hurt',
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
const AVATAR_RUNTIME_METHODS = Object.freeze([
|
|
16
|
+
'spawn',
|
|
17
|
+
'destroy',
|
|
18
|
+
'setInput',
|
|
19
|
+
'setAnimations',
|
|
20
|
+
'setAnimationState',
|
|
21
|
+
'defineSocket',
|
|
22
|
+
'attach',
|
|
23
|
+
'detach',
|
|
24
|
+
'onAnimationEvent',
|
|
25
|
+
'playAnimation',
|
|
26
|
+
'clearAnimation',
|
|
27
|
+
'tick',
|
|
28
|
+
'getState',
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
DEFAULT_AVATAR_ACTION_KEYS,
|
|
33
|
+
DEFAULT_AVATAR_LOCOMOTION_KEYS,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function normalizeAvatarAnimationGraphConfig(config = {}) {
|
|
37
|
+
if (!isPlainObject(config)) {
|
|
38
|
+
throw new TypeError('Avatar animation graph config must be an object.');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const normalized = {
|
|
42
|
+
avatar: isAvatarRuntime(config.avatar) ? config.avatar : null,
|
|
43
|
+
avatarOptions: isAvatarRuntime(config.avatar)
|
|
44
|
+
? {}
|
|
45
|
+
: collectAvatarCreationOptions(config),
|
|
46
|
+
animations: normalizeAnimationMap(config.animations),
|
|
47
|
+
animationState: normalizeAnimationState(config.animationState),
|
|
48
|
+
sockets: normalizeSocketMap(config.sockets),
|
|
49
|
+
actions: normalizeActionMap(
|
|
50
|
+
config.actions,
|
|
51
|
+
normalizeAnimationMap(config.animations),
|
|
52
|
+
),
|
|
53
|
+
onAnimationEvent: typeof config.onAnimationEvent === 'function'
|
|
54
|
+
? config.onAnimationEvent
|
|
55
|
+
: null,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
if (!normalized.avatar && !Object.keys(normalized.avatarOptions).length) {
|
|
59
|
+
normalized.avatarOptions = {};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return normalized;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function createAvatarAnimationGraph(aura, config = {}) {
|
|
66
|
+
const normalized = normalizeAvatarAnimationGraphConfig(config);
|
|
67
|
+
const avatar = normalized.avatar ?? createRuntimeAvatar(aura, normalized.avatarOptions);
|
|
68
|
+
|
|
69
|
+
const state = {
|
|
70
|
+
config: normalized,
|
|
71
|
+
avatar,
|
|
72
|
+
listeners: [],
|
|
73
|
+
nextListenerId: 1,
|
|
74
|
+
runtimeUnsubscribe: null,
|
|
75
|
+
lastAvatarState: null,
|
|
76
|
+
cooldowns: Object.create(null),
|
|
77
|
+
activeAction: null,
|
|
78
|
+
lastTriggeredAction: null,
|
|
79
|
+
lastCompletedAction: null,
|
|
80
|
+
lastEvent: null,
|
|
81
|
+
lastActionEvent: null,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
bindRuntimeEventBridge(state);
|
|
85
|
+
applyNormalizedGraphConfig(state, normalized, { resetActions: true });
|
|
86
|
+
|
|
87
|
+
if (normalized.onAnimationEvent) {
|
|
88
|
+
addGraphListener(state, normalized.onAnimationEvent);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
syncGraphState(state);
|
|
92
|
+
|
|
93
|
+
const controller = {
|
|
94
|
+
aura,
|
|
95
|
+
avatar,
|
|
96
|
+
configure(nextConfig = {}) {
|
|
97
|
+
const merged = mergeGraphConfig(state.config, nextConfig);
|
|
98
|
+
applyNormalizedGraphConfig(state, merged, { resetActions: false });
|
|
99
|
+
syncGraphState(state);
|
|
100
|
+
return controller.getState();
|
|
101
|
+
},
|
|
102
|
+
spawn(spawnOptions = {}) {
|
|
103
|
+
const result = avatar.spawn(isPlainObject(spawnOptions) ? spawnOptions : {});
|
|
104
|
+
syncGraphState(state);
|
|
105
|
+
return result;
|
|
106
|
+
},
|
|
107
|
+
destroy() {
|
|
108
|
+
const result = avatar.destroy();
|
|
109
|
+
if (typeof state.runtimeUnsubscribe === 'function') {
|
|
110
|
+
state.runtimeUnsubscribe();
|
|
111
|
+
state.runtimeUnsubscribe = null;
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
},
|
|
115
|
+
setInput(input = {}) {
|
|
116
|
+
const snapshot = avatar.setInput(isPlainObject(input) ? input : {});
|
|
117
|
+
syncGraphState(state, snapshot);
|
|
118
|
+
return controller.getState();
|
|
119
|
+
},
|
|
120
|
+
setAnimations(animations = {}, animationOptions = {}) {
|
|
121
|
+
const patch = { animations };
|
|
122
|
+
if (isPlainObject(animationOptions) && Object.keys(animationOptions).length > 0) {
|
|
123
|
+
patch.visual = {};
|
|
124
|
+
if (Object.prototype.hasOwnProperty.call(animationOptions, 'importId')) {
|
|
125
|
+
patch.visual.importId = animationOptions.importId;
|
|
126
|
+
}
|
|
127
|
+
if (Object.prototype.hasOwnProperty.call(animationOptions, 'autoMatchAnimations')) {
|
|
128
|
+
patch.visual.autoMatchAnimations = animationOptions.autoMatchAnimations;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return controller.configure(patch);
|
|
132
|
+
},
|
|
133
|
+
setAnimationState(animationState = {}) {
|
|
134
|
+
return controller.configure({ animationState });
|
|
135
|
+
},
|
|
136
|
+
defineSocket(name, socketOptions = {}) {
|
|
137
|
+
const normalizedName = normalizeString(name);
|
|
138
|
+
if (!normalizedName) {
|
|
139
|
+
throw new TypeError('Socket names must be non-empty strings.');
|
|
140
|
+
}
|
|
141
|
+
const result = avatar.defineSocket(normalizedName, socketOptions);
|
|
142
|
+
if (!isPlainObject(state.config.sockets)) {
|
|
143
|
+
state.config.sockets = {};
|
|
144
|
+
}
|
|
145
|
+
state.config.sockets[normalizedName] = cloneValue(socketOptions);
|
|
146
|
+
syncGraphState(state);
|
|
147
|
+
return result;
|
|
148
|
+
},
|
|
149
|
+
attach(socketName, sceneNodeId, attachmentOptions = {}) {
|
|
150
|
+
const result = avatar.attach(socketName, sceneNodeId, attachmentOptions);
|
|
151
|
+
syncGraphState(state);
|
|
152
|
+
return result;
|
|
153
|
+
},
|
|
154
|
+
detach(socketName) {
|
|
155
|
+
const result = avatar.detach(socketName);
|
|
156
|
+
syncGraphState(state);
|
|
157
|
+
return result;
|
|
158
|
+
},
|
|
159
|
+
getSockets() {
|
|
160
|
+
return avatar.getSockets();
|
|
161
|
+
},
|
|
162
|
+
onAnimationEvent(callback) {
|
|
163
|
+
return addGraphListener(state, callback);
|
|
164
|
+
},
|
|
165
|
+
playAction(name, playOptions = {}) {
|
|
166
|
+
return playGraphAction(state, name, playOptions);
|
|
167
|
+
},
|
|
168
|
+
clearAction() {
|
|
169
|
+
const result = avatar.clearAnimation();
|
|
170
|
+
syncGraphState(state);
|
|
171
|
+
return result;
|
|
172
|
+
},
|
|
173
|
+
tick(dtSeconds, input = null) {
|
|
174
|
+
if (input != null) {
|
|
175
|
+
controller.setInput(input);
|
|
176
|
+
}
|
|
177
|
+
reduceCooldowns(state, dtSeconds);
|
|
178
|
+
const snapshot = avatar.tick(dtSeconds);
|
|
179
|
+
syncGraphState(state, snapshot);
|
|
180
|
+
return controller.getState();
|
|
181
|
+
},
|
|
182
|
+
getState() {
|
|
183
|
+
return buildGraphSnapshot(state);
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
for (const actionName of DEFAULT_AVATAR_ACTION_KEYS) {
|
|
188
|
+
controller[actionName] = (playOptions = {}) => controller.playAction(actionName, playOptions);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return controller;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export default createAvatarAnimationGraph;
|
|
195
|
+
|
|
196
|
+
function createRuntimeAvatar(aura, avatarOptions) {
|
|
197
|
+
if (!aura || typeof aura !== 'object' || !aura.scene3d || typeof aura.scene3d.createAvatar !== 'function') {
|
|
198
|
+
throw new TypeError('Avatar animation graph requires aura.scene3d.createAvatar() when no existing avatar is provided.');
|
|
199
|
+
}
|
|
200
|
+
const avatar = aura.scene3d.createAvatar(avatarOptions);
|
|
201
|
+
if (!isAvatarRuntime(avatar)) {
|
|
202
|
+
throw new Error('aura.scene3d.createAvatar() did not return an avatar runtime object.');
|
|
203
|
+
}
|
|
204
|
+
return avatar;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function bindRuntimeEventBridge(state) {
|
|
208
|
+
if (typeof state.avatar.onAnimationEvent !== 'function') return;
|
|
209
|
+
state.runtimeUnsubscribe = state.avatar.onAnimationEvent((event) => {
|
|
210
|
+
const normalizedEvent = normalizeRuntimeEvent(event, state.config.actions);
|
|
211
|
+
state.lastEvent = normalizedEvent;
|
|
212
|
+
state.lastActionEvent = normalizedEvent.action ? normalizedEvent : state.lastActionEvent;
|
|
213
|
+
for (const listener of state.listeners.slice().sort((left, right) => left.id - right.id)) {
|
|
214
|
+
try {
|
|
215
|
+
listener.callback(normalizedEvent, buildGraphSnapshot(state));
|
|
216
|
+
} catch {
|
|
217
|
+
// Author callbacks should never break deterministic graph updates.
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function applyNormalizedGraphConfig(state, normalized, options = {}) {
|
|
224
|
+
state.config = normalized;
|
|
225
|
+
const animationOptions = {};
|
|
226
|
+
const importId = normalized.avatarOptions?.visual?.importId;
|
|
227
|
+
const autoMatchAnimations = normalized.avatarOptions?.visual?.autoMatchAnimations;
|
|
228
|
+
if (Number.isInteger(importId) && importId > 0) {
|
|
229
|
+
animationOptions.importId = importId;
|
|
230
|
+
}
|
|
231
|
+
if (typeof autoMatchAnimations === 'boolean') {
|
|
232
|
+
animationOptions.autoMatchAnimations = autoMatchAnimations;
|
|
233
|
+
}
|
|
234
|
+
state.avatar.setAnimations(normalized.animations, animationOptions);
|
|
235
|
+
state.avatar.setAnimationState(normalized.animationState);
|
|
236
|
+
for (const [socketName, socketOptions] of Object.entries(normalized.sockets)) {
|
|
237
|
+
state.avatar.defineSocket(socketName, socketOptions);
|
|
238
|
+
}
|
|
239
|
+
if (options.resetActions === true) {
|
|
240
|
+
state.cooldowns = Object.create(null);
|
|
241
|
+
state.activeAction = null;
|
|
242
|
+
state.lastTriggeredAction = null;
|
|
243
|
+
state.lastCompletedAction = null;
|
|
244
|
+
state.lastActionEvent = null;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function buildGraphSnapshot(state) {
|
|
249
|
+
const avatarState = cloneValue(state.lastAvatarState || state.avatar.getState());
|
|
250
|
+
const cooldowns = {};
|
|
251
|
+
for (const [name, remaining] of Object.entries(state.cooldowns)) {
|
|
252
|
+
cooldowns[name] = round6(remaining);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return {
|
|
256
|
+
avatar: avatarState,
|
|
257
|
+
graph: {
|
|
258
|
+
locomotionKeys: listConfiguredLocomotionKeys(state.config.animations),
|
|
259
|
+
actionKeys: Object.keys(state.config.actions).sort((left, right) => left.localeCompare(right)),
|
|
260
|
+
sockets: Object.keys(state.config.sockets).sort((left, right) => left.localeCompare(right)),
|
|
261
|
+
activeAction: state.activeAction ? cloneValue(state.activeAction) : null,
|
|
262
|
+
lastTriggeredAction: state.lastTriggeredAction ? cloneValue(state.lastTriggeredAction) : null,
|
|
263
|
+
lastCompletedAction: state.lastCompletedAction ? cloneValue(state.lastCompletedAction) : null,
|
|
264
|
+
cooldowns,
|
|
265
|
+
lastEvent: state.lastEvent ? cloneValue(state.lastEvent) : null,
|
|
266
|
+
lastActionEvent: state.lastActionEvent ? cloneValue(state.lastActionEvent) : null,
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function playGraphAction(state, name, playOptions = {}) {
|
|
272
|
+
const actionName = normalizeString(name);
|
|
273
|
+
if (!actionName) {
|
|
274
|
+
return { ok: false, reason: 'invalid_action', reasonCode: 'invalid_action' };
|
|
275
|
+
}
|
|
276
|
+
const action = resolveGraphAction(state.config.actions, actionName);
|
|
277
|
+
if (!action) {
|
|
278
|
+
return { ok: false, reason: 'missing_action', reasonCode: 'missing_action' };
|
|
279
|
+
}
|
|
280
|
+
const cooldownRemaining = Number(state.cooldowns[action.name] || 0);
|
|
281
|
+
if (cooldownRemaining > 0) {
|
|
282
|
+
return {
|
|
283
|
+
ok: false,
|
|
284
|
+
reason: 'action_cooldown',
|
|
285
|
+
reasonCode: 'action_cooldown',
|
|
286
|
+
cooldownRemaining: round6(cooldownRemaining),
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
if (state.activeAction && action.interrupt !== true && state.activeAction.name !== action.name) {
|
|
290
|
+
return {
|
|
291
|
+
ok: false,
|
|
292
|
+
reason: 'action_locked',
|
|
293
|
+
reasonCode: 'action_locked',
|
|
294
|
+
activeAction: state.activeAction.name,
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const playback = buildActionPlayback(action, playOptions);
|
|
299
|
+
const result = state.avatar.playAnimation(playback.clipKeyOrEntry, playback.playOptions);
|
|
300
|
+
if (!result || result.ok !== true) {
|
|
301
|
+
return {
|
|
302
|
+
ok: false,
|
|
303
|
+
reason: 'action_play_failed',
|
|
304
|
+
reasonCode: 'action_play_failed',
|
|
305
|
+
playback: cloneValue(result),
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
state.cooldowns[action.name] = action.cooldownSeconds;
|
|
310
|
+
state.lastTriggeredAction = {
|
|
311
|
+
name: action.name,
|
|
312
|
+
clipKey: action.clipKey,
|
|
313
|
+
cooldownSeconds: round6(action.cooldownSeconds),
|
|
314
|
+
};
|
|
315
|
+
syncGraphState(state);
|
|
316
|
+
|
|
317
|
+
return {
|
|
318
|
+
ok: true,
|
|
319
|
+
action: action.name,
|
|
320
|
+
playback: cloneValue(result),
|
|
321
|
+
state: buildGraphSnapshot(state),
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function buildActionPlayback(action, playOptions = {}) {
|
|
326
|
+
const overrides = isPlainObject(playOptions) ? playOptions : {};
|
|
327
|
+
const clipKeyOrEntry = action.entry ?? action.clipKey;
|
|
328
|
+
return {
|
|
329
|
+
clipKeyOrEntry,
|
|
330
|
+
playOptions: {
|
|
331
|
+
holdSeconds: finiteOr(overrides.holdSeconds, action.holdSeconds),
|
|
332
|
+
waitForCompletion: overrides.waitForCompletion === true || action.waitForCompletion === true,
|
|
333
|
+
interrupt: overrides.interrupt !== false && action.interrupt === true,
|
|
334
|
+
loop: Object.prototype.hasOwnProperty.call(overrides, 'loop')
|
|
335
|
+
? overrides.loop === true
|
|
336
|
+
: action.loop,
|
|
337
|
+
speed: finiteOr(overrides.speed, action.speed),
|
|
338
|
+
transitionSeconds: finiteOr(overrides.transitionSeconds, action.transitionSeconds),
|
|
339
|
+
key: typeof overrides.key === 'string' && overrides.key.trim().length > 0
|
|
340
|
+
? overrides.key.trim()
|
|
341
|
+
: action.name,
|
|
342
|
+
},
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function reduceCooldowns(state, dtSeconds) {
|
|
347
|
+
const delta = Number(dtSeconds);
|
|
348
|
+
if (!Number.isFinite(delta) || delta <= 0) return;
|
|
349
|
+
for (const name of Object.keys(state.cooldowns)) {
|
|
350
|
+
state.cooldowns[name] = Math.max(0, Number(state.cooldowns[name] || 0) - delta);
|
|
351
|
+
if (state.cooldowns[name] <= 0) {
|
|
352
|
+
delete state.cooldowns[name];
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function syncGraphState(state, avatarSnapshot = null) {
|
|
358
|
+
const avatarState = cloneValue(avatarSnapshot || state.avatar.getState());
|
|
359
|
+
state.lastAvatarState = avatarState;
|
|
360
|
+
|
|
361
|
+
const overrideKey = normalizeString(avatarState?.animation?.overrideKey);
|
|
362
|
+
const nextAction = overrideKey ? resolveGraphAction(state.config.actions, overrideKey) : null;
|
|
363
|
+
|
|
364
|
+
if (state.activeAction && !nextAction) {
|
|
365
|
+
state.lastCompletedAction = {
|
|
366
|
+
name: state.activeAction.name,
|
|
367
|
+
clipKey: state.activeAction.clipKey,
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
state.activeAction = nextAction
|
|
372
|
+
? {
|
|
373
|
+
name: nextAction.name,
|
|
374
|
+
clipKey: nextAction.clipKey,
|
|
375
|
+
cooldownRemaining: round6(Number(state.cooldowns[nextAction.name] || 0)),
|
|
376
|
+
}
|
|
377
|
+
: null;
|
|
378
|
+
|
|
379
|
+
return avatarState;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function addGraphListener(state, callback) {
|
|
383
|
+
if (typeof callback !== 'function') {
|
|
384
|
+
throw new TypeError('Avatar animation graph listeners must be functions.');
|
|
385
|
+
}
|
|
386
|
+
const listener = {
|
|
387
|
+
id: state.nextListenerId++,
|
|
388
|
+
callback,
|
|
389
|
+
};
|
|
390
|
+
state.listeners.push(listener);
|
|
391
|
+
return () => {
|
|
392
|
+
const index = state.listeners.indexOf(listener);
|
|
393
|
+
if (index >= 0) state.listeners.splice(index, 1);
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function resolveGraphAction(actionMap, name) {
|
|
398
|
+
const normalizedName = normalizeString(name);
|
|
399
|
+
if (!normalizedName || !isPlainObject(actionMap)) return null;
|
|
400
|
+
const direct = actionMap[normalizedName];
|
|
401
|
+
if (direct) return direct;
|
|
402
|
+
for (const entry of Object.values(actionMap)) {
|
|
403
|
+
if (entry && entry.clipKey === normalizedName) {
|
|
404
|
+
return entry;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return null;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function normalizeRuntimeEvent(event, actionMap) {
|
|
411
|
+
const normalized = isPlainObject(event) ? cloneValue(event) : {};
|
|
412
|
+
const action = resolveGraphAction(actionMap, normalized.clipKey || normalized.name || '');
|
|
413
|
+
return {
|
|
414
|
+
...normalized,
|
|
415
|
+
action: action
|
|
416
|
+
? {
|
|
417
|
+
name: action.name,
|
|
418
|
+
clipKey: action.clipKey,
|
|
419
|
+
}
|
|
420
|
+
: null,
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function mergeGraphConfig(previous, patch) {
|
|
425
|
+
const nextPatch = normalizeAvatarAnimationGraphConfig({
|
|
426
|
+
...collectAvatarCreationOptions(previous.avatarOptions || {}),
|
|
427
|
+
...cloneValue(patch),
|
|
428
|
+
});
|
|
429
|
+
return {
|
|
430
|
+
avatar: previous.avatar,
|
|
431
|
+
avatarOptions: mergePlainObjects(previous.avatarOptions, nextPatch.avatarOptions),
|
|
432
|
+
animations: {
|
|
433
|
+
...cloneValue(previous.animations),
|
|
434
|
+
...cloneValue(nextPatch.animations),
|
|
435
|
+
},
|
|
436
|
+
animationState: {
|
|
437
|
+
...cloneValue(previous.animationState),
|
|
438
|
+
...cloneValue(nextPatch.animationState),
|
|
439
|
+
},
|
|
440
|
+
sockets: {
|
|
441
|
+
...cloneValue(previous.sockets),
|
|
442
|
+
...cloneValue(nextPatch.sockets),
|
|
443
|
+
},
|
|
444
|
+
actions: {
|
|
445
|
+
...cloneValue(previous.actions),
|
|
446
|
+
...cloneValue(nextPatch.actions),
|
|
447
|
+
},
|
|
448
|
+
onAnimationEvent: nextPatch.onAnimationEvent || previous.onAnimationEvent || null,
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function collectAvatarCreationOptions(config) {
|
|
453
|
+
const source = isPlainObject(config) ? config : {};
|
|
454
|
+
const out = {};
|
|
455
|
+
const directKeys = [
|
|
456
|
+
'position',
|
|
457
|
+
'radius',
|
|
458
|
+
'height',
|
|
459
|
+
'stepHeight',
|
|
460
|
+
'slopeLimit',
|
|
461
|
+
'gravity',
|
|
462
|
+
'moveSpeed',
|
|
463
|
+
'runSpeed',
|
|
464
|
+
'jumpSpeed',
|
|
465
|
+
'facingYaw',
|
|
466
|
+
'spawn',
|
|
467
|
+
'sceneNodeId',
|
|
468
|
+
'importId',
|
|
469
|
+
'body',
|
|
470
|
+
];
|
|
471
|
+
for (const key of directKeys) {
|
|
472
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
473
|
+
out[key] = cloneValue(source[key]);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (isPlainObject(source.visual)) out.visual = cloneValue(source.visual);
|
|
477
|
+
if (isPlainObject(source.camera)) out.camera = cloneValue(source.camera);
|
|
478
|
+
return out;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
function listConfiguredLocomotionKeys(animationMap) {
|
|
482
|
+
return DEFAULT_AVATAR_LOCOMOTION_KEYS.filter((key) => Object.prototype.hasOwnProperty.call(animationMap, key));
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
function normalizeAnimationMap(animations) {
|
|
486
|
+
if (!isPlainObject(animations)) return {};
|
|
487
|
+
const out = {};
|
|
488
|
+
for (const [key, value] of Object.entries(animations)) {
|
|
489
|
+
const normalizedKey = normalizeString(key);
|
|
490
|
+
if (!normalizedKey) continue;
|
|
491
|
+
out[normalizedKey] = cloneValue(value);
|
|
492
|
+
}
|
|
493
|
+
return out;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
function normalizeAnimationState(animationState) {
|
|
497
|
+
if (!isPlainObject(animationState)) return {};
|
|
498
|
+
const out = {};
|
|
499
|
+
if (Object.prototype.hasOwnProperty.call(animationState, 'walkThreshold')) {
|
|
500
|
+
out.walkThreshold = clamp01(animationState.walkThreshold, 0.1);
|
|
501
|
+
}
|
|
502
|
+
if (Object.prototype.hasOwnProperty.call(animationState, 'runThreshold')) {
|
|
503
|
+
out.runThreshold = Math.max(
|
|
504
|
+
Object.prototype.hasOwnProperty.call(out, 'walkThreshold') ? out.walkThreshold : 0,
|
|
505
|
+
clamp01(animationState.runThreshold, 0.82),
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
if (Object.prototype.hasOwnProperty.call(animationState, 'jumpVelocityThreshold')) {
|
|
509
|
+
out.jumpVelocityThreshold = finiteOr(animationState.jumpVelocityThreshold, 0.2);
|
|
510
|
+
}
|
|
511
|
+
if (Object.prototype.hasOwnProperty.call(animationState, 'landHoldSeconds')) {
|
|
512
|
+
out.landHoldSeconds = Math.max(0, finiteOr(animationState.landHoldSeconds, 0.14));
|
|
513
|
+
}
|
|
514
|
+
return out;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function normalizeSocketMap(sockets) {
|
|
518
|
+
if (!isPlainObject(sockets)) return {};
|
|
519
|
+
const out = {};
|
|
520
|
+
for (const [name, value] of Object.entries(sockets)) {
|
|
521
|
+
const normalizedName = normalizeString(name);
|
|
522
|
+
if (!normalizedName) continue;
|
|
523
|
+
out[normalizedName] = cloneValue(value);
|
|
524
|
+
}
|
|
525
|
+
return out;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
function normalizeActionMap(actions, animationMap) {
|
|
529
|
+
const out = {};
|
|
530
|
+
if (isPlainObject(actions)) {
|
|
531
|
+
for (const [name, value] of Object.entries(actions)) {
|
|
532
|
+
const normalized = normalizeActionDefinition(name, value);
|
|
533
|
+
if (!normalized) continue;
|
|
534
|
+
out[normalized.name] = normalized;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
for (const fallbackName of DEFAULT_AVATAR_ACTION_KEYS) {
|
|
538
|
+
if (out[fallbackName]) continue;
|
|
539
|
+
if (!Object.prototype.hasOwnProperty.call(animationMap, fallbackName)) continue;
|
|
540
|
+
const normalized = normalizeActionDefinition(fallbackName, animationMap[fallbackName]);
|
|
541
|
+
if (!normalized) continue;
|
|
542
|
+
out[normalized.name] = normalized;
|
|
543
|
+
}
|
|
544
|
+
return out;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
function normalizeActionDefinition(name, value) {
|
|
548
|
+
const normalizedName = normalizeString(name);
|
|
549
|
+
if (!normalizedName) return null;
|
|
550
|
+
|
|
551
|
+
if (value === true || value == null) {
|
|
552
|
+
return createActionDefinition(normalizedName, normalizedName, null, {});
|
|
553
|
+
}
|
|
554
|
+
if (typeof value === 'string') {
|
|
555
|
+
return createActionDefinition(normalizedName, value.trim(), null, {});
|
|
556
|
+
}
|
|
557
|
+
if (!isPlainObject(value)) {
|
|
558
|
+
return null;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
const clipKey = normalizeString(value.clipKey)
|
|
562
|
+
|| normalizeString(value.key)
|
|
563
|
+
|| normalizeString(value.animation)
|
|
564
|
+
|| normalizedName;
|
|
565
|
+
const entry = hasActionEntryShape(value)
|
|
566
|
+
? cloneValue(value)
|
|
567
|
+
: null;
|
|
568
|
+
|
|
569
|
+
return createActionDefinition(normalizedName, clipKey, entry, value);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
function createActionDefinition(name, clipKey, entry, options) {
|
|
573
|
+
const source = isPlainObject(options) ? options : {};
|
|
574
|
+
return {
|
|
575
|
+
name,
|
|
576
|
+
clipKey,
|
|
577
|
+
entry,
|
|
578
|
+
cooldownSeconds: Math.max(0, finiteOr(source.cooldownSeconds, 0)),
|
|
579
|
+
holdSeconds: source.holdSeconds === Infinity ? Infinity : Math.max(0, finiteOr(source.holdSeconds, 0)),
|
|
580
|
+
waitForCompletion: source.waitForCompletion !== false,
|
|
581
|
+
interrupt: source.interrupt !== false,
|
|
582
|
+
loop: source.loop === true,
|
|
583
|
+
speed: finiteOr(source.speed, 1),
|
|
584
|
+
transitionSeconds: Math.max(0, finiteOr(source.transitionSeconds, 0.12)),
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
function hasActionEntryShape(value) {
|
|
589
|
+
if (!isPlainObject(value)) return false;
|
|
590
|
+
return (
|
|
591
|
+
Object.prototype.hasOwnProperty.call(value, 'clipId')
|
|
592
|
+
|| Object.prototype.hasOwnProperty.call(value, 'importId')
|
|
593
|
+
|| Object.prototype.hasOwnProperty.call(value, 'animation')
|
|
594
|
+
|| Object.prototype.hasOwnProperty.call(value, 'events')
|
|
595
|
+
|| Object.prototype.hasOwnProperty.call(value, 'tags')
|
|
596
|
+
|| Object.prototype.hasOwnProperty.call(value, 'loop')
|
|
597
|
+
|| Object.prototype.hasOwnProperty.call(value, 'speed')
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
function isAvatarRuntime(value) {
|
|
602
|
+
return isPlainObject(value)
|
|
603
|
+
&& AVATAR_RUNTIME_METHODS.every((method) => typeof value[method] === 'function');
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
function isPlainObject(value) {
|
|
607
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
function normalizeString(value) {
|
|
611
|
+
if (typeof value !== 'string') return null;
|
|
612
|
+
const trimmed = value.trim();
|
|
613
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
function finiteOr(value, fallback) {
|
|
617
|
+
const numeric = Number(value);
|
|
618
|
+
return Number.isFinite(numeric) ? numeric : fallback;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
function clamp01(value, fallback) {
|
|
622
|
+
return Math.min(1, Math.max(0, finiteOr(value, fallback)));
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
function round6(value) {
|
|
626
|
+
return Number(Number(value || 0).toFixed(6));
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
function cloneValue(value) {
|
|
630
|
+
if (Array.isArray(value)) {
|
|
631
|
+
return value.map((entry) => cloneValue(entry));
|
|
632
|
+
}
|
|
633
|
+
if (isPlainObject(value)) {
|
|
634
|
+
const out = {};
|
|
635
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
636
|
+
out[key] = cloneValue(entry);
|
|
637
|
+
}
|
|
638
|
+
return out;
|
|
639
|
+
}
|
|
640
|
+
return value;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
function mergePlainObjects(left, right) {
|
|
644
|
+
return {
|
|
645
|
+
...(isPlainObject(left) ? cloneValue(left) : {}),
|
|
646
|
+
...(isPlainObject(right) ? cloneValue(right) : {}),
|
|
647
|
+
};
|
|
648
|
+
}
|