@zylem/game-lib 0.8.8 → 0.9.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 +7 -1
- package/dist/actions.d.ts +2 -2
- package/dist/actions.js +1 -1
- package/dist/api/game-lib.api.json +35786 -18973
- package/dist/api/game-lib.api.md +1209 -13
- package/dist/api/game-lib.d.ts +1609 -7
- package/dist/api/game-lib.typedoc.json +220861 -97409
- package/dist/audio.d.ts +193 -1
- package/dist/audio.js +1 -1
- package/dist/behavior.js +1 -1
- package/dist/bridge.d.ts +46 -6
- package/dist/bridge.js +1 -1
- package/dist/catalog.d.ts +91 -3
- package/dist/catalog.js +1 -1
- package/dist/chunk-2HSR5XDQ.js +1 -0
- package/dist/chunk-2MHB4X6B.js +24 -0
- package/dist/chunk-2PFNNGTV.js +1 -0
- package/dist/chunk-2XMG3NJS.js +1 -0
- package/dist/chunk-4CZZZCFB.js +9 -0
- package/dist/{chunk-7NYP4YAG.js → chunk-6FGXC4T6.js} +1 -1
- package/dist/chunk-6XFXPIVB.js +1 -0
- package/dist/{chunk-CBUQBP2U.js → chunk-BQRMYLYD.js} +1 -1
- package/dist/chunk-FZNEWOC5.js +1 -0
- package/dist/chunk-GPCSX3M6.js +1 -0
- package/dist/chunk-HISTSRAL.js +1 -0
- package/dist/chunk-K3NNXZIJ.js +1 -0
- package/dist/chunk-KP6DLLJO.js +1 -0
- package/dist/{chunk-JNFFTNMH.js → chunk-KSEP7AUF.js} +1 -1
- package/dist/{chunk-YOVE25NW.js → chunk-LI43BZQN.js} +1 -1
- package/dist/chunk-LSFWI46T.js +1 -0
- package/dist/chunk-NVVLLWIM.js +1 -0
- package/dist/chunk-QGIYILYI.js +1 -0
- package/dist/chunk-STVEILJJ.js +1 -0
- package/dist/chunk-UUOPT2N4.js +1 -0
- package/dist/chunk-VMXSE3EC.js +0 -0
- package/dist/chunk-VSFULLND.js +1 -0
- package/dist/chunk-VUJXR5K5.js +1 -0
- package/dist/chunk-WOT6VMZA.js +1 -0
- package/dist/chunk-YNX3Q3CL.js +1 -0
- package/dist/chunk-YQS7CGXE.js +1 -0
- package/dist/chunk-ZZO4CKRU.js +1 -0
- package/dist/cinematics.d.ts +279 -0
- package/dist/cinematics.js +1 -0
- package/dist/core.d.ts +13 -10
- package/dist/core.js +1 -1
- package/dist/cutscene-definition-C479fkei.d.ts +509 -0
- package/dist/{debug-state-CpnNRUFh.d.ts → debug-state-Cg3f5FB6.d.ts} +1 -1
- package/dist/debug.d.ts +3 -2
- package/dist/debug.js +1 -1
- package/dist/{entity-XZNGBeca.d.ts → entity-XqvuWgPm.d.ts} +54 -0
- package/dist/{entity-type-map-CkkFMSrL.d.ts → entity-type-map-CrsrKT8c.d.ts} +13 -4
- package/dist/entity.d.ts +4 -3
- package/dist/entity.js +1 -1
- package/dist/events.js +1 -1
- package/dist/game-9PjI5z2p.d.ts +652 -0
- package/dist/game-default-WBKQCEDJ.js +1 -0
- package/dist/globals.js +1 -1
- package/dist/graphics.d.ts +1 -1
- package/dist/graphics.js +1 -1
- package/dist/input-ui.js +1 -1
- package/dist/input.js +1 -1
- package/dist/public.d.ts +14 -8
- package/dist/public.js +1 -1
- package/dist/runtime.js +1 -1
- package/dist/schema/cutscene.schema.json +782 -0
- package/dist/schema/entity.schema.json +24 -24
- package/dist/schema/game-config.schema.json +10 -10
- package/dist/schema/song.schema.json +430 -0
- package/dist/schema/stage.schema.json +29 -29
- package/dist/schema.d.ts +2 -0
- package/dist/schema.js +1 -1
- package/dist/selection-bounds-BKmSo9aG.d.ts +50 -0
- package/dist/song-definition-rEKksP0B.d.ts +263 -0
- package/dist/song-player-7QPLFLAS.js +1 -0
- package/dist/{game-BPOr7zTB.d.ts → stage-BuGkjZnr.d.ts} +90 -644
- package/dist/web-components.d.ts +7 -5
- package/dist/web-components.js +1 -1
- package/dist/{zylem-camera-DZTpPOiD.d.ts → zylem-camera-Baf5vH8Z.d.ts} +8 -0
- package/package.json +25 -16
- package/dist/chunk-34MYRTRP.js +0 -9
- package/dist/chunk-AE3CTVHY.js +0 -1
- package/dist/chunk-BMRFDDMR.js +0 -1
- package/dist/chunk-EVMLNMGU.js +0 -1
- package/dist/chunk-F5LROYZL.js +0 -24
- package/dist/chunk-GHJQ2HKI.js +0 -1
- package/dist/chunk-HNCTOJP7.js +0 -1
- package/dist/chunk-IBJLPJLE.js +0 -1
- package/dist/chunk-MXO4VGDB.js +0 -1
- package/dist/chunk-QDQ4QMAI.js +0 -1
- package/dist/chunk-SAQA4SXW.js +0 -1
- package/dist/chunk-XK63E4SX.js +0 -1
- package/dist/chunk-ZRT3ZQVH.js +0 -1
- package/dist/chunk-ZTYNZ2N2.js +0 -1
- package/dist/game-default-7HCJJF5S.js +0 -1
- /package/dist/{chunk-MSCVL5OK.js → chunk-ELQN62PQ.js} +0 -0
package/dist/web-components.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { G as Game, D as DeviceProfile } from './game-
|
|
2
|
-
import { v as DebugTools } from './debug-state-
|
|
1
|
+
import { G as Game, D as DeviceProfile } from './game-9PjI5z2p.js';
|
|
2
|
+
import { v as DebugTools } from './debug-state-Cg3f5FB6.js';
|
|
3
3
|
import './base-node-life-cycle-BK9xebT9.js';
|
|
4
4
|
import 'three';
|
|
5
5
|
import './stage-transition-CmGpV4tc.js';
|
|
6
6
|
import './game-interfaces-vF5sRi1n.js';
|
|
7
7
|
import './base-node-idopiSw5.js';
|
|
8
|
-
import './
|
|
9
|
-
import './entity-
|
|
8
|
+
import './stage-BuGkjZnr.js';
|
|
9
|
+
import './entity-type-map-CrsrKT8c.js';
|
|
10
|
+
import './entity-XqvuWgPm.js';
|
|
10
11
|
import '@zylem/behaviors/core';
|
|
11
12
|
import './simulation-body-zQw-emOr.js';
|
|
12
13
|
import './vector-D3eDzvcA.js';
|
|
@@ -15,10 +16,11 @@ import 'three/webgpu';
|
|
|
15
16
|
import './collision-builder-BckxkdmA.js';
|
|
16
17
|
import './events.js';
|
|
17
18
|
import 'mitt';
|
|
19
|
+
import './selection-bounds-BKmSo9aG.js';
|
|
18
20
|
import './entity-BIf_a4dl.js';
|
|
19
21
|
import '@zylem/behaviors/particle-emitter';
|
|
20
22
|
import 'three/addons/lines/webgpu/Line2.js';
|
|
21
|
-
import './zylem-camera-
|
|
23
|
+
import './zylem-camera-Baf5vH8Z.js';
|
|
22
24
|
import '@zylem/bridge';
|
|
23
25
|
import './default-controls-CAKJ5zlo.js';
|
|
24
26
|
|
package/dist/web-components.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-4CZZZCFB.js";import"./chunk-GPCSX3M6.js";import"./chunk-WOT6VMZA.js";export{a as ZylemGameElement};
|
|
@@ -137,6 +137,14 @@ declare class RendererManager {
|
|
|
137
137
|
* its pipeline is set up. Call before tearing down the outgoing stage.
|
|
138
138
|
*/
|
|
139
139
|
beginSnapshotTransition(resolved: ResolvedStageTransition, scene: Scene, camera: Camera): void;
|
|
140
|
+
/**
|
|
141
|
+
* Blend from the current picture into the frames that follow without
|
|
142
|
+
* changing stage: snapshot the outgoing frame, then rebuild the pipeline
|
|
143
|
+
* so the blend is composed immediately. Used by cutscene scene changes
|
|
144
|
+
* and any in-stage "cut" the game wants to soften. Move the camera right
|
|
145
|
+
* after calling this so the snapshot shows the outgoing shot.
|
|
146
|
+
*/
|
|
147
|
+
beginInStageTransition(resolved: ResolvedStageTransition, scene: Scene, camera: Camera): void;
|
|
140
148
|
/**
|
|
141
149
|
* Complete the active transition immediately: rebuild the normal
|
|
142
150
|
* pipeline, release transition resources, and fire `onComplete`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zylem/game-lib",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A powerful and easy-to-use framework for creating simple 3D digital interactive applications using TypeScript.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,6 +33,10 @@
|
|
|
33
33
|
"types": "./dist/audio.d.ts",
|
|
34
34
|
"import": "./dist/audio.js"
|
|
35
35
|
},
|
|
36
|
+
"./cinematics": {
|
|
37
|
+
"types": "./dist/cinematics.d.ts",
|
|
38
|
+
"import": "./dist/cinematics.js"
|
|
39
|
+
},
|
|
36
40
|
"./globals": {
|
|
37
41
|
"types": "./dist/globals.d.ts",
|
|
38
42
|
"import": "./dist/globals.js"
|
|
@@ -89,7 +93,9 @@
|
|
|
89
93
|
"./schema/stage": "./dist/schema/stage.schema.json",
|
|
90
94
|
"./schema/game-config": "./dist/schema/game-config.schema.json",
|
|
91
95
|
"./schema/stage-config": "./dist/schema/stage-config.schema.json",
|
|
92
|
-
"./schema/input-config": "./dist/schema/input-config.schema.json"
|
|
96
|
+
"./schema/input-config": "./dist/schema/input-config.schema.json",
|
|
97
|
+
"./schema/song": "./dist/schema/song.schema.json",
|
|
98
|
+
"./schema/cutscene": "./dist/schema/cutscene.schema.json"
|
|
93
99
|
},
|
|
94
100
|
"keywords": [
|
|
95
101
|
"game",
|
|
@@ -115,23 +121,26 @@
|
|
|
115
121
|
"lint": "biome check .",
|
|
116
122
|
"typecheck": "tsc --noEmit",
|
|
117
123
|
"test": "vitest --reporter=verbose",
|
|
118
|
-
"coverage": "vitest run --coverage"
|
|
124
|
+
"coverage": "vitest run --coverage",
|
|
125
|
+
"zw:postunlink": "pnpm -w run deps:latest",
|
|
126
|
+
"zw:prerelease": "pnpm -w run deps:latest --check"
|
|
119
127
|
},
|
|
120
128
|
"dependencies": {
|
|
121
129
|
"@dgreenheck/three-pinata": "^2.0.1",
|
|
122
|
-
"@sinclair/typebox": "^0.34.
|
|
123
|
-
"@types/howler": "^2.2.
|
|
130
|
+
"@sinclair/typebox": "^0.34.52",
|
|
131
|
+
"@types/howler": "^2.2.13",
|
|
124
132
|
"@zylem/behaviors": "^0.8.8",
|
|
125
|
-
"@zylem/bridge": "
|
|
133
|
+
"@zylem/bridge": "workspace:^",
|
|
126
134
|
"comlink": "^4.4.2",
|
|
127
135
|
"howler": "^2.2.4",
|
|
128
|
-
"idb-keyval": "^6.2.
|
|
129
|
-
"msgpackr": "^1.11.
|
|
130
|
-
"nanoid": "^5.1.
|
|
136
|
+
"idb-keyval": "^6.2.6",
|
|
137
|
+
"msgpackr": "^1.11.14",
|
|
138
|
+
"nanoid": "^5.1.16",
|
|
131
139
|
"stats.js": "^0.17.0",
|
|
132
|
-
"three": "^0.185.
|
|
140
|
+
"three": "^0.185.1",
|
|
141
|
+
"tone": "^15.1.22",
|
|
133
142
|
"typescript-fsm": "^1.6.0",
|
|
134
|
-
"valtio": "^2.1.
|
|
143
|
+
"valtio": "^2.1.8"
|
|
135
144
|
},
|
|
136
145
|
"peerDependencies": {
|
|
137
146
|
"howler": "^2.2.4",
|
|
@@ -140,10 +149,10 @@
|
|
|
140
149
|
"valtio": "^2.1.7"
|
|
141
150
|
},
|
|
142
151
|
"devDependencies": {
|
|
143
|
-
"@microsoft/api-extractor": "^7.58.
|
|
144
|
-
"@types/node": "^20.19.
|
|
152
|
+
"@microsoft/api-extractor": "^7.58.13",
|
|
153
|
+
"@types/node": "^20.19.43",
|
|
145
154
|
"@types/stats.js": "^0.17.4",
|
|
146
|
-
"@types/three": "^0.185.
|
|
155
|
+
"@types/three": "^0.185.4",
|
|
147
156
|
"@typescript/native": "npm:typescript@7.0.2",
|
|
148
157
|
"happy-dom": "^18.0.1",
|
|
149
158
|
"jsdom": "^27.2.0",
|
|
@@ -151,7 +160,7 @@
|
|
|
151
160
|
"tsup": "^8.5.1",
|
|
152
161
|
"typedoc": "^0.28.20",
|
|
153
162
|
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
154
|
-
"vite-plugin-solid": "^2.11.
|
|
155
|
-
"vitest": "^4.0.
|
|
163
|
+
"vite-plugin-solid": "^2.11.14",
|
|
164
|
+
"vitest": "^4.0.18"
|
|
156
165
|
}
|
|
157
166
|
}
|
package/dist/chunk-34MYRTRP.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import{d as s,h as o,j as a}from"./chunk-EVMLNMGU.js";import{announceBridgeReady as c}from"@zylem/bridge";var n=class r extends HTMLElement{_game=null;_state={};container;resizeObserver=null;_viewportProfile="auto";static HOST_CONFIG_MARKER=Symbol("zylem:host-config");constructor(){super(),this.attachShadow({mode:"open"});let e=document.createElement("style");e.textContent=`
|
|
2
|
-
:host {
|
|
3
|
-
display: block;
|
|
4
|
-
width: 100%;
|
|
5
|
-
height: 100%;
|
|
6
|
-
min-width: 0;
|
|
7
|
-
min-height: 0;
|
|
8
|
-
}
|
|
9
|
-
`,this.container=document.createElement("div"),this.container.style.width="100%",this.container.style.height="100%",this.container.style.position="relative",this.container.style.outline="none",this.container.tabIndex=0,this.shadowRoot.append(e,this.container)}focus(){this.container.focus()}connectedCallback(){typeof ResizeObserver<"u"&&!this.resizeObserver&&(this.resizeObserver=new ResizeObserver(()=>{this.syncDisplayRuntime()}),this.resizeObserver.observe(this)),this.syncDisplayRuntime()}set game(e){this._game&&this._game.dispose(),this._game=e,this.attachHostContainer(e),this.syncDisplayRuntime(),e.start(),c(this)}get game(){return this._game}set state(e){this._state=e,this.syncDebugState(),this.syncToolbarState()}get state(){return this._state}set viewportProfile(e){let t=e==="mobile"||e==="desktop"?e:"auto";this._viewportProfile!==t&&(this._viewportProfile=t,this.syncDisplayRuntime())}get viewportProfile(){return this._viewportProfile}static get observedAttributes(){return["viewport-profile"]}attributeChangedCallback(e,t,i){e==="viewport-profile"&&(this.viewportProfile=i??"auto")}syncDebugState(){let e=this._state.gameState?.debugFlag;e!==void 0&&(s.enabled=e)}syncToolbarState(){let{tool:e,paused:t}=this._state.toolbarState??{};e!==void 0&&a(e),t!==void 0&&o(t)}disconnectedCallback(){this.resizeObserver?.disconnect(),this.resizeObserver=null,this._game&&(this._game.dispose(),this._game=null)}attachHostContainer(e){let t=r.HOST_CONFIG_MARKER,i=e.options.find(l=>!!l?.[t]);if(i){i.container=this.container;return}e.options.push({container:this.container,[t]:!0})}syncDisplayRuntime(){if(!this._game)return;let e=this.getBoundingClientRect(),t=Math.round(e.width||this.clientWidth||0),i=Math.round(e.height||this.clientHeight||0);this._game.setDisplayRuntime({deviceProfile:this._viewportProfile,viewportSize:t>0&&i>0?{width:t,height:i}:void 0})}};customElements.define("zylem-game",n);export{n as a};
|
package/dist/chunk-AE3CTVHY.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var n=new Map,i=new Set;function r(){for(let t of i)try{t()}catch(e){console.error("[zylem] entity registry listener failed",e)}}function y(t){return n.set(t.id,t),r(),()=>{n.get(t.id)===t&&(n.delete(t.id),r())}}function p(t){for(let e of t)n.set(e.id,e);return r(),()=>{for(let e of t)n.get(e.id)===e&&n.delete(e.id);r()}}function c(t){return n.get(t)??null}function o(){return[...n.values()]}function s(){return o().map(({create:t,...e})=>e)}function a(t){return i.add(t),()=>i.delete(t)}function d(){n.clear(),r()}export{y as a,p as b,c,o as d,s as e,a as f,d as g};
|
package/dist/chunk-BMRFDDMR.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b as R,c as gt,d as ft,e as bt,f as xt,g as Ot,h as wt,j as St,r as p,s as f,t as c,v as b,w as N,x as $,y as D,z as T}from"./chunk-SAQA4SXW.js";import{j as vt}from"./chunk-7NYP4YAG.js";import{d as V}from"./chunk-4QLJUQSJ.js";import{b as j,c as dt,d as yt,h as q,i as E}from"./chunk-7WRQ2UAN.js";import{BoxGeometry as qt,CapsuleGeometry as Jt,ConeGeometry as Ct,CylinderGeometry as Kt,Mesh as z,MeshStandardMaterial as Qt,SphereGeometry as te}from"three";function B(e,t=Symbol("mesh")){if(e.material||e.color){let i=new vt;if(i.build({...e.material,color:e.color??e.material?.color},t),i.materials.length>0)return i.materials}return[new Qt]}function L(e,t){if(t.position){let i=q(t.position,dt);e.position.set(i.x,i.y,i.z)}return e.castShadow=!0,e.receiveShadow=!0,e}function Mt(e={}){let t=q(e.size,yt),i=new qt(t.x,t.y,t.z),o=B(e);return L(new z(i,o.at(-1)),e)}function Pt(e={}){let t=new te(e.radius??1),i=B(e);return L(new z(t,i.at(-1)),e)}function Zt(e={}){let t=new Ct(e.radius??1,e.height??2,e.radialSegments??32),i=B(e);return L(new z(t,i.at(-1)),e)}function Et(e={}){let t=new Ct(e.radius??1,e.height??2,4),i=B(e);return L(new z(t,i.at(-1)),e)}function _t(e={}){let t=new Kt(e.radiusTop??1,e.radiusBottom??1,e.height??2,e.radialSegments??32),i=B(e);return L(new z(t,i.at(-1)),e)}function Rt(e={}){let t=new Jt(e.radius??.5,e.length??1,e.capSegments??10,e.radialSegments??20),i=B(e);return L(new z(t,i.at(-1)),e)}import{Vector3 as se}from"three";import{MeshStandardMaterial as ee,MeshBasicMaterial as ie,MeshPhongMaterial as oe}from"three";function ne(e){return e&&typeof e.getDebugInfo=="function"}var u=class{entity;constructor(t){this.entity=t}getPositionString(){if(this.entity.mesh){let{x:n,y:s,z:l}=this.entity.mesh.position;return`${n.toFixed(2)}, ${s.toFixed(2)}, ${l.toFixed(2)}`}let{x:t,y:i,z:o}=this.entity.options.position||{x:0,y:0,z:0};return`${t.toFixed(2)}, ${i.toFixed(2)}, ${o.toFixed(2)}`}getRotationString(){if(this.entity.mesh){let{x:s,y:l,z:r}=this.entity.mesh.rotation,a=m=>(m*180/Math.PI).toFixed(1);return`${a(s)}\xB0, ${a(l)}\xB0, ${a(r)}\xB0`}let{x:t,y:i,z:o}=this.entity.options.rotation||{x:0,y:0,z:0},n=s=>(s*180/Math.PI).toFixed(1);return`${n(t)}\xB0, ${n(i)}\xB0, ${n(o)}\xB0`}getMaterialInfo(){if(!this.entity.mesh||!this.entity.mesh.material)return{type:"none"};let t=Array.isArray(this.entity.mesh.material)?this.entity.mesh.material[0]:this.entity.mesh.material,i={type:t.type};return(t instanceof ee||t instanceof ie||t instanceof oe)&&(i.color=`#${t.color.getHexString()}`,i.opacity=t.opacity,i.transparent=t.transparent),"roughness"in t&&(i.roughness=t.roughness),"metalness"in t&&(i.metalness=t.metalness),i}getPhysicsInfo(){if(!this.entity.body)return null;let t={type:this.entity.body.bodyType(),mass:this.entity.body.mass(),isEnabled:this.entity.body.isEnabled(),isSleeping:this.entity.body.isSleeping()},i=this.entity.body.linvel();return t.velocity=`${i.x.toFixed(2)}, ${i.y.toFixed(2)}, ${i.z.toFixed(2)}`,t}buildDebugInfo(){let t={name:this.entity.name||this.entity.uuid,uuid:this.entity.uuid,position:this.getPositionString(),rotation:this.getRotationString(),material:this.getMaterialInfo()},i=this.getPhysicsInfo();if(i&&(t.physics=i),ne(this.entity)){let o=this.entity.getDebugInfo();return{...t,...o}}return t}};var Dt={...p,size:new se(1,1,1)},re=Symbol("Box"),J=class e extends c{static type=re;constructor(t){super(),this.options={...Dt,...t}}buildInfo(){let i=new u(this).buildDebugInfo(),{x:o,y:n,z:s}=this.options.size??{x:1,y:1,z:1};return{...i,type:String(e.type),size:`${o}, ${n}, ${s}`}}};function ae(...e){let t=f(e,Dt),i=new J(t);return i.add(Mt({size:t.size,material:t.material,color:t.color}),gt({size:t.size,static:t.collision?.static,sensor:t.collision?.sensor,canSleep:t.collision?.canSleep,ccdEnabled:t.collision?.ccdEnabled,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),b(i,o=>ae(o??{}))}var Tt={...p,radius:1},le=Symbol("Sphere"),K=class e extends c{static type=le;constructor(t){super(),this.options={...Tt,...t}}buildInfo(){let i=new u(this).buildDebugInfo(),o=this.options.radius??1;return{...i,type:String(e.type),radius:o.toFixed(2)}}};function ce(...e){let t=f(e,Tt),i=new K(t);return i.add(Pt({radius:t.radius,material:t.material,color:t.color}),ft({radius:t.radius,static:t.collision?.static,sensor:t.collision?.sensor,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),b(i,o=>ce(o??{}))}var zt={...p,radius:1,height:2,radialSegments:32},he=Symbol("Cone"),Q=class e extends c{static type=he;constructor(t){super(),this.options={...zt,...t}}buildInfo(){let i=new u(this).buildDebugInfo(),o=this.options.radius??1,n=this.options.height??2;return{...i,type:String(e.type),radius:o.toFixed(2),height:n.toFixed(2)}}};function me(...e){let t=f(e,zt),i=new Q(t);return i.add(Zt({radius:t.radius,height:t.height,radialSegments:t.radialSegments,material:t.material,color:t.color}),bt({radius:t.radius,height:t.height,static:t.collision?.static,sensor:t.collision?.sensor,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),b(i,o=>me(o??{}))}var Bt={...p,radius:1,height:2},pe=Symbol("Pyramid"),tt=class e extends c{static type=pe;constructor(t){super(),this.options={...Bt,...t}}buildInfo(){let i=new u(this).buildDebugInfo(),o=this.options.radius??1,n=this.options.height??2;return{...i,type:String(e.type),radius:o.toFixed(2),height:n.toFixed(2)}}};function ue(...e){let t=f(e,Bt),i=new tt(t);return i.add(Et({radius:t.radius,height:t.height,material:t.material,color:t.color}),xt({radius:t.radius,height:t.height,static:t.collision?.static,sensor:t.collision?.sensor,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),b(i,o=>ue(o??{}))}var Lt={...p,radiusTop:1,radiusBottom:1,height:2,radialSegments:32},de=Symbol("Cylinder"),et=class e extends c{static type=de;constructor(t){super(),this.options={...Lt,...t}}buildInfo(){let i=new u(this).buildDebugInfo(),o=this.options.radiusTop??1,n=this.options.radiusBottom??1,s=this.options.height??2;return{...i,type:String(e.type),radiusTop:o.toFixed(2),radiusBottom:n.toFixed(2),height:s.toFixed(2)}}};function ye(...e){let t=f(e,Lt),i=new et(t);return i.add(_t({radiusTop:t.radiusTop,radiusBottom:t.radiusBottom,height:t.height,radialSegments:t.radialSegments,material:t.material,color:t.color}),Ot({radiusTop:t.radiusTop,radiusBottom:t.radiusBottom,height:t.height,static:t.collision?.static,sensor:t.collision?.sensor,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),b(i,o=>ye(o??{}))}var It={...p,radius:.5,length:1,capSegments:10,radialSegments:20},ge=Symbol("Pill"),it=class e extends c{static type=ge;constructor(t){super(),this.options={...It,...t}}buildInfo(){let i=new u(this).buildDebugInfo(),o=this.options.radius??.5,n=this.options.length??1;return{...i,type:String(e.type),radius:o.toFixed(2),length:n.toFixed(2)}}};function fe(...e){let t=f(e,It),i=new it(t);return i.add(Rt({radius:t.radius,length:t.length,capSegments:t.capSegments,radialSegments:t.radialSegments,material:t.material,color:t.color}),wt({radius:t.radius,length:t.length,static:t.collision?.static,sensor:t.collision?.sensor,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),b(i,o=>fe(o??{}))}import{Group as be,RingGeometry as xe}from"three";var kt={...p,innerRadius:0,outerRadius:1,thetaSegments:32},ot=class extends N{collider(t){let i=t.outerRadius??1;return{shape:{type:"cylinder",halfHeight:.1/2,radius:i}}}},nt=class extends ${build(t){let i=t.innerRadius??0,o=t.outerRadius??1,n=t.thetaSegments??32,s=new xe(i,o,n);return s.rotateX(-Math.PI/2),s}},st=class extends D{createEntity(t){return new F(t)}build(){let t=super.build();return t.mesh&&!t.group&&(t.group=new be,t.group.add(t.mesh)),t}},Oe=Symbol("Disk"),F=class e extends c{static type=Oe;constructor(t){super(),this.options={...kt,...t}}buildInfo(){let i=new u(this).buildDebugInfo(),o=this.options.innerRadius??0,n=this.options.outerRadius??1;return{...i,type:String(e.type),innerRadius:o.toFixed(2),outerRadius:n.toFixed(2)}}};function we(...e){return T({args:e,defaultConfig:kt,EntityClass:F,BuilderClass:st,MeshBuilderClass:nt,CollisionBuilderClass:ot,entityType:F.type,cloneFactory:t=>we(t??{})})}import{PlaneGeometry as ve,Vector2 as Ft,Vector3 as Gt}from"three";import{BufferGeometry as Se,Float32BufferAttribute as rt}from"three";var X=class e extends Se{constructor(t=1,i=1,o=1,n=1){super(),this.type="XZPlaneGeometry",this.parameters={width:t,height:i,widthSegments:o,heightSegments:n};let s=t/2,l=i/2,r=Math.floor(o),a=Math.floor(n),m=r+1,C=a+1,M=t/r,x=i/a,O=[],w=[],d=[],P=[];for(let y=0;y<C;y++){let h=y*x-l;for(let S=0;S<m;S++){let Z=S*M-s;w.push(Z,0,h),d.push(0,1,0),P.push(S/r),P.push(1-y/a)}}for(let y=0;y<a;y++)for(let h=0;h<r;h++){let S=h+m*y,Z=h+m*(y+1),g=h+1+m*(y+1),v=h+1+m*y;O.push(S,Z,v),O.push(Z,g,v)}this.setIndex(O),this.setAttribute("position",new rt(w,3)),this.setAttribute("normal",new rt(d,3)),this.setAttribute("uv",new rt(P,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new e(t.width,t.height,t.widthSegments,t.heightSegments)}};var Y=4,Ht={...p,tile:new Ft(10,10),repeat:new Ft(1,1),collision:{static:!0},subdivisions:Y,randomizeHeight:!1,heightScale:1};function At(e){let t=e.subdivisions??Y,i=e.heightMap2D,o=e.heightMap,n=e.subdivisionsX??t,s=e.subdivisionsZ??t;return i&&i.length>0&&i[0]?.length>0?(s=i.length-1,n=i[0].length-1):o&&o.length>0&&(n=o.length-1),{subdivisionsX:n,subdivisionsZ:s}}var at=class extends N{collider(t){let i=E(t.tile,j),{subdivisionsX:o,subdivisionsZ:n}=At(t),s=new Gt(i.x,1,i.y),l=t._builders?.meshBuilder?.heightData??new Float32Array((o+1)*(n+1));return{shape:{type:"heightfield",rows:o,cols:n,heights:l,scale:[s.x,1,s.z]}}}},lt=class extends ${heightData=new Float32Array;columnsRows=new Map;subdivisionsX=Y;subdivisionsZ=Y;build(t){let i=E(t.tile,j),{subdivisionsX:o,subdivisionsZ:n}=At(t);this.subdivisionsX=o,this.subdivisionsZ=n;let s=new Gt(i.x,1,i.y),l=t.heightScale??1,r=new X(s.x,s.z,o,n),a=new ve(s.x,s.z,o,n),m=o>0?s.x/o:1,C=n>0?s.z/n:1,M=r.attributes.position.array,x=a.attributes.position.array,O=new Map,w=t.heightMap2D,d=t.heightMap,P=t.randomizeHeight??!1,y=(h,S)=>h<0?0:h>S?S:h;for(let h=0;h<x.length;h+=3){let S=x[h],Z=x[h+1],g=y(Math.round((S+s.x/2)/m),o),v=y(Math.round((s.z/2-Z)/C),n),_=0;if(w){let ut=w[v];ut&&(_=ut[g]??0)}else d&&d.length>0?_=d[g]??0:P&&(_=Math.random()*4);let k=_*l;x[h+2]=k,M[h+1]=k,O.get(v)||O.set(v,new Map),O.get(v).set(g,k)}return this.columnsRows=O,r}postBuild(){let t=[];for(let i=0;i<=this.subdivisionsX;++i)for(let o=0;o<=this.subdivisionsZ;++o){let n=this.columnsRows.get(o);t.push(n?.get(i)??0)}this.heightData=new Float32Array(t)}},ct=class extends D{createEntity(t){return new G(t)}},Ce=Symbol("Plane"),G=class extends c{static type=Ce;constructor(t){super(),this.options=R(Ht,t)}};function Me(...e){return T({args:e,defaultConfig:Ht,EntityClass:G,BuilderClass:ct,MeshBuilderClass:lt,CollisionBuilderClass:at,entityType:G.type,cloneFactory:t=>Me(t??{})})}import{Vector3 as Pe}from"three";var Vt={...p,size:new Pe(1,1,1),collision:{static:!0}},Ze=Symbol("Zone"),ht=class extends c{static type=Ze;_enteredZone=new Map;_exitedZone=new Map;_zoneEntities=new Map;constructor(t){super(),this.options=R(Vt,t)}handlePostCollision({delta:t}){return this._enteredZone.forEach((i,o)=>{this.exited(t,o)}),this._enteredZone.size>0}handleIntersectionEvent({other:t,delta:i}){this._enteredZone.get(t.uuid)?this.held(i,t):(this.entered(t),this._zoneEntities.set(t.uuid,t))}onEnter(t){return this.options.onEnter=t,this}onHeld(t){return this.options.onHeld=t,this}onExit(t){return this.options.onExit=t,this}entered(t){this._enteredZone.set(t.uuid,1),this.options.onEnter&&this.options.onEnter({self:this,visitor:t,globals:V.globals})}exited(t,i){let o=this._exitedZone.get(i);if(o&&o>1+t){this._exitedZone.delete(i),this._enteredZone.delete(i);let n=this._zoneEntities.get(i);this.options.onExit&&this.options.onExit({self:this,visitor:n,globals:V.globals});return}this._exitedZone.set(i,1+t)}held(t,i){let o=this._enteredZone.get(i.uuid)??0;this._enteredZone.set(i.uuid,o+t),this._exitedZone.set(i.uuid,1),this.options.onHeld&&this.options.onHeld({delta:t,self:this,visitor:i,globals:V.globals,heldTime:o})}};function Ee(...e){let t=f(e,Vt),i=new ht(t);return i.add(St({size:t.size,static:t.collision?.static??!0,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),b(i,o=>Ee(o??{}))}import{Color as Nt,Group as _e,Sprite as Re,SpriteMaterial as De,CanvasTexture as $t,LinearFilter as W,Vector2 as U,ClampToEdgeWrapping as Xt,ShaderMaterial as Yt,Mesh as Te,PlaneGeometry as ze,Vector3 as Wt}from"three";var I={position:void 0,width:120,height:48,fillColor:"#FFFFFF",strokeColor:null,strokeWidth:0,radius:0,padding:0,stickToViewport:!0,screenPosition:new U(24,24),zDistance:1,anchor:new U(0,0)},mt=class extends D{createEntity(t){return new H(t)}},Be=Symbol("Rect"),H=class e extends c{static type=Be;_sprite=null;_mesh=null;_texture=null;_canvas=null;_ctx=null;_cameraRef=null;_lastCanvasW=0;_lastCanvasH=0;constructor(t){super(),this.options=R(I,t),this.options.screenPosition=E(this.options.screenPosition,I.screenPosition),this.options.anchor=E(this.options.anchor,I.anchor),this.group=new _e,this.createSprite(),this.prependSetup(this.rectSetup.bind(this)),this.prependUpdate(this.rectUpdate.bind(this))}createSprite(){this._canvas=document.createElement("canvas"),this._ctx=this._canvas.getContext("2d"),this._texture=new $t(this._canvas),this._texture.minFilter=W,this._texture.magFilter=W;let t=new De({map:this._texture,transparent:!0,depthTest:!1,depthWrite:!1,alphaTest:.5});this._sprite=new Re(t),this.group?.add(this._sprite),this.redrawRect()}redrawRect(){if(!this._canvas||!this._ctx)return;let t=Math.max(2,Math.floor(this.options.width??120)),i=Math.max(2,Math.floor(this.options.height??48)),o=this.options.padding??0,n=this.options.strokeWidth??0,s=t+o*2+n,l=i+o*2+n,r=Math.max(2,s),a=Math.max(2,l),m=r!==this._lastCanvasW||a!==this._lastCanvasH;this._canvas.width=r,this._canvas.height=a,this._lastCanvasW=r,this._lastCanvasH=a,this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height);let C=Math.max(0,this.options.radius??0),M=Math.floor(o+n/2),x=Math.floor(o+n/2),O=Math.floor(t),w=Math.floor(i);if(this._ctx.beginPath(),C>0?this.roundedRectPath(this._ctx,M,x,O,w,C):this._ctx.rect(M,x,O,w),this.options.fillColor&&(this._ctx.fillStyle=this.toCssColor(this.options.fillColor),this._ctx.fill()),this.options.strokeColor&&n>0&&(this._ctx.lineWidth=n,this._ctx.strokeStyle=this.toCssColor(this.options.strokeColor),this._ctx.stroke()),this._texture){if(m&&(this._texture.dispose(),this._texture=new $t(this._canvas),this._texture.minFilter=W,this._texture.magFilter=W,this._texture.wrapS=Xt,this._texture.wrapT=Xt,this._sprite&&this._sprite.material instanceof Yt)){let d=this._sprite.material;d.uniforms?.tDiffuse&&(d.uniforms.tDiffuse.value=this._texture),d.uniforms?.iResolution&&d.uniforms.iResolution.value.set(this._canvas.width,this._canvas.height,1)}this._texture.image=this._canvas,this._texture.needsUpdate=!0,this._sprite&&this._sprite.material&&(this._sprite.material.map=this._texture,this._sprite.material.needsUpdate=!0)}}getWidth(){return this.options.width??0}getHeight(){return this.options.height??0}roundedRectPath(t,i,o,n,s,l){let r=Math.min(l,Math.floor(Math.min(n,s)/2));t.moveTo(i+r,o),t.lineTo(i+n-r,o),t.quadraticCurveTo(i+n,o,i+n,o+r),t.lineTo(i+n,o+s-r),t.quadraticCurveTo(i+n,o+s,i+n-r,o+s),t.lineTo(i+r,o+s),t.quadraticCurveTo(i,o+s,i,o+s-r),t.lineTo(i,o+r),t.quadraticCurveTo(i,o,i+r,o)}toCssColor(t){return typeof t=="string"?t:`#${(t instanceof Nt?t:new Nt(t)).getHexString()}`}getResolution(){try{let t=this._cameraRef?.renderer?.domElement;if(t)return{width:t.clientWidth||1,height:t.clientHeight||1}}catch{}return{width:this._cameraRef?.screenResolution?.x??1,height:this._cameraRef?.screenResolution?.y??1}}rectSetup(t){if(this._cameraRef=t.camera,this.options.stickToViewport&&this._cameraRef&&this._cameraRef.camera.add(this.group),this.materials?.length&&this._sprite){let i=this.materials[0];i instanceof Yt&&(i.transparent=!0,i.depthTest=!1,i.depthWrite=!1,this._texture&&(i.uniforms?.tDiffuse&&(i.uniforms.tDiffuse.value=this._texture),i.uniforms?.iResolution&&this._canvas&&i.uniforms.iResolution.value.set(this._canvas.width,this._canvas.height,1)),this._mesh=new Te(new ze(1,1),i),this.group?.add(this._mesh),this._sprite.visible=!1)}}rectUpdate(t){if(this._sprite){if(this._cameraRef&&this.options.bounds){let i=this.computeScreenBoundsFromOptions(this.options.bounds);if(i){let{x:o,y:n,width:s,height:l}=i,r=Math.max(2,Math.floor(s)),a=Math.max(2,Math.floor(l)),m=r!==(this.options.width??0)||a!==(this.options.height??0);this.options.screenPosition=new U(Math.floor(o),Math.floor(n)),this.options.width=r,this.options.height=a,this.options.anchor=new U(0,0),m&&this.redrawRect()}}this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}}updateStickyTransform(){if(!this._sprite||!this._cameraRef)return;let t=this._cameraRef.camera,{width:i,height:o}=this.getResolution(),n=E(this.options.screenPosition,I.screenPosition),s=n.x,l=n.y,r=Math.max(.001,this.options.zDistance??1),a=1,m=1;if(t.isPerspectiveCamera){let g=t,v=Math.tan(g.fov*Math.PI/180/2)*r;a=v*g.aspect,m=v}else if(t.isOrthographicCamera){let g=t;a=(g.right-g.left)/2,m=(g.top-g.bottom)/2}let C=s/i*2-1,M=1-l/o*2,x=C*a,O=M*m,w=1,d=1;if(this._canvas){let v=m*2/o,_=this._canvas.height;d=Math.max(1e-4,_*v);let k=this._canvas.width/this._canvas.height;w=d*k,this._sprite.scale.set(w,d,1),this._mesh&&this._mesh.scale.set(w,d,1)}let P=E(this.options.anchor,I.anchor),y=Math.min(100,Math.max(0,P.x))/100,h=Math.min(100,Math.max(0,P.y))/100,S=(.5-y)*w,Z=(h-.5)*d;this.group?.position.set(x+S,O+Z,-r)}worldToScreen(t){if(!this._cameraRef)return{x:0,y:0};let i=this._cameraRef.camera,{width:o,height:n}=this.getResolution(),s=t.clone().project(i),l=(s.x+1)/2*o,r=(1-s.y)/2*n;return{x:l,y:r}}computeScreenBoundsFromOptions(t){if(!this._cameraRef)return null;if(t.screen)return{...t.screen};if(t.world){let{left:i,right:o,top:n,bottom:s,z:l=0}=t.world,r=this.worldToScreen(new Wt(i,n,l)),a=this.worldToScreen(new Wt(o,s,l)),m=Math.min(r.x,a.x),C=Math.min(r.y,a.y),M=Math.abs(a.x-r.x),x=Math.abs(a.y-r.y);return{x:m,y:C,width:M,height:x}}return null}updateRect(t){this.options={...this.options,...t},this.redrawRect(),this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}buildInfo(){return{...new u(this).buildDebugInfo(),type:String(e.type),width:this.options.width??0,height:this.options.height??0,sticky:this.options.stickToViewport}}};function Le(...e){return T({args:e,defaultConfig:{...I},EntityClass:H,BuilderClass:mt,entityType:H.type,cloneFactory:t=>Le(t??{})})}import{AmbientLight as Ie,DirectionalLight as ke,Group as Fe,HemisphereLight as Ge,Object3D as He,PointLight as Ae,SpotLight as Ve}from"three";var Ne=Symbol("Light"),$e={x:0,y:0,z:0},A=16777215,Xe={mapSize:2048,near:.1,far:500,bias:0,radius:1,left:-100,right:100,top:100,bottom:-100},Ye={mapSize:1024,near:.1,far:500,bias:0,radius:1},pt=class extends c{static type=Ne;light=null;lightTarget=null;constructor(t){super(),this.options={...t}}create(){super.create();let t=new Fe,{light:i,target:o}=We(this.options);return t.add(i),o&&t.add(o),this.group=t,this.light=i,this.lightTarget=o,this}_cleanup(t){this.light?.shadow?.map?.dispose?.(),this.light=null,this.lightTarget=null,super._cleanup(t)}};function We(e){switch(e.type){case"ambient":return{light:Ue(e),target:null};case"hemisphere":return{light:je(e),target:null};case"directional":return qe(e);case"point":return{light:Je(e),target:null};case"spot":return Ke(e)}}function Ue(e){let t=new Ie(e.color??A,e.intensity??1);return e.name&&(t.name=e.name),t}function je(e){let t=e.skyColor??e.color??A,i=e.groundColor??0,o=new Ge(t,i,e.intensity??1);return e.name&&(o.name=e.name),o}function qe(e){let t=new ke(e.color??A,e.intensity??1);e.name&&(t.name=e.name),Qe(t,e.castShadow??!1,e.shadow);let i=Ut(e.position,e.target);return i&&(t.target=i),{light:t,target:i}}function Je(e){let t=new Ae(e.color??A,e.intensity??1,e.distance,e.decay);return e.name&&(t.name=e.name),jt(t,e.castShadow??!1,e.shadow),t}function Ke(e){let t=new Ve(e.color??A,e.intensity??1,e.distance,e.angle,e.penumbra,e.decay);e.name&&(t.name=e.name),jt(t,e.castShadow??!1,e.shadow);let i=Ut(e.position,e.target);return i&&(t.target=i),{light:t,target:i}}function Ut(e,t){if(!t)return null;let i=e??$e,o=new He;return o.position.set(t.x-i.x,t.y-i.y,t.z-i.z),o}function Qe(e,t,i){if(!t){e.castShadow=!1;return}e.castShadow=!0;let o={...Xe,...i??{}};e.shadow.mapSize.set(o.mapSize,o.mapSize),e.shadow.camera.near=o.near,e.shadow.camera.far=o.far,e.shadow.camera.left=o.left,e.shadow.camera.right=o.right,e.shadow.camera.top=o.top,e.shadow.camera.bottom=o.bottom,e.shadow.bias=o.bias,e.shadow.radius=o.radius,e.shadow.camera.updateProjectionMatrix()}function jt(e,t,i){if(!t){e.castShadow=!1;return}e.castShadow=!0;let o={...Ye,...i??{}};e.shadow.mapSize.set(o.mapSize,o.mapSize),e.shadow.camera.near=o.near,e.shadow.camera.far=o.far,e.shadow.bias=o.bias,e.shadow.radius=o.radius,e.shadow.camera.updateProjectionMatrix()}function No(e){return new pt(e)}export{u as a,Mt as b,Pt as c,Zt as d,Et as e,_t as f,Rt as g,re as h,J as i,ae as j,le as k,K as l,ce as m,he as n,Q as o,me as p,pe as q,tt as r,ue as s,de as t,et as u,ye as v,ge as w,it as x,fe as y,Oe as z,F as A,we as B,Ce as C,G as D,Me as E,Ze as F,ht as G,Ee as H,Be as I,H as J,Le as K,Ne as L,pt as M,No as N};
|
package/dist/chunk-EVMLNMGU.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{proxy as u}from"valtio/vanilla";var a=["translate","rotate","scale"];function E(e){return a.includes(e)}var c={enabled:!0,translate:.25,rotate:Math.PI/12,scale:.1},t=u({enabled:!1,paused:!1,tool:"none",selectedEntityId:null,selectedEntityIds:[],hoveredEntityId:null,snap:{...c},gridVisible:!1,addTypeId:null,addTypeProps:null,pickMode:!1,flags:new Set}),i=null;function b(e){return i=e,()=>{i===e&&(i=null)}}function d(e){return!e||!i?null:i(e)}function r(e,n){if(e==null)return null;if(typeof e=="string")return e;let l=e.uuid;if(typeof l=="string")return console.warn(`${n}: received a live entity. Pass the UUID instead \u2014 storing entities in debugState makes valtio deep-proxy the scene graph.`),l;throw new TypeError(`${n} expects an entity UUID string or null, received ${typeof e}.`)}function x(){return t.paused}function I(e){t.paused=e}function S(){return t.tool}function v(e){t.tool=e}function T(){return t.enabled||t.tool!=="none"||t.pickMode}function m(e){t.pickMode=e,!e&&t.tool!=="select"&&t.tool!=="delete"&&g()}function D(){return t.pickMode}function h(){return t.selectedEntityId}function p(e){let n=r(e,"setSelectedEntityId");t.selectedEntityId!==n&&(t.selectedEntityId=n,t.selectedEntityIds=n?[n]:[])}function k(){return[...t.selectedEntityIds]}function P(e){let n=e.map((o,s)=>r(o,`setSelectedEntityIds[${s}]`)).filter(o=>o!==null);n.length===t.selectedEntityIds.length&&n.every((o,s)=>t.selectedEntityIds[s]===o)||(t.selectedEntityIds=n,t.selectedEntityId=n[0]??null)}function R(){return{...t.snap}}function M(e){Object.assign(t.snap,e)}function G(e){t.gridVisible=e}function w(e,n){t.addTypeId=e,t.addTypeProps=e?n??null:null}function H(){return t.hoveredEntityId}function y(e){let n=r(e,"setHoveredEntityId");t.hoveredEntityId!==n&&(t.hoveredEntityId=n)}function g(){y(null)}function O(){return d(t.selectedEntityId)}function A(){return d(t.hoveredEntityId)}function U(e){p(r(e,"setSelectedEntity"))}export{a,E as b,c,t as d,b as e,d as f,x as g,I as h,S as i,v as j,T as k,m as l,D as m,h as n,p as o,k as p,P as q,R as r,M as s,G as t,w as u,H as v,y as w,g as x,O as y,A as z,U as A};
|
package/dist/chunk-F5LROYZL.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import{b as he,d as G,j as Te,u as L,v as E}from"./chunk-IBJLPJLE.js";import{b as Re}from"./chunk-7GYFZKK7.js";import{b as y}from"./chunk-Q2YDBMVY.js";import{b as Ee}from"./chunk-QDQ4QMAI.js";import{c as we,e as Ce,f as xe}from"./chunk-AE3CTVHY.js";import{b as ye,c as be,d as ve,f as Se}from"./chunk-ZTYNZ2N2.js";import{d as g,g as me,h as K}from"./chunk-EVMLNMGU.js";import{k as Be}from"./chunk-YOVE25NW.js";import{a as W,t as j}from"./chunk-SAQA4SXW.js";import{j as Ge}from"./chunk-7NYP4YAG.js";import{a as fe,b}from"./chunk-AIQ6IVT5.js";import{c as S}from"./chunk-D2PATZCC.js";import{c as re,d as C,e as le,h as ue,i as pe,j as de,k as J,l as x,m as ce}from"./chunk-4QLJUQSJ.js";import{j as $}from"./chunk-7WRQ2UAN.js";import{g as ge}from"./chunk-PCFF4LLO.js";import{l as v}from"./chunk-UG22Z42P.js";function _e(){return{pressed:!1,released:!1,held:0}}function Ne(){return{value:0,held:0}}function k(a){let e=new Map;if(!a)return e;for(let[t,n]of Object.entries(a)){if(!n||n.length===0)continue;let i=[];for(let o of n){let[r,s]=(o||"").split(".");if(!r||!s)continue;let l=r.toLowerCase(),u=s.toLowerCase();if(l==="buttons"){let p={a:"A",b:"B",x:"X",y:"Y",start:"Start",select:"Select",l:"L",r:"R"}[u];p&&i.push({category:"buttons",property:p})}else if(l==="directions"){let p={up:"Up",down:"Down",left:"Left",right:"Right"}[u];p&&i.push({category:"directions",property:p})}else if(l==="shoulders"){let p={ltrigger:"LTrigger",rtrigger:"RTrigger"}[u];p&&i.push({category:"shoulders",property:p})}else if(l==="axes"){let p={left:{property:"Horizontal",direction:-1},right:{property:"Horizontal",direction:1},up:{property:"Vertical",direction:-1},down:{property:"Vertical",direction:1},secondaryleft:{property:"SecondaryHorizontal",direction:-1},secondaryright:{property:"SecondaryHorizontal",direction:1},secondaryup:{property:"SecondaryVertical",direction:-1},secondarydown:{property:"SecondaryVertical",direction:1}}[u];p&&i.push({category:"axes",property:p.property,axisDirection:p.direction})}}i.length>0&&e.set(t,i)}return e}function d(a,e){return!a&&!e?_e():a?e?{pressed:a.pressed||e.pressed,released:a.released||e.released,held:a.held+e.held}:{...a}:{...e}}function f(a,e){return!a&&!e?Ne():a?e?{value:a.value+e.value,held:a.held+e.held}:{...a}:{...e}}var w=class{keyStates=new Map;keyButtonStates=new Map;analogStates=new Map;compiledMapping;includeDefaultBase=!0;onKeyDown=({key:e})=>this.keyStates.set(e,!0);onKeyUp=({key:e})=>this.keyStates.set(e,!1);constructor(e,t){this.includeDefaultBase=t?.includeDefaultBase??!0,this.compiledMapping=k(e??null),window.addEventListener("keydown",this.onKeyDown),window.addEventListener("keyup",this.onKeyUp)}dispose(){window.removeEventListener("keydown",this.onKeyDown),window.removeEventListener("keyup",this.onKeyUp),this.keyStates.clear(),this.keyButtonStates.clear(),this.analogStates.clear()}isKeyPressed(e){return this.keyStates.get(e)||!1}handleButtonState(e,t){let n=this.keyButtonStates.get(e);n||(n={pressed:!1,released:!1,held:0},this.keyButtonStates.set(e,n));let i=this.isKeyPressed(e);return n.pressed=i&&n.held===0,n.released=!i&&n.held>0,n.held=i?n.held+t:0,n}handleAnalogState(e,t,n){let i=`${e}:${t}`,o=this.analogStates.get(i);return o||(o={value:0,held:0},this.analogStates.set(i,o)),o.value=this.getAxisValue(e,t),o.held=o.value!==0?o.held+n:0,o}applyCustomMapping(e,t){if(this.compiledMapping.size===0)return e;let n=new Map;for(let[i,o]of this.compiledMapping.entries()){let r=null;for(let s of o)if(s.category==="axes")n.has(s.property)||n.set(s.property,0),this.isKeyPressed(i)&&n.set(s.property,n.get(s.property)+s.axisDirection);else{r||(r=this.handleButtonState(i,t));let l=e[s.category]??={};l[s.property]=d(l[s.property],r)}}if(n.size>0){e.axes||(e.axes={});for(let[i,o]of n.entries()){let r=`custom:${i}`,s=this.analogStates.get(r);s||(s={value:0,held:0},this.analogStates.set(r,s)),s.value=o,s.held=o!==0?s.held+t:0,e.axes[i]=f(e.axes[i],s)}}return e}getInput(e){let t={};return this.includeDefaultBase&&(t.buttons={A:this.handleButtonState("z",e),B:this.handleButtonState("x",e),X:this.handleButtonState("a",e),Y:this.handleButtonState("s",e),Start:this.handleButtonState(" ",e),Select:this.handleButtonState("Enter",e),L:this.handleButtonState("q",e),R:this.handleButtonState("e",e)},t.directions={Up:this.handleButtonState("ArrowUp",e),Down:this.handleButtonState("ArrowDown",e),Left:this.handleButtonState("ArrowLeft",e),Right:this.handleButtonState("ArrowRight",e)},t.shoulders={LTrigger:this.handleButtonState("Q",e),RTrigger:this.handleButtonState("E",e)}),this.applyCustomMapping(t,e)}getName(){return"keyboard"}getAxisValue(e,t){return(this.isKeyPressed(t)?1:0)-(this.isKeyPressed(e)?1:0)}isConnected(){return!0}};var D=class{gamepadIndex;connected=!1;buttonStates={};analogStates={};onConnected=e=>{e.gamepad.index===this.gamepadIndex&&(this.connected=!0)};onDisconnected=e=>{e.gamepad.index===this.gamepadIndex&&(this.connected=!1)};constructor(e){this.gamepadIndex=e,window.addEventListener("gamepadconnected",this.onConnected),window.addEventListener("gamepaddisconnected",this.onDisconnected)}dispose(){window.removeEventListener("gamepadconnected",this.onConnected),window.removeEventListener("gamepaddisconnected",this.onDisconnected),this.buttonStates={},this.analogStates={}}handleButtonState(e,t,n){let i=this.buttonStates[e];i||(i={pressed:!1,released:!1,held:0},this.buttonStates[e]=i);let o=t.buttons[e].pressed;return i.pressed=o&&i.held===0,i.released=!o&&i.held>0,i.held=o?i.held+n:0,i}handleAnalogState(e,t,n){let i=this.analogStates[e];return i||(i={value:0,held:0},this.analogStates[e]=i),i.value=t.axes[e],i.held=i.value!==0?i.held+n:0,i}getInput(e){let t=navigator.getGamepads()[this.gamepadIndex];return t?{buttons:{A:this.handleButtonState(0,t,e),B:this.handleButtonState(1,t,e),X:this.handleButtonState(2,t,e),Y:this.handleButtonState(3,t,e),Start:this.handleButtonState(9,t,e),Select:this.handleButtonState(8,t,e),L:this.handleButtonState(4,t,e),R:this.handleButtonState(5,t,e)},directions:{Up:this.handleButtonState(12,t,e),Down:this.handleButtonState(13,t,e),Left:this.handleButtonState(14,t,e),Right:this.handleButtonState(15,t,e)},axes:{Horizontal:this.handleAnalogState(0,t,e),Vertical:this.handleAnalogState(1,t,e),SecondaryHorizontal:this.handleAnalogState(2,t,e),SecondaryVertical:this.handleAnalogState(3,t,e)},shoulders:{LTrigger:this.handleButtonState(6,t,e),RTrigger:this.handleButtonState(7,t,e)}}:{}}getName(){return`gamepad-${this.gamepadIndex+1}`}isConnected(){return this.connected}};import{subscribe as Fe}from"valtio/vanilla";var Xe=.002;function z(a,e,t){return Math.max(e,Math.min(t,a))}function Ye(a){if(a instanceof HTMLCanvasElement)return a;let e=a.querySelector("canvas");if(e instanceof HTMLCanvasElement)return e;for(let t of a.querySelectorAll("*")){let n=t.shadowRoot;if(!n)continue;let i=n.querySelector("canvas");if(i instanceof HTMLCanvasElement)return i}return null}var R=class{buttonStates=new Map;analogStates=new Map;compiledMapping;movementX=0;movementY=0;pointerX=.5;pointerY=.5;pointerCenterX=0;pointerCenterY=0;mouseButtonDown=new Set;sensitivity;usePointerLock;lookMode;isLocked=!1;targetElement;debugUnsubscribe=null;updatePointerPosition(e,t){this.pointerX=e/window.innerWidth,this.pointerY=t/window.innerHeight;let n=Ye(this.targetElement);if(n){let i=n.getBoundingClientRect();if(i.width>0&&i.height>0){let o=i.left+i.width/2,r=i.top+i.height/2;this.pointerCenterX=z((e-o)/(i.width/2),-1,1),this.pointerCenterY=z((t-r)/(i.height/2),-1,1);return}}this.pointerCenterX=z((this.pointerX-.5)*2,-1,1),this.pointerCenterY=z((this.pointerY-.5)*2,-1,1)}onMouseMove=e=>{this.updatePointerPosition(e.clientX,e.clientY),!(g.enabled||this.lookMode==="screenCenter")&&(this.movementX+=e.movementX,this.movementY+=e.movementY)};onMouseDown=e=>{let t=e.target;t instanceof HTMLCanvasElement&&this.targetElement.contains(t)&&(this.mouseButtonDown.add(e.button),this.usePointerLock&&!this.isLocked&&!g.enabled&&this.targetElement.requestPointerLock())};onMouseUp=e=>{this.mouseButtonDown.delete(e.button)};onContextMenu=e=>{e.preventDefault()};onPointerLockChange=()=>{this.isLocked=document.pointerLockElement===this.targetElement};constructor(e,t){this.sensitivity=e?.sensitivity??Xe,this.lookMode=e?.lookMode??"delta",this.usePointerLock=e?.pointerLock??!1,this.compiledMapping=k(e?.mapping??null),this.targetElement=t??document.body,window.addEventListener("mousemove",this.onMouseMove),this.targetElement.addEventListener("mousedown",this.onMouseDown),this.targetElement.addEventListener("mouseup",this.onMouseUp),this.targetElement.addEventListener("contextmenu",this.onContextMenu),this.usePointerLock&&(document.addEventListener("pointerlockchange",this.onPointerLockChange),this.debugUnsubscribe=Fe(g,()=>{g.enabled&&document.pointerLockElement===this.targetElement&&document.exitPointerLock()}))}dispose(){window.removeEventListener("mousemove",this.onMouseMove),this.targetElement.removeEventListener("mousedown",this.onMouseDown),this.targetElement.removeEventListener("mouseup",this.onMouseUp),this.targetElement.removeEventListener("contextmenu",this.onContextMenu),document.removeEventListener("pointerlockchange",this.onPointerLockChange),this.debugUnsubscribe?.(),this.debugUnsubscribe=null,this.isLocked&&document.exitPointerLock(),this.buttonStates.clear(),this.analogStates.clear(),this.mouseButtonDown.clear(),this.movementX=0,this.movementY=0}handleMouseButton(e,t){let n=this.buttonStates.get(e);n||(n={pressed:!1,released:!1,held:0},this.buttonStates.set(e,n));let i=this.mouseButtonDown.has(e);return n.pressed=i&&n.held===0,n.released=!i&&n.held>0,n.held=i?n.held+t:0,n}handleMovementAxis(e,t){let n=this.analogStates.get(e);n||(n={value:0,held:0},this.analogStates.set(e,n));let i=e==="x"?this.movementX:this.movementY;return n.value=Math.max(-1,Math.min(1,i*this.sensitivity)),n.held=n.value!==0?n.held+t:0,n}applyCustomMapping(e,t){if(this.compiledMapping.size===0)return e;let n=new Map,i={leftbutton:()=>this.handleMouseButton(0,t),rightbutton:()=>this.handleMouseButton(2,t),middlebutton:()=>this.handleMouseButton(1,t)};for(let[o,r]of this.compiledMapping.entries()){let s=o.toLowerCase();for(let l of r)if(l.category==="axes")n.has(l.property)||n.set(l.property,0),s==="movex"?n.set(l.property,n.get(l.property)+Math.max(-1,Math.min(1,this.movementX*this.sensitivity))*l.axisDirection):s==="movey"?n.set(l.property,n.get(l.property)+Math.max(-1,Math.min(1,this.movementY*this.sensitivity))*l.axisDirection):s in i&&this.mouseButtonDown.has(this.buttonIndexForAction(s))&&n.set(l.property,n.get(l.property)+l.axisDirection);else{let u=i[s];if(u){let m=u();if(m){let p=e[l.category]??={};p[l.property]=d(p[l.property],m)}}}}if(n.size>0){e.axes||(e.axes={});for(let[o,r]of n.entries()){let s=`custom:${o}`,l=this.analogStates.get(s);l||(l={value:0,held:0},this.analogStates.set(s,l)),l.value=Math.max(-1,Math.min(1,r)),l.held=r!==0?l.held+t:0,e.axes[o]=f(e.axes[o],l)}}return e}buttonIndexForAction(e){switch(e){case"leftbutton":return 0;case"middlebutton":return 1;case"rightbutton":return 2;default:return-1}}getInput(e){g.enabled&&(this.movementX=0,this.movementY=0);let t={value:0,held:0},n=this.lookMode==="delta",i={axes:{Horizontal:t,Vertical:t,SecondaryHorizontal:n?this.handleMovementAxis("x",e):t,SecondaryVertical:n?this.handleMovementAxis("y",e):t},shoulders:{LTrigger:this.handleMouseButton(0,e),RTrigger:this.handleMouseButton(2,e)},pointer:{x:this.pointerX,y:this.pointerY,centerX:this.pointerCenterX,centerY:this.pointerCenterY}};return this.movementX=0,this.movementY=0,this.applyCustomMapping(i,e)}getName(){return"mouse"}isConnected(){return!0}};function T(a={}){if(typeof window>"u"||typeof navigator>"u")return!1;let e=navigator.userAgent,t=/android/i.test(e)||/iPad|iPhone|iPod/.test(e),n="ontouchstart"in window||navigator.maxTouchPoints>0,i=typeof window.matchMedia=="function"?window.matchMedia("(pointer: coarse)").matches:!1,o=a.viewportSize?.width??window.innerWidth??0,r=a.viewportSize?.height??window.innerHeight??0,s=Math.max(o,r),l=s===0||s<=1024;return a.allowViewportOnly&&a.viewportSize?l:t||(n||i)&&l}var Ze=["A","B","X","Y","Start","Select","L","R","LTrigger","RTrigger","Up","Down","Left","Right"],Je=new Set(["flex","flexGrow","flexShrink","fontWeight","lineHeight","opacity","order","zIndex","zoom"]),Ke={A:{size:72,label:"A",position:{right:98,bottom:44}},B:{size:72,label:"B",position:{right:24,bottom:108}},X:{size:72,label:"X",position:{right:172,bottom:108}},Y:{size:72,label:"Y",position:{right:98,bottom:172}},Start:{size:64,label:"Start",position:{left:"50%",top:24,transform:"translateX(28px)"}},Select:{size:64,label:"Select",position:{left:"50%",top:24,transform:"translateX(-108px)"}},L:{size:62,label:"L",position:{left:28,bottom:184}},R:{size:62,label:"R",position:{right:236,bottom:184}},LTrigger:{size:76,label:"LT",position:{left:24,top:24}},RTrigger:{size:76,label:"RT",position:{right:24,top:24}},Up:{enabled:!1,size:64,label:"Up"},Down:{enabled:!1,size:64,label:"Down"},Left:{enabled:!1,size:64,label:"Left"},Right:{enabled:!1,size:64,label:"Right"}},$e={left:{size:140,thumbSize:58,maxDistance:44,deadzone:.12,directionThreshold:.34,horizontalAxis:"Horizontal",verticalAxis:"Vertical",emitDirections:!0,position:{left:24,bottom:24}},right:{size:140,thumbSize:58,maxDistance:44,deadzone:.12,directionThreshold:.34,horizontalAxis:"SecondaryHorizontal",verticalAxis:"SecondaryVertical",emitDirections:!1,position:{right:24,bottom:236}}},M=class{config;targetElement;buttonStates=new Map;analogStates=new Map;buttons=new Map;joysticks=new Map;rootElement=null;enabled=!1;onPointerMove=e=>{for(let t of this.joysticks.values())t.pointerId===e.pointerId&&(this.consumeEvent(e),this.updateJoystickFromPoint(t,e.clientX,e.clientY))};onPointerUp=e=>{for(let t of this.buttons.values())t.pointerId===e.pointerId&&(this.consumeEvent(e),this.releaseButton(t));for(let t of this.joysticks.values())t.pointerId===e.pointerId&&(this.consumeEvent(e),this.releaseJoystick(t))};onWindowBlur=()=>{for(let e of this.buttons.values())this.releaseButton(e);for(let e of this.joysticks.values())this.releaseJoystick(e)};constructor(e,t){this.config=e??{},this.targetElement=t??document.body,this.enabled=this.resolveEnabledState(),this.enabled&&(this.mountControls(),window.addEventListener("pointermove",this.onPointerMove),window.addEventListener("pointerup",this.onPointerUp),window.addEventListener("pointercancel",this.onPointerUp),window.addEventListener("blur",this.onWindowBlur))}getInput(e){if(!this.enabled)return{};let t={};for(let n of this.buttons.values()){let i=this.handleButtonState(`button:${n.slot}`,n.pointerId!==null,e);this.assignButtonState(t,this.resolveButtonTarget(n.slot),i)}for(let n of this.joysticks.values()){let i=this.handleAnalogState(`joystick:${n.id}:x`,n.valueX,e),o=this.handleAnalogState(`joystick:${n.id}:y`,n.valueY,e);this.assignAxisState(t,n.config.horizontalAxis,i),this.assignAxisState(t,n.config.verticalAxis,o),n.config.emitDirections&&(this.assignButtonState(t,this.resolveButtonTarget("Left"),this.handleButtonState(`joystick:${n.id}:left`,n.valueX<=-n.config.directionThreshold,e)),this.assignButtonState(t,this.resolveButtonTarget("Right"),this.handleButtonState(`joystick:${n.id}:right`,n.valueX>=n.config.directionThreshold,e)),this.assignButtonState(t,this.resolveButtonTarget("Up"),this.handleButtonState(`joystick:${n.id}:up`,n.valueY<=-n.config.directionThreshold,e)),this.assignButtonState(t,this.resolveButtonTarget("Down"),this.handleButtonState(`joystick:${n.id}:down`,n.valueY>=n.config.directionThreshold,e)))}return t}getName(){return"virtual-touch"}isConnected(){return this.enabled}dispose(){window.removeEventListener("pointermove",this.onPointerMove),window.removeEventListener("pointerup",this.onPointerUp),window.removeEventListener("pointercancel",this.onPointerUp),window.removeEventListener("blur",this.onWindowBlur),this.rootElement?.remove(),this.rootElement=null,this.buttons.clear(),this.joysticks.clear(),this.buttonStates.clear(),this.analogStates.clear()}resolveEnabledState(){return typeof window>"u"||typeof document>"u"?!1:this.config.enabled===!0?!0:this.config.enabled===!1?!1:T()}mountControls(){this.rootElement=document.createElement("div"),this.rootElement.className="zylem-virtual-touch",this.rootElement.dataset.zylemTouchRoot="true",this.rootElement.style.position="absolute",this.rootElement.style.inset="0",this.rootElement.style.pointerEvents="none",this.rootElement.style.touchAction="none",this.rootElement.style.userSelect="none",this.rootElement.style.WebkitUserSelect="none",this.rootElement.style.WebkitTouchCallout="none",this.rootElement.style.color="rgba(245, 247, 255, 0.96)",this.rootElement.style.zIndex="20",this.appendClassName(this.rootElement,this.config.className),B(this.rootElement,this.config.style),this.rootElement.addEventListener("contextmenu",e=>e.preventDefault());for(let[e,t]of this.resolveButtons())this.rootElement.appendChild(this.createButton(e,t));for(let[e,t]of this.resolveJoysticks())this.rootElement.appendChild(this.createJoystick(e,t));this.targetElement.appendChild(this.rootElement)}resolveButtons(){if(this.config.buttons===!1)return[];let e=this.config.buttons,t=[];for(let n of Ze){let i=Ke[n],o=e?.[n];if(o===!1)continue;let r={...i,...o??{},style:{...i.style,...o?.style},position:{...i.position,...o?.position},label:o?.label??i.label??n,size:o?.size??i.size??72};r.enabled!==!1&&t.push([n,r])}return t}resolveJoysticks(){if(this.config.joysticks===!1)return[];let e=this.config.joysticks,t=[];for(let n of["left","right"]){let i=$e[n],o=e?.[n];if(o===!1)continue;let r={...i,...o??{},style:{...i.style,...o?.style},position:{...i.position,...o?.position},svg:{...i.svg,...o?.svg},size:o?.size??i.size??140,thumbSize:o?.thumbSize??i.thumbSize??58,maxDistance:o?.maxDistance??i.maxDistance??44,deadzone:o?.deadzone??i.deadzone??.12,directionThreshold:o?.directionThreshold??i.directionThreshold??.34,horizontalAxis:o?.horizontalAxis??i.horizontalAxis??"Horizontal",verticalAxis:o?.verticalAxis??i.verticalAxis??"Vertical",emitDirections:o?.emitDirections??i.emitDirections??!1};r.enabled!==!1&&t.push([n,r])}return t}createButton(e,t){let n=document.createElement("button"),i=document.createElement("div");n.type="button",n.ariaLabel=t.label,n.className=`zylem-virtual-touch__button zylem-virtual-touch__button--${e}`,n.dataset.zylemTouchButton=e,n.dataset.active="false",n.style.position="absolute",n.style.width=`${t.size}px`,n.style.height=`${t.size}px`,n.style.padding="0",n.style.margin="0",n.style.border="0",n.style.background="transparent",n.style.pointerEvents="auto",n.style.touchAction="none",n.style.cursor="pointer",n.style.appearance="none",n.style.outline="none",n.style.userSelect="none",n.style.WebkitTapHighlightColor="transparent",B(n,t.position),B(n,t.style),this.appendClassName(n,t.className),i.className="zylem-virtual-touch__button-content",i.style.width="100%",i.style.height="100%",i.style.pointerEvents="none",i.style.transform="scale(1)",i.style.transformOrigin="center",i.style.transition="transform 120ms ease, opacity 120ms ease",i.style.opacity="0.92",i.innerHTML=t.svg??je(t.label),n.appendChild(i),n.addEventListener("pointerdown",r=>{if(!Me(r))return;let s=this.buttons.get(e);!s||s.pointerId!==null||(this.consumeEvent(r),s.pointerId=r.pointerId,this.updateButtonVisual(s,!0))});let o={slot:e,config:t,element:n,content:i,pointerId:null};return this.buttons.set(e,o),n}createJoystick(e,t){let n=document.createElement("div"),i=document.createElement("div"),o=document.createElement("div");n.className=`zylem-virtual-touch__joystick zylem-virtual-touch__joystick--${e}`,n.dataset.zylemTouchJoystick=e,n.dataset.active="false",n.style.position="absolute",n.style.width=`${t.size}px`,n.style.height=`${t.size}px`,n.style.pointerEvents="auto",n.style.touchAction="none",n.style.userSelect="none",B(n,t.position),B(n,t.style),this.appendClassName(n,t.className),i.className="zylem-virtual-touch__joystick-base",i.style.position="absolute",i.style.inset="0",i.style.pointerEvents="none",i.style.opacity="0.88",i.style.transition="opacity 120ms ease",i.innerHTML=t.svg?.base??qe(),o.className="zylem-virtual-touch__joystick-thumb",o.style.position="absolute",o.style.left="50%",o.style.top="50%",o.style.width=`${t.thumbSize}px`,o.style.height=`${t.thumbSize}px`,o.style.pointerEvents="none",o.style.transform="translate(-50%, -50%) translate(0px, 0px)",o.style.transition="transform 60ms linear, opacity 120ms ease",o.style.opacity="0.94",o.innerHTML=t.svg?.thumb??Qe(),n.append(i,o);let r={id:e,config:t,element:n,base:i,thumb:o,pointerId:null,centerX:0,centerY:0,rawX:0,rawY:0,valueX:0,valueY:0};return this.joysticks.set(e,r),n.addEventListener("pointerdown",s=>{if(!Me(s))return;let l=this.joysticks.get(e);if(!l||l.pointerId!==null)return;this.consumeEvent(s);let u=l.element.getBoundingClientRect();l.pointerId=s.pointerId,l.centerX=u.left+u.width/2,l.centerY=u.top+u.height/2,this.updateJoystickVisual(l,!0),this.updateJoystickFromPoint(l,s.clientX,s.clientY)}),n}handleButtonState(e,t,n){let i=this.buttonStates.get(e);return i||(i={pressed:!1,released:!1,held:0},this.buttonStates.set(e,i)),i.pressed=t&&i.held===0,i.released=!t&&i.held>0,i.held=t?i.held+n:0,i}handleAnalogState(e,t,n){let i=this.analogStates.get(e);return i||(i={value:0,held:0},this.analogStates.set(e,i)),i.value=t,i.held=t!==0?i.held+n:0,i}assignAxisState(e,t,n){e.axes||(e.axes={}),e.axes[t]=f(e.axes[t],n)}assignButtonState(e,t,n){if(t.category==="buttons"){e.buttons??={},e.buttons[t.property]=d(e.buttons[t.property],n);return}if(t.category==="directions"){e.directions??={},e.directions[t.property]=d(e.directions[t.property],n);return}e.shoulders??={},e.shoulders[t.property]=d(e.shoulders[t.property],n)}resolveButtonTarget(e){switch(e){case"LTrigger":case"RTrigger":return{category:"shoulders",property:e};case"Up":case"Down":case"Left":case"Right":return{category:"directions",property:e};default:return{category:"buttons",property:e}}}updateJoystickFromPoint(e,t,n){let i=t-e.centerX,o=n-e.centerY,r=Math.hypot(i,o),s=e.config.maxDistance,l=r>s&&r>0?s/r:1;e.rawX=i*l,e.rawY=o*l;let u=We(e.rawX/s,e.rawY/s,e.config.deadzone);e.valueX=u.x,e.valueY=u.y,e.thumb.style.transform=`translate(-50%, -50%) translate(${e.rawX}px, ${e.rawY}px)`}releaseButton(e){e.pointerId=null,this.updateButtonVisual(e,!1)}releaseJoystick(e){e.pointerId=null,e.rawX=0,e.rawY=0,e.valueX=0,e.valueY=0,e.thumb.style.transform="translate(-50%, -50%) translate(0px, 0px)",this.updateJoystickVisual(e,!1)}updateButtonVisual(e,t){e.element.dataset.active=String(t),e.content.style.transform=t?"scale(0.94)":"scale(1)",e.content.style.opacity=t?"1":"0.92"}updateJoystickVisual(e,t){e.element.dataset.active=String(t),e.base.style.opacity=t?"1":"0.88",e.thumb.style.opacity=t?"1":"0.94"}consumeEvent(e){e.cancelable&&e.preventDefault(),e.stopPropagation()}appendClassName(e,t){t&&(e.className=`${e.className} ${t}`.trim())}};function B(a,e){if(e)for(let[t,n]of Object.entries(e)){if(n==null)continue;let i=typeof n=="number"&&!Je.has(t)?`${n}px`:String(n);t.includes("-")?a.style.setProperty(t,i):a.style[t]=i}}function We(a,e,t){let n=Math.hypot(a,e);if(n===0||n<=t)return{x:0,y:0};let o=Math.min(1,(n-t)/Math.max(1-t,1e-4))/n;return{x:a*o,y:e*o}}function je(a){let e=et(a);return`
|
|
2
|
-
<svg viewBox="0 0 100 100" width="100%" height="100%" aria-hidden="true">
|
|
3
|
-
<circle cx="50" cy="50" r="45" fill="rgba(12,18,24,0.72)" stroke="currentColor" stroke-width="4" />
|
|
4
|
-
<circle cx="50" cy="50" r="34" fill="rgba(255,255,255,0.06)" stroke="rgba(255,255,255,0.12)" stroke-width="1.5" />
|
|
5
|
-
<text
|
|
6
|
-
x="50"
|
|
7
|
-
y="56"
|
|
8
|
-
text-anchor="middle"
|
|
9
|
-
font-family="ui-sans-serif, system-ui, sans-serif"
|
|
10
|
-
font-size="${e.length>2?24:34}"
|
|
11
|
-
font-weight="700"
|
|
12
|
-
fill="currentColor"
|
|
13
|
-
>${e}</text>
|
|
14
|
-
</svg>
|
|
15
|
-
`}function qe(){return`
|
|
16
|
-
<svg viewBox="0 0 140 140" width="100%" height="100%" aria-hidden="true">
|
|
17
|
-
<circle cx="70" cy="70" r="62" fill="rgba(10,16,20,0.64)" stroke="currentColor" stroke-width="4" />
|
|
18
|
-
<circle cx="70" cy="70" r="40" fill="rgba(255,255,255,0.04)" stroke="rgba(255,255,255,0.12)" stroke-width="1.5" />
|
|
19
|
-
</svg>
|
|
20
|
-
`}function Qe(){return`
|
|
21
|
-
<svg viewBox="0 0 64 64" width="100%" height="100%" aria-hidden="true">
|
|
22
|
-
<circle cx="32" cy="32" r="28" fill="rgba(22,30,38,0.9)" stroke="currentColor" stroke-width="3.5" />
|
|
23
|
-
</svg>
|
|
24
|
-
`}function et(a){return a.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'")}function Me(a){return a.pointerType==="touch"}var A=class{inputMap=new Map;currentInputs={};previousInputs={};targetElement;mouseTargetElement;constructor(e,t){this.targetElement=t?.targetElement,this.mouseTargetElement=t?.mouseTargetElement??t?.targetElement;let n=this.buildPlayerEntries(e);for(let{player:i,config:o,gamepadIndex:r,isP1:s}of n)this.addConfigurableProviders(i,o,s),this.addInputProvider(i,new D(r))}configure(e){let t=this.buildPlayerEntries(e);for(let{player:n,config:i,isP1:o}of t){let s=(this.inputMap.get(n)??[]).filter(l=>l instanceof w||l instanceof R||l instanceof M?(l.dispose(),!1):!0);this.inputMap.set(n,[...this.createConfigurableProviders(i,o),...s])}}addInputProvider(e,t){this.inputMap.has(e)||this.inputMap.set(e,[]),this.inputMap.get(e)?.push(t)}dispose(){for(let e of this.inputMap.values())for(let t of e)t.dispose?.();this.inputMap.clear(),this.currentInputs={},this.previousInputs={}}getInputs(e){let t={};return this.inputMap.forEach((n,i)=>{let o=`p${i}`,r=n.reduce((s,l)=>{let u=l.getInput(e);return this.mergeInputs(s,u)},{});t[o]={playerNumber:i,...r}}),t}buildPlayerEntries(e){return[{player:1,config:e?.p1,gamepadIndex:0,isP1:!0},{player:2,config:e?.p2,gamepadIndex:1,isP1:!1},{player:3,config:e?.p3,gamepadIndex:2,isP1:!1},{player:4,config:e?.p4,gamepadIndex:3,isP1:!1},{player:5,config:e?.p5,gamepadIndex:4,isP1:!1},{player:6,config:e?.p6,gamepadIndex:5,isP1:!1},{player:7,config:e?.p7,gamepadIndex:6,isP1:!1},{player:8,config:e?.p8,gamepadIndex:7,isP1:!1}]}addConfigurableProviders(e,t,n){for(let i of this.createConfigurableProviders(t,n))this.addInputProvider(e,i)}createConfigurableProviders(e,t){let n=[];if(e?.key){let i=e.includeDefaults??t;n.push(new w(e.key,{includeDefaultBase:i}))}else t&&n.push(new w);return e?.mouse&&n.push(new R(e.mouse,this.mouseTargetElement)),e?.touch&&n.push(new M(e.touch,this.targetElement)),n}mergeInputs(e,t){return{buttons:{A:d(e.buttons?.A,t.buttons?.A),B:d(e.buttons?.B,t.buttons?.B),X:d(e.buttons?.X,t.buttons?.X),Y:d(e.buttons?.Y,t.buttons?.Y),Start:d(e.buttons?.Start,t.buttons?.Start),Select:d(e.buttons?.Select,t.buttons?.Select),L:d(e.buttons?.L,t.buttons?.L),R:d(e.buttons?.R,t.buttons?.R)},directions:{Up:d(e.directions?.Up,t.directions?.Up),Down:d(e.directions?.Down,t.directions?.Down),Left:d(e.directions?.Left,t.directions?.Left),Right:d(e.directions?.Right,t.directions?.Right)},axes:{Horizontal:f(e.axes?.Horizontal,t.axes?.Horizontal),Vertical:f(e.axes?.Vertical,t.axes?.Vertical),SecondaryHorizontal:f(e.axes?.SecondaryHorizontal,t.axes?.SecondaryHorizontal),SecondaryVertical:f(e.axes?.SecondaryVertical,t.axes?.SecondaryVertical)},shoulders:{LTrigger:d(e.shoulders?.LTrigger,t.shoulders?.LTrigger),RTrigger:d(e.shoulders?.RTrigger,t.shoulders?.RTrigger)},pointer:t.pointer??e.pointer}}};var V=class{_previousTime;_currentTime;_startTime;_delta;_elapsed;_timescale;_document;_pageVisibilityHandler;constructor(){this._previousTime=0,this._currentTime=0,this._startTime=q(),this._delta=0,this._elapsed=0,this._timescale=1,this._document=null,this._pageVisibilityHandler=null}connect(e){this._document=e,e.hidden!==void 0&&(this._pageVisibilityHandler=tt.bind(this),e.addEventListener("visibilitychange",this._pageVisibilityHandler,!1))}disconnect(){this._pageVisibilityHandler!==null&&(this._document.removeEventListener("visibilitychange",this._pageVisibilityHandler),this._pageVisibilityHandler=null),this._document=null}getDelta(){return this._delta/1e3}getElapsed(){return this._elapsed/1e3}getTimescale(){return this._timescale}setTimescale(e){return this._timescale=e,this}reset(){return this._currentTime=q()-this._startTime,this}dispose(){this.disconnect()}update(e){return this._pageVisibilityHandler!==null&&this._document.hidden===!0?this._delta=0:(this._previousTime=this._currentTime,this._currentTime=(e!==void 0?e:q())-this._startTime,this._delta=(this._currentTime-this._previousTime)*this._timescale,this._elapsed+=this._delta),this}};function q(){return performance.now()}function tt(){this._document.hidden===!1&&this.reset()}var I={FourByThree:1.3333333333333333,SixteenByNine:1.7777777777777777,NineBySixteen:.5625,TwentyOneByNine:2.3333333333333335,OneByOne:1},H=class{container;canvas;aspectRatio;onResize;handleResizeBound;resizeObserver=null;constructor(e){this.container=e.container,this.canvas=e.canvas,this.aspectRatio=(typeof e.aspectRatio=="number",e.aspectRatio),this.onResize=e.onResize,this.handleResizeBound=this.apply.bind(this)}attach(){window.addEventListener("resize",this.handleResizeBound),typeof ResizeObserver<"u"&&(this.resizeObserver=new ResizeObserver(this.handleResizeBound),this.resizeObserver.observe(this.container)),this.apply()}detach(){window.removeEventListener("resize",this.handleResizeBound),this.resizeObserver?.disconnect(),this.resizeObserver=null}measure(){let e=this.container.getBoundingClientRect(),t=Math.round(e.width||this.container.clientWidth||0),n=Math.round(e.height||this.container.clientHeight||0);if(t>0&&n>0){if(t/n>this.aspectRatio){let u=n;return{width:Math.round(u*this.aspectRatio),height:u}}let s=t,l=Math.round(s/this.aspectRatio);return{width:s,height:l}}if(t>0){let r=t,s=Math.round(r/this.aspectRatio);return{width:r,height:s}}if(n>0){let r=n;return{width:Math.round(r*this.aspectRatio),height:r}}let i=window.innerWidth,o=Math.round(i/this.aspectRatio);return{width:i,height:o}}apply(){let{width:e,height:t}=this.measure();this.canvas.style.width=`${e}px`,this.canvas.style.height=`${t}px`,this.onResize?.(e,t)}};var Ie={NES:{displayAspect:1.3333333333333333,resolutions:[{key:"256x240",width:256,height:240,notes:"Standard NTSC; effective 240p."}]},SNES:{displayAspect:1.3333333333333333,resolutions:[{key:"256x224",width:256,height:224,notes:"Common 240p-equivalent mode."},{key:"512x448",width:512,height:448,notes:"Hi-res interlaced (480i)."}]},N64:{displayAspect:1.3333333333333333,resolutions:[{key:"320x240",width:320,height:240,notes:"Common 240p mode."},{key:"640x480",width:640,height:480,notes:"Higher resolution (480i)."}]},PS1:{displayAspect:1.3333333333333333,resolutions:[{key:"320x240",width:320,height:240,notes:"Progressive 240p common."},{key:"640x480",width:640,height:480,notes:"Interlaced 480i for higher detail."}]},PS2:{displayAspect:1.3333333333333333,resolutions:[{key:"640x480",width:640,height:480,notes:"480i/480p baseline."},{key:"720x480",width:720,height:480,notes:"480p (widescreen capable in some titles)."},{key:"1280x720",width:1280,height:720,notes:"720p (select titles)."}]},PS5:{displayAspect:1.7777777777777777,resolutions:[{key:"720x480",width:720,height:480,notes:"Legacy compatibility."},{key:"1280x720",width:1280,height:720,notes:"720p."},{key:"1920x1080",width:1920,height:1080,notes:"1080p."},{key:"2560x1440",width:2560,height:1440,notes:"1440p."},{key:"3840x2160",width:3840,height:2160,notes:"4K (up to 120Hz)."},{key:"7680x4320",width:7680,height:4320,notes:"8K (limited)."}]},XboxOne:{displayAspect:1.7777777777777777,resolutions:[{key:"1280x720",width:1280,height:720,notes:"720p (original)."},{key:"1920x1080",width:1920,height:1080,notes:"1080p (original)."},{key:"3840x2160",width:3840,height:2160,notes:"4K UHD (S/X models)."}]},MobilePortrait:{displayAspect:.5625,resolutions:[{key:"360x640",width:360,height:640,notes:"Low-density phone portrait baseline."},{key:"720x1280",width:720,height:1280,notes:"HD phone portrait."},{key:"1080x1920",width:1080,height:1920,notes:"Full HD phone portrait."}]}};function Q(a){return Ie[a].displayAspect}function ee(a,e){let t=Ie[a]?.resolutions||[];if(!e)return t[0];let n=e.toLowerCase().replace(/\s+/g,"").replace("\xD7","x");return t.find(i=>i.key.toLowerCase()===n)}function te(a){if(!a)return null;let t=String(a).toLowerCase().trim().replace(/\s+/g,"").replace("\xD7","x").match(/^(\d+)x(\d+)$/);if(!t)return null;let n=parseInt(t[1],10),i=parseInt(t[2],10);return!Number.isFinite(n)||!Number.isFinite(i)?null:{width:n,height:i}}var ne=null,ie=class{constructor(e,t,n,i,o,r,s,l,u,m,p,h,Z){this.id=e;this.globals=t;this.stages=n;this.debug=i;this.time=o;this.input=r;this.aspectRatio=s;this.internalResolution=l;this.fullscreen=u;this.bodyBackground=m;this.container=p;this.containerId=h;this.canvas=Z}};function nt(a={}){return a.deviceProfile==="mobile"?!0:a.deviceProfile==="desktop"?!1:a.viewportSize?T({viewportSize:a.viewportSize,allowViewportOnly:!0}):T()}function it(a,e){if(e)return e;if(a){let i=document.getElementById(a);if(i)return i}let t=a||"zylem-root",n=document.createElement("main");return n.setAttribute("id",t),n.style.position="relative",n.style.width="100%",n.style.height="100%",document.body.appendChild(n),n}function at(a){let e=a?.id??"zylem";return{id:e,globals:a?.globals??{},stages:a?.stages??[],debug:!!a?.debug,time:a?.time??0,input:a?.input,aspectRatio:I.SixteenByNine,fullscreen:!0,bodyBackground:"#000000",containerId:e}}var Pe=360;function Le(a,e){if(!a)return;if(typeof a=="string"){if(a==="native")return ne;let i=te(a);if(i)return i;if(e){let o=ee(e,a);if(o)return{width:o.width,height:o.height}}return}let t=a.width,n=a.height;if(Number.isFinite(t)&&Number.isFinite(n))return{width:t,height:n}}function ot(a,e,t,n){if(typeof a=="number")return a;if(typeof a=="string")return I[a]??t;if(e)try{return Q(e)||t}catch{return t}return n?n.width/n.height:t}function st(a){let e=Number.isFinite(a)&&a>0?a:I.SixteenByNine;if(e>=1){let i=Pe;return{width:Math.round(i*e),height:i}}let t=Pe,n=Math.round(t/e);return{width:t,height:n}}function P(a,e={}){let t=at({id:a?.id??"zylem",debug:!!a?.debug,time:a?.time??0,input:a?.input,stages:a?.stages??[],globals:a?.globals??{}}),n=a?.containerId??t.containerId,i=it(n,a?.container??null),o=a?.mobile,r=nt(e),s=r?o?.preset??a?.preset:a?.preset,l=Le(a?.resolution,a?.preset),u=Le(o?.resolution,o?.preset??a?.preset),m=(r?ke(u):void 0)??ke(l),p=r?o?.aspectRatio??a?.aspectRatio:a?.aspectRatio,h=ot(p,s,t.aspectRatio,m),Z=rt(r,u,l,h),Ve=a?.fullscreen??t.fullscreen,He=a?.bodyBackground??t.bodyBackground,Oe=a?.canvas??void 0,Ue=lt(a?.input??t.input,o?.controls);return new ie(a?.id??t.id,a?.globals??t.globals,a?.stages??t.stages,!!(a?.debug??t.debug),a?.time??t.time,Ue,h,Z,Ve,He,i,n,Oe)}function ke(a){if(a)return a}function rt(a,e,t,n){if(a)return e===ne?void 0:e??st(n);if(t!==ne)return t}function lt(a,e){if(!e)return a;let n=ge("p1",{enabled:"auto",...e===!0?{}:e});return v(n,a??{})}function ut(a){return{...a}}var O=class{id;container;canvas;bodyBackground;fullscreen;aspectRatio;ratioDelegate=null;overlayContainer=null;constructor(e){this.id=e.id,this.container=this.ensureContainer(e.containerId??e.id,e.container),this.canvas=e.canvas??document.createElement("canvas"),this.bodyBackground=e.bodyBackground,this.fullscreen=!!e.fullscreen,this.aspectRatio=(typeof e.aspectRatio=="number",e.aspectRatio)}applyBodyBackground(){this.bodyBackground&&(document.body.style.background=this.bodyBackground)}mountCanvas(){this.mountChildren(this.canvas)}mountRenderer(e,t){this.mountChildren(e),this.canvas=e,this.attachAspectRatio(t)}getOverlayContainer(){return this.ensureOverlayContainer()}centerIfFullscreen(){if(!this.fullscreen)return;let e=this.container.style;e.display="flex",e.alignItems="center",e.justifyContent="center",e.position="relative",e.inset="0"}attachAspectRatio(e){this.ratioDelegate?(this.ratioDelegate.canvas=this.canvas,this.ratioDelegate.onResize=e,this.ratioDelegate.aspectRatio=this.aspectRatio,this.ratioDelegate.apply()):(this.ratioDelegate=new H({container:this.container,canvas:this.canvas,aspectRatio:this.aspectRatio,onResize:e}),this.ratioDelegate.attach())}setAspectRatio(e){this.aspectRatio=e,this.ratioDelegate&&(this.ratioDelegate.aspectRatio=e,this.ratioDelegate.apply())}reapplyLayout(){this.ratioDelegate?.apply()}destroy(){this.ratioDelegate?.detach(),this.ratioDelegate=null}mountChildren(e){for(;this.container.firstChild;)this.container.removeChild(this.container.firstChild);this.container.appendChild(e),this.container.appendChild(this.ensureOverlayContainer())}ensureOverlayContainer(){if(this.overlayContainer)return this.overlayContainer;let e=document.createElement("div");return e.dataset.zylemOverlayRoot="true",e.style.position="absolute",e.style.inset="0",e.style.pointerEvents="none",e.style.touchAction="none",e.style.zIndex="10",this.overlayContainer=e,e}ensureContainer(e,t){if(t)return t;if(e){let o=document.getElementById(e);if(o)return o}let n=e||this.id||"zylem-root",i=document.createElement("main");return i.setAttribute("id",n),i.style.position="relative",i.style.width="100%",i.style.height="100%",document.body.appendChild(i),i}};import pt from"stats.js";import{subscribe as dt}from"valtio/vanilla";var U=class{statsRef=null;unsubscribe=null;constructor(){this.updateDebugUI(),this.unsubscribe=dt(g,()=>{this.updateDebugUI()})}begin(){this.statsRef?.begin()}end(){this.statsRef?.end()}updateDebugUI(){g.enabled&&!this.statsRef?(this.statsRef=new pt,this.statsRef.showPanel(0),this.statsRef.dom.style.position="absolute",this.statsRef.dom.style.bottom="0",this.statsRef.dom.style.right="0",this.statsRef.dom.style.top="auto",this.statsRef.dom.style.left="auto",document.body.appendChild(this.statsRef.dom)):!g.enabled&&this.statsRef&&(this.statsRef.dom.parentNode&&this.statsRef.dom.parentNode.removeChild(this.statsRef.dom),this.statsRef=null)}dispose(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null),this.statsRef?.dom?.parentNode&&this.statsRef.dom.parentNode.removeChild(this.statsRef.dom),this.statsRef=null}};var _=class{loadingHandlers=[];stageLoadingUnsubscribes=[];onLoading(e){return this.loadingHandlers.push(e),()=>{this.loadingHandlers=this.loadingHandlers.filter(t=>t!==e)}}emit(e){for(let n of this.loadingHandlers)try{n(e)}catch(i){console.error("Game loading handler failed",i)}let t=`loading:${e.type}`;b.emit(t,e)}wireStageLoading(e,t){let n=e.onLoading(i=>{this.emit({type:i.type,message:i.message??"",progress:i.progress??0,current:i.current,total:i.total,stageName:e.uuid??`Stage ${t}`,stageIndex:t})});typeof n=="function"&&this.stageLoadingUnsubscribes.push(n)}unwireAllStages(){for(let e of this.stageLoadingUnsubscribes)try{e()}catch{}this.stageLoadingUnsubscribes=[]}dispose(){this.unwireAllStages(),this.loadingHandlers=[]}};import{getZylemBridge as ct}from"@zylem/bridge";var N=class{container=null;camera=null;rendererManager=null;gameCanvas=null;config=null;stage=null;mounted=!1;setGameCanvas(e){this.gameCanvas=e,this.tryMount()}setConfig(e){this.config=e,this.tryMount()}setContainer(e){this.container=e,this.tryMount()}setStage(e){this.stage=e,this.mounted&&this.gameCanvas?.reapplyLayout()}setCamera(e){this.camera=e,this.tryMount()}setRendererManager(e){this.rendererManager=e,this.tryMount()}tryMount(){this.mounted||!this.container||!this.gameCanvas||(this.rendererManager?this.mountWithRendererManager():this.camera&&this.mountWithCamera())}mountWithRendererManager(){if(!this.rendererManager||!this.gameCanvas)return;let e=this.rendererManager.getDomElement();this.gameCanvas.mountRenderer(e,(t,n)=>{if(!this.rendererManager)return;let i=this.config?.internalResolution;if(i)this.rendererManager.setPixelRatio(1),this.rendererManager.resize(i.width,i.height),this.stage?.resize(i.width,i.height);else{let o=window.devicePixelRatio||1;this.rendererManager.setPixelRatio(o),this.rendererManager.resize(t,n),this.stage?.resize(t,n)}}),this.mounted=!0}mountWithCamera(){if(!this.camera||!this.gameCanvas)return;let e=this.camera.getDomElement();this.gameCanvas.mountRenderer(e,(t,n)=>{if(!this.camera)return;let i=this.config?.internalResolution;if(i)this.camera.setPixelRatio(1),this.camera.resize(i.width,i.height);else{let o=window.devicePixelRatio||1;this.camera.setPixelRatio(o),this.camera.resize(t,n)}}),this.mounted=!0}reset(){this.camera=null,this.stage=null,this.mounted=!1}dispose(){this.container=null,this.camera=null,this.rendererManager=null,this.gameCanvas=null,this.config=null,this.stage=null,this.mounted=!1}};var F=class a{id;initialGlobals={};customSetup=null;customUpdate=null;customDestroy=null;stages=[];stageMap=new Map;currentStageId="";previousTimeStamp=0;totalTime=0;timer;inputManager;wrapperRef;globalInputConfig;defaultCamera=null;rendererManager=null;container=null;canvas=null;aspectRatioDelegate=null;resolvedConfig=null;gameCanvas=null;animationFrameId=null;isDisposed=!1;loadInFlight=!1;hasStarted=!1;debugDelegate=null;loadingDelegate=new _;rendererObserver=new N;eventBusUnsubscribes=[];thumbnailUnsubscribes=[];lastPublishedGameConfig=null;gameBridge=new Se;catalogUnsubscribe=null;gameUpdateParams={};stageSetupParams={};stageUpdateParams={};frameCallback=e=>this.loop(e);sourceOptions;displayRuntime;static FRAME_LIMIT=120;static FRAME_DURATION=1e3/a.FRAME_LIMIT;static MAX_DELTA_SECONDS=1/30;constructor(e,t,n={}){this.wrapperRef=t,this.timer=new V,this.timer.connect(document),this.sourceOptions={...e},this.displayRuntime={...n};let i=P(e,this.displayRuntime);this.globalInputConfig=i.input,this.id=i.id,this.stages=i.stages||[],this.container=i.container,this.canvas=i.canvas??null,this.resolvedConfig=i,this.loadGameCanvas(i),this.container=this.gameCanvas?.container??this.container,this.inputManager=new A(i.input,{targetElement:this.gameCanvas?.getOverlayContainer(),mouseTargetElement:this.gameCanvas?.container}),this.loadDebugOptions(e),this.setGlobals(e),Ee(),this.gameBridge.connect({resolveEntity:o=>this.currentStage()?.wrappedStage?.entityDelegate.childrenMap.get(o)??null,setStageVariable:(o,r)=>{let s=this.currentStage()?.wrappedStage?.state;s&&(s.variables[o]=r)},createEntity:(o,r,s)=>{this.createCatalogEntity(o,r,s)},applySceneOperation:(o,r)=>{this.currentStage()?.wrappedStage?.debugDelegate?.applySceneOperation(o,r)}}),this.publishEntityCatalog(),this.catalogUnsubscribe=xe(()=>this.publishEntityCatalog())}publishEntityCatalog(){this.gameBridge.publishCatalog(Ce())}createCatalogEntity(e,t,n){let i=this.currentStage()?.wrappedStage,o=we(e);if(!i||!o)return;let r=n?.position??{x:0,y:0,z:0},s=o.create({position:r,props:{...o.defaultProps??{},...t??{}}});s&&Promise.resolve(s).then(l=>l&&i.entityDelegate.spawnEntity(l)).catch(l=>{console.error("entity:create failed",l)})}setDisplayRuntime(e){this.displayRuntime={...e};let t=P(this.sourceOptions,this.displayRuntime);this.resolvedConfig=t,this.rendererObserver.setConfig(t),this.gameCanvas?.setAspectRatio(t.aspectRatio),this.publishGameConfig()}loadGameCanvas(e){this.gameCanvas=new O({id:e.id,container:e.container,containerId:e.containerId,canvas:this.canvas??void 0,bodyBackground:e.bodyBackground,fullscreen:e.fullscreen,aspectRatio:e.aspectRatio}),this.gameCanvas.applyBodyBackground(),this.gameCanvas.mountCanvas(),this.gameCanvas.centerIfFullscreen(),this.rendererObserver.setGameCanvas(this.gameCanvas),this.resolvedConfig&&this.rendererObserver.setConfig(this.resolvedConfig),this.container&&this.rendererObserver.setContainer(this.container),this.subscribeToEventBus()}loadDebugOptions(e){e.debug!==void 0&&(g.enabled=!!e.debug),this.debugDelegate=new U}isLoading(){return this.loadInFlight}async loadStage(e,t=0,n){if(this.loadInFlight){console.warn("loadStage ignored: a stage load is already in progress");return}this.loadInFlight=!0;try{await this.performLoadStage(e,t,n)}finally{this.loadInFlight=!1}}async performLoadStage(e,t=0,n){let i=n?Re(n):null,o=this.currentStage()??null,r=o?.wrappedStage??null,s=r?.scene?.scene??null,l=r?.cameraManagerRef?.primaryCamera?.camera??r?.cameraRef?.camera??null;i&&this.rendererManager?.initialized&&o&&s&&l&&this.rendererManager.beginSnapshotTransition(i,s,l),this.unloadCurrentStage();let m=e.options[0];if(this.loadingDelegate.wireStageLoading(e,t),this.rendererManager||(this.rendererManager=new he,await this.rendererManager.initRenderer()),y.setRenderer(this.rendererManager.renderer),await e.load(this.id,m?.camera,this.rendererManager),this.stageMap.set(e.wrappedStage.uuid,e),this.currentStageId=e.wrappedStage.uuid,this.defaultCamera=e.wrappedStage.cameraRef,this.wireEntityThumbnails(e),this.rendererObserver.setStage(e.wrappedStage??null),this.rendererManager&&this.rendererObserver.setRendererManager(this.rendererManager),this.applyInputConfig(e),e.onInputConfigChanged=()=>this.applyInputConfig(e),this.hasStarted&&e.wrappedStage&&!e.wrappedStage.hasSetup){let p=this.params(),h={...this.stageSetupParams};h.inputs=p.inputs,h.globals=p.globals,h.camera=p.camera,h.stage=p.stage,h.game=p.game,h.me=e.wrappedStage,e.start(h)}this.publishGameConfig(),this.publishStageSnapshot()}applyInputConfig(e){let t=v(this.globalInputConfig??{},e.inputConfig??{});this.inputManager.configure(t)}setGlobalInputConfig(e){this.globalInputConfig=e;let t=this.currentStage();t&&this.applyInputConfig(t)}unloadCurrentStage(){if(!this.currentStageId)return;let e=this.getStage(this.currentStageId);if(e){if(this.clearEntityThumbnailWiring(),y.clear(),e.onInputConfigChanged=null,e?.wrappedStage){try{e.wrappedStage.nodeDestroy({me:e.wrappedStage,globals:C.globals})}catch(t){console.error("Failed to destroy previous stage",t)}e.wrappedStage=null}e.dispose(),this.stageMap.delete(this.currentStageId),this.currentStageId="",this.defaultCamera=null,this.rendererObserver.reset()}}setGlobals(e){this.initialGlobals={...e.globals};for(let t in this.initialGlobals){let n=this.initialGlobals[t];n===void 0&&console.error(`global ${t} is undefined`),le(t,n)}}params(){let e=this.currentStage(),t=this.timer.getDelta(),n=this.inputManager.getInputs(t),i=e?.wrappedStage?.cameraRef||this.defaultCamera,o=this.gameUpdateParams;return o.delta=t,o.inputs=n,o.globals=de(),o.me=this,o.camera=i,o.stage=e,o.game=this.wrapperRef,o}start(){let e=this.currentStage(),t=this.params(),n=this.stageSetupParams;n.inputs=t.inputs,n.globals=t.globals,n.camera=t.camera,n.stage=t.stage,n.game=t.game,n.me=e.wrappedStage,e.start(n),this.customSetup&&this.customSetup(t),this.hasStarted=!0,this.loop(0)}step(e){let t=this.currentStage();if(!t||!t.wrappedStage)return;let n=this.params(),i=e!==void 0?e:n.delta,o=Math.min(Math.max(i,0),a.MAX_DELTA_SECONDS);n.delta=o,this.customUpdate&&this.customUpdate(n);let r=this.currentStage();if(r!==t||!r?.wrappedStage){this.totalTime+=o,C.time=this.totalTime;return}let s=this.stageUpdateParams;s.delta=n.delta,s.inputs=n.inputs,s.globals=n.globals,s.camera=n.camera,s.stage=n.stage,s.game=n.game,s.me=t.wrappedStage,t.wrappedStage?.nodeUpdate(s),this.totalTime+=o,C.time=this.totalTime}loop(e){this.debugDelegate?.begin(),me()||(this.timer.update(e),this.step(),this.previousTimeStamp=e),this.debugDelegate?.end(),this.outOfLoop(),this.isDisposed||(this.animationFrameId=requestAnimationFrame(this.frameCallback))}dispose(){this.isDisposed=!0,this.catalogUnsubscribe?.(),this.catalogUnsubscribe=null,this.gameBridge.disconnect(),this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.unloadCurrentStage(),this.debugDelegate&&(this.debugDelegate.dispose(),this.debugDelegate=null),this.eventBusUnsubscribes.forEach(e=>e()),this.eventBusUnsubscribes=[],this.rendererObserver.dispose(),this.inputManager.dispose(),this.rendererManager&&(y.setRenderer(null),this.rendererManager.dispose(),this.rendererManager=null),y.clear(),ct().channel.reset(),this.timer.dispose(),this.customDestroy&&this.customDestroy({me:this,globals:C.globals}),x()}outOfLoop(){let e=this.currentStage();e&&e.wrappedStage.outOfLoop()}getStage(e){return this.stageMap.get(e)}currentStage(){return this.getStage(this.currentStageId)}onLoading(e){return this.loadingDelegate.onLoading(e)}buildStageConfigPayload(){let e=this.currentStage();if(!e?.wrappedStage)return null;let t=e.wrappedStage.state,n=t.backgroundColor,i=typeof n=="string"?n:`#${n.getHexString()}`;return{id:e.wrappedStage.uuid,backgroundColor:i,backgroundImage:t.backgroundImage,gravity:{x:t.gravity.x,y:t.gravity.y,z:t.gravity.z},inputs:t.inputs,variables:t.variables}}buildEntitySummary(e){if(G(e.options))return null;let t=e.position??{x:0,y:0,z:0},n=e.rotation??{x:0,y:0,z:0},i=ye(e),o=be(e),r=y.get(e.uuid);return{uuid:e.uuid,name:e.name||"Unnamed",type:ve(e),position:{x:t.x??0,y:t.y??0,z:t.z??0},rotation:{x:n.x??0,y:n.y??0,z:n.z??0},scale:i,quaternion:o,thumbnail:r?.dataUrl??null,bounds:r?.bounds}}buildEntitiesPayload(){let e=this.currentStage();if(!e?.wrappedStage)return[];let t=[];return e.wrappedStage.entityDelegate.childrenMap.forEach(n=>{let i=this.buildEntitySummary(n);i&&t.push(i)}),t}wireEntityThumbnails(e){if(this.clearEntityThumbnailWiring(),!e.wrappedStage)return;let t=r=>{if(!this.gameBridge.wantsThumbnails()||G(r.options))return;let s=r.group??r.mesh??null;s&&y.ensure(r.uuid,s).then(l=>{l&&!this.isDisposed&&this.gameBridge.queueThumbnails([{uuid:r.uuid,url:l.dataUrl,bounds:l.bounds}])})},n=e.wrappedStage.onEntityAdded(r=>{if(this.gameBridge.wantsEntityUpdates()){let s=this.buildEntitySummary(r);s&&this.gameBridge.queueEntityUpsert([s])}t(r)},{replayExisting:!0});this.thumbnailUnsubscribes.push(n);let i=r=>{if(!r.success)return;let s=e.wrappedStage?.entityDelegate.childrenMap.get(r.entityId);s&&(y.invalidate(r.entityId),t(s))};b.on("entity:model:loaded",i),this.thumbnailUnsubscribes.push(()=>{b.off("entity:model:loaded",i)});let o=r=>{y.invalidate(r.entityId),this.gameBridge.wantsEntityUpdates()&&this.gameBridge.queueEntityRemoved([r.entityId])};b.on("entity:destroyed",o),this.thumbnailUnsubscribes.push(()=>{b.off("entity:destroyed",o)}),this.wireEditorBackfill(e)}wireEditorBackfill(e){let t=this.gameBridge.onEditorAttached(()=>{if(!(this.isDisposed||this.currentStage()!==e)){this.lastPublishedGameConfig=null,this.publishGameConfig(),this.publishStageSnapshot();for(let n of e.wrappedStage?.entityDelegate.childrenMap.values()??[]){let i=n;if(G(i.options))continue;let o=i.group??i.mesh??null;o&&y.ensure(i.uuid,o).then(r=>{r&&!this.isDisposed&&this.gameBridge.queueThumbnails([{uuid:i.uuid,url:r.dataUrl,bounds:r.bounds}])})}}});this.thumbnailUnsubscribes.push(t)}clearEntityThumbnailWiring(){this.thumbnailUnsubscribes.forEach(e=>{try{e()}catch{}}),this.thumbnailUnsubscribes=[]}buildGameConfigPayload(){return this.resolvedConfig?{id:this.resolvedConfig.id,aspectRatio:this.resolvedConfig.aspectRatio,fullscreen:this.resolvedConfig.fullscreen,bodyBackground:this.resolvedConfig.bodyBackground,internalResolution:this.resolvedConfig.internalResolution,debug:this.resolvedConfig.debug}:null}publishGameConfig(){let e=this.buildGameConfigPayload();if(!e)return;let t=JSON.stringify(e);t!==this.lastPublishedGameConfig&&(this.lastPublishedGameConfig=t,this.gameBridge.publishConfig(e))}publishStageSnapshot(){this.gameBridge.publishStageSnapshot({stage:this.buildStageConfigPayload(),entities:this.buildEntitiesPayload()})}subscribeToEventBus(){this.eventBusUnsubscribes.push(re.on("game:state:updated",e=>{this.gameBridge.publishVariable({path:e.path,value:e.value,previousValue:e.previousValue})}))}};async function De(a){let{getGameDefaultConfig:e}=await import("./game-default-7HCJJF5S.js"),t={...e()},n=[],i=[],o=[];Object.values(a).forEach(s=>{if(s instanceof L)i.push(s);else if(s instanceof j)o.push(s);else if(s instanceof W)o.push(s);else if(s?.constructor?.name==="Object"&&typeof s=="object"){let l=Object.assign({...e()},{...s});n.push(l)}}),n.forEach(s=>{t=Object.assign(t,{...s})});let r=t;return r.input=n[0].input,i.forEach(s=>{s.addEntities(o)}),i.length?r.stages=i:r.stages[0].addEntities(o),r}function ze(a){return!!a.find(t=>t instanceof L)}function ae(a){for(let e of a)if(e&&typeof e=="object"&&!(e instanceof L)&&!(e instanceof W)&&!(e instanceof j)){let t=e;if(t.globals)return t.globals}}import{proxy as mt}from"valtio/vanilla";import{get as ht,set as gt}from"idb-keyval";import{pack as ft,unpack as yt}from"msgpackr";var c=mt({previous:null,current:null,next:null,isLoading:!1}),X={staticRegistry:new Map,registerStaticStage(a,e){this.staticRegistry.set(a,e)},async loadStageData(a){try{let e=await ht(a);if(e)return yt(e)}catch(e){console.warn(`Failed to load stage ${a} from storage`,e)}if(this.staticRegistry.has(a))return this.staticRegistry.get(a);throw new Error(`Stage ${a} not found in storage and static loading not fully implemented.`)},async transitionForward(a,e){if(!c.isLoading){c.isLoading=!0;try{c.current&&await gt(c.current.id,ft(c.current)),c.previous=c.current,c.current=c.next,c.current?.id!==a&&(e?c.current=await e(a):c.current=await this.loadStageData(a)),c.next=null}catch(t){console.error("Failed to transition stage:",t)}finally{c.isLoading=!1}}},async preloadNext(a,e){e?c.next=await e(a):c.next=await this.loadStageData(a)}};var oe={async createFromBlueprint(a){let e=E({});if(a.entities)for(let t of a.entities)try{let n=await Be.createFromBlueprint(t);e.add(n)}catch(n){console.error(`Failed to create entity ${t.id} for stage ${a.id}`,n)}return e}};var Y=class{wrappedGame=null;options;setupCallbacks=[];updateCallbacks=[];destroyCallbacks=[];pendingLoadingCallbacks=[];globalChangeCallbacks=[];globalChangesCallbacks=[];activeGlobalSubscriptions=[];eventDelegate=new fe;pendingInputConfig=null;displayRuntime={};refErrorMessage="lost reference to game";constructor(e){this.options=e,ze(e)||this.options.push(E());let t=ae(e);t&&J(t)}onSetup(...e){return this.setupCallbacks.push(...e),this}onUpdate(...e){return this.updateCallbacks.push(...e),this}onDestroy(...e){return this.destroyCallbacks.push(...e),this}setInputConfiguration(...e){let t=v(...e);return this.pendingInputConfig=t,this.wrappedGame&&this.wrappedGame.setGlobalInputConfig(t),this}async start(){x();let e=ae(this.options);e&&J(e);let t=await this.load();return this.wrappedGame=t,this.setOverrides(),this.registerGlobalSubscriptions(),t.start(),this}setDisplayRuntime(e){return this.displayRuntime={...this.displayRuntime,...e},this.wrappedGame&&this.wrappedGame.setDisplayRuntime(this.displayRuntime),this}setDeviceProfile(e){return this.setDisplayRuntime({deviceProfile:e})}setViewportSize(e,t){return this.setDisplayRuntime({viewportSize:{width:e,height:t}})}async load(){let e=await De(this.options),t=P(e,this.displayRuntime);this.pendingInputConfig&&(t.input=v(t.input??{},this.pendingInputConfig));let n=new F({...e,...t},this,this.displayRuntime);for(let i of this.pendingLoadingCallbacks)n.onLoading(i);return await n.loadStage(e.stages[0]),n}setOverrides(){if(!this.wrappedGame){console.error(this.refErrorMessage);return}this.wrappedGame.customSetup=e=>{this.setupCallbacks.forEach(t=>t(e))},this.wrappedGame.customUpdate=e=>{this.updateCallbacks.forEach(t=>t(e))},this.wrappedGame.customDestroy=e=>{this.destroyCallbacks.forEach(t=>t(e))}}onGlobalChange(e,t){return this.globalChangeCallbacks.push({path:e,callback:t}),this}onGlobalChanges(e,t){return this.globalChangesCallbacks.push({paths:e,callback:t}),this}registerGlobalSubscriptions(){for(let{path:e,callback:t}of this.globalChangeCallbacks){let n=ue(e,i=>{t(i,this.getCurrentStage())});this.activeGlobalSubscriptions.push(n)}for(let{paths:e,callback:t}of this.globalChangesCallbacks){let n=pe(e,i=>{t(i,this.getCurrentStage())});this.activeGlobalSubscriptions.push(n)}}getCurrentStage(){return this.wrappedGame?.currentStage()??null}experimental={getRuntime:()=>this.getCurrentStage()?.wrappedStage?.world?.simulation??null};async pause(){K(!0)}async resume(){K(!1),this.wrappedGame&&(this.wrappedGame.previousTimeStamp=0,this.wrappedGame.timer.reset())}step(e=1/60){if(!this.wrappedGame){console.error(this.refErrorMessage);return}this.wrappedGame.step(e)}async reset(e){if(!this.wrappedGame){console.error(this.refErrorMessage);return}this.wrappedGame.isLoading()||await this.wrappedGame.loadStage(this.wrappedGame.stages[0],0,e?.transition)}previousStage(e){if(!this.wrappedGame){console.error(this.refErrorMessage);return}if(this.wrappedGame.isLoading())return;let t=this.wrappedGame.currentStageId,n=this.wrappedGame.stages.findIndex(o=>o.wrappedStage?.uuid===t),i=this.wrappedGame.stages[n-1];if(!i){console.error("previous stage called on first stage");return}this.wrappedGame.loadStage(i,n-1,e?.transition)}async loadStageFromId(e){if(!this.wrappedGame){console.error(this.refErrorMessage);return}try{let t=await X.loadStageData(e),n=await oe.createFromBlueprint(t);await this.wrappedGame.loadStage(n),c.current=t}catch(t){console.error(`Failed to load stage ${e}`,t)}}nextStage(e){if(!this.wrappedGame){console.error(this.refErrorMessage);return}if(this.wrappedGame.isLoading())return;if(c.next){console.log("next stage called");let o=c.next.id;if(X.transitionForward(o),c.current){oe.createFromBlueprint(c.current).then(r=>{this.wrappedGame?.loadStage(r,0,e?.transition)});return}}let t=this.wrappedGame.currentStageId,n=this.wrappedGame.stages.findIndex(o=>o.wrappedStage?.uuid===t),i=this.wrappedGame.stages[n+1];if(!i){console.error("next stage called on last stage");return}this.wrappedGame.loadStage(i,n+1,e?.transition)}async goToStage(){}async end(){}dispose(){this.eventDelegate.dispose();for(let e of this.activeGlobalSubscriptions)e();this.activeGlobalSubscriptions=[],this.wrappedGame&&(this.wrappedGame.dispose(),this.wrappedGame=null),ce(),x(),Ge.clearSharedMaterialCache()}dispatch(e,t){this.eventDelegate.dispatch(e,t),b.emit(e,t)}listen(e,t){return this.eventDelegate.listen(e,t)}onLoading(e){return this.wrappedGame?this.wrappedGame.onLoading(e):(this.pendingLoadingCallbacks.push(e),()=>{this.pendingLoadingCallbacks=this.pendingLoadingCallbacks.filter(t=>t!==e),this.wrappedGame})}};function bt(...a){return new Y(a)}import{Euler as vt,Quaternion as St,Vector2 as wt}from"three";function Ct(a){return{spawn:async(e,t,n)=>{let i=await Promise.resolve(a(t,n));return e.add(i),i},spawnRelative:async(e,t,n=new wt(0,1))=>{if(!e.body){console.warn("body missing for entity during spawnRelative");return}let{x:i,y:o,z:r}=e.body.translation(),s=e._rotation2DAngle??0;try{let p=e.body.rotation(),h=new St(p.x,p.y,p.z,p.w);s=new vt().setFromQuaternion(h,"XYZ").z}catch{}let l=Math.sin(-s)*(n.x??0),u=Math.cos(-s)*(n.y??0),m=await Promise.resolve(a(i+l,o+u));return t.add(m),m}}}import{subscribe as xt}from"valtio/vanilla";var se="STAGE_STATE_CHANGE";function Gt(){return xt(S,()=>{let a={entities:S.entities,variables:S.variables};window.dispatchEvent(new CustomEvent(se,{detail:a}))})}function Et(){let a={entities:S.entities,variables:S.variables};window.dispatchEvent(new CustomEvent(se,{detail:a}))}import{MathUtils as Rt,Vector3 as Tt}from"three";var Ae={targetKey:"primary",offset:new Tt(0,0,0),lerpFactor:.1};function Bt(a){let e={...Ae,...a,offset:$(a?.offset,Ae.offset)},t=null;return{priority:0,enabled:!0,onAttach(){t=null},update(n,i){let o=n.targets[e.targetKey];if(!o)return i;let r=o.position.clone().add(e.offset),s=Te(i);if(!t)t=r.clone();else{let l=Rt.clamp(e.lerpFactor,0,1),u=1-Math.pow(1-l,n.dt*60);t.lerp(r,u)}return s.position.copy(t),s.lookAt=o.position.clone(),s},onDetach(){t=null}}}import{MeshBasicMaterial as Mt}from"three";function It(a,e,t){let n=e.cameraRef;if(!n.renderTarget){let r=t?.width??512,s=t?.height??512;n.createRenderTarget(r,s)}let i=n.getRenderTexture();if(!i){console.warn("setCameraFeed: Failed to obtain render texture from camera.");return}if(!a.mesh){console.warn("setCameraFeed: Entity has no mesh to apply the camera feed to.");return}let o=new Mt({map:i});a.mesh.material=o}export{I as a,Q as b,ee as c,te as d,ut as e,c as f,X as g,Y as h,bt as i,Ct as j,se as k,Gt as l,Et as m,Bt as n,It as o};
|
package/dist/chunk-GHJQ2HKI.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as T,b as u,r as w,t as f,v as d}from"./chunk-SAQA4SXW.js";import{j as v}from"./chunk-4QLJUQSJ.js";import{a as _,g as E,i as O,j as b}from"./chunk-7WRQ2UAN.js";import{Group as k,Quaternion as G,Vector3 as N}from"three";import{ParticleEmitterBehavior as x}from"@zylem/behaviors/particle-emitter";var V={...w,effect:{create(){throw new Error("createParticleSystem(...) requires an effect or preset definition.")}},preset:void 0,autoplay:!0,localOffset:void 0,followPosition:!0,followRotation:!0,autoDestroy:!1},I=Symbol("ParticleSystem");function W(n){return{effect:n.preset??n.effect,autoplay:n.autoplay,localOffset:n.localOffset,followPosition:n.followPosition,followRotation:n.followRotation,autoDestroy:n.autoDestroy}}var P=class n extends f{static type=I;particleHandle=null;constructor(o,e=!0){super(),this.options=u(V,o),this.group=new k;let t=this.options.position;t&&this.group.position.copy(b(t)),this.__zylemParticleSystemEntity=!0,this.bindStandaloneTransforms(),e&&(this.particleHandle=this.use(x,W(this.options)))}bindStandaloneTransforms(){let o=()=>{this.options.position=new N(this.group?.position.x??0,this.group?.position.y??0,this.group?.position.z??0)},e=()=>{this.group&&(this._rotation2DAngle=this.group.rotation.z)};this.setPosition=(t,i,r)=>{this.group?.position.set(t,i,r),o()},this.setPositionX=t=>{this.group&&(this.group.position.x=t,o())},this.setPositionY=t=>{this.group&&(this.group.position.y=t,o())},this.setPositionZ=t=>{this.group&&(this.group.position.z=t,o())},this.getPosition=()=>this.group?{x:this.group.position.x,y:this.group.position.y,z:this.group.position.z}:null,this.setRotation=(t,i,r)=>{this.group?.rotation.set(t,i,r),e()},this.setRotationX=t=>{this.group&&(this.group.rotation.x=t,e())},this.setRotationY=t=>{this.group&&(this.group.rotation.y=t,e())},this.setRotationZ=t=>{this.group&&(this.group.rotation.z=t,e())},this.setRotationDegrees=(t,i,r)=>{this.group?.rotation.set(t*Math.PI/180,i*Math.PI/180,r*Math.PI/180),e()},this.setRotationDegreesX=t=>{this.group&&(this.group.rotation.x=t*Math.PI/180,e())},this.setRotationDegreesY=t=>{this.group&&(this.group.rotation.y=t*Math.PI/180,e())},this.setRotationDegreesZ=t=>{this.group&&(this.group.rotation.z=t*Math.PI/180,e())},this.rotateX=t=>{this.group?.rotateX(t),e()},this.rotateY=t=>{this.group?.rotateY(t),e()},this.rotateZ=t=>{this.group?.rotateZ(t),e()},this.getRotation=()=>{if(!this.group)return null;let t=new G;return this.group.getWorldQuaternion(t),t}}resolveParticleHandle(){if(this.particleHandle)return this.particleHandle;let o=this.getBehaviorRefs().find(i=>i.descriptor.key===x.key);if(!o)return null;let e={getFSM:()=>o.fsm??null,getOptions:()=>o.options,ref:o},t=x.createHandle?.(o)??{};return this.particleHandle={...e,...t},this.particleHandle}play(){this.resolveParticleHandle()?.play()}stop(){this.resolveParticleHandle()?.stop()}pause(){this.resolveParticleHandle()?.pause()}restart(){this.resolveParticleHandle()?.restart()}burst(){this.resolveParticleHandle()?.burst()}isPlaying(){return this.resolveParticleHandle()?.isPlaying()??!1}getSystem(){return this.resolveParticleHandle()?.getSystem()}buildInfo(){return{...super.buildInfo(),type:String(n.type)}}};function Z(n,o=!0){let e=new P(n,o);return d(e,t=>Z(t,!1))}function X(n){return Z(n,!0)}import{Group as U,Sprite as Q,SpriteMaterial as $,CanvasTexture as q,LinearFilter as R,Color as H,ClampToEdgeWrapping as M}from"three";import{getCooldown as z}from"@zylem/behaviors/cooldown";var K={"top-left":{fx:0,fy:0},"top-center":{fx:.5,fy:0},"top-right":{fx:1,fy:0},"center-left":{fx:0,fy:.5},center:{fx:.5,fy:.5},"center-right":{fx:1,fy:.5},"bottom-left":{fx:0,fy:1},"bottom-center":{fx:.5,fy:1},"bottom-right":{fx:1,fy:1}},D=192,j={xs:8,sm:16,md:32,lg:48,xl:64},C={position:void 0,cooldown:"",iconSize:"md",fillColor:"#333333",showTimer:!0,stickToViewport:!0,screenAnchor:"top-left",screenPosition:{x:0,y:0},zDistance:1,overlayColor:"rgba(0, 0, 0, 0.65)"},J=Symbol("CooldownIcon"),S=class extends f{static type=J;_sprite=null;_texture=null;_canvas=null;_ctx=null;_cameraRef=null;_iconTexture=null;_iconImage=null;_lastRenderedProgress=-1;constructor(o){super(),this.options=u(C,o),this.options.screenPosition=O(this.options.screenPosition,C.screenPosition),this.group=new U,this.createSprite(),this.prependSetup(this.iconSetup.bind(this)),this.prependUpdate(this.iconUpdate.bind(this)),this.onCleanup(this.iconDestroy.bind(this))}createSprite(){this._canvas=document.createElement("canvas"),this._canvas.width=256,this._canvas.height=256,this._ctx=this._canvas.getContext("2d"),this._texture=new q(this._canvas),this._texture.minFilter=R,this._texture.magFilter=R,this._texture.wrapS=M,this._texture.wrapT=M;let e=new $({map:this._texture,transparent:!0,depthTest:!1,depthWrite:!1});if(this._sprite=new Q(e),this.group?.add(this._sprite),this.options.icon){let t=new Image;t.crossOrigin="anonymous",t.onload=()=>{this._iconImage=t,this.redraw(this._lastRenderedProgress>=0?this._lastRenderedProgress:1)},t.src=this.options.icon}this.redraw(1)}redraw(o){if(!this._canvas||!this._ctx)return;let e=this._ctx,t=this._canvas.width,i=this._canvas.height,r=t/2,s=i/2,l=Math.min(r,s);if(e.clearRect(0,0,t,i),this._iconImage?e.drawImage(this._iconImage,0,0,t,i):(e.fillStyle=this.toCssColor(this.options.fillColor??"#333333"),e.fillRect(0,0,t,i)),o<1){let p=(1-o)*Math.PI*2,c=-Math.PI/2,h=c+p;if(e.save(),e.fillStyle=this.options.overlayColor??"rgba(0, 0, 0, 0.65)",e.beginPath(),e.moveTo(r,s),e.arc(r,s,l+1,c,h,!1),e.closePath(),e.fill(),e.restore(),this.options.showTimer){let a=z(this.options.cooldown);if(a){let m=Math.max(0,a.duration-a.elapsed),g=m>=10?Math.ceil(m).toString():m.toFixed(1),y=Math.floor(t*.3);e.font=`bold ${y}px sans-serif`,e.textAlign="center",e.textBaseline="middle",e.fillStyle="#FFFFFF",e.strokeStyle="#000000",e.lineWidth=2,e.strokeText(g,r,s),e.fillText(g,r,s)}}}this._texture&&(this._texture.needsUpdate=!0),this._lastRenderedProgress=o}toCssColor(o){return typeof o=="string"?o:`#${(o instanceof H?o:new H(o)).getHexString()}`}getResolution(){try{let o=this._cameraRef?.renderer?.domElement;if(o)return{width:o.clientWidth||1,height:o.clientHeight||1}}catch{}return{width:this._cameraRef?.screenResolution?.x??1,height:this._cameraRef?.screenResolution?.y??1}}iconSetup(o){this._sprite||this.createSprite(),this._cameraRef=o.camera,this.options.stickToViewport&&this._cameraRef&&(this._cameraRef.camera.add(this.group),this.updateStickyTransform())}iconUpdate(o){let t=z(this.options.cooldown)?.progress??1;(Math.abs(t-this._lastRenderedProgress)>.02||t===1&&this._lastRenderedProgress!==1)&&this.redraw(t),this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}resolveScreenPosition(o,e){let t=this.options.screenAnchor??"top-left",i=E(this.options.screenPosition,_),r=i.x,s=i.y,{fx:l,fy:p}=K[t],c=l*o,h=p*e,a=e/D;return{px:c+r*a,py:h+s*a}}resolveIconSize(o){let e=this.options.iconSize??"md",t,i;typeof e=="string"?t=i=j[e]:typeof e=="number"?t=i=e:(t=e.width,i=e.height);let r=o/D;return{widthPx:t*r,heightPx:i*r}}computeWorldExtents(o,e){let t=1,i=1;if(o.isPerspectiveCamera){let r=o,s=Math.tan(r.fov*Math.PI/180/2)*e;t=s*r.aspect,i=s}else if(o.isOrthographicCamera){let r=o;t=(r.right-r.left)/2,i=(r.top-r.bottom)/2}return{worldHalfW:t,worldHalfH:i}}updateStickyTransform(){if(!this._sprite||!this._cameraRef)return;let o=this._cameraRef.camera,{width:e,height:t}=this.getResolution(),{px:i,py:r}=this.resolveScreenPosition(e,t),s=Math.max(.001,this.options.zDistance??1),{worldHalfW:l,worldHalfH:p}=this.computeWorldExtents(o,s),c=i/e*2-1,h=1-r/t*2,a=c*l,m=h*p;{let y=p*2/t,{widthPx:F,heightPx:L}=this.resolveIconSize(t),A=Math.max(1e-4,F*y),B=Math.max(1e-4,L*y);this._sprite.scale.set(A,B,1)}this.group?.position.set(a,m,-s)}iconDestroy(){this._texture?.dispose(),this._sprite?.material&&this._sprite.material.dispose(),this._sprite&&this._sprite.removeFromParent(),this.group?.removeFromParent(),this._iconTexture?.dispose(),this._sprite=null,this._texture=null,this._canvas=null,this._ctx=null,this._cameraRef=null,this._iconTexture=null,this._iconImage=null}};function Y(...n){let o=n.filter(t=>!(t instanceof T)),e={...C};for(let t of o)e={...e,...t};return d(new S(e),t=>Y(t??{}))}function tt(n,o,e){e({me:n,globals:o})}function et(n,o){let e=o??v();tt(n,e,n.nodeDestroy.bind(n))}export{I as a,P as b,X as c,Y as d,et as e};
|
package/dist/chunk-HNCTOJP7.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{getZylemBridge as d,announceBridgeReady as o,BRIDGE_READY_EVENT as g}from"@zylem/bridge";export{d as a,o as b,g as c};
|