incanto 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/3d.d.ts CHANGED
@@ -101,6 +101,9 @@ interface RenderContext3D {
101
101
  gl: WebGLRenderer;
102
102
  scene: Scene;
103
103
  camera: PerspectiveCamera;
104
+ /** Unit world direction TOWARD the scene's shadow-casting sun (reused vector),
105
+ * so a billboard shadow caster can face the light. `null` when no sun light. */
106
+ sunDir?: Vector3 | null;
104
107
  }
105
108
  /**
106
109
  * Implement on a Node3D subclass to receive {@link RenderContext3D} once per
package/dist/3d.js CHANGED
@@ -1,5 +1,5 @@
1
- import { a as Environment3D, c as sunDirectionFromElevationAzimuth, i as syncTree, l as sunDirectionFromSky, o as horizonColorFromSky, r as Renderer3D, s as parseEnvironment3D, t as createGame3D, u as AssetStore3D } from "./create-game-BS24DKlv.js";
2
- import { A as QUARTER_PITCH, C as Area3D, D as StaticBody3D, E as RigidBody3D, M as keyboardIntensity, N as movementState, O as Node3D, P as rigPose, S as terrainThemeLayers, T as PhysicsBody3D, _ as CharacterController3D, a as VoxelGrid3D, b as DEFAULT_TERRAIN_TEXTURE_BASE, c as ModelInstance3D, d as OmniLight3D, f as Foliage3D, g as FLOWER_VARIETIES, h as resolveFlowerDensity, i as VOXEL_PALETTE, j as cameraRelative, l as MeshInstance3D, m as Flowers3D, n as Water3D, o as Tree3D, p as DENSITY_PRESETS, r as WATER_MAX_RIPPLES, s as Particles3D, t as registerNodes3D, u as DirectionalLight3D, v as Camera3D, w as CharacterBody3D, x as TERRAIN_THEMES, y as Terrain3D } from "./register-CmKNH6jz.js";
1
+ import { a as Environment3D, c as sunDirectionFromElevationAzimuth, i as syncTree, l as sunDirectionFromSky, o as horizonColorFromSky, r as Renderer3D, s as parseEnvironment3D, t as createGame3D, u as AssetStore3D } from "./create-game-BM7BffzK.js";
2
+ import { A as QUARTER_PITCH, C as Area3D, D as StaticBody3D, E as RigidBody3D, M as keyboardIntensity, N as movementState, O as Node3D, P as rigPose, S as terrainThemeLayers, T as PhysicsBody3D, _ as CharacterController3D, a as VoxelGrid3D, b as DEFAULT_TERRAIN_TEXTURE_BASE, c as ModelInstance3D, d as OmniLight3D, f as Foliage3D, g as FLOWER_VARIETIES, h as resolveFlowerDensity, i as VOXEL_PALETTE, j as cameraRelative, l as MeshInstance3D, m as Flowers3D, n as Water3D, o as Tree3D, p as DENSITY_PRESETS, r as WATER_MAX_RIPPLES, s as Particles3D, t as registerNodes3D, u as DirectionalLight3D, v as Camera3D, w as CharacterBody3D, x as TERRAIN_THEMES, y as Terrain3D } from "./register-QFuyOugX.js";
3
3
  import { n as splatWeights, t as buildHeightmap } from "./heightmap-CroQPEER.js";
4
- import { n as enablePhysics3D, t as Physics3D } from "./physics-3d-CCgpIRLE.js";
4
+ import { n as enablePhysics3D, t as Physics3D } from "./physics-3d-DNYm3rQz.js";
5
5
  export { Area3D, AssetStore3D, Camera3D, CharacterBody3D, CharacterController3D, DEFAULT_TERRAIN_TEXTURE_BASE, DirectionalLight3D, Environment3D, DENSITY_PRESETS as FLOWER_DENSITY_PRESETS, FLOWER_VARIETIES, Flowers3D, Foliage3D, MeshInstance3D, ModelInstance3D, Node3D, OmniLight3D, Particles3D, Physics3D, PhysicsBody3D, QUARTER_PITCH, Renderer3D, RigidBody3D, StaticBody3D, TERRAIN_THEMES, Terrain3D, Tree3D, VOXEL_PALETTE, VoxelGrid3D, WATER_MAX_RIPPLES, Water3D, buildHeightmap, cameraRelative, createGame3D, enablePhysics3D, horizonColorFromSky, keyboardIntensity, movementState, parseEnvironment3D, registerNodes3D, resolveFlowerDensity, rigPose, splatWeights, sunDirectionFromElevationAzimuth, sunDirectionFromSky, syncTree, terrainThemeLayers };
@@ -6,8 +6,8 @@ import { r as AudioPlayer } from "./register-BuUV1_KB.js";
6
6
  import { i as resolveRendering, n as attachTouchControls } from "./touch-031PxtCR.js";
7
7
  import { n as registerGameplayBehaviors } from "./gameplay-Ccruc3Wd.js";
8
8
  import { t as debugSources } from "./debug-draw-CZmOYjL2.js";
9
- import { O as Node3D, T as PhysicsBody3D, c as ModelInstance3D, t as registerNodes3D, u as DirectionalLight3D, v as Camera3D } from "./register-CmKNH6jz.js";
10
- import { n as enablePhysics3D } from "./physics-3d-CCgpIRLE.js";
9
+ import { O as Node3D, T as PhysicsBody3D, c as ModelInstance3D, t as registerNodes3D, u as DirectionalLight3D, v as Camera3D } from "./register-QFuyOugX.js";
10
+ import { n as enablePhysics3D } from "./physics-3d-DNYm3rQz.js";
11
11
  import { ACESFilmicToneMapping, AmbientLight, BufferAttribute, BufferGeometry, Color, DepthTexture, EquirectangularReflectionMapping, FloatType, Fog, LineBasicMaterial, LineSegments, Matrix4, Mesh, PCFShadowMap, PMREMGenerator, PerspectiveCamera, PlaneGeometry, Quaternion, Raycaster, Scene, ShaderMaterial, Vector2, Vector3, WebGLRenderTarget, WebGLRenderer } from "three";
12
12
  import { VRMLoaderPlugin, VRMUtils } from "@pixiv/three-vrm";
13
13
  import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
@@ -1318,6 +1318,11 @@ var Renderer3D = class {
1318
1318
  };
1319
1319
  const ctx = this.renderCtx;
1320
1320
  ctx.camera = activeCamera;
1321
+ if (threeLight) {
1322
+ threeLight.updateWorldMatrix(true, false);
1323
+ threeLight.target.updateWorldMatrix(true, false);
1324
+ ctx.sunDir = sunDirScratch.setFromMatrixPosition(threeLight.matrixWorld).sub(sunTargetScratch.setFromMatrixPosition(threeLight.target.matrixWorld)).normalize();
1325
+ } else ctx.sunDir = null;
1321
1326
  for (let i = 0; i < renderHooks.length; i++) renderHooks[i]?._onRender3D(ctx);
1322
1327
  let underwater = null;
1323
1328
  for (let i = 0; i < renderHooks.length; i++) {
@@ -1576,6 +1581,8 @@ var Renderer3D = class {
1576
1581
  const sizeScratch = new Vector2();
1577
1582
  const lookScratch = new Vector3();
1578
1583
  const projScratch = new Vector3();
1584
+ const sunDirScratch = new Vector3();
1585
+ const sunTargetScratch = new Vector3();
1579
1586
  const basisQuat = new Quaternion();
1580
1587
  /** Reused camera world-position scratch (shadow-follow focus + underwater test). */
1581
1588
  const camPosScratch = new Vector3();
package/dist/index.js CHANGED
@@ -57,6 +57,6 @@ function newUid() {
57
57
  //#endregion
58
58
  //#region src/index.ts
59
59
  /** Engine version. Kept in sync with package.json by the release pipeline. */
60
- const VERSION = "0.3.0";
60
+ const VERSION = "0.3.2";
61
61
  //#endregion
62
62
  export { AudioBuses, AudioPlayer, Behavior, CONST_REF_KEY, Engine, IncantoError, InputMap, LogManager, MusicManager, Node, PARTICLE_PRESETS, PARTICLE_PRESET_NAMES, ParticleSim, ROLLOFF_MODELS, Rng, SCENE_FORMAT, SFX_PRESETS, SFX_PRESET_NAMES, Scene, SceneTree, SfxEngine, Signal, Timer, TouchControls, VERSION, WebAudioMusicBackend, applyParticlePreset, assetUrls, attachTouchControls, clearBehaviors, clearRegistry, computeViewport, createNode, createNoise2D, crossfadeGains, duplicateNode, fadeGain, getBehavior, getNodeSchema, getNodeSignals, getNodeType, isAudioContextAvailable, isConstRef, joystickVector, jsonClone, jsonEquals, jsonKind, loadScene, mergeStaticSignals, newUid, parseNodePath, preloadUrls, registerBehavior, registerCoreNodes, registerNode, registeredBehaviors, registeredTypes, resolveConstants, resolveRendering, resolveViewport, serializeNode, spatialGain, spatialPan, synthSfx };
@@ -1,7 +1,7 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
2
2
  import { t as IncantoError } from "./errors-BpWbnbb_.js";
3
3
  import { n as registerDebugSource } from "./debug-draw-CZmOYjL2.js";
4
- import { C as Area3D, E as RigidBody3D, O as Node3D, T as PhysicsBody3D, k as validateCollider3D, w as CharacterBody3D, y as Terrain3D } from "./register-CmKNH6jz.js";
4
+ import { C as Area3D, E as RigidBody3D, O as Node3D, T as PhysicsBody3D, k as validateCollider3D, w as CharacterBody3D, y as Terrain3D } from "./register-QFuyOugX.js";
5
5
  import { Euler, Quaternion } from "three";
6
6
  //#region src/3d/physics/physics-3d.ts
7
7
  var physics_3d_exports = /* @__PURE__ */ __exportAll({
package/dist/react.js CHANGED
@@ -156,7 +156,7 @@ function IncantoCanvas(props) {
156
156
  pointer: latest.pointer,
157
157
  ...keyboard !== void 0 ? { keyboard } : {}
158
158
  };
159
- const next = await (_gameFactory ?? (mode === "3d" ? async (o) => (await import("./create-game-BS24DKlv.js").then((n) => n.n)).createGame3D(o) : async (o) => (await import("./create-game-CZHROKcT.js").then((n) => n.n)).createGame2D(o)))(opts);
159
+ const next = await (_gameFactory ?? (mode === "3d" ? async (o) => (await import("./create-game-BM7BffzK.js").then((n) => n.n)).createGame3D(o) : async (o) => (await import("./create-game-CZHROKcT.js").then((n) => n.n)).createGame2D(o)))(opts);
160
160
  if (disposed) {
161
161
  next.dispose();
162
162
  return;
@@ -1320,6 +1320,25 @@ function validateLayer(nodeName, layer, index) {
1320
1320
  //#region src/3d/nodes/sprite-3d.ts
1321
1321
  /** Shared unit quad — sprites are sized via the quad's scale, never THREE.Sprite. */
1322
1322
  const UNIT_PLANE = new PlaneGeometry(1, 1);
1323
+ /** Shared soft radial-gradient texture for `shadowMode: "blob"` (lazily built). */
1324
+ let _blobTex = null;
1325
+ function blobTexture() {
1326
+ if (_blobTex) return _blobTex;
1327
+ if (typeof document === "undefined") return null;
1328
+ const c = document.createElement("canvas");
1329
+ c.width = 64;
1330
+ c.height = 64;
1331
+ const g = c.getContext("2d");
1332
+ if (!g) return null;
1333
+ const grad = g.createRadialGradient(32, 32, 0, 32, 32, 31);
1334
+ grad.addColorStop(0, "rgba(0,0,0,0.55)");
1335
+ grad.addColorStop(.55, "rgba(0,0,0,0.34)");
1336
+ grad.addColorStop(1, "rgba(0,0,0,0)");
1337
+ g.fillStyle = grad;
1338
+ g.fillRect(0, 0, 64, 64);
1339
+ _blobTex = new CanvasTexture(c);
1340
+ return _blobTex;
1341
+ }
1323
1342
  const Z_AXIS = new Vector3(0, 0, 1);
1324
1343
  const _spritePos = new Vector3();
1325
1344
  const _dir = new Vector3();
@@ -1357,7 +1376,11 @@ var Sprite3D = class extends Node3D {
1357
1376
  flipX: { default: false },
1358
1377
  pixelArt: { default: true },
1359
1378
  alphaTest: { default: .5 },
1360
- castShadow: { default: false }
1379
+ castShadow: { default: false },
1380
+ shadowMode: {
1381
+ default: "silhouette",
1382
+ options: ["silhouette", "blob"]
1383
+ }
1361
1384
  };
1362
1385
  /** Image URL (sampled sRGB, tinted by `tint`). Empty = hidden. */
1363
1386
  texture = "";
@@ -1376,15 +1399,22 @@ var Sprite3D = class extends Node3D {
1376
1399
  alphaTest = .5;
1377
1400
  /** Cast a sprite-shaped (alpha-tested) shadow onto the scene. */
1378
1401
  castShadow = false;
1402
+ /** Shape of the cast shadow — see {@link ShadowMode}. */
1403
+ shadowMode = "silhouette";
1379
1404
  quadMesh = null;
1380
1405
  textureRef = "";
1381
1406
  loadedTexture = null;
1407
+ /** Dedicated light-facing caster for `shadowMode: "silhouette"` (lazily made). */
1408
+ shadowMesh = null;
1409
+ /** Flat ground oval for `shadowMode: "blob"` (lazily made). */
1410
+ blobMesh = null;
1382
1411
  /** @internal The drawable quad (lazily created, attached under the backing object). */
1383
1412
  _quad() {
1384
1413
  if (!this.quadMesh) {
1385
1414
  this.quadMesh = new Mesh(UNIT_PLANE, new MeshBasicMaterial({
1386
1415
  transparent: false,
1387
- depthWrite: true
1416
+ depthWrite: true,
1417
+ side: DoubleSide
1388
1418
  }));
1389
1419
  this._ensureObject3D().add(this.quadMesh);
1390
1420
  }
@@ -1429,27 +1459,83 @@ var Sprite3D = class extends Node3D {
1429
1459
  mat.transparent = this.opacity < 1;
1430
1460
  mat.alphaTest = this.alphaTest;
1431
1461
  quad.renderOrder = this.renderOrder;
1432
- quad.castShadow = this.castShadow;
1433
- if (this.castShadow) {
1434
- let depth = quad.customDepthMaterial;
1435
- if (!depth) {
1436
- depth = new MeshDepthMaterial({ depthPacking: RGBADepthPacking });
1437
- quad.customDepthMaterial = depth;
1462
+ const wantShadow = this.castShadow && tex !== null;
1463
+ quad.castShadow = false;
1464
+ if (wantShadow && this.shadowMode === "silhouette") {
1465
+ const s = this._shadowCaster();
1466
+ s.visible = true;
1467
+ s.castShadow = true;
1468
+ s.scale.set(this.flipX ? -w : w, h, 1);
1469
+ s.position.set((.5 - ax) * w, (.5 - ay) * h, 0);
1470
+ const sm = s.material;
1471
+ if (sm.map !== tex) {
1472
+ sm.map = tex;
1473
+ sm.needsUpdate = true;
1438
1474
  }
1439
- if (depth.map !== tex) {
1440
- depth.map = tex;
1441
- depth.needsUpdate = true;
1475
+ const dm = s.customDepthMaterial;
1476
+ if (dm.map !== tex) {
1477
+ dm.map = tex;
1478
+ dm.needsUpdate = true;
1442
1479
  }
1443
- depth.alphaTest = this.alphaTest;
1480
+ sm.alphaTest = this.alphaTest;
1481
+ dm.alphaTest = this.alphaTest;
1482
+ } else if (this.shadowMesh) {
1483
+ this.shadowMesh.visible = false;
1484
+ this.shadowMesh.castShadow = false;
1485
+ }
1486
+ if (wantShadow && this.shadowMode === "blob") {
1487
+ const b = this._blob();
1488
+ b.visible = true;
1489
+ b.scale.set(w * .52, w * .52, 1);
1490
+ } else if (this.blobMesh) this.blobMesh.visible = false;
1491
+ }
1492
+ /** @internal Lazily make the silhouette caster — an invisible plane (no colour/
1493
+ * depth write) that exists only to throw a physical shadow, kept broad to the
1494
+ * light in `_onRender3D`. A custom depth material is explicit so the shadow
1495
+ * pass always uses the current texture frame + low alpha cutoff. */
1496
+ _shadowCaster() {
1497
+ if (!this.shadowMesh) {
1498
+ this.shadowMesh = new Mesh(UNIT_PLANE, new MeshBasicMaterial({
1499
+ colorWrite: false,
1500
+ depthWrite: false,
1501
+ side: DoubleSide
1502
+ }));
1503
+ this.shadowMesh.customDepthMaterial = new MeshDepthMaterial({
1504
+ depthPacking: RGBADepthPacking,
1505
+ side: DoubleSide
1506
+ });
1507
+ this._ensureObject3D().add(this.shadowMesh);
1444
1508
  }
1509
+ return this.shadowMesh;
1510
+ }
1511
+ /** @internal Lazily make the blob oval — a flat ground decal with a soft radial
1512
+ * gradient, lying in the XZ plane at the node origin (the feet). */
1513
+ _blob() {
1514
+ if (!this.blobMesh) {
1515
+ this.blobMesh = new Mesh(UNIT_PLANE, new MeshBasicMaterial({
1516
+ map: blobTexture(),
1517
+ color: 0,
1518
+ transparent: true,
1519
+ depthWrite: false
1520
+ }));
1521
+ this.blobMesh.rotation.x = -Math.PI / 2;
1522
+ this.blobMesh.position.y = .02;
1523
+ this.blobMesh.renderOrder = -1;
1524
+ this._ensureObject3D().add(this.blobMesh);
1525
+ }
1526
+ return this.blobMesh;
1445
1527
  }
1446
- /** @internal Billboard the quad toward the live camera. Headless runs have no
1447
- * Renderer3D and never call this, so plain trees pay nothing. */
1528
+ /** @internal Billboard the visible quad toward the camera, and aim the silhouette
1529
+ * caster at the light. Headless runs have no Renderer3D and never call this, so
1530
+ * plain trees pay nothing. */
1448
1531
  _onRender3D(ctx) {
1449
- if (this.billboard === "none") return;
1450
- const quad = this._quad();
1532
+ if (this.billboard !== "none") this._faceToward(this._quad(), ctx.camera.position);
1533
+ if (this.shadowMesh?.castShadow && ctx.sunDir) this._faceDir(this.shadowMesh, ctx.sunDir);
1534
+ }
1535
+ /** @internal Aim the quad's +Z at a world point, honoring billboard mode. */
1536
+ _faceToward(quad, targetWorld) {
1451
1537
  quad.getWorldPosition(_spritePos);
1452
- _dir.copy(ctx.camera.position).sub(_spritePos);
1538
+ _dir.copy(targetWorld).sub(_spritePos);
1453
1539
  if (this.billboard === "y") _dir.y = 0;
1454
1540
  if (_dir.lengthSq() < 1e-12) return;
1455
1541
  _dir.normalize();
@@ -1457,10 +1543,25 @@ var Sprite3D = class extends Node3D {
1457
1543
  quad.parent?.getWorldQuaternion(_parent);
1458
1544
  quad.quaternion.copy(_parent.invert()).multiply(_target);
1459
1545
  }
1546
+ /** @internal Aim a mesh's +Z along a world DIRECTION (vs a point), honoring
1547
+ * billboard mode — keeps the silhouette shadow caster broad to the light. */
1548
+ _faceDir(mesh, dir) {
1549
+ _dir.copy(dir);
1550
+ if (this.billboard === "y") _dir.y = 0;
1551
+ if (_dir.lengthSq() < 1e-12) return;
1552
+ _dir.normalize();
1553
+ _target.setFromUnitVectors(Z_AXIS, _dir);
1554
+ mesh.parent?.getWorldQuaternion(_parent);
1555
+ mesh.quaternion.copy(_parent.invert()).multiply(_target);
1556
+ }
1460
1557
  free() {
1461
1558
  this.loadedTexture?.dispose();
1462
1559
  this.loadedTexture = null;
1463
- (this.quadMesh?.customDepthMaterial)?.dispose();
1560
+ if (this.shadowMesh) {
1561
+ this.shadowMesh.material.dispose();
1562
+ this.shadowMesh.customDepthMaterial?.dispose();
1563
+ }
1564
+ if (this.blobMesh) this.blobMesh.material.dispose();
1464
1565
  super.free();
1465
1566
  }
1466
1567
  };
@@ -4642,7 +4743,7 @@ var DirectionalLight3D = class extends Node3D {
4642
4743
  }
4643
4744
  light.shadow.mapSize.set(this.shadowMapSize, this.shadowMapSize);
4644
4745
  light.shadow.bias = -2e-4;
4645
- light.shadow.normalBias = 4 * this.shadowArea / this.shadowMapSize;
4746
+ light.shadow.normalBias = .002;
4646
4747
  }
4647
4748
  }
4648
4749
  };
package/dist/test.js CHANGED
@@ -5,7 +5,7 @@ import { n as jsonEquals, t as jsonClone } from "./json-BLk7H2Qa.js";
5
5
  import { i as getNodeSchema, s as mergeStaticProps } from "./registry-BVJ2HbCn.js";
6
6
  import { n as registerGameplayBehaviors } from "./gameplay-Ccruc3Wd.js";
7
7
  import { t as registerNodes2D } from "./register-DPEV9_9t.js";
8
- import { t as registerNodes3D } from "./register-CmKNH6jz.js";
8
+ import { t as registerNodes3D } from "./register-QFuyOugX.js";
9
9
  import { t as registerNodesNet } from "./register-Dasmnurl.js";
10
10
  //#region src/test/index.ts
11
11
  /**
@@ -132,7 +132,7 @@ async function runScript(json, opts) {
132
132
  const { enablePhysics2D } = await import("./physics-2d-KuMWPTf6.js").then((n) => n.r);
133
133
  await enablePhysics2D(engine);
134
134
  } else if (physics === "3d" || physics === "auto" && scene.dimension === "3d") {
135
- const { enablePhysics3D } = await import("./physics-3d-CCgpIRLE.js").then((n) => n.r);
135
+ const { enablePhysics3D } = await import("./physics-3d-DNYm3rQz.js").then((n) => n.r);
136
136
  await enablePhysics3D(engine);
137
137
  }
138
138
  const failures = [];
@@ -237,7 +237,7 @@ async function createPlaySession(json, opts = {}) {
237
237
  const { enablePhysics2D } = await import("./physics-2d-KuMWPTf6.js").then((n) => n.r);
238
238
  await enablePhysics2D(engine);
239
239
  } else if (physics === "3d" || physics === "auto" && scene.dimension === "3d") {
240
- const { enablePhysics3D } = await import("./physics-3d-CCgpIRLE.js").then((n) => n.r);
240
+ const { enablePhysics3D } = await import("./physics-3d-DNYm3rQz.js").then((n) => n.r);
241
241
  await enablePhysics3D(engine);
242
242
  }
243
243
  const stepMs = 1e3 / (opts.fixedHz ?? 60);
@@ -1 +1 @@
1
- import{t as e}from"./index-DJZWJVbh.js";async function t(t){return new n((await e(()=>import(`./GameServer-C56iOUgF.js`),[],import.meta.url)).GameServer,t)}var n=class{raw;active=new Map;constructor(e,t){this.raw=new e({...t})}get account(){return this.raw.account}get connected(){return this.raw.connected}connect(){return this.rawConnect()}rawConnect(){return this.raw.connect({onDisconnect:()=>void this.reconnect()})}disconnect(){for(let e of this.active.values())e.off();return this.active.clear(),this.raw.disconnect()}remoteFunction(e,t,n){return this.raw.remoteFunction(e,t,n)}track(e){let t=Symbol(`sub`),n={make:e,off:e()};return this.active.set(t,n),()=>{n.off(),this.active.delete(t)}}async reconnect(){await this.rawConnect();for(let e of this.active.values())e.off(),e.off=e.make()}subscribeRoomState(e,t){return this.track(()=>this.raw.subscribeRoomState(e,t))}subscribeRoomMyState(e,t){return this.track(()=>this.raw.subscribeRoomMyState(e,t))}subscribeRoomAllUserStates(e,t){return this.track(()=>this.raw.subscribeRoomAllUserStates(e,e=>{let n={};for(let t of e??[]){if(!t||typeof t.account!=`string`||t.__leaved)continue;let{account:e,__updated:r,__leaved:i,...a}=t;n[e]=a}t(n)}))}subscribeRoomCollection(e,t,n){return this.track(()=>this.raw.subscribeRoomCollection(e,t,({items:e})=>{let t={};for(let n of e??[])n&&typeof n.__id==`string`&&(t[n.__id]=n);n(t)}))}onRoomMessage(e,t,n){return this.track(()=>this.raw.onRoomMessage(e,t,n))}onRoomUserJoin(e,t){return this.track(()=>this.raw.onRoomUserJoin(e,t))}onRoomUserLeave(e,t){return this.track(()=>this.raw.onRoomUserLeave(e,t))}subscribeGlobalState(e){return this.track(()=>this.raw.subscribeGlobalState(e))}subscribeGlobalMyState(e){return this.track(()=>this.raw.subscribeGlobalMyState(e))}subscribeGlobalUserState(e,t){return this.track(()=>this.raw.subscribeGlobalUserState(e,t))}subscribeGlobalCollection(e,t){return this.track(()=>this.raw.subscribeGlobalCollection(e,({items:e})=>{let n={};for(let t of e??[])t&&typeof t.__id==`string`&&(n[t.__id]=t);t(n)}))}subscribeAsset(e,t){return this.track(()=>this.raw.subscribeAsset(e,t))}onGlobalMessage(e,t){return this.track(()=>this.raw.onGlobalMessage(e,t))}};export{t as createAgent8Server};
1
+ import{t as e}from"./index-CXElxUZa.js";async function t(t){return new n((await e(()=>import(`./GameServer-C56iOUgF.js`),[],import.meta.url)).GameServer,t)}var n=class{raw;active=new Map;constructor(e,t){this.raw=new e({...t})}get account(){return this.raw.account}get connected(){return this.raw.connected}connect(){return this.rawConnect()}rawConnect(){return this.raw.connect({onDisconnect:()=>void this.reconnect()})}disconnect(){for(let e of this.active.values())e.off();return this.active.clear(),this.raw.disconnect()}remoteFunction(e,t,n){return this.raw.remoteFunction(e,t,n)}track(e){let t=Symbol(`sub`),n={make:e,off:e()};return this.active.set(t,n),()=>{n.off(),this.active.delete(t)}}async reconnect(){await this.rawConnect();for(let e of this.active.values())e.off(),e.off=e.make()}subscribeRoomState(e,t){return this.track(()=>this.raw.subscribeRoomState(e,t))}subscribeRoomMyState(e,t){return this.track(()=>this.raw.subscribeRoomMyState(e,t))}subscribeRoomAllUserStates(e,t){return this.track(()=>this.raw.subscribeRoomAllUserStates(e,e=>{let n={};for(let t of e??[]){if(!t||typeof t.account!=`string`||t.__leaved)continue;let{account:e,__updated:r,__leaved:i,...a}=t;n[e]=a}t(n)}))}subscribeRoomCollection(e,t,n){return this.track(()=>this.raw.subscribeRoomCollection(e,t,({items:e})=>{let t={};for(let n of e??[])n&&typeof n.__id==`string`&&(t[n.__id]=n);n(t)}))}onRoomMessage(e,t,n){return this.track(()=>this.raw.onRoomMessage(e,t,n))}onRoomUserJoin(e,t){return this.track(()=>this.raw.onRoomUserJoin(e,t))}onRoomUserLeave(e,t){return this.track(()=>this.raw.onRoomUserLeave(e,t))}subscribeGlobalState(e){return this.track(()=>this.raw.subscribeGlobalState(e))}subscribeGlobalMyState(e){return this.track(()=>this.raw.subscribeGlobalMyState(e))}subscribeGlobalUserState(e,t){return this.track(()=>this.raw.subscribeGlobalUserState(e,t))}subscribeGlobalCollection(e,t){return this.track(()=>this.raw.subscribeGlobalCollection(e,({items:e})=>{let n={};for(let t of e??[])t&&typeof t.__id==`string`&&(n[t.__id]=t);t(n)}))}subscribeAsset(e,t){return this.track(()=>this.raw.subscribeAsset(e,t))}onGlobalMessage(e,t){return this.track(()=>this.raw.onGlobalMessage(e,t))}};export{t as createAgent8Server};