@hology/core 0.0.212 → 0.0.214
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/effects/sequence/index.d.ts +1 -0
- package/dist/effects/sequence/index.js +1 -1
- package/dist/effects/sequence/sequence-action.d.ts +5 -0
- package/dist/effects/sequence/sequence-actor.d.ts +7 -0
- package/dist/effects/sequence/sequence-actor.js +1 -1
- package/dist/effects/sequence/sequence-animation-retiming.js +1 -1
- package/dist/effects/sequence/sequence-data.d.ts +9 -0
- package/dist/effects/sequence/sequence-data.js +1 -1
- package/dist/effects/sequence/sequence-player.d.ts +12 -1
- package/dist/effects/sequence/sequence-player.js +1 -1
- package/dist/effects/sequence/sequence-transform.d.ts +10 -0
- package/dist/effects/sequence/sequence-transform.js +4 -0
- package/dist/effects/sequence/sequence-value-lane.d.ts +2 -0
- package/dist/effects/sequence/sequence-value-lane.js +1 -1
- package/dist/effects/vfx/initializsers.d.ts +4 -0
- package/dist/effects/vfx/initializsers.js +1 -1
- package/dist/effects/vfx/vfx-actor.d.ts +5 -0
- package/dist/effects/vfx/vfx-actor.js +1 -1
- package/dist/effects/vfx/vfx-asset.d.ts +2 -1
- package/dist/effects/vfx/vfx-asset.js +1 -1
- package/dist/effects/vfx/vfx-materializer.js +1 -1
- package/dist/effects/vfx/vfx-renderers.d.ts +1 -0
- package/dist/effects/vfx/vfx-renderers.js +1 -1
- package/dist/gameplay/actors/actor.d.ts +9 -5
- package/dist/gameplay/actors/actor.js +1 -1
- package/dist/gameplay/actors/builtin/components/character/character-animation.d.ts +3 -0
- package/dist/gameplay/actors/builtin/components/character/character-animation.js +1 -1
- package/dist/gameplay/actors/builtin/components/character/character-movement-like.d.ts +2 -0
- package/dist/gameplay/actors/builtin/components/character/character-movement.d.ts +13 -0
- package/dist/gameplay/actors/builtin/components/character/character-movement.js +1 -1
- package/dist/gameplay/actors/builtin/components/character/net-character-movement-protocol.d.ts +4 -1
- package/dist/gameplay/actors/builtin/components/character/net-character-movement-protocol.js +1 -1
- package/dist/gameplay/actors/builtin/components/mesh-component.d.ts +1 -0
- package/dist/gameplay/actors/builtin/components/mesh-component.js +1 -1
- package/dist/gameplay/actors/builtin/components/tween-component.js +1 -1
- package/dist/gameplay/actors/builtin/navmesh-actor.d.ts +2 -0
- package/dist/gameplay/actors/builtin/navmesh-actor.js +1 -1
- package/dist/gameplay/actors/builtin/trigger-volume.d.ts +3 -3
- package/dist/gameplay/actors/builtin/trigger-volume.js +1 -1
- package/dist/gameplay/actors/camera/camera-component.d.ts +1 -3
- package/dist/gameplay/actors/camera/camera-component.js +1 -1
- package/dist/gameplay/actors/component.d.ts +9 -0
- package/dist/gameplay/actors/component.js +1 -1
- package/dist/gameplay/actors/type-registry.d.ts +10 -0
- package/dist/gameplay/actors/type-registry.js +4 -0
- package/dist/gameplay/animation/retarget.d.ts +50 -0
- package/dist/gameplay/animation/retarget.js +4 -0
- package/dist/gameplay/animation/root-motion.js +1 -1
- package/dist/gameplay/event-graph/actor-transform-properties.d.ts +6 -0
- package/dist/gameplay/event-graph/actor-transform-properties.js +4 -0
- package/dist/gameplay/event-graph/asset-actor-types.d.ts +3 -0
- package/dist/gameplay/event-graph/asset-actor-types.js +4 -0
- package/dist/gameplay/event-graph/asset-references.d.ts +12 -0
- package/dist/gameplay/event-graph/asset-references.js +4 -0
- package/dist/gameplay/event-graph/compiler.d.ts +107 -0
- package/dist/gameplay/event-graph/compiler.js +4 -0
- package/dist/gameplay/event-graph/decorators.d.ts +74 -0
- package/dist/gameplay/event-graph/decorators.js +4 -0
- package/dist/gameplay/event-graph/document-compiler.d.ts +107 -0
- package/dist/gameplay/event-graph/document-compiler.js +4 -0
- package/dist/gameplay/event-graph/event-graph-demo.d.ts +2 -0
- package/dist/gameplay/event-graph/event-graph-demo.js +4 -0
- package/dist/gameplay/event-graph/graph.d.ts +106 -0
- package/dist/gameplay/event-graph/graph.js +4 -0
- package/dist/gameplay/event-graph/index.d.ts +13 -0
- package/dist/gameplay/event-graph/index.js +4 -0
- package/dist/gameplay/event-graph/model.d.ts +71 -0
- package/dist/gameplay/event-graph/model.js +4 -0
- package/dist/gameplay/event-graph/nodes/execution-nodes.d.ts +115 -0
- package/dist/gameplay/event-graph/nodes/execution-nodes.js +4 -0
- package/dist/gameplay/event-graph/nodes/gameplay-nodes.d.ts +208 -0
- package/dist/gameplay/event-graph/nodes/gameplay-nodes.js +4 -0
- package/dist/gameplay/event-graph/nodes/index.d.ts +4 -0
- package/dist/gameplay/event-graph/nodes/index.js +4 -0
- package/dist/gameplay/event-graph/nodes/value-nodes.d.ts +53 -0
- package/dist/gameplay/event-graph/nodes/value-nodes.js +4 -0
- package/dist/gameplay/event-graph/registry.d.ts +33 -0
- package/dist/gameplay/event-graph/registry.js +4 -0
- package/dist/gameplay/event-graph/runtime-assets.d.ts +21 -0
- package/dist/gameplay/event-graph/runtime-assets.js +4 -0
- package/dist/gameplay/event-graph/runtime.d.ts +160 -0
- package/dist/gameplay/event-graph/runtime.js +4 -0
- package/dist/gameplay/event-graph/type-inference.d.ts +41 -0
- package/dist/gameplay/event-graph/type-inference.js +4 -0
- package/dist/gameplay/event-graph/types.d.ts +77 -0
- package/dist/gameplay/event-graph/types.js +4 -0
- package/dist/gameplay/index.d.ts +15 -2
- package/dist/gameplay/index.js +1 -1
- package/dist/gameplay/initiate.js +1 -1
- package/dist/gameplay/input/input.d.ts +22 -17
- package/dist/gameplay/input/input.js +1 -1
- package/dist/gameplay/net/service/net-decorator.d.ts +1 -1
- package/dist/gameplay/net/service/net-decorator.js +1 -1
- package/dist/gameplay/net/service/net-serializer.js +1 -1
- package/dist/gameplay/net/service/net-service.d.ts +6 -6
- package/dist/gameplay/net/service/net-service.js +1 -1
- package/dist/gameplay/net/service/rpc-decorator.js +1 -1
- package/dist/gameplay/services/asset-loader.d.ts +7 -0
- package/dist/gameplay/services/asset-loader.js +1 -1
- package/dist/gameplay/services/physics/physics-system.d.ts +14 -0
- package/dist/gameplay/services/physics/physics-system.js +1 -1
- package/dist/gameplay/services/world.d.ts +12 -0
- package/dist/gameplay/services/world.js +1 -1
- package/dist/rendering.js +1 -1
- package/dist/scene/asset-resource-loader.d.ts +7 -1
- package/dist/scene/asset-resource-loader.js +1 -1
- package/dist/scene/assets-provider.d.ts +1 -0
- package/dist/scene/assets-provider.js +1 -1
- package/dist/scene/custom-param-deserialize.js +1 -1
- package/dist/scene/custom-param-runtime-types.js +1 -1
- package/dist/scene/materializer.d.ts +32 -0
- package/dist/scene/materializer.js +1 -1
- package/dist/scene/model.d.ts +114 -2
- package/dist/scene/model.js +1 -1
- package/dist/scene/objects/prefab.js +1 -1
- package/dist/scene/runtime-asset-service.d.ts +7 -1
- package/dist/scene/runtime-asset-service.js +1 -1
- package/dist/shader/graph/compiler.d.ts +3 -0
- package/dist/shader/graph/compiler.js +1 -1
- package/dist/shader/graph/model.d.ts +1 -1
- package/dist/shader/graph/registry.js +1 -1
- package/dist/test/animation-retarget.test.d.ts +2 -0
- package/dist/test/animation-retarget.test.js +4 -0
- package/dist/test/event-graph-generated-code.test.d.ts +2 -0
- package/dist/test/event-graph-generated-code.test.js +4 -0
- package/dist/test/event-graph-types.test.d.ts +2 -0
- package/dist/test/event-graph-types.test.js +4 -0
- package/dist/test/event-graph.test.d.ts +2 -0
- package/dist/test/event-graph.test.js +4 -0
- package/dist/test/input.test.d.ts +2 -0
- package/dist/test/input.test.js +4 -0
- package/dist/test/net-character-movement.test.js +1 -1
- package/dist/test/prefab-instance-params.test.js +1 -1
- package/dist/test/runtime-asset-service.test.js +1 -1
- package/dist/test/sequence-camera-control.test.js +1 -1
- package/dist/test/sequence-scene-binding.test.d.ts +2 -0
- package/dist/test/sequence-scene-binding.test.js +4 -0
- package/dist/test/sequence-transform.test.d.ts +2 -0
- package/dist/test/sequence-transform.test.js +4 -0
- package/dist/test/shader-graph.test.js +1 -1
- package/dist/test/vfx-world-space-emitter-rotation.test.d.ts +2 -0
- package/dist/test/vfx-world-space-emitter-rotation.test.js +4 -0
- package/dist/test/world-prefab-spawn.test.js +1 -1
- package/package.json +10 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Type } from '../../utils/type.js';
|
|
2
|
+
import type { BaseActor } from '../actors/actor.js';
|
|
3
|
+
import { type EventGraphCallableInfo, type EventGraphEventSourceInfo, type EventGraphPropertyInfo } from './decorators.js';
|
|
4
|
+
import type { EventGraphDocument } from './model.js';
|
|
5
|
+
import { type EventGraphType } from './types.js';
|
|
6
|
+
export interface EventGraphTypeContext {
|
|
7
|
+
/** Resolves a prefab-local actor id, including `$self`, to its concrete class. */
|
|
8
|
+
resolveActorClass?(actorId: string): Type<BaseActor> | undefined;
|
|
9
|
+
/** When present, an undefined result means the referenced asset is missing. */
|
|
10
|
+
resolveAssetType?(assetId: string): string | undefined;
|
|
11
|
+
}
|
|
12
|
+
/** Creates the class resolver shared by prefab editors and build-time compilation. */
|
|
13
|
+
export declare function createEventGraphTypeContext(actorClassesById: ReadonlyMap<string, Type<BaseActor>>, mainActorId?: string): EventGraphTypeContext;
|
|
14
|
+
export interface EventGraphTypeDiagnostic {
|
|
15
|
+
severity: 'error' | 'warning';
|
|
16
|
+
nodeId: string;
|
|
17
|
+
port?: string;
|
|
18
|
+
message: string;
|
|
19
|
+
}
|
|
20
|
+
export interface EventGraphNodeTypeInfo {
|
|
21
|
+
inputs: Readonly<Record<string, EventGraphType>>;
|
|
22
|
+
outputs: Readonly<Record<string, EventGraphType>>;
|
|
23
|
+
}
|
|
24
|
+
export interface EventGraphTypeAnalysis {
|
|
25
|
+
nodes: ReadonlyMap<string, EventGraphNodeTypeInfo>;
|
|
26
|
+
diagnostics: readonly EventGraphTypeDiagnostic[];
|
|
27
|
+
getInputType(nodeId: string, port: string): EventGraphType;
|
|
28
|
+
getOutputType(nodeId: string, port: string): EventGraphType;
|
|
29
|
+
}
|
|
30
|
+
export interface EventGraphTypeMembers {
|
|
31
|
+
properties: readonly EventGraphPropertyInfo[];
|
|
32
|
+
callables: readonly EventGraphCallableInfo[];
|
|
33
|
+
eventSources: readonly EventGraphEventSourceInfo[];
|
|
34
|
+
}
|
|
35
|
+
/** Returns the exposed members an editor can offer after resolving a data-pin type. */
|
|
36
|
+
export declare function getEventGraphMembersForType(type: EventGraphType): EventGraphTypeMembers;
|
|
37
|
+
/** Infers data-port types and reports issues without requiring a compilable document. */
|
|
38
|
+
export declare function analyzeEventGraphTypes(graph: EventGraphDocument, context?: EventGraphTypeContext): EventGraphTypeAnalysis;
|
|
39
|
+
/** Performs type analysis and throws a combined error for compiler-facing use. */
|
|
40
|
+
export declare function assertEventGraphTypes(graph: EventGraphDocument, context?: EventGraphTypeContext): EventGraphTypeAnalysis;
|
|
41
|
+
//# sourceMappingURL=type-inference.d.ts.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{getActorClassById as e,getComponentClassById as t}from"../actors/type-registry.js";import{getEventGraphCallableInfo as r,getEventGraphCallableInfos as n,getEventGraphEventSourceInfo as s,getEventGraphEventSourceInfos as o,getEventGraphPropertyInfo as a,getEventGraphPropertyInfos as i}from"./decorators.js";import{EVENT_GRAPH_ACTOR_TRANSFORM_PROPERTIES as u,getEventGraphActorTransformPropertyInfo as l,isEventGraphActorTransformProperty as c}from"./actor-transform-properties.js";import{isEventGraphAssetReference as p}from"./asset-references.js";import{SEQUENCE_ACTOR_TYPE_ID as d,VFX_ACTOR_TYPE_ID as v}from"./asset-actor-types.js";import{getEventGraphInputDefault as h,getEventGraphNodePorts as y}from"./registry.js";import{EVENT_GRAPH_ACTOR_TYPE as f,EVENT_GRAPH_ANY_TYPE as m,EVENT_GRAPH_BOOLEAN_TYPE as g,EVENT_GRAPH_COMPONENT_TYPE as b,EVENT_GRAPH_NUMBER_TYPE as k,EVENT_GRAPH_OBJECT_TYPE as T,EVENT_GRAPH_ROTATION_TYPE as $,EVENT_GRAPH_STRING_TYPE as I,EVENT_GRAPH_VECTOR2_TYPE as S,EVENT_GRAPH_VECTOR3_TYPE as V,eventGraphActorType as C,eventGraphAssetType as N,eventGraphOptionalType as w,eventGraphTypeName as x,inferEventGraphLiteralType as A,isTweenableEventGraphType as O,isEventGraphLiteralAssignableToType as q,isEventGraphTypeAssignable as E}from"./types.js";export function createEventGraphTypeContext(e,t){return{resolveActorClass(r){const n="$self"===r?t:r;return null!=n?e.get(n):void 0}}}export function getEventGraphMembersForType(e){const t=P(e),r=null!=t?i(t):[];return{properties:"actor"===e.kind?[...u,...r.filter(e=>!c(e.propertyName))]:r,callables:null!=t?n(t):[],eventSources:null!=t?o(t):[]}}export function analyzeEventGraphTypes(e,t={}){return new M(e,t).analyze()}export function assertEventGraphTypes(e,t={}){const r=analyzeEventGraphTypes(e,t),n=r.diagnostics.filter(e=>"error"===e.severity);if(n.length>0)throw new Error(`Event graph type errors:\n${n.map(U).join("\n")}`);return r}class M{constructor(e,t){this.graph=e,this.context=t,this.graphNodes=new Map,this.variables=new Map,this.incoming=new Map,this.nodeTypes=new Map,this.resolving=new Set,this.diagnostics=[],this.diagnosticKeys=new Set;for(const t of e.nodes)this.graphNodes.set(t.id,t);for(const t of e.variables??[])this.variables.set(t.name,t.type??A(t.defaultValue));for(const t of e.edges)this.isDataPort(t.from.nodeId,t.from.port,"outputs")&&this.incoming.set(K(t.to),t.from)}analyze(){for(const e of this.graph.nodes)this.inferNode(e);for(const e of this.graph.nodes)this.validateInputs(e);const e=this.nodeTypes;return{nodes:e,diagnostics:this.diagnostics,getInputType:(t,r)=>e.get(t)?.inputs[r]??m,getOutputType:(t,r)=>e.get(t)?.outputs[r]??m}}inferNode(e){const t=this.nodeTypes.get(e.id);if(null!=t)return t;if(this.resolving.has(e.id))return{inputs:{},outputs:{}};this.resolving.add(e.id);const r={inputs:Object.fromEntries(y(e,"inputs").filter(e=>"data"===e.kind).map(e=>[e.name,e.type??m])),outputs:Object.fromEntries(y(e,"outputs").filter(e=>"data"===e.kind).map(e=>[e.name,e.type??m]))};this.nodeTypes.set(e.id,r);try{return this.inferSpecializedNode(e,r),r}finally{this.resolving.delete(e.id)}}inferSpecializedNode(r,n){switch(r.kind){case"constant.boolean":return void(n.outputs.value=g);case"constant.number":return void(n.outputs.value=k);case"constant.string":return void(n.outputs.value=I);case"constant.vector2":return void(n.outputs.value=S);case"constant.vector3":return void(n.outputs.value=V);case"event.update":return void(n.outputs.deltaTime=k);case"event.observable":{const e=this.observableTargetType(r),t=this.propertyInfo(e,R(r,"property"));return void("observable"===t?.type.kind?n.outputs.value=t.type.value:"any"===t?.type.kind?n.outputs.value=m:null!=t?this.error(r,"value",`${t.label} is not an Observable`):null!=P(e)&&this.error(r,"value",`Property ${JSON.stringify(R(r,"property"))} is not exposed to event graphs`))}case"event.source":{const e=this.observableTargetType(r),t=this.eventSourceInfo(e,R(r,"source"));return void(null!=t?(n.outputs.value=this.eventSourcePayloadType(r,t),this.validateStaticEventSourceArguments(r,t)):null!=P(e)&&this.error(r,"value",`Event source ${JSON.stringify(R(r,"source"))} is not exposed to event graphs`))}case"flow.switch":{const e=this.inputValueType(r,"value");return void("vector2"!==e.kind&&"vector3"!==e.kind||this.error(r,"value",`Switch does not support ${x(e)} values`))}case"flow.isValid":{const e=this.inputValueType(r,"value");return n.inputs.value=e,void(n.outputs.value="optional"===e.kind?e.value:"null"===e.kind?m:e)}case"variable.get":return void(n.outputs.value=this.variableType(r));case"variable.set":return void(n.inputs.value=this.variableType(r));case"actor.reference":{const e=R(r,"actorId"),t=null!=e?this.context.resolveActorClass?.(e):void 0;return void(n.outputs.value=null!=t?C(t):f)}case"actor.spawnClass":{const t=e(R(r,"classId")??"");return void(n.outputs.value=null!=t?C(t):f)}case"flow.forEach":{const e=this.inputValueType(r,"array"),t="array"===e.kind?e:{kind:"array",element:m};return n.inputs.array=t,n.outputs.arrayElement=t.element,void(n.outputs.arrayIndex=k)}case"actor.findByType":case"actor.findAllByType":{const e=this.actorClassInputType(r,"actorClass");n.inputs.actorClass=e;const t=null!=e.classId?{kind:"actor",classId:e.classId}:f;return void(n.outputs.value="actor.findByType"===r.kind?w(t):{kind:"array",element:t})}case"asset.reference":{const e=r.params?.reference;return void(p(e)?n.outputs.value=N(e.assetType):this.error(r,void 0,"Asset Reference requires a valid asset"))}case"vfx.play":return void(n.outputs.value={kind:"actor",classId:v});case"sequence.play":return void(n.outputs.value={kind:"actor",classId:d});case"actor.component":{n.inputs.target=f;const e=t(R(r,"componentTypeId")??"");if(null!=e)return void(n.outputs.value={kind:"component",classId:e.__componentId??e.name});const s=this.propertyInfo(this.inputValueType(r,"target"),R(r,"property"));return void("component"===s?.type.kind?n.outputs.value=s.type:null!=s&&this.error(r,"target",`${s.label} is not an actor component`))}case"actor.getProperty":{const e=this.inputValueType(r,"target"),t=this.propertyInfo(e,R(r,"property"));return void(null!=t?n.outputs.value=t.type:null!=P(e)&&this.error(r,"target",`Property ${JSON.stringify(R(r,"property"))} is not exposed to event graphs`))}case"actor.setProperty":{const e=this.inputValueType(r,"target"),t=this.propertyInfo(e,R(r,"property"));return void(null!=t?(n.inputs.value=t.type,t.writable||this.error(r,"value",`${t.label} is read-only`)):null!=P(e)&&this.error(r,"target",`Property ${JSON.stringify(R(r,"property"))} is not exposed to event graphs`))}case"actor.tweenProperty":{const e=this.inputValueType(r,"target"),t=R(r,"property"),s=this.propertyInfo(e,t);return void(null!=s?(n.inputs.to=s.type,s.writable||this.error(r,"to",`${s.label} is read-only`),O(s.type)||this.error(r,"to",`${s.label} cannot be tweened`)):null==t?this.error(r,"target","Tween Property requires a property"):null!=P(e)&&this.error(r,"target",`Property ${JSON.stringify(t)} is not exposed to event graphs`))}case"actor.callMethod":case"actor.tryCallMethod":{const e=this.inputValueType(r,"target"),t=this.callableInfo(e,R(r,"method")),s=G(r,"argumentCount")??0;for(let e=0;e<s;e++)n.inputs[`arg${e}`]=t?.parameters[e]?.type??m;if(null!=t){if(n.outputs.value=t.returnType,t.parametersKnown){const e=t.parameters.filter(e=>!0!==e.optional).length;(s<e||s>t.parameters.length)&&this.error(r,void 0,`${t.label} expects ${e===t.parameters.length?e:`${e}-${t.parameters.length}`} arguments, received ${s}`)}t.awaitResult&&!0!==r.params?.awaitResult&&this.error(r,void 0,`${t.label} is asynchronous and must be awaited`)}else null!=P(e)&&this.error(r,"target",`Method ${JSON.stringify(R(r,"method"))} is not exposed to event graphs`);return}case"event.bindSource":{n.inputs.target=null!=R(r,"component")||null!=R(r,"componentTypeId")?f:T;const e=this.eventBindSourceTargetType(r),t=this.eventSourceInfo(e,R(r,"source")),s=G(r,"argumentCount")??0;if(null!=t){n.outputs.value=this.eventSourcePayloadType(r,t);let e=0;for(const r of t.parameters)"actorClass"!==r.type.kind&&(n.inputs["arg"+e++]=r.type);t.parametersKnown&&s!==e&&this.error(r,void 0,`${t.label} expects ${e} connected arguments, received ${s}`),this.validateEventSourceActorClassArguments(r,t)}else null!=P(e)&&this.error(r,"target",`Event source ${JSON.stringify(R(r,"source"))} is not exposed to event graphs`);return}case"math.add":case"math.subtract":case"math.multiply":case"math.divide":case"math.modulo":return void this.inferMathNode(r,n);case"vector.length":case"vector.lengthSquared":return void this.inferVectorUnaryNode(r,n,k);case"vector.normalize":return void this.inferVectorUnaryNode(r,n,m);case"vector.distance":case"vector.distanceSquared":case"vector.dot":return void this.inferVectorBinaryNode(r,n,k);case"vector.lerp":return this.inferVectorBinaryNode(r,n,m),void(n.inputs.alpha=k);case"vector.cross":return n.inputs.a=V,n.inputs.b=V,void(n.outputs.value=V);case"vector.applyRotation":return n.inputs.value=V,n.inputs.rotation=$,void(n.outputs.value=V);case"boolean.and":case"boolean.or":return n.inputs.a=g,n.inputs.b=g,void(n.outputs.value=g);case"boolean.not":return n.inputs.value=g,void(n.outputs.value=g);case"compare.greaterThan":case"compare.greaterThanOrEqual":case"compare.lessThan":case"compare.lessThanOrEqual":{const e=(s=this.inputValueType(r,"a"),o=this.inputValueType(r,"b"),"string"===s.kind||"string"===o.kind?I:k);return n.inputs.a=e,n.inputs.b=e,void(n.outputs.value=g)}case"compare.equal":case"compare.notEqual":{const e=this.inputValueType(r,"a"),t=this.inputValueType(r,"b");return"vector2"!==e.kind&&"vector3"!==e.kind||!this.inputLiteralMatches(r,"b",e)?"vector2"!==t.kind&&"vector3"!==t.kind||!this.inputLiteralMatches(r,"a",t)?(n.inputs.a="any"===t.kind?e:t,n.inputs.b="any"===e.kind?t:e,void(n.outputs.value=g)):(n.inputs.a=t,n.inputs.b=t,void(n.outputs.value=g)):(n.inputs.a=e,n.inputs.b=e,void(n.outputs.value=g))}}var s,o}validateInputs(e){const t=this.inferNode(e);for(const[r,n]of Object.entries(t.inputs)){const t=this.input(e,r);if(null==t)continue;const s="value"in t?A(t.value):this.outputType(t);("value"in t?q(t.value,n):E(s,n))||this.error(e,r,`Expected ${x(n)}, received ${x(s)}`)}}inputValueType(e,t){const r=this.input(e,t);return null==r?m:"value"in r?A(r.value):this.outputType(r)}outputType(e){const t=this.graphNodes.get(e.nodeId);return null!=t?this.inferNode(t).outputs[e.port]??m:m}input(e,t){const r=this.incoming.get(K({nodeId:e.id,port:t}))??e.inputs?.[t];if(null!=r)return r;const n=h(e,t);return void 0!==n?{value:n}:void 0}inputLiteralMatches(e,t,r){const n=this.input(e,t);return null!=n&&"value"in n&&q(n.value,r)}inferMathNode(e,t){const r=this.inputValueType(e,"a"),n=this.inputValueType(e,"b"),s=this.vectorOperandType(e,"a",r),o=this.vectorOperandType(e,"b",n),a=function(e){switch(e){case"math.add":return"Add";case"math.subtract":return"Subtract";case"math.multiply":return"Multiply";case"math.divide":return"Divide";case"math.modulo":return"Modulo";default:return"Math"}}(e.kind);if("math.add"===e.kind){const s=function(e,t){return"string"!==e.kind||"string"!==t.kind&&"any"!==t.kind?"string"===t.kind&&"any"===e.kind?I:void 0:I}(r,n);if(null!=s)return t.inputs.a=s,t.inputs.b=s,void(t.outputs.value=s);if("string"===r.kind||"string"===n.kind)return t.inputs.a=m,t.inputs.b=m,t.outputs.value=m,void this.error(e,void 0,`Add requires two numbers, two strings, or vector-compatible operands, received ${x(r)} and ${x(n)}`)}const i=j(s,o);return"mismatch"===i?(t.inputs.a=s??m,t.inputs.b=o??m,t.outputs.value=m,void this.error(e,void 0,`${a} requires vector operands to have the same dimension, received ${x(s)} and ${x(o)}`)):null!=i?(t.inputs.a=J(r,s,i),t.inputs.b=J(n,o,i),t.outputs.value=i,void(B(r,s,i)&&B(n,o,i)||this.error(e,void 0,`${a} requires numbers or ${x(i)} values, received ${x(r)} and ${x(n)}`))):(t.inputs.a=k,t.inputs.b=k,t.outputs.value=k,void(D(r)&&D(n)||this.error(e,void 0,`${a} requires number or vector operands, received ${x(r)} and ${x(n)}`)))}vectorOperandType(e,t,r){if("vector2"===r.kind)return S;if("vector3"===r.kind)return V;const n=this.input(e,t);return null!=n&&"value"in n?q(n.value,S)?S:q(n.value,V)?V:void 0:void 0}inferVectorUnaryNode(e,t,r){const n=this.inputValueType(e,"value"),s=this.vectorOperandType(e,"value",n);t.inputs.value=s??m,t.outputs.value="any"===r.kind?s??m:r,null==s&&"any"!==n.kind&&this.error(e,"value",`${L(e.kind)} requires a Vector2 or Vector3, received ${x(n)}`)}inferVectorBinaryNode(e,t,r){const n=this.inputValueType(e,"a"),s=this.inputValueType(e,"b"),o=this.vectorOperandType(e,"a",n),a=this.vectorOperandType(e,"b",s),i=j(o,a);return"mismatch"===i?(t.inputs.a=o??m,t.inputs.b=a??m,t.outputs.value=r,void this.error(e,void 0,`${L(e.kind)} requires matching vector dimensions, received ${x(o)} and ${x(a)}`)):null!=i?(t.inputs.a=z(n,o,i),t.inputs.b=z(s,a,i),void(t.outputs.value="any"===r.kind?i:r)):(t.inputs.a=m,t.inputs.b=m,t.outputs.value=r,void("any"!==n.kind&&"any"!==s.kind&&this.error(e,void 0,`${L(e.kind)} requires Vector2 or Vector3 inputs, received ${x(n)} and ${x(s)}`)))}observableTargetType(e){const t=R(e,"actorId"),r=null!=t?this.context.resolveActorClass?.(t):void 0;let n=null!=r?C(r):f;const s=R(e,"component"),o=R(e,"componentTypeId");return this.componentTargetType(n,s,o)}actorClassInputType(t,r){const n=this.input(t,r);if(null==n)return{kind:"actorClass"};if("value"in n)return"string"!=typeof n.value||0===n.value.length?{kind:"actorClass"}:null==e(n.value)?(this.error(t,r,`Actor class ${JSON.stringify(n.value)} does not exist`),{kind:"actorClass"}):{kind:"actorClass",classId:n.value};const s=this.outputType(n);return"actorClass"===s.kind?s:{kind:"actorClass"}}eventBindSourceTargetType(e){const t=this.inputValueType(e,"target"),r=R(e,"component"),n=R(e,"componentTypeId");return this.componentTargetType(t,r,n)}componentTargetType(e,t,r){if(null!=t){const r=this.propertyInfo(e,t)?.type;if(null!=r)return r}return null!=r?{kind:"component",classId:r}:null!=t?b:e}eventSourceInfo(e,t){if(null==t)return;const r=P(e);return null!=r?s(r,t):void 0}eventSourcePayloadType(e,t){let r=t.valueType,n=0;for(let s=0;s<t.parameters.length;s++){const o=t.parameters[s];if("actor"===r.kind&&"actorClass"===o.type.kind){const t=R(e,`arg${s}ActorClassId`);null!=t&&(r={kind:"actor",classId:t})}else if("actor"===r.kind&&"actor"===o.type.kind)if("event.source"===e.kind){const t=R(e,`arg${s}ActorId`),n=null!=t?this.context.resolveActorClass?.(t):void 0;null!=n&&(r=C(n))}else{const t=this.inputValueType(e,`arg${n}`);"actor"===t.kind&&null!=t.classId&&(r=t)}"actorClass"!==o.type.kind&&n++}return r}validateStaticEventSourceArguments(t,r){for(let n=0;n<r.parameters.length;n++){const s=r.parameters[n];if("actorClass"===s.type.kind){const o=R(t,`arg${n}ActorClassId`);null==o?this.error(t,void 0,`${r.label} requires an actor class for ${s.name}`):null==e(o)&&this.error(t,void 0,`Actor class ${JSON.stringify(o)} does not exist`);continue}if("actor"===s.type.kind){const e=R(t,`arg${n}ActorId`);null==e?this.error(t,void 0,`${r.label} requires an actor for ${s.name}`):null!=this.context.resolveActorClass&&null==this.context.resolveActorClass(e)&&this.error(t,void 0,`Actor ${JSON.stringify(e)} does not exist`);continue}this.error(t,void 0,`${r.label} parameter ${s.name} cannot be authored on a static event source`)}}validateEventSourceActorClassArguments(t,r){for(let n=0;n<r.parameters.length;n++){const s=r.parameters[n];if("actorClass"!==s.type.kind)continue;const o=R(t,`arg${n}ActorClassId`);null==o?this.error(t,void 0,`${r.label} requires an actor class for ${s.name}`):null==e(o)&&this.error(t,void 0,`Actor class ${JSON.stringify(o)} does not exist`)}}propertyInfo(e,t){if(null==t)return;if("actor"===e.kind){const e=l(t);if(null!=e)return e}const r=P(e);return null!=r?a(r,t):void 0}callableInfo(e,t){if(null==t)return;const n=P(e);return null!=n?r(n,t):void 0}variableType(e){return this.variables.get(R(e,"variable")??"")??m}isDataPort(e,t,r){const n=this.graphNodes.get(e);return null!=n&&y(n,r).some(e=>e.name===t&&"data"===e.kind)}error(e,t,r){const n=`${e.id}:${t??""}:${r}`;this.diagnosticKeys.has(n)||(this.diagnosticKeys.add(n),this.diagnostics.push({severity:"error",nodeId:e.id,...null!=t?{port:t}:{},message:r}))}}function P(r){return"actor"===r.kind&&null!=r.classId?e(r.classId):"component"===r.kind&&null!=r.classId?t(r.classId):void 0}function j(e,t){return null==e?t:null==t||e.kind===t.kind?e:"mismatch"}function J(e,t,r){return null!=t?t.kind===r.kind?r:t:"number"===e.kind?k:(e.kind,m)}function z(e,t,r){return null!=t?t.kind===r.kind?r:t:"any"===e.kind?r:m}function B(e,t,r){return"any"===e.kind||"number"===e.kind||t?.kind===r.kind}function D(e){return"number"===e.kind||"any"===e.kind}function L(e){switch(e){case"vector.length":return"Length";case"vector.lengthSquared":return"Length Squared";case"vector.distance":return"Distance";case"vector.distanceSquared":return"Distance Squared";case"vector.normalize":return"Normalize";case"vector.dot":return"Dot Product";case"vector.cross":return"Cross Product";case"vector.lerp":return"Lerp";case"vector.applyRotation":return"Apply Rotation";default:return"Vector"}}function R(e,t){const r=e.params?.[t];return"string"==typeof r&&r.length>0?r:void 0}function G(e,t){const r=e.params?.[t];return"number"==typeof r?r:void 0}function K(e){return`${e.nodeId}:${e.port}`}function U(e){return`- ${null==e.port?e.nodeId:`${e.nodeId}:${e.port}`}: ${e.message}`}/*
|
|
2
|
+
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
|
+
* See the LICENSE.md file for details.
|
|
4
|
+
*/
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { EventGraphAssetKind } from './model.js';
|
|
2
|
+
export type EventGraphType = {
|
|
3
|
+
kind: 'any';
|
|
4
|
+
} | {
|
|
5
|
+
kind: 'void';
|
|
6
|
+
} | {
|
|
7
|
+
kind: 'null';
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'boolean';
|
|
10
|
+
} | {
|
|
11
|
+
kind: 'number';
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'string';
|
|
14
|
+
} | {
|
|
15
|
+
kind: 'vector2';
|
|
16
|
+
} | {
|
|
17
|
+
kind: 'vector3';
|
|
18
|
+
} | {
|
|
19
|
+
kind: 'euler';
|
|
20
|
+
} | {
|
|
21
|
+
kind: 'asset';
|
|
22
|
+
assetType: EventGraphAssetKind;
|
|
23
|
+
} | {
|
|
24
|
+
kind: 'optional';
|
|
25
|
+
value: EventGraphType;
|
|
26
|
+
} | {
|
|
27
|
+
kind: 'object';
|
|
28
|
+
classId?: string;
|
|
29
|
+
} | {
|
|
30
|
+
kind: 'actor';
|
|
31
|
+
classId?: string;
|
|
32
|
+
} | {
|
|
33
|
+
kind: 'actorClass';
|
|
34
|
+
classId?: string;
|
|
35
|
+
} | {
|
|
36
|
+
kind: 'component';
|
|
37
|
+
classId?: string;
|
|
38
|
+
} | {
|
|
39
|
+
kind: 'observable';
|
|
40
|
+
value: EventGraphType;
|
|
41
|
+
} | {
|
|
42
|
+
kind: 'array';
|
|
43
|
+
element: EventGraphType;
|
|
44
|
+
};
|
|
45
|
+
export type EventGraphTypeSource = EventGraphType | Function;
|
|
46
|
+
export declare const EVENT_GRAPH_ANY_TYPE: EventGraphType;
|
|
47
|
+
export declare const EVENT_GRAPH_VOID_TYPE: EventGraphType;
|
|
48
|
+
export declare const EVENT_GRAPH_BOOLEAN_TYPE: EventGraphType;
|
|
49
|
+
export declare const EVENT_GRAPH_NUMBER_TYPE: EventGraphType;
|
|
50
|
+
export declare const EVENT_GRAPH_STRING_TYPE: EventGraphType;
|
|
51
|
+
export declare const EVENT_GRAPH_VECTOR2_TYPE: EventGraphType;
|
|
52
|
+
export declare const EVENT_GRAPH_VECTOR3_TYPE: EventGraphType;
|
|
53
|
+
export declare const EVENT_GRAPH_ROTATION_TYPE: EventGraphType;
|
|
54
|
+
/** @deprecated Use EVENT_GRAPH_ROTATION_TYPE. */
|
|
55
|
+
export declare const EVENT_GRAPH_EULER_TYPE: {
|
|
56
|
+
kind: "euler";
|
|
57
|
+
};
|
|
58
|
+
export declare const EVENT_GRAPH_OBJECT_TYPE: EventGraphType;
|
|
59
|
+
export declare const EVENT_GRAPH_ACTOR_TYPE: EventGraphType;
|
|
60
|
+
export declare const EVENT_GRAPH_ACTOR_CLASS_TYPE: EventGraphType;
|
|
61
|
+
export declare const EVENT_GRAPH_COMPONENT_TYPE: EventGraphType;
|
|
62
|
+
export declare function isTweenableEventGraphType(type: EventGraphType): boolean;
|
|
63
|
+
export declare function eventGraphAssetType(assetType: EventGraphAssetKind): EventGraphType;
|
|
64
|
+
export declare function eventGraphOptionalType(value: EventGraphType): EventGraphType;
|
|
65
|
+
export declare function eventGraphActorType(type?: Function): EventGraphType;
|
|
66
|
+
export declare function eventGraphActorClassType(type?: Function): EventGraphType;
|
|
67
|
+
export declare function eventGraphComponentType(type?: Function): EventGraphType;
|
|
68
|
+
export declare function resolveEventGraphType(source?: EventGraphTypeSource | null): EventGraphType;
|
|
69
|
+
export declare function eventGraphTypeFromConstructor(type?: Function | null): EventGraphType;
|
|
70
|
+
export declare function inferEventGraphLiteralType(value: unknown): EventGraphType;
|
|
71
|
+
export declare function isEventGraphType(value: unknown): value is EventGraphType;
|
|
72
|
+
/** Returns true when a value of `actual` can connect to a port expecting `expected`. */
|
|
73
|
+
export declare function isEventGraphTypeAssignable(actual: EventGraphType, expected: EventGraphType): boolean;
|
|
74
|
+
/** Validates a serialized literal against its contextual graph type. */
|
|
75
|
+
export declare function isEventGraphLiteralAssignableToType(value: unknown, expected: EventGraphType): boolean;
|
|
76
|
+
export declare function eventGraphTypeName(type: EventGraphType): string;
|
|
77
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{Observable as e}from"rxjs";import{Euler as n,Vector2 as t,Vector3 as r}from"three";import{getActorClassById as s,getActorClassId as a,getComponentClassById as o,getComponentClassId as i}from"../actors/type-registry.js";import{isEventGraphAssetReference as p}from"./asset-references.js";export const EVENT_GRAPH_ANY_TYPE=Object.freeze({kind:"any"});export const EVENT_GRAPH_VOID_TYPE=Object.freeze({kind:"void"});export const EVENT_GRAPH_BOOLEAN_TYPE=Object.freeze({kind:"boolean"});export const EVENT_GRAPH_NUMBER_TYPE=Object.freeze({kind:"number"});export const EVENT_GRAPH_STRING_TYPE=Object.freeze({kind:"string"});export const EVENT_GRAPH_VECTOR2_TYPE=Object.freeze({kind:"vector2"});export const EVENT_GRAPH_VECTOR3_TYPE=Object.freeze({kind:"vector3"});export const EVENT_GRAPH_ROTATION_TYPE=Object.freeze({kind:"euler"});export const EVENT_GRAPH_EULER_TYPE=EVENT_GRAPH_ROTATION_TYPE;export const EVENT_GRAPH_OBJECT_TYPE=Object.freeze({kind:"object"});export const EVENT_GRAPH_ACTOR_TYPE=Object.freeze({kind:"actor"});export const EVENT_GRAPH_ACTOR_CLASS_TYPE=Object.freeze({kind:"actorClass"});export const EVENT_GRAPH_COMPONENT_TYPE=Object.freeze({kind:"component"});export function isTweenableEventGraphType(e){return"number"===e.kind||"vector2"===e.kind||"vector3"===e.kind||"euler"===e.kind}export function eventGraphAssetType(e){return{kind:"asset",assetType:e}}export function eventGraphOptionalType(e){return{kind:"optional",value:e}}export function eventGraphActorType(e){return{kind:"actor",...null!=e?{classId:a(e)??e.name}:{}}}export function eventGraphActorClassType(e){return{kind:"actorClass",...null!=e?{classId:a(e)??e.name}:{}}}export function eventGraphComponentType(e){return{kind:"component",...null!=e?{classId:i(e)??e.name}:{}}}export function resolveEventGraphType(e){return null==e?EVENT_GRAPH_ANY_TYPE:isEventGraphType(e)?e:eventGraphTypeFromConstructor(e)}export function eventGraphTypeFromConstructor(s){return null==s?EVENT_GRAPH_VOID_TYPE:s===Number?EVENT_GRAPH_NUMBER_TYPE:s===String?EVENT_GRAPH_STRING_TYPE:s===Boolean?EVENT_GRAPH_BOOLEAN_TYPE:s===t?EVENT_GRAPH_VECTOR2_TYPE:s===r?EVENT_GRAPH_VECTOR3_TYPE:s===n?EVENT_GRAPH_ROTATION_TYPE:s===Array?{kind:"array",element:EVENT_GRAPH_ANY_TYPE}:s===e||null!=s.prototype&&s.prototype instanceof e?{kind:"observable",value:EVENT_GRAPH_ANY_TYPE}:null!=a(s)||!0===s.__isActor?eventGraphActorType(s):null!=i(s)||!0===s.__isActorComponent?eventGraphComponentType(s):s===Object||s===Promise?EVENT_GRAPH_OBJECT_TYPE:{kind:"object",classId:s.name||void 0}}export function inferEventGraphLiteralType(e){if(void 0===e)return EVENT_GRAPH_ANY_TYPE;if(null===e)return{kind:"null"};if("boolean"==typeof e)return EVENT_GRAPH_BOOLEAN_TYPE;if("number"==typeof e)return EVENT_GRAPH_NUMBER_TYPE;if("string"==typeof e)return EVENT_GRAPH_STRING_TYPE;if(p(e))return eventGraphAssetType(e.assetType);if(Array.isArray(e)){return{kind:"array",element:e.length>0?inferEventGraphLiteralType(e[0]):EVENT_GRAPH_ANY_TYPE}}return EVENT_GRAPH_OBJECT_TYPE}export function isEventGraphType(e){if(null==e||"object"!=typeof e||"string"!=typeof e.kind)return!1;const n=e;switch(n.kind){case"any":case"void":case"null":case"boolean":case"number":case"string":case"vector2":case"vector3":case"euler":return!0;case"asset":return"prefab"===n.assetType||"vfx"===n.assetType||"sequence"===n.assetType;case"optional":return isEventGraphType(n.value)&&"void"!==n.value.kind;case"object":case"actor":case"actorClass":case"component":return null==n.classId||"string"==typeof n.classId;case"observable":return isEventGraphType(n.value);case"array":return isEventGraphType(n.element);default:return!1}}export function isEventGraphTypeAssignable(e,n){return"any"===e.kind||"any"===n.kind||("optional"===n.kind?"null"===e.kind||isEventGraphTypeAssignable("optional"===e.kind?e.value:e,n.value):"optional"!==e.kind&&("object"===n.kind?null==n.classId?"object"===e.kind||"actor"===e.kind||"component"===e.kind||"vector2"===e.kind||"vector3"===e.kind:"object"===e.kind&&(null==e.classId||e.classId===n.classId):e.kind===n.kind&&("asset"===e.kind&&"asset"===n.kind?e.assetType===n.assetType:"actor"===e.kind&&"actor"===n.kind||"actorClass"===e.kind&&"actorClass"===n.kind?l(e.classId,n.classId,s):"component"===e.kind&&"component"===n.kind?l(e.classId,n.classId,o):"observable"===e.kind&&"observable"===n.kind?isEventGraphTypeAssignable(e.value,n.value):"array"!==e.kind||"array"!==n.kind||isEventGraphTypeAssignable(e.element,n.element))))}export function isEventGraphLiteralAssignableToType(e,n){return"any"===n.kind?c(e):"actorClass"===n.kind?"string"==typeof e&&e.length>0:"vector2"===n.kind?T(e,2):"vector3"===n.kind||"euler"===n.kind?T(e,3):"asset"===n.kind?p(e)&&e.assetType===n.assetType&&e.assetId.length>0:"optional"===n.kind?null===e||isEventGraphLiteralAssignableToType(e,n.value):"array"===n.kind?Array.isArray(e)&&e.every(e=>isEventGraphLiteralAssignableToType(e,n.element)):c(e)&&isEventGraphTypeAssignable(inferEventGraphLiteralType(e),n)}export function eventGraphTypeName(e){return"actor"===e.kind||"component"===e.kind||"object"===e.kind?e.classId??e.kind:"actorClass"===e.kind?null!=e.classId?`${e.classId} Class`:"Actor Class":"observable"===e.kind?`Observable<${eventGraphTypeName(e.value)}>`:"array"===e.kind?`${eventGraphTypeName(e.element)}[]`:"asset"===e.kind?"vfx"===e.assetType?"VFX Asset":`${e.assetType[0].toUpperCase()}${e.assetType.slice(1)} Asset`:"optional"===e.kind?`${eventGraphTypeName(e.value)}?`:"euler"===e.kind?"Rotation":e.kind}function l(e,n,t){if(null==n||null==e)return!0;if(e===n)return!0;const r=t(e),s=t(n);return null!=r&&null!=s&&r.prototype instanceof s}function c(e){return"number"==typeof e?Number.isFinite(e):Array.isArray(e)?e.every(c):null==e||"object"!=typeof e||Object.values(e).every(c)}function T(e,n){return Array.isArray(e)&&e.length===n&&e.every(e=>"number"==typeof e&&Number.isFinite(e))}/*
|
|
2
|
+
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
|
+
* See the LICENSE.md file for details.
|
|
4
|
+
*/
|
package/dist/gameplay/index.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ export * from './initiate.js';
|
|
|
4
4
|
export * from './inject.js';
|
|
5
5
|
export { Service, Inject } from 'typedi';
|
|
6
6
|
export { ActorFactory } from './actors/factory.js';
|
|
7
|
-
export { Actor, BaseActor, getActorClassById } from './actors/actor.js';
|
|
8
|
-
export { Component, ActorComponent, type ComponentOptions, attach, Attach } from './actors/component.js';
|
|
7
|
+
export { Actor, BaseActor, getActorClassById, getActorClassId, getRegisteredActorClasses } from './actors/actor.js';
|
|
8
|
+
export { Component, ActorComponent, type ComponentOptions, attach, Attach, getComponentClassById, getComponentClassId, getRegisteredComponentClasses } from './actors/component.js';
|
|
9
9
|
export * from './services/world.js';
|
|
10
10
|
export * from './services/game-time-scheduler.js';
|
|
11
11
|
export * from './services/camera-shake.js';
|
|
@@ -13,6 +13,7 @@ export * from './services/render.js';
|
|
|
13
13
|
export * from './services/physics/physics-system.js';
|
|
14
14
|
export * from './animation/anim-sm.js';
|
|
15
15
|
export * from './animation/root-motion.js';
|
|
16
|
+
export * from './animation/retarget.js';
|
|
16
17
|
export * from './services/asset-loader.js';
|
|
17
18
|
export * from './services/pointer-events.js';
|
|
18
19
|
export { VisualEffect } from '../effects/vfx/vfx-param.js';
|
|
@@ -21,6 +22,18 @@ export * from '../shader/parameter.js';
|
|
|
21
22
|
export * from './ai/index.js';
|
|
22
23
|
export * from '../effects/vfx/index.js';
|
|
23
24
|
export * from './services/shader-provider.js';
|
|
25
|
+
export { EventGraphCallable, EventGraphEventSource, EventGraphProperty, getEventGraphCallableInfo, getEventGraphCallableInfos, getEventGraphCallableMethods, getEventGraphEventSourceInfo, getEventGraphEventSourceInfos, getEventGraphEventSourceMethods, getEventGraphPropertyInfo, getEventGraphPropertyInfos, getEventGraphProperties, isEventGraphEventSource, } from './event-graph/decorators.js';
|
|
26
|
+
export type { EventGraphCallableInfo, EventGraphCallableOptions, EventGraphEventSourceInfo, EventGraphEventSourceOptions, EventGraphParameterInfo, EventGraphPropertyInfo, EventGraphPropertyOptions, } from './event-graph/decorators.js';
|
|
27
|
+
export { EventGraphCompiler, validateEventGraphDocument } from './event-graph/document-compiler.js';
|
|
28
|
+
export type { CompiledEventGraph, CompiledEventGraphHandler, CompiledEventSourceArgument, CompiledEventSourceEvent, CompiledObservableEvent, EventGraphExecutionContext, EventGraphHandler, EventGraphDiagnostic, EventGraphValidationResult, } from './event-graph/document-compiler.js';
|
|
29
|
+
export type { EventGraphDocument, EventGraphEdge, EventGraphInput, EventGraphNode, EventGraphNodeKind, EventGraphSocketRef, EventGraphVariable, EventGraphVector2Literal, EventGraphVector3Literal, } from './event-graph/model.js';
|
|
30
|
+
export { createDefaultEventGraphDocument, hasExecutableEventGraphDocument } from './event-graph/model.js';
|
|
31
|
+
export { EVENT_GRAPH_NODE_DEFINITIONS, getEventGraphNodePorts, getEventGraphPortDefinition } from './event-graph/registry.js';
|
|
32
|
+
export { EventGraphInstance } from './event-graph/runtime.js';
|
|
33
|
+
export { analyzeEventGraphTypes, assertEventGraphTypes, createEventGraphTypeContext, getEventGraphMembersForType, } from './event-graph/type-inference.js';
|
|
34
|
+
export type { EventGraphNodeTypeInfo, EventGraphTypeAnalysis, EventGraphTypeContext, EventGraphTypeDiagnostic, EventGraphTypeMembers, } from './event-graph/type-inference.js';
|
|
35
|
+
export { EVENT_GRAPH_ACTOR_TYPE, EVENT_GRAPH_ACTOR_CLASS_TYPE, EVENT_GRAPH_ANY_TYPE, EVENT_GRAPH_BOOLEAN_TYPE, EVENT_GRAPH_COMPONENT_TYPE, EVENT_GRAPH_NUMBER_TYPE, EVENT_GRAPH_OBJECT_TYPE, EVENT_GRAPH_STRING_TYPE, EVENT_GRAPH_VOID_TYPE, EVENT_GRAPH_VECTOR2_TYPE, EVENT_GRAPH_VECTOR3_TYPE, eventGraphActorClassType, eventGraphActorType, eventGraphComponentType, eventGraphTypeName, isEventGraphTypeAssignable, } from './event-graph/types.js';
|
|
36
|
+
export type { EventGraphType, EventGraphTypeSource } from './event-graph/types.js';
|
|
24
37
|
export * from './net/net-connection.js';
|
|
25
38
|
export * from './net/net-session.js';
|
|
26
39
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/gameplay/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import"reflect-metadata";export{Container as DIContainer}from"typedi";export*from"./initiate.js";export*from"./inject.js";export{Service,Inject}from"typedi";export{ActorFactory}from"./actors/factory.js";export{Actor,BaseActor,getActorClassById}from"./actors/actor.js";export{Component,ActorComponent,attach,Attach}from"./actors/component.js";export*from"./services/world.js";export*from"./services/game-time-scheduler.js";export*from"./services/camera-shake.js";export*from"./services/render.js";export*from"./services/physics/physics-system.js";export*from"./animation/anim-sm.js";export*from"./animation/root-motion.js";export*from"./services/asset-loader.js";export*from"./services/pointer-events.js";export{VisualEffect}from"../effects/vfx/vfx-param.js";export{DataAssetRef}from"../scene/objects/data-asset.js";export*from"../shader/parameter.js";export*from"./ai/index.js";export*from"../effects/vfx/index.js";export*from"./services/shader-provider.js";export*from"./net/net-connection.js";export*from"./net/net-session.js";/*
|
|
1
|
+
import"reflect-metadata";export{Container as DIContainer}from"typedi";export*from"./initiate.js";export*from"./inject.js";export{Service,Inject}from"typedi";export{ActorFactory}from"./actors/factory.js";export{Actor,BaseActor,getActorClassById,getActorClassId,getRegisteredActorClasses}from"./actors/actor.js";export{Component,ActorComponent,attach,Attach,getComponentClassById,getComponentClassId,getRegisteredComponentClasses}from"./actors/component.js";export*from"./services/world.js";export*from"./services/game-time-scheduler.js";export*from"./services/camera-shake.js";export*from"./services/render.js";export*from"./services/physics/physics-system.js";export*from"./animation/anim-sm.js";export*from"./animation/root-motion.js";export*from"./animation/retarget.js";export*from"./services/asset-loader.js";export*from"./services/pointer-events.js";export{VisualEffect}from"../effects/vfx/vfx-param.js";export{DataAssetRef}from"../scene/objects/data-asset.js";export*from"../shader/parameter.js";export*from"./ai/index.js";export*from"../effects/vfx/index.js";export*from"./services/shader-provider.js";export{EventGraphCallable,EventGraphEventSource,EventGraphProperty,getEventGraphCallableInfo,getEventGraphCallableInfos,getEventGraphCallableMethods,getEventGraphEventSourceInfo,getEventGraphEventSourceInfos,getEventGraphEventSourceMethods,getEventGraphPropertyInfo,getEventGraphPropertyInfos,getEventGraphProperties,isEventGraphEventSource}from"./event-graph/decorators.js";export{EventGraphCompiler,validateEventGraphDocument}from"./event-graph/document-compiler.js";export{createDefaultEventGraphDocument,hasExecutableEventGraphDocument}from"./event-graph/model.js";export{EVENT_GRAPH_NODE_DEFINITIONS,getEventGraphNodePorts,getEventGraphPortDefinition}from"./event-graph/registry.js";export{EventGraphInstance}from"./event-graph/runtime.js";export{analyzeEventGraphTypes,assertEventGraphTypes,createEventGraphTypeContext,getEventGraphMembersForType}from"./event-graph/type-inference.js";export{EVENT_GRAPH_ACTOR_TYPE,EVENT_GRAPH_ACTOR_CLASS_TYPE,EVENT_GRAPH_ANY_TYPE,EVENT_GRAPH_BOOLEAN_TYPE,EVENT_GRAPH_COMPONENT_TYPE,EVENT_GRAPH_NUMBER_TYPE,EVENT_GRAPH_OBJECT_TYPE,EVENT_GRAPH_STRING_TYPE,EVENT_GRAPH_VOID_TYPE,EVENT_GRAPH_VECTOR2_TYPE,EVENT_GRAPH_VECTOR3_TYPE,eventGraphActorClassType,eventGraphActorType,eventGraphComponentType,eventGraphTypeName,isEventGraphTypeAssignable}from"./event-graph/types.js";export*from"./net/net-connection.js";export*from"./net/net-session.js";/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import e from"typedi";import{loadScene as t}from"../scene/bootstrap.js";import{ActorFactory as s}from"./actors/factory.js";import{World as n}from"./services/world.js";import{SceneMaterializer as o}from"../scene/materializer.js";import{ViewController as r}from"./services/render.js";import{RenderingView as i}from"../rendering.js";import{PhysicsSystem as a}from"./services/physics/physics-system.js";import{MeshComponent as c}from"./actors/builtin/components/mesh-component.js";import{builtInComponents as d}from"./actors/builtin/components/index.js";import{activeContainerInstance as m}from"./actors/internal/container-map.js";import{InputService as l}from"./input/index.js";import{RuntimeAssetsService as p}from"../scene/runtime-asset-service.js";import{AssetResourceLoader as h}from"../scene/asset-resource-loader.js";import{AssetLoader as u}from"./services/asset-loader.js";import{polyfillClient as f}from"./polyfill.js";import{Subject as g}from"rxjs";import{PointerEvents as w}from"./services/pointer-events.js";import{RuntimeBundledBackendService as
|
|
1
|
+
import e from"typedi";import{loadScene as t}from"../scene/bootstrap.js";import{ActorFactory as s}from"./actors/factory.js";import{World as n}from"./services/world.js";import{SceneMaterializer as o}from"../scene/materializer.js";import{ViewController as r}from"./services/render.js";import{RenderingView as i}from"../rendering.js";import{PhysicsSystem as a}from"./services/physics/physics-system.js";import{MeshComponent as c}from"./actors/builtin/components/mesh-component.js";import{builtInComponents as d}from"./actors/builtin/components/index.js";import{activeContainerInstance as m}from"./actors/internal/container-map.js";import{InputService as l}from"./input/index.js";import{RuntimeAssetsService as p}from"../scene/runtime-asset-service.js";import{AssetResourceLoader as h}from"../scene/asset-resource-loader.js";import{AssetLoader as u}from"./services/asset-loader.js";import{polyfillClient as f}from"./polyfill.js";import{Subject as g}from"rxjs";import{PointerEvents as w}from"./services/pointer-events.js";import{RuntimeBundledBackendService as v}from"../scene/runtime-bundled-backend-service.js";import{Scene as b}from"three";import{ShaderProvider as j}from"./services/shader-provider.js";import{SceneDataService as S}from"../scene/scene-data-service.js";import{NetMode as y}from"./net/net-session.js";import{AssetsProvider as x}from"../scene/assets-provider.js";export function initiateGame(g,I){if(f(),0!=I.element.childNodes.length)return console.error("Can not initialize the game with a non-empty html element"),null;e.has(r);const E=e.of("default"),R=new HologyRuntime(E),G=new s(E,{inEditor:!1});var P;G.classes=I.actors,e.set(s,G),P=I.element,Object.assign(P.style,{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",overflow:"hidden"});const D=new i(I.element,{enableXR:!0===I.xr?.enabled,maxPixelRatio:I.rendering?.maxPixelRatio,resolutionScale:I.rendering?.resolutionScale,dynamicResolution:I.rendering?.dynamicResolution,upscaling:I.rendering?.upscaling,msaa:I.rendering?.msaa,fpsCap:I.rendering?.fpsCap,depthPrepass:{enabled:!0===I.rendering?.depthPrepass?.enabled},bloom:{enabled:!1!==I?.rendering?.bloom?.enabled},reflection:{enabled:!1!==I?.rendering?.reflection?.enabled},shadows:{cascadeUpdateIntervals:[22,40,60,120]}});D.renderer.shadowMap.enabled=I.rendering?.shadows?.enabled??!0,D.renderer.shadowMap.autoUpdate=I.rendering?.shadows?.autoUpdate??!0,D.renderer.debug.checkShaderErrors=!1,e.set(i,D);const M=new r(D);e.set(r,M);const z=new v,A=new p(z),O=new h;O.setDataDir(I.dataDir),O.initKtx2(D.renderer);const C=Object.entries(I.shaders).map(([e,t])=>({name:e,type:t})),H=Object.entries(I.actors).map(([e,t])=>({name:e,type:t})),N={...d,...I.components??{}},T=Object.entries(N).map(([e,t])=>({name:e,type:t})),U=new j(C);e.set(j,U);const k=new u(O,A,C);e.set(x,A),e.set(h,O),e.set(u,k);const F=new b,W=new o(F,new S,A,O,D,C,H,G,T);W.inEditor=!1,W.netMode=I.multi?.session?.mode??y.none,e.set(o,W);const _=e.get(n);return e.set(n,_),_.materializer=W,(async()=>{const s=e.get(a);if(await s.start(),R.isShutdown)return;if(await z.preloadData(),R.isShutdown)return;if(_.scene=F,null!=I.multi?.session){const{NetService:e}=await import("./net/service/net-service.js"),t=E.get(e);t.session=I.multi.session,t.start(),R.shutdownStarted.subscribe(()=>t.stop())}const{scene:n,actors:o,materializer:r}=await t(D,I.sceneName,I.dataDir,I.shaders,I.actors,N,G,z,A,O,{detailTier:I.detailTier,nodeMode:I.multi?.session?.mode??y.none});_.scene=n,s.scene=_.scene;for(const e of F.children)_.scene.add(e);if(R.isShutdown)return void D.stop();e.import([c]);for(const e of o)_.addActor(e);s.addFromScene(n),await _.startSceneEventGraphs(r),console.log("Start compile shaders"),console.time("compile shaders"),await D.compileAsync(),console.timeEnd("compile shaders"),console.log("Finished compile shaders. Programs: ",D.renderer.info.programs?.length??0),console.log("Start init scene textures"),console.time("init scene textures"),D.initTextures(),console.timeEnd("init scene textures");const i=E.get(l);D.loop(e=>{i.update(e)}),R.status=5,R.shutdownStarted.subscribe(()=>{O.disposeAll()}),m.value=E,E.remove(g),E.set({id:g,type:g});const d=E.get(g);m.value=null,R.gameInstance=d,E.get(w).start(),d instanceof GameInstance&&await d.onStart(),R._resolver(!0)})(),R}export class GameInstance{onStart(){}onShutdown(){}}export function createHologyScene(){}export class HologyRuntime{constructor(e){this.containerInstance=e,this.status=0,this.isShutdown=!1,this.shutdownStarted=new g,this.ready=new Promise(e=>{this._resolver=e})}getWorld(){return this.containerInstance.get(n)}getService(e){return this.containerInstance.get(e)}shutdown(){this.isShutdown=!0;const e=this.shutdownStarted;e.next(),e.complete(),this.gameInstance instanceof GameInstance&&this.gameInstance.onShutdown(),this.containerInstance.get(l).stop();const t=this.containerInstance.get(i);t?.stop();const s=this.getWorld();s.stopSceneEventGraphs();const n=this.containerInstance.get(r);n.setMuted(!0),n.dispose();for(const e of[...s.actors])s.removeActor(e);this.containerInstance.get(a).stop(),this.containerInstance.get(o).dispose();const c=this.containerInstance.get(x);c instanceof p&&c.dispose(),this.containerInstance.get(w).stop(),this.containerInstance.reset(),this.shutdownStarted.complete()}}/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -11,20 +11,34 @@ export declare class AxisInput {
|
|
|
11
11
|
readonly setY: (value: number) => void;
|
|
12
12
|
}
|
|
13
13
|
type Callback = () => void;
|
|
14
|
+
export type ButtonInputMode = 'hold' | 'toggle';
|
|
14
15
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* ButtonInput stores a boolean activation state from key/button press/release events.
|
|
17
|
+
*
|
|
18
|
+
* In hold mode, the input stays active while the key/button is down.
|
|
19
|
+
* In toggle mode, the input flips each time the key/button is released.
|
|
20
|
+
* Start/end callbacks are emitted after activated has changed.
|
|
20
21
|
*/
|
|
21
|
-
export declare class
|
|
22
|
+
export declare class ButtonInput {
|
|
23
|
+
mode: ButtonInputMode;
|
|
22
24
|
private readonly emitter;
|
|
23
25
|
activated: boolean;
|
|
26
|
+
constructor(mode?: ButtonInputMode, activated?: boolean);
|
|
27
|
+
setActivated(active: boolean): void;
|
|
24
28
|
readonly toggle: (active: boolean) => void;
|
|
25
29
|
onStart(cb: Callback): void;
|
|
26
30
|
onEnd(cb: Callback): void;
|
|
27
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* ActionInput is for activating state while holding down a key.
|
|
34
|
+
* Example use case:
|
|
35
|
+
* - Sprinting temporarily
|
|
36
|
+
* - Jump
|
|
37
|
+
* - Shoot
|
|
38
|
+
*/
|
|
39
|
+
export declare class ActionInput extends ButtonInput {
|
|
40
|
+
constructor(activated?: boolean);
|
|
41
|
+
}
|
|
28
42
|
/**
|
|
29
43
|
* ToggleInput will be activated after a keypress. It is used
|
|
30
44
|
* for state that should be activated or deactivated without continuously
|
|
@@ -34,21 +48,12 @@ export declare class ActionInput {
|
|
|
34
48
|
* A ToggleInput may be for something slower paced or for something that should
|
|
35
49
|
* persist longer.
|
|
36
50
|
*
|
|
37
|
-
*
|
|
51
|
+
* Example use case:
|
|
38
52
|
* - Switch between running to normal walking speed.
|
|
39
53
|
* - Turning on a flash light.
|
|
40
54
|
*/
|
|
41
|
-
export declare class ToggleInput {
|
|
42
|
-
private readonly emitter;
|
|
43
|
-
activated: boolean;
|
|
55
|
+
export declare class ToggleInput extends ButtonInput {
|
|
44
56
|
constructor(activated?: boolean);
|
|
45
|
-
/**
|
|
46
|
-
* When called with true, does nothing if already activated.
|
|
47
|
-
* When called with false, toggles the state and emits the appropriate event.
|
|
48
|
-
*/
|
|
49
|
-
readonly toggle: (active: boolean) => void;
|
|
50
|
-
onStart(cb: Callback): void;
|
|
51
|
-
onEnd(cb: Callback): void;
|
|
52
57
|
}
|
|
53
58
|
export declare class RotationInput {
|
|
54
59
|
readonly rotation: Euler;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Euler as t,Vector2 as i}from"three";import{ArrayMap as s}from"../../utils/collections.js";import{clamp as
|
|
1
|
+
import{Euler as t,Vector2 as i}from"three";import{ArrayMap as s}from"../../utils/collections.js";import{clamp as o}from"../../utils/math.js";export class AxisInput{constructor(){this.vector=new i,this.togglePositiveY=t=>{this.vector.y=t?1:Math.min(this.vector.y,0)},this.toggleNegativeY=t=>{this.vector.y=t?-1:Math.max(this.vector.y,0)},this.togglePositiveX=t=>{this.vector.x=t?1:Math.min(this.vector.x,0)},this.toggleNegativeX=t=>{this.vector.x=t?-1:Math.max(this.vector.x,0)},this.setX=t=>{this.vector.x=t},this.setY=t=>{this.vector.y=t}}get horizontal(){return this.vector.x}get vertical(){return this.vector.y}}class e{constructor(){this.map=new s}emit(t){this.map.get(t).forEach(t=>t())}add(t,i){this.map.push(t,i)}}export class ButtonInput{constructor(t="hold",i=!1){this.mode=t,this.emitter=new e,this.activated=!1,this.toggle=t=>{if("toggle"!==this.mode)this.setActivated(t);else{if(t)return;this.setActivated(!this.activated)}},this.activated=i}setActivated(t){t!==this.activated&&(this.activated=t,this.activated?this.emitter.emit("start"):this.emitter.emit("end"))}onStart(t){this.emitter.add("start",t)}onEnd(t){this.emitter.add("end",t)}}export class ActionInput extends ButtonInput{constructor(t=!1){super("hold",t)}}export class ToggleInput extends ButtonInput{constructor(t=!1){super("toggle",t)}}const h=2*Math.PI;export class RotationInput{constructor(){this.rotation=new t,this.rotateX=t=>{this.rotation.x=(this.rotation.x+t)%h},this.rotateY=t=>{this.rotation.y=(this.rotation.y+t)%h},this.rotateZ=t=>{this.rotation.z=(this.rotation.z+t)%h}}}export class RestrictedRotationInput extends RotationInput{constructor(i=-1/0,s=1/0,e=-1/0,h=1/0,r=-1/0,a=1/0){super(),this.minX=i,this.maxX=s,this.minY=e,this.maxY=h,this.minZ=r,this.maxZ=a,this.rotation=new t,this.rotateX=t=>{this.rotation.x=o(this.rotation.x+t,this.minX,this.maxX)},this.rotateY=t=>{this.rotation.y=o(this.rotation.y+t,this.minY,this.maxY)},this.rotateZ=t=>{this.rotation.z=o(this.rotation.z+t,this.minZ,this.maxZ)}}}export class DecimalInput{constructor(t=0,i,s){this.min=i,this.max=s,this.increment=t=>{this.value=o(this.value+t,this.min,this.max)},this.set=t=>{this.value=t},this.value=t}}/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{BaseActor as t}from"../../actors/actor";import{NetService as e}from"./net-service";import{inject as n}from"../../inject";import{ReplOn as r}from"./replication";import{isSignalLike as i}from"./net-utils";import{ActorComponent as o}from"../../actors/component";export function RunIfServer(){return function(r,i){let o;return i.addInitializer(function(){this instanceof t?o=n(e):console.warn("RunIfServer should not be defined on a non actor")}),function(...t){if(o.isServer)return r.apply(this,t)}}}export function RunIfClient(){return function(r,i){let o;return i.addInitializer(function(){this instanceof t?o=n(e):console.warn("RunIfClient should not be defined on a non actor")}),function(...t){if(!o.isServer)return r.apply(this,t)}}}export function RunIfNotDedicatedServer(){return function(r,i){let o;return i.addInitializer(function(){this instanceof t?o=n(e):console.warn("RunIfClient should not be defined on a non actor")}),function(...t){if(!o.isDedicatedServer)return r.apply(this,t)}}}export function Replicated(s=r.all,c=!0){return function(r,a){let f;a.addInitializer(function(){if(!(this instanceof t||this instanceof o))return void console.warn("RunIfClient should not only be used on actors and actor components");let r,u;if(this instanceof t)r=this;else if(this instanceof o&&(r=this.actor,u=this,null==r))return;f=n(e),f.registerReplicatedProperty(s,c,r,a.name.toString(),this,u);const l=this[a.name];if(i(l)){const t=l.subscribe(t=>{if(f.isServer){if(null==r.__netid)return;f.handlePropertySet(s,c,r,a.name.toString(),t,u)}});return void r.disposed.subscribe(()=>{t()})}let d=l;Object.defineProperty(this,a.name,{set:t=>{f.isServer&&f.handlePropertySet(s,c,r,a.name.toString(),t,u),d=t},get:()=>d})})}}export function makePropertyReplicated(t,e,n,r,i){n.registerReplicatedProperty(i,r,t,e,this,null);let o=t[e];Object.defineProperty(t,e,{set:s=>{n.isServer&&n.handlePropertySet(i,r,t,e,s,null),o=s},get:()=>o})}/*
|
|
1
|
+
import{BaseActor as t}from"../../actors/actor.js";import{NetService as e}from"./net-service.js";import{inject as n}from"../../inject.js";import{ReplOn as r}from"./replication.js";import{isSignalLike as i}from"./net-utils.js";import{ActorComponent as o}from"../../actors/component.js";export function RunIfServer(){return function(r,i){let o;return i.addInitializer(function(){this instanceof t?o=n(e):console.warn("RunIfServer should not be defined on a non actor")}),function(...t){if(o.isServer)return r.apply(this,t)}}}export function RunIfClient(){return function(r,i){let o;return i.addInitializer(function(){this instanceof t?o=n(e):console.warn("RunIfClient should not be defined on a non actor")}),function(...t){if(!o.isServer)return r.apply(this,t)}}}export function RunIfNotDedicatedServer(){return function(r,i){let o;return i.addInitializer(function(){this instanceof t?o=n(e):console.warn("RunIfClient should not be defined on a non actor")}),function(...t){if(!o.isDedicatedServer)return r.apply(this,t)}}}export function Replicated(s=r.all,c=!0){return function(r,a){let f;a.addInitializer(function(){if(!(this instanceof t||this instanceof o))return void console.warn("RunIfClient should not only be used on actors and actor components");let r,u;if(this instanceof t)r=this;else if(this instanceof o&&(r=this.actor,u=this,null==r))return;f=n(e),f.registerReplicatedProperty(s,c,r,a.name.toString(),this,u);const l=this[a.name];if(i(l)){const t=l.subscribe(t=>{if(f.isServer){if(null==r.__netid)return;f.handlePropertySet(s,c,r,a.name.toString(),t,u)}});return void r.disposed.subscribe(()=>{t()})}let d=l;Object.defineProperty(this,a.name,{set:t=>{f.isServer&&f.handlePropertySet(s,c,r,a.name.toString(),t,u),d=t},get:()=>d})})}}export function makePropertyReplicated(t,e,n,r,i){n.registerReplicatedProperty(i,r,t,e,this,null);let o=t[e];Object.defineProperty(t,e,{set:s=>{n.isServer&&n.handlePropertySet(i,r,t,e,s,null),o=s},get:()=>o})}/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as r}from"tslib";import{World as t}from"../../services/world";import{inject as e}from"../../inject";import{Service as s}from"typedi";import{BaseActor as n}from"../../actors/actor";import{Euler as o,Quaternion as i,Vector2 as a,Vector3 as c,Vector4 as f}from"three";import{DataAssetRef as u}from"../../../scene/objects/data-asset";import{AssetLoader as l}from"../../services/asset-loader";const p="-a",m="-v2",d="-v3",w="-v4",y="-e",A="-q",h="-s",
|
|
1
|
+
import{__decorate as r}from"tslib";import{World as t}from"../../services/world.js";import{inject as e}from"../../inject.js";import{Service as s}from"typedi";import{BaseActor as n}from"../../actors/actor.js";import{Euler as o,Quaternion as i,Vector2 as a,Vector3 as c,Vector4 as f}from"three";import{DataAssetRef as u}from"../../../scene/objects/data-asset.js";import{AssetLoader as l}from"../../services/asset-loader.js";const p="-a",m="-v2",d="-v3",w="-v4",y="-e",A="-q",h="-s",j="-m",b="-dar";export class DecodeResult{constructor(){this.error=!1,this.requiresAssetLookups=!1}reset(){this.error=!1,this.missingActorId=void 0,this.requiresAssetLookups=!1}}let O=class{constructor(){this.world=e(t),this.assetLoader=e(l)}encode(r){return JSON.stringify(this.wrapObject(r))}decode(r,t){t.reset();const e=JSON.parse(r);return this.unwrapObject(e,t)}wrapObject(r){if(null!=r&&"object"==typeof r){if(Array.isArray(r))return r.map(r=>this.wrapObject(r));if(r instanceof n){if(null!=r.__netid)return{[p]:r.__netid};console.warn("Missing netid on actor",r)}else{if(r instanceof a)return{[m]:r.toArray([])};if(r instanceof c)return{[d]:r.toArray([])};if(r instanceof f)return{[w]:r.toArray([])};if(r instanceof o)return{[y]:r.toArray([])};if(r instanceof i)return{[A]:r.toArray([])};if(r instanceof Map)return{[j]:Array.from(r.entries()).map(([r,t])=>[r,this.wrapObject(t)])};if(r instanceof Set)return{[h]:Array.from(r.values()).map(r=>this.wrapObject(r))};if(r instanceof u)return{[b]:r.id}}const t={};for(const e of Object.keys(r))t[e]=this.wrapObject(r[e]);return t}return r}unwrapObject(r,t){if(null!=r&&"object"==typeof r){if(Array.isArray(r))return r.map(r=>this.unwrapObject(r,t));{if(null!=r[p]){const e=r[p],s=this.world.actors.find(r=>r.__netid===e);return null==s&&(t.error=!0,t.missingActorId=e,console.warn(`Failed to find replicated actor with netid "${e}"`)),s}if(null!=r[m]){const t=r[m];return(new a).fromArray(t)}if(null!=r[d]){const t=r[d];return(new c).fromArray(t)}if(null!=r[w]){const t=r[w];return(new f).fromArray(t)}if(null!=r[y]){const t=r[y];return(new o).fromArray(t)}if(null!=r[A]){const t=r[A];return(new i).fromArray(t)}if(null!=r[j]){const e=r[j];return new Map(e.map(([r,e])=>[r,this.unwrapObject(e,t)]))}if(null!=r[h]){const e=r[h];return new Set(e.map(r=>this.unwrapObject(r,t)))}if(null!=r[b])return t.requiresAssetLookups=!0,r;const e={};for(const s of Object.keys(r))e[s]=this.unwrapObject(r[s],t);return e}}return r}async decodeAssets(r){if(null!=r&&"object"==typeof r){if(Array.isArray(r))return await Promise.all(r.map(r=>this.decodeAssets(r)));if(r instanceof Map){const t=await Promise.all(Array.from(r.entries()).map(async([r,t])=>[r,await this.decodeAssets(t)]));r.clear();for(const[e,s]of t)r.set(e,s);return r}if(r instanceof Set){const t=await Promise.all(Array.from(r.values()).map(r=>this.decodeAssets(r)));r.clear();for(const e of t)r.add(e);return r}{const t=r;if(null!=t[b])return await this.assetLoader.getDataAssetById(t[b]);for(const r of Object.keys(t))t[r]=await this.decodeAssets(t[r]);return t}}return r}};O=r([s()],O);export{O as NetSerializer};new a,new c,new f,new o,new i;/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ActorOptions, BaseActor } from '../../actors/actor';
|
|
2
|
-
import { ActorComponent } from '../../actors/component';
|
|
3
|
-
import { NetConnection } from '../net-connection';
|
|
4
|
-
import { NetMode, NetSession } from '../net-session';
|
|
5
|
-
import { ReplOn } from "./replication";
|
|
6
|
-
import { RunsOn } from './rpc';
|
|
1
|
+
import { ActorOptions, BaseActor } from '../../actors/actor.js';
|
|
2
|
+
import { ActorComponent } from '../../actors/component.js';
|
|
3
|
+
import { NetConnection } from '../net-connection.js';
|
|
4
|
+
import { NetMode, NetSession } from '../net-session.js';
|
|
5
|
+
import { ReplOn } from "./replication.js";
|
|
6
|
+
import { RunsOn } from './rpc.js';
|
|
7
7
|
export declare class NetService {
|
|
8
8
|
session?: NetSession;
|
|
9
9
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as e}from"tslib";import{delay as t,interval as n,Subject as r,takeUntil as s,tap as o}from"rxjs";import{Euler as i,Vector3 as c}from"three";import{Service as a}from"typedi";import{$actorOptions as l,BaseActor as d,getActorClassById as p}from"../../actors/actor";import{ActorComponent as u}from"../../actors/component";import{$actorComponents as f}from"../../actors/internal/component-init";import{inject as h}from"../../inject";import{World as g}from"../../services/world";import{NetMode as y}from"../net-session";import{NetRole as w}from"./net-actor-role";import{DecodeResult as m,NetSerializer as v}from"./net-serializer";import{isSignalLike as A}from"./net-utils";import{ReplOn as b}from"./replication";import{getRpcMethodId as R,getRpcMethodName as _,RunsOn as S}from"./rpc";import{ActorController as U,BasePlayerController as M}from"../../actors/controller/actor-controller";import{makePropertyReplicated as C}from"./net-decorator";var P;!function(e){e[e.rpc=1]="rpc",e[e.prop=2]="prop",e[e.spawn=3]="spawn",e[e.removeActor=4]="removeActor",e[e.rpcComponent=5]="rpcComponent",e[e.propComponent=6]="propComponent",e[e.rpcBinary=21]="rpcBinary",e[e.rpcComponentBinary=25]="rpcComponentBinary",e[e.actorReady=7]="actorReady",e[e.propSnapshot=8]="propSnapshot",e[e.serverTime=100]="serverTime"}(P||(P={}));var $;!function(e){e[e.actor=0]="actor",e[e.component=1]="component"}($||($={}));let L=class{constructor(){this.actorConnection=new Map,this.destroyed=new r,this.world=h(g),this.serializer=h(v),this.serverTimeOffset=0,this.actorPreSpawnMessageBuffer=new Map,this.actorRefMissingMessageQueue=new Map,this.netStartupActorSpawnQueue=new Map,this.spawningActorNetIds=new Set,this.nextNetId=1,this.shouldReplicateMap=new Map,this.replicatedActors=new Map,this.replicatedProperties=new Map,this.replicatedPropertyRegistry=new Map}get mode(){return this.session?.mode??y.none}get isClient(){return this.mode===y.client}get isServer(){return this.mode<y.client}get isDedicatedServer(){return this.mode===y.dedicatedServer}start(){if(this.stop(),this.destroyed=new r,this.isServer)for(const e of this.session.clients)this.sendServerTime(e);n(15).pipe(s(this.destroyed)).subscribe(()=>{this.processMessages()}),this.world.actorAdded.pipe(s(this.destroyed),o(e=>{this.configureMaterializedActorRole(e),this.isServer?this.defineNetId(e):this.processQueuedNetStartupActorSpawns(e)}),t(8)).subscribe(e=>{this.shouldReplicate(e)&&(C(e,"owner",this,!0,b.all),this.sendActorSpawn(e))}),this.world.actorRemoved.pipe(s(this.destroyed),t(10)).subscribe(e=>{this.sendActorRemove(e),this.replicatedActors.delete(e),this.replicatedProperties.delete(e),this.replicatedPropertyRegistry.delete(e),this.actorPreSpawnMessageBuffer.delete(e)}),this.session.playerJoined.pipe(s(this.destroyed)).subscribe(e=>{this.sendServerTime(e),this.isServer&&this.replicatedActors.size>0&&this.spawnOnLateClient(e)})}stop(){this.destroyed.next(null),this.destroyed.complete()}configureMaterializedActorRole(e){null!=e.__netSceneId&&this.mode!==y.none&&(this.shouldReplicate(e)?e.netRole=this.isServer?w.authority:w.simulatedProxy:this.isServer||(e.netRole=w.none))}shouldReplicate(e){const t=this.shouldReplicateMap.get(e);if(null==t){const t=e.constructor[l],n=!0===t?.replicate;return this.shouldReplicateMap.set(e,n),n}return!0===t}setReplicate(e,t){this.shouldReplicateMap.set(e,t)}isRelevant(e,t){const n=this.getRelevancyOptions(e);return!(!0===n?.ownerOnly)||this.resolveActorConnection(e)?.id===t.id}getRelevancyOptions(e){return e.constructor[l].relevancy}spawnOnLateClient(e){const t=[e];for(const e of this.replicatedActors.keys())this.sendActorSpawn(e,t)}async processMessages(){const e=this.session.hasMessage();for(let t=0;t<e;t++){const e=this.session.readMessage();null!=e&&await this.processMessage(e)}}async processMessage(e){try{switch(new DataView(e.buffer).getUint8(0)){case P.rpc:case P.rpcComponent:case P.rpcBinary:case P.rpcComponentBinary:this.processRpc(e.from,e.buffer);break;case P.prop:case P.propComponent:this.processProp(e.from,e.buffer);break;case P.propSnapshot:this.processPropSnapshot(e.from,e.buffer);break;case P.spawn:await this.processSpawn(e.from,e.buffer);break;case P.removeActor:this.processRemoveActor(e.from,e.buffer);break;case P.serverTime:this.processServerTime(e.from,e.buffer);break;case P.actorReady:this.processActorReady(e.from,e.buffer)}}catch(e){console.error("Failed to process message",e)}}processServerTime(e,t){if(this.isServer||this.session.server?.id!==e.id)return;const n=this.parseServerTime(t);this.serverTimeOffset=Date.now()-n}getActorRefMissingMessageQueue(e){let t=this.actorRefMissingMessageQueue.get(e);return null==t&&(t=[],this.actorRefMissingMessageQueue.set(e,t)),t}processRpc(e,t){let n=0;const r=new DataView(t),s=r.getUint8(n);n+=1;const o=r.getUint32(n,!0);n+=4;const i=r.getUint8(n);n+=1;const c=s===P.rpcBinary||s===P.rpcComponentBinary;let a,l,d="";if(c){const e=r.getUint32(n,!0);n+=4,l=new Uint8Array(t,n,e),n+=e}else{const e=r.getUint16(n,!0);n+=2,d=O(t,n,e),n+=e;try{a=this.serializer.decode(d,F)}catch(e){return void console.warn("Failed to parse RPC args JSON",d,e)}}if(!c&&F.error){if(null!=F.missingActorId){const n=this.getActorRefMissingMessageQueue(F.missingActorId);console.debug(`Missing referenced actor ${F.missingActorId}. Queueing message for later`),n.push({from:e,buffer:t})}else console.log("Unknown decode error",d);return}const p=this.world.actors.find(e=>e.__netid===o);if(null==p){return this.getActorRefMissingMessageQueue(o).push({from:e,buffer:t}),void console.debug(`Missing actor ${o}. Queueing message for later`)}let u;if(s===P.rpcComponent||s===P.rpcComponentBinary){const e=r.getUint8(n),t=p[f];if(null!=t&&(u=t.find(t=>t.__netid===e)),null==u)return void console.error(`RPC failed: Failed to find component with netid ${e} on actor with netid ${o}`)}if(this.isServer){if(!this.session.clients.some(t=>t.id==e.id))return void console.warn("Received RCP from non client");const t=this.resolveActorConnection(p);if(null==t)return void console.error("Received server RPC for actor without owner which can't be processed");if(t.id!==e.id)return void console.warn(`Received RPC for actor net id ${p.__netid} from connection ${e.id}, but this connection is not the owner. Can't process.`)}else{if(!(this.session.server?.id===e.id))return void console.warn("Received RCP from non server which is not allowed")}const h=u??p,g=_(h,i);if(null!=g)if("function"==typeof h[g])if(c)h[g](l);else{if(F.requiresAssetLookups)return this.serializer.decodeAssets(a).then(e=>{h[g](...e)}).catch(e=>{console.warn(`Failed to decode asset references for RPC '${g}' on actor net id ${p.__netid}`,e)});h[g](...a)}else console.error(`RPC function '${g}' not found on actor net id ${p.__netid}`+(null!=u?` and component net id ${u.__netid}`:""));else console.error(`RPC method id ${i} not found on actor net id ${p.__netid}`+(null!=u?` and component net id ${u.__netid}`:""))}processProp(e,t){if(this.session.server?.id!==e.id)return void console.warn(`Received property replication from non-server connection (id: ${e.id}), ignoring.`);let n=0;const r=new DataView(t),s=r.getUint8(n);n+=1;const o=r.getUint32(n,!0);n+=4;const i=r.getUint8(n);n+=1;let c="";for(let e=0;e<i;e++)c+=String.fromCharCode(r.getUint8(n+e));n+=i;const a=r.getUint16(n,!0);n+=2;const l=t.slice(n,n+a);n+=a;const d=this.world.actors.find(e=>e.__netid===o);if(!d){return this.getActorRefMissingMessageQueue(o).push({from:e,buffer:t}),void console.error("Failed to process property replication. No actor found with id",o,c)}let p;if(s===P.propComponent){const e=r.getUint8(n),t=d[f];if(null!=t&&(p=t.find(t=>t.__netid===e)),null==p)return void console.error(`Failed to find component with netid ${e} on actor with netid ${o}`)}const u=p??d;try{const n=this.decodeReplicatedValue(l);if(F.error){if(null!=F.missingActorId){let n=this.getActorRefMissingMessageQueue(F.missingActorId);console.debug(`Missing referenced actor ${F.missingActorId}. Queueing message for later`),n.push({from:e,buffer:t})}return}if(F.requiresAssetLookups)return this.serializer.decodeAssets(n).then(e=>{this.applyReplicatedProperty(u,c,e),this.callRepNotify(u,c)}).catch(e=>{console.warn(`Failed to decode asset references for replicated property '${c}' on actor id ${o}`,e)});this.applyReplicatedProperty(u,c,n),this.callRepNotify(u,c)}catch(e){console.warn(`Failed to decode replicated property '${c}' on actor id ${o}`,e)}}processPropSnapshot(e,t){if(this.session.server?.id!==e.id)return void console.warn(`Received property snapshot from non-server connection (id: ${e.id}), ignoring.`);let n=0;const r=new DataView(t);n+=1;const s=r.getUint32(n,!0);n+=4;const o=this.world.actors.find(e=>e.__netid===s);if(null==o){return this.getActorRefMissingMessageQueue(s).push({from:e,buffer:t}),void console.debug(`Missing actor ${s}. Queueing property snapshot for later`)}const i=r.getUint16(n,!0);n+=2;const c=[];for(let a=0;a<i;a++){const i=r.getUint8(n);n+=1;let a=o;if(i===$.component){const e=r.getUint8(n);n+=1;const t=o[f];if(a=t?.find(t=>t.__netid===e),null==a)return void console.error(`Failed to process property snapshot. No component found with netid ${e} on actor with netid ${s}`)}else if(i!==$.actor)return void console.error(`Failed to process property snapshot. Unknown target kind ${i}`);const l=r.getUint8(n);n+=1;let d="";for(let e=0;e<l;e++)d+=String.fromCharCode(r.getUint8(n+e));n+=l;const p=r.getUint32(n,!0);n+=4;const u=t.slice(n,n+p);n+=p;try{const n=this.decodeReplicatedValue(u);if(F.error){if(null!=F.missingActorId){this.getActorRefMissingMessageQueue(F.missingActorId).push({from:e,buffer:t}),console.debug(`Missing referenced actor ${F.missingActorId}. Queueing property snapshot for later`)}else console.warn(`Unknown decode error in property snapshot for actor ${s}`);return}c.push({target:a,property:d,value:n,requiresAssetLookups:F.requiresAssetLookups})}catch(e){return void console.warn(`Failed to decode replicated property snapshot entry '${d}' on actor id ${s}`,e)}}if(c.some(e=>e.requiresAssetLookups))return Promise.all(c.map(async e=>{e.requiresAssetLookups&&(e.value=await this.serializer.decodeAssets(e.value))})).then(()=>{this.applyReplicatedProperties(c)}).catch(e=>{console.warn(`Failed to decode asset references for property snapshot on actor id ${s}`,e)});this.applyReplicatedProperties(c)}applyReplicatedProperties(e){for(const t of e)this.applyReplicatedProperty(t.target,t.property,t.value);for(const t of e)this.callRepNotify(t.target,t.property)}async processSpawn(e,t){if(this.isServer)return;const n=new DataView(t);let r=0;r+=1;const s=n.getUint32(r,!0);r+=4;const o=n.getUint8(r);r+=1;let i="";for(let e=0;e<o;e++)i+=String.fromCharCode(n.getUint8(r+e));r+=o,Q.set(n.getFloat32(r,!0),n.getFloat32(r+4,!0),n.getFloat32(r+8,!0)),r+=12,B.set(n.getFloat32(r,!0),n.getFloat32(r+4,!0),n.getFloat32(r+8,!0)),r+=12;const c=n.getUint8(r);r+=1;const a=n.getUint32(r);r+=4;const l=this.readOptionalSceneId(t,r);console.log("Spawning "+i);const d=p(i);if(!d)return void console.error(`Failed to spawn actor: unknown actor type '${i}'`);const u=this.world.actors.find(e=>e.__netid===s);if(null!=u)return void this.applySpawnNetInfo(u,s,c,a);if(this.spawningActorNetIds.has(s))return void console.log("Actor was already spawned",null!=u);const f=this.findMaterializedNetStartupActor(l,i,s);if(null!=f)return this.applySpawnNetInfo(f,s,c,a),this.processQueuedActorMessages(s),void this.sendActorReady(f);if(null==l){this.spawningActorNetIds.add(s);try{const e=await this.world.spawnActorWithNetInfo(d,s,c,a,Q,B);this.processQueuedActorMessages(s),this.sendActorReady(e)}catch(e){return void console.error("Spawning replicated actor on client failed",e)}finally{this.spawningActorNetIds.delete(s)}}else this.getNetStartupActorSpawnQueue(l).push({from:e,buffer:t})}readOptionalSceneId(e,t){if(t+2>e.byteLength)return;const n=new DataView(e).getUint16(t,!0);return t+=2,0===n||t+n>e.byteLength?void 0:O(e,t,n)}findMaterializedNetStartupActor(e,t,n){if(null!=e)return this.world.actors.find(r=>{if(r.__netSceneId!==e)return!1;if(null!=r.__netid&&r.__netid!==n)return!1;return(r.constructor.__actorId??r.constructor.name)===t})}applySpawnNetInfo(e,t,n,r){if(e.__netid=t,e.netRole=n,0===r)e.owner=void 0;else{const t=this.world.actors.find(e=>e.__netid===r);null!=t&&(e.owner=t)}e instanceof M&&(e.isLocallyControlled=n===w.autonomousProxy)}getNetStartupActorSpawnQueue(e){let t=this.netStartupActorSpawnQueue.get(e);return null==t&&(t=[],this.netStartupActorSpawnQueue.set(e,t)),t}processQueuedNetStartupActorSpawns(e){if(null==e.__netSceneId)return;const t=this.netStartupActorSpawnQueue.get(e.__netSceneId);if(null!=t){this.netStartupActorSpawnQueue.delete(e.__netSceneId);for(const e of t)this.processMessage(e)}}processQueuedActorMessages(e){const t=this.actorRefMissingMessageQueue.get(e);if(null!=t){console.log(`Processing queued messages for actor ${e}`),this.actorRefMissingMessageQueue.delete(e);for(const e of t)this.processMessage(e)}}sendActorReady(e){if(this.mode===y.none)return;if(!e||null==e.__netid)return void console.warn("sendActorReady: actor or actor.__netid is undefined");if(this.isServer)return;const t=new ArrayBuffer(5),n=new DataView(t);let r=0;n.setUint8(r,P.actorReady),r+=1,n.setUint32(r,e.__netid,!0),this.session.server&&this.session.sendMessage(this.session.server,!0,t)}processActorReady(e,t){if(!this.isServer)return;const n=new DataView(t).getUint32(1,!0),r=this.world.actors.find(e=>e.__netid===n);if(!r)return void console.warn(`processActorReady: No actor found with net id ${n}`);const s=this.actorPreSpawnMessageBuffer.get(r),o=this.getConnectionKey(e),i=s?.get(o);if(null!=i){this.sendPropertySnapshot(r,e);const t=i.filter(e=>!this.isPropertyMessage(e.buffer));if(t.length>0){console.log(`Sending ${t.length} queued messages for actor ${r.__netid}`);for(const e of t)this.session.sendMessage(e.connection,e.reliable,e.buffer)}s.delete(o),0===s.size&&this.actorPreSpawnMessageBuffer.delete(r)}}sendRpc(e,t,n,r,s,o){if(this.mode==y.none)return;if(!this.shouldReplicate(n))return;const i=n.__netid;if(null==i)return void console.warn("No __netid defined on actor. Actor must be repliated for RPC");const c=this.resolveActorConnection(n),a=[];if(this.isServer)switch(e){case S.all:a.push(...this.session.clients.filter(e=>this.isRelevant(n,e)));break;case S.client:null!=c&&a.push(c);break;case S.notOwner:a.push(...this.session.clients.filter(e=>e.id!==c?.id&&this.isRelevant(n,e)));case S.server:}else switch(e){case S.all:case S.client:case S.notOwner:break;case S.server:a.push(this.session.server)}if(0==a.length)return;if(null!=o&&null==o.__netid)return void console.warn("No __netid defined on component. Component must be initialized for RPC",o);const l=null!=o,d=o??n,p=R(d,r);if(null==p)return void console.warn(`RPC function '${r}' is not registered on ${d.constructor?.name??"target"}`);const u=1===s.length?function(e){if(e instanceof Uint8Array)return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if("undefined"!=typeof SharedArrayBuffer&&e instanceof SharedArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);return null}(s[0]):null;if(null!=u){let e=10+u.byteLength;l&&(e+=1);const r=new ArrayBuffer(e),s=new DataView(r);let c=0;s.setUint8(c,l?P.rpcComponentBinary:P.rpcBinary),c+=1,s.setUint32(c,i,!0),c+=4,s.setUint8(c,p),c+=1,s.setUint32(c,u.byteLength,!0),c+=4,D(r,c,u),c+=u.byteLength,l&&(s.setUint8(c,o.__netid),c+=1);for(const e of a)null!=e&&this.sendWithQueue(n,{connection:e,reliable:t,buffer:r});return}const f=this.serializer.encode(s),h=I.encode(f);if(h.byteLength>65535)return void console.warn("RPC arguments are too large to send with the JSON RPC format",r);let g=8+h.byteLength;l&&(g+=1);const w=new ArrayBuffer(g),m=new DataView(w);let v=0;m.setUint8(v,l?P.rpcComponent:P.rpc),v+=1,m.setUint32(v,i,!0),v+=4,m.setUint8(v,p),v+=1,m.setUint16(v,h.byteLength,!0),v+=2,D(w,v,h),v+=h.byteLength,l&&(m.setUint8(v,o.__netid),v+=1);for(const e of a)null!=e&&this.sendWithQueue(n,{connection:e,reliable:t,buffer:w})}sendWithQueue(e,t){if(this.shouldQueueMessageUntilActorReady(e,t.connection)){return void this.getPreSpawnMessageQueue(e,t.connection).push(t)}this.session.sendMessage(t.connection,t.reliable,t.buffer)}findQueuedActorsInData(e,t=[]){if("object"==typeof e){if(Array.isArray(e))for(const t of e)this.findQueuedActorsInData(t);if(e instanceof d){this.actorPreSpawnMessageBuffer.get(e)}}}handlePropertySet(e,t,n,r,s,o){if(this.mode==y.none)return;if(!this.isServer)return;if(!this.shouldReplicate(n))return;let i=this.replicatedProperties.get(n);null==i&&(i={},this.replicatedProperties.set(n,i));const c=this.serializer.encode(s),a=I.encode(c),l=a.buffer.slice(a.byteOffset,a.byteOffset+a.byteLength);i[this.getReplicatedPropertyKey(r,o)]={property:r,replOn:e,reliable:t,buffer:l,component:o},this.sendProperty(e,t,n,r,l,o)}sendProperty(e,t,n,r,s,o){if(!this.isServer)return;const i=[],c=this.resolveActorConnection(n);switch(e){case b.all:i.push(...this.session.clients);break;case b.owner:null!=c&&i.push(c);break;case b.notOwner:null==c?i.push(...this.session.clients):i.push(...this.session.clients.filter(e=>e.id!==c.id))}const a=null!=o&&null!=o.__netid;let l=6+r.length+2+s.byteLength;a&&(l+=1);const d=new ArrayBuffer(l),p=new DataView(d);let u=0;p.setUint8(u,a?P.propComponent:P.prop),u+=1,p.setUint32(u,n.__netid,!0),u+=4,p.setUint8(u,r.length),u+=1;for(let e=0;e<r.length;e++)p.setUint8(u++,r.charCodeAt(e));p.setUint16(u,s.byteLength,!0),u+=2,new Uint8Array(d,u,s.byteLength).set(new Uint8Array(s)),u+=s.byteLength,a&&(p.setUint8(u,o.__netid),u+=1);for(const e of i)null!=e&&this.isRelevant(n,e)&&this.sendWithQueue(n,{connection:e,reliable:t,buffer:d})}defineNetId(e){null==e.__netid&&(e.__netid=this.nextNetId++)}registerReplicatedProperty(e,t,n,r,s,o){if(null==n||null==r||null==s)return;let i=this.replicatedPropertyRegistry.get(n);null==i&&(i=[],this.replicatedPropertyRegistry.set(n,i));const c=o??(s instanceof u?s:void 0),a=i.find(e=>e.target===s&&e.property===r);if(null!=a)return a.replOn=e,a.reliable=t,void(a.component=c);i.push({property:r,replOn:e,reliable:t,target:s,component:c})}sendActorSpawn(e,t=this.session.clients){if(!this.isServer)return;const n=t.filter(t=>this.isRelevant(e,t));this.defineNetId(e);const r=e.__netid;let s=e.constructor.__actorId??e.constructor.name;const o=I.encode(s);let i;null!=e.__netSceneId&&(i=I.encode(e.__netSceneId),i.byteLength>65535&&(console.warn(`Scene actor id is too long to replicate as a startup actor: ${e.__netSceneId}`),i=void 0));const c=i?.byteLength??0,a=6+o.length+12+12+1+4+2+c,l=new ArrayBuffer(a),d=new DataView(l);let p=0;d.setUint8(p,P.spawn),p+=1,d.setUint32(p,r,!0),p+=4,d.setUint8(p,o.length),p+=1,new Uint8Array(l).set(o,p),p+=o.length,d.setFloat32(p,e.position.x,!0),p+=4,d.setFloat32(p,e.position.y,!0),p+=4,d.setFloat32(p,e.position.z,!0),p+=4,d.setFloat32(p,e.rotation.x,!0),p+=4,d.setFloat32(p,e.rotation.y,!0),p+=4,d.setFloat32(p,e.rotation.z,!0),p+=4;let u=p;p+=1,d.setUint32(p,e.owner?.__netid??0),p+=4,d.setUint16(p,c,!0),p+=2,null!=i&&(D(l,p,i),p+=i.byteLength);let f=this.replicatedActors.get(e);null==f&&(f={spawnedAt:Date.now(),connections:[]},this.replicatedActors.set(e,f));for(const t of n){const n=l.slice(0),r=new DataView(n),s=this.resolveActorConnection(e)?.id===t.id?w.autonomousProxy:w.simulatedProxy;r.setUint8(u,s),this.getPreSpawnMessageQueue(e,t),this.session.sendMessage(t,!0,n),f.connections.some(e=>e.id===t.id)||f.connections.push(t)}}sendActorRemove(e){if(!this.isServer)return;const t=new ArrayBuffer(5),n=new DataView(t);let r=0;n.setUint8(r,P.removeActor),r+=1,n.setUint32(r,e.__netid,!0);for(const e of this.session.clients)this.session.sendMessage(e,!0,t)}processRemoveActor(e,t){if(this.isServer||this.session.server?.id!==e.id)return;const n=new DataView(t).getUint32(1,!0),r=this.world.actors.find(e=>e.__netid===n);r&&(this.world.removeActor(r),this.replicatedActors?.delete?.(r),this.replicatedProperties?.delete?.(r))}setOwningConnection(e,t){this.actorConnection.set(e.id,t)}getOwningConnection(e){return this.actorConnection.get(e.id)}getActorsByOwningConnection(e){const t=[];return this.actorConnection.forEach((n,r)=>{if(n.id===e.id){const e=this.world.actors.find(e=>e.id===r);null!=e&&t.push(e)}}),t}resolveActorConnection(e){let t;for(;null==t&&null!=e;)t=this.actorConnection.get(e.id),null==t&&(e=e.owner);return t}isLocallyControlled(e){let t=e;for(;null!=t;){if(t.netRole===w.autonomousProxy)return!0;if(t instanceof U)return t.isLocallyControlled;t=e.owner}return!1}isLocalOwner(e){return this.isLocallyControlled(e)}sendServerTime(e){const t=new ArrayBuffer(9),n=new DataView(t);n.setUint8(0,P.serverTime),n.setBigUint64(1,BigInt(Date.now()),!0),this.session.sendMessage(e,!0,t)}parseServerTime(e){const t=new DataView(e).getBigUint64(1,!0);return Number(t)}getConnectionKey(e){return e.id.toString()}getPreSpawnMessageQueue(e,t){let n=this.actorPreSpawnMessageBuffer.get(e);null==n&&(n=new Map,this.actorPreSpawnMessageBuffer.set(e,n));const r=this.getConnectionKey(t);let s=n.get(r);return null==s&&(s=[],n.set(r,s)),s}shouldQueueMessageUntilActorReady(e,t){const n=this.actorPreSpawnMessageBuffer.get(e);return!!n?.has(this.getConnectionKey(t))||this.isServer&&!this.replicatedActors.has(e)&&this.shouldReplicate(e)}isPropertyMessage(e){const t=new DataView(e).getUint8(0);return t===P.prop||t===P.propComponent}getReplicatedPropertyKey(e,t){return null!=t?.__netid?`component:${t.__netid}:${e}`:`actor:${e}`}sendPropertySnapshot(e,t){const n=this.buildPropertySnapshotEntries(e,t);if(0===n.length)return;const r=this.createPropertySnapshotBuffer(e,n);this.session.sendMessage(t,!0,r)}buildPropertySnapshotEntries(e,t){if(!this.isRelevant(e,t))return[];const n=this.replicatedPropertyRegistry.get(e);if(null==n)return[];const r=[];for(const s of n){if(!this.shouldReplicatePropertyToConnection(e,s.replOn,t))continue;if(null!=s.component&&null==s.component.__netid)continue;const n=this.readReplicatedPropertyValue(s),o=this.serializer.encode(n),i=I.encode(o),c=i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength);r.push({property:s.property,component:s.component,buffer:c})}return r}shouldReplicatePropertyToConnection(e,t,n){const r=this.resolveActorConnection(e);switch(t){case b.all:return!0;case b.owner:return r?.id===n.id;case b.notOwner:return null==r||r.id!==n.id}}readReplicatedPropertyValue(e){const t=e.target[e.property];return A(t)?t.value:t}createPropertySnapshotBuffer(e,t){let n=7;const r=t.map(e=>I.encode(e.property));for(let e=0;e<t.length;e++){const s=t[e];n+=1,null!=s.component&&(n+=1),n+=1+r[e].byteLength+4+s.buffer.byteLength}const s=new ArrayBuffer(n),o=new DataView(s);let i=0;o.setUint8(i,P.propSnapshot),i+=1,o.setUint32(i,e.__netid,!0),i+=4,o.setUint16(i,t.length,!0),i+=2;for(let e=0;e<t.length;e++){const n=t[e],c=r[e],a=null!=n.component;o.setUint8(i,a?$.component:$.actor),i+=1,a&&(o.setUint8(i,n.component.__netid),i+=1),o.setUint8(i,c.byteLength),i+=1,new Uint8Array(s,i,c.byteLength).set(c),i+=c.byteLength,o.setUint32(i,n.buffer.byteLength,!0),i+=4,new Uint8Array(s,i,n.buffer.byteLength).set(new Uint8Array(n.buffer)),i+=n.buffer.byteLength}return s}decodeReplicatedValue(e){let t;if(null!=N)t=N.decode(e);else{t="";const n=new Uint8Array(e);for(let e=0;e<n.length;e++)t+=String.fromCharCode(n[e])}return this.serializer.decode(t,F)}applyReplicatedProperty(e,t,n){A(e[t])?e[t].value=n:e[t]=n}callRepNotify(e,t){const n=e[`onRep_${t}`];"function"==typeof n&&n.call(e)}};L=e([a()],L);export{L as NetService};const Q=new c,B=new i,I=new TextEncoder,N="undefined"!=typeof TextDecoder?new TextDecoder:void 0;function O(e,t,n){const r=new Uint8Array(e,t,n);if(null!=N)return N.decode(r);let s="";for(let e=0;e<r.length;e++)s+=String.fromCharCode(r[e]);return s}function D(e,t,n){new Uint8Array(e,t,n.byteLength).set(n)}const F=new m;/*
|
|
1
|
+
import{__decorate as e}from"tslib";import{delay as t,interval as n,Subject as r,takeUntil as s,tap as o}from"rxjs";import{Euler as i,Vector3 as c}from"three";import{Service as a}from"typedi";import{$actorOptions as l,BaseActor as d,getActorClassById as p}from"../../actors/actor.js";import{ActorComponent as u}from"../../actors/component.js";import{$actorComponents as f}from"../../actors/internal/component-init.js";import{inject as h}from"../../inject.js";import{World as g}from"../../services/world.js";import{NetMode as y}from"../net-session.js";import{NetRole as w}from"./net-actor-role.js";import{DecodeResult as m,NetSerializer as v}from"./net-serializer.js";import{isSignalLike as A}from"./net-utils.js";import{ReplOn as b}from"./replication.js";import{getRpcMethodId as R,getRpcMethodName as _,RunsOn as S}from"./rpc.js";import{ActorController as U,BasePlayerController as M}from"../../actors/controller/actor-controller.js";import{makePropertyReplicated as C}from"./net-decorator.js";var P;!function(e){e[e.rpc=1]="rpc",e[e.prop=2]="prop",e[e.spawn=3]="spawn",e[e.removeActor=4]="removeActor",e[e.rpcComponent=5]="rpcComponent",e[e.propComponent=6]="propComponent",e[e.rpcBinary=21]="rpcBinary",e[e.rpcComponentBinary=25]="rpcComponentBinary",e[e.actorReady=7]="actorReady",e[e.propSnapshot=8]="propSnapshot",e[e.serverTime=100]="serverTime"}(P||(P={}));var $;!function(e){e[e.actor=0]="actor",e[e.component=1]="component"}($||($={}));let L=class{constructor(){this.actorConnection=new Map,this.destroyed=new r,this.world=h(g),this.serializer=h(v),this.serverTimeOffset=0,this.actorPreSpawnMessageBuffer=new Map,this.actorRefMissingMessageQueue=new Map,this.netStartupActorSpawnQueue=new Map,this.spawningActorNetIds=new Set,this.nextNetId=1,this.shouldReplicateMap=new Map,this.replicatedActors=new Map,this.replicatedProperties=new Map,this.replicatedPropertyRegistry=new Map}get mode(){return this.session?.mode??y.none}get isClient(){return this.mode===y.client}get isServer(){return this.mode<y.client}get isDedicatedServer(){return this.mode===y.dedicatedServer}start(){if(this.stop(),this.destroyed=new r,this.isServer)for(const e of this.session.clients)this.sendServerTime(e);n(15).pipe(s(this.destroyed)).subscribe(()=>{this.processMessages()}),this.world.actorAdded.pipe(s(this.destroyed),o(e=>{this.configureMaterializedActorRole(e),this.isServer?this.defineNetId(e):this.processQueuedNetStartupActorSpawns(e)}),t(8)).subscribe(e=>{this.shouldReplicate(e)&&(C(e,"owner",this,!0,b.all),this.sendActorSpawn(e))}),this.world.actorRemoved.pipe(s(this.destroyed),t(10)).subscribe(e=>{this.sendActorRemove(e),this.replicatedActors.delete(e),this.replicatedProperties.delete(e),this.replicatedPropertyRegistry.delete(e),this.actorPreSpawnMessageBuffer.delete(e)}),this.session.playerJoined.pipe(s(this.destroyed)).subscribe(e=>{this.sendServerTime(e),this.isServer&&this.replicatedActors.size>0&&this.spawnOnLateClient(e)})}stop(){this.destroyed.next(null),this.destroyed.complete()}configureMaterializedActorRole(e){null!=e.__netSceneId&&this.mode!==y.none&&(this.shouldReplicate(e)?e.netRole=this.isServer?w.authority:w.simulatedProxy:this.isServer||(e.netRole=w.none))}shouldReplicate(e){const t=this.shouldReplicateMap.get(e);if(null==t){const t=e.constructor[l],n=!0===t?.replicate;return this.shouldReplicateMap.set(e,n),n}return!0===t}setReplicate(e,t){this.shouldReplicateMap.set(e,t)}isRelevant(e,t){const n=this.getRelevancyOptions(e);return!(!0===n?.ownerOnly)||this.resolveActorConnection(e)?.id===t.id}getRelevancyOptions(e){return e.constructor[l].relevancy}spawnOnLateClient(e){const t=[e];for(const e of this.replicatedActors.keys())this.sendActorSpawn(e,t)}async processMessages(){const e=this.session.hasMessage();for(let t=0;t<e;t++){const e=this.session.readMessage();null!=e&&await this.processMessage(e)}}async processMessage(e){try{switch(new DataView(e.buffer).getUint8(0)){case P.rpc:case P.rpcComponent:case P.rpcBinary:case P.rpcComponentBinary:this.processRpc(e.from,e.buffer);break;case P.prop:case P.propComponent:this.processProp(e.from,e.buffer);break;case P.propSnapshot:this.processPropSnapshot(e.from,e.buffer);break;case P.spawn:await this.processSpawn(e.from,e.buffer);break;case P.removeActor:this.processRemoveActor(e.from,e.buffer);break;case P.serverTime:this.processServerTime(e.from,e.buffer);break;case P.actorReady:this.processActorReady(e.from,e.buffer)}}catch(e){console.error("Failed to process message",e)}}processServerTime(e,t){if(this.isServer||this.session.server?.id!==e.id)return;const n=this.parseServerTime(t);this.serverTimeOffset=Date.now()-n}getActorRefMissingMessageQueue(e){let t=this.actorRefMissingMessageQueue.get(e);return null==t&&(t=[],this.actorRefMissingMessageQueue.set(e,t)),t}processRpc(e,t){let n=0;const r=new DataView(t),s=r.getUint8(n);n+=1;const o=r.getUint32(n,!0);n+=4;const i=r.getUint8(n);n+=1;const c=s===P.rpcBinary||s===P.rpcComponentBinary;let a,l,d="";if(c){const e=r.getUint32(n,!0);n+=4,l=new Uint8Array(t,n,e),n+=e}else{const e=r.getUint16(n,!0);n+=2,d=O(t,n,e),n+=e;try{a=this.serializer.decode(d,F)}catch(e){return void console.warn("Failed to parse RPC args JSON",d,e)}}if(!c&&F.error){if(null!=F.missingActorId){const n=this.getActorRefMissingMessageQueue(F.missingActorId);console.debug(`Missing referenced actor ${F.missingActorId}. Queueing message for later`),n.push({from:e,buffer:t})}else console.log("Unknown decode error",d);return}const p=this.world.actors.find(e=>e.__netid===o);if(null==p){return this.getActorRefMissingMessageQueue(o).push({from:e,buffer:t}),void console.debug(`Missing actor ${o}. Queueing message for later`)}let u;if(s===P.rpcComponent||s===P.rpcComponentBinary){const e=r.getUint8(n),t=p[f];if(null!=t&&(u=t.find(t=>t.__netid===e)),null==u)return void console.error(`RPC failed: Failed to find component with netid ${e} on actor with netid ${o}`)}if(this.isServer){if(!this.session.clients.some(t=>t.id==e.id))return void console.warn("Received RCP from non client");const t=this.resolveActorConnection(p);if(null==t)return void console.error("Received server RPC for actor without owner which can't be processed");if(t.id!==e.id)return void console.warn(`Received RPC for actor net id ${p.__netid} from connection ${e.id}, but this connection is not the owner. Can't process.`)}else{if(!(this.session.server?.id===e.id))return void console.warn("Received RCP from non server which is not allowed")}const h=u??p,g=_(h,i);if(null!=g)if("function"==typeof h[g])if(c)h[g](l);else{if(F.requiresAssetLookups)return this.serializer.decodeAssets(a).then(e=>{h[g](...e)}).catch(e=>{console.warn(`Failed to decode asset references for RPC '${g}' on actor net id ${p.__netid}`,e)});h[g](...a)}else console.error(`RPC function '${g}' not found on actor net id ${p.__netid}`+(null!=u?` and component net id ${u.__netid}`:""));else console.error(`RPC method id ${i} not found on actor net id ${p.__netid}`+(null!=u?` and component net id ${u.__netid}`:""))}processProp(e,t){if(this.session.server?.id!==e.id)return void console.warn(`Received property replication from non-server connection (id: ${e.id}), ignoring.`);let n=0;const r=new DataView(t),s=r.getUint8(n);n+=1;const o=r.getUint32(n,!0);n+=4;const i=r.getUint8(n);n+=1;let c="";for(let e=0;e<i;e++)c+=String.fromCharCode(r.getUint8(n+e));n+=i;const a=r.getUint16(n,!0);n+=2;const l=t.slice(n,n+a);n+=a;const d=this.world.actors.find(e=>e.__netid===o);if(!d){return this.getActorRefMissingMessageQueue(o).push({from:e,buffer:t}),void console.error("Failed to process property replication. No actor found with id",o,c)}let p;if(s===P.propComponent){const e=r.getUint8(n),t=d[f];if(null!=t&&(p=t.find(t=>t.__netid===e)),null==p)return void console.error(`Failed to find component with netid ${e} on actor with netid ${o}`)}const u=p??d;try{const n=this.decodeReplicatedValue(l);if(F.error){if(null!=F.missingActorId){let n=this.getActorRefMissingMessageQueue(F.missingActorId);console.debug(`Missing referenced actor ${F.missingActorId}. Queueing message for later`),n.push({from:e,buffer:t})}return}if(F.requiresAssetLookups)return this.serializer.decodeAssets(n).then(e=>{this.applyReplicatedProperty(u,c,e),this.callRepNotify(u,c)}).catch(e=>{console.warn(`Failed to decode asset references for replicated property '${c}' on actor id ${o}`,e)});this.applyReplicatedProperty(u,c,n),this.callRepNotify(u,c)}catch(e){console.warn(`Failed to decode replicated property '${c}' on actor id ${o}`,e)}}processPropSnapshot(e,t){if(this.session.server?.id!==e.id)return void console.warn(`Received property snapshot from non-server connection (id: ${e.id}), ignoring.`);let n=0;const r=new DataView(t);n+=1;const s=r.getUint32(n,!0);n+=4;const o=this.world.actors.find(e=>e.__netid===s);if(null==o){return this.getActorRefMissingMessageQueue(s).push({from:e,buffer:t}),void console.debug(`Missing actor ${s}. Queueing property snapshot for later`)}const i=r.getUint16(n,!0);n+=2;const c=[];for(let a=0;a<i;a++){const i=r.getUint8(n);n+=1;let a=o;if(i===$.component){const e=r.getUint8(n);n+=1;const t=o[f];if(a=t?.find(t=>t.__netid===e),null==a)return void console.error(`Failed to process property snapshot. No component found with netid ${e} on actor with netid ${s}`)}else if(i!==$.actor)return void console.error(`Failed to process property snapshot. Unknown target kind ${i}`);const l=r.getUint8(n);n+=1;let d="";for(let e=0;e<l;e++)d+=String.fromCharCode(r.getUint8(n+e));n+=l;const p=r.getUint32(n,!0);n+=4;const u=t.slice(n,n+p);n+=p;try{const n=this.decodeReplicatedValue(u);if(F.error){if(null!=F.missingActorId){this.getActorRefMissingMessageQueue(F.missingActorId).push({from:e,buffer:t}),console.debug(`Missing referenced actor ${F.missingActorId}. Queueing property snapshot for later`)}else console.warn(`Unknown decode error in property snapshot for actor ${s}`);return}c.push({target:a,property:d,value:n,requiresAssetLookups:F.requiresAssetLookups})}catch(e){return void console.warn(`Failed to decode replicated property snapshot entry '${d}' on actor id ${s}`,e)}}if(c.some(e=>e.requiresAssetLookups))return Promise.all(c.map(async e=>{e.requiresAssetLookups&&(e.value=await this.serializer.decodeAssets(e.value))})).then(()=>{this.applyReplicatedProperties(c)}).catch(e=>{console.warn(`Failed to decode asset references for property snapshot on actor id ${s}`,e)});this.applyReplicatedProperties(c)}applyReplicatedProperties(e){for(const t of e)this.applyReplicatedProperty(t.target,t.property,t.value);for(const t of e)this.callRepNotify(t.target,t.property)}async processSpawn(e,t){if(this.isServer)return;const n=new DataView(t);let r=0;r+=1;const s=n.getUint32(r,!0);r+=4;const o=n.getUint8(r);r+=1;let i="";for(let e=0;e<o;e++)i+=String.fromCharCode(n.getUint8(r+e));r+=o,Q.set(n.getFloat32(r,!0),n.getFloat32(r+4,!0),n.getFloat32(r+8,!0)),r+=12,B.set(n.getFloat32(r,!0),n.getFloat32(r+4,!0),n.getFloat32(r+8,!0)),r+=12;const c=n.getUint8(r);r+=1;const a=n.getUint32(r);r+=4;const l=this.readOptionalSceneId(t,r);console.log("Spawning "+i);const d=p(i);if(!d)return void console.error(`Failed to spawn actor: unknown actor type '${i}'`);const u=this.world.actors.find(e=>e.__netid===s);if(null!=u)return void this.applySpawnNetInfo(u,s,c,a);if(this.spawningActorNetIds.has(s))return void console.log("Actor was already spawned",null!=u);const f=this.findMaterializedNetStartupActor(l,i,s);if(null!=f)return this.applySpawnNetInfo(f,s,c,a),this.processQueuedActorMessages(s),void this.sendActorReady(f);if(null==l){this.spawningActorNetIds.add(s);try{const e=await this.world.spawnActorWithNetInfo(d,s,c,a,Q,B);this.processQueuedActorMessages(s),this.sendActorReady(e)}catch(e){return void console.error("Spawning replicated actor on client failed",e)}finally{this.spawningActorNetIds.delete(s)}}else this.getNetStartupActorSpawnQueue(l).push({from:e,buffer:t})}readOptionalSceneId(e,t){if(t+2>e.byteLength)return;const n=new DataView(e).getUint16(t,!0);return t+=2,0===n||t+n>e.byteLength?void 0:O(e,t,n)}findMaterializedNetStartupActor(e,t,n){if(null!=e)return this.world.actors.find(r=>{if(r.__netSceneId!==e)return!1;if(null!=r.__netid&&r.__netid!==n)return!1;return(r.constructor.__actorId??r.constructor.name)===t})}applySpawnNetInfo(e,t,n,r){if(e.__netid=t,e.netRole=n,0===r)e.owner=void 0;else{const t=this.world.actors.find(e=>e.__netid===r);null!=t&&(e.owner=t)}e instanceof M&&(e.isLocallyControlled=n===w.autonomousProxy)}getNetStartupActorSpawnQueue(e){let t=this.netStartupActorSpawnQueue.get(e);return null==t&&(t=[],this.netStartupActorSpawnQueue.set(e,t)),t}processQueuedNetStartupActorSpawns(e){if(null==e.__netSceneId)return;const t=this.netStartupActorSpawnQueue.get(e.__netSceneId);if(null!=t){this.netStartupActorSpawnQueue.delete(e.__netSceneId);for(const e of t)this.processMessage(e)}}processQueuedActorMessages(e){const t=this.actorRefMissingMessageQueue.get(e);if(null!=t){console.log(`Processing queued messages for actor ${e}`),this.actorRefMissingMessageQueue.delete(e);for(const e of t)this.processMessage(e)}}sendActorReady(e){if(this.mode===y.none)return;if(!e||null==e.__netid)return void console.warn("sendActorReady: actor or actor.__netid is undefined");if(this.isServer)return;const t=new ArrayBuffer(5),n=new DataView(t);let r=0;n.setUint8(r,P.actorReady),r+=1,n.setUint32(r,e.__netid,!0),this.session.server&&this.session.sendMessage(this.session.server,!0,t)}processActorReady(e,t){if(!this.isServer)return;const n=new DataView(t).getUint32(1,!0),r=this.world.actors.find(e=>e.__netid===n);if(!r)return void console.warn(`processActorReady: No actor found with net id ${n}`);const s=this.actorPreSpawnMessageBuffer.get(r),o=this.getConnectionKey(e),i=s?.get(o);if(null!=i){this.sendPropertySnapshot(r,e);const t=i.filter(e=>!this.isPropertyMessage(e.buffer));if(t.length>0){console.log(`Sending ${t.length} queued messages for actor ${r.__netid}`);for(const e of t)this.session.sendMessage(e.connection,e.reliable,e.buffer)}s.delete(o),0===s.size&&this.actorPreSpawnMessageBuffer.delete(r)}}sendRpc(e,t,n,r,s,o){if(this.mode==y.none)return;if(!this.shouldReplicate(n))return;const i=n.__netid;if(null==i)return void console.warn("No __netid defined on actor. Actor must be repliated for RPC");const c=this.resolveActorConnection(n),a=[];if(this.isServer)switch(e){case S.all:a.push(...this.session.clients.filter(e=>this.isRelevant(n,e)));break;case S.client:null!=c&&a.push(c);break;case S.notOwner:a.push(...this.session.clients.filter(e=>e.id!==c?.id&&this.isRelevant(n,e)));case S.server:}else switch(e){case S.all:case S.client:case S.notOwner:break;case S.server:a.push(this.session.server)}if(0==a.length)return;if(null!=o&&null==o.__netid)return void console.warn("No __netid defined on component. Component must be initialized for RPC",o);const l=null!=o,d=o??n,p=R(d,r);if(null==p)return void console.warn(`RPC function '${r}' is not registered on ${d.constructor?.name??"target"}`);const u=1===s.length?function(e){if(e instanceof Uint8Array)return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if("undefined"!=typeof SharedArrayBuffer&&e instanceof SharedArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);return null}(s[0]):null;if(null!=u){let e=10+u.byteLength;l&&(e+=1);const r=new ArrayBuffer(e),s=new DataView(r);let c=0;s.setUint8(c,l?P.rpcComponentBinary:P.rpcBinary),c+=1,s.setUint32(c,i,!0),c+=4,s.setUint8(c,p),c+=1,s.setUint32(c,u.byteLength,!0),c+=4,D(r,c,u),c+=u.byteLength,l&&(s.setUint8(c,o.__netid),c+=1);for(const e of a)null!=e&&this.sendWithQueue(n,{connection:e,reliable:t,buffer:r});return}const f=this.serializer.encode(s),h=I.encode(f);if(h.byteLength>65535)return void console.warn("RPC arguments are too large to send with the JSON RPC format",r);let g=8+h.byteLength;l&&(g+=1);const w=new ArrayBuffer(g),m=new DataView(w);let v=0;m.setUint8(v,l?P.rpcComponent:P.rpc),v+=1,m.setUint32(v,i,!0),v+=4,m.setUint8(v,p),v+=1,m.setUint16(v,h.byteLength,!0),v+=2,D(w,v,h),v+=h.byteLength,l&&(m.setUint8(v,o.__netid),v+=1);for(const e of a)null!=e&&this.sendWithQueue(n,{connection:e,reliable:t,buffer:w})}sendWithQueue(e,t){if(this.shouldQueueMessageUntilActorReady(e,t.connection)){return void this.getPreSpawnMessageQueue(e,t.connection).push(t)}this.session.sendMessage(t.connection,t.reliable,t.buffer)}findQueuedActorsInData(e,t=[]){if("object"==typeof e){if(Array.isArray(e))for(const t of e)this.findQueuedActorsInData(t);if(e instanceof d){this.actorPreSpawnMessageBuffer.get(e)}}}handlePropertySet(e,t,n,r,s,o){if(this.mode==y.none)return;if(!this.isServer)return;if(!this.shouldReplicate(n))return;let i=this.replicatedProperties.get(n);null==i&&(i={},this.replicatedProperties.set(n,i));const c=this.serializer.encode(s),a=I.encode(c),l=a.buffer.slice(a.byteOffset,a.byteOffset+a.byteLength);i[this.getReplicatedPropertyKey(r,o)]={property:r,replOn:e,reliable:t,buffer:l,component:o},this.sendProperty(e,t,n,r,l,o)}sendProperty(e,t,n,r,s,o){if(!this.isServer)return;const i=[],c=this.resolveActorConnection(n);switch(e){case b.all:i.push(...this.session.clients);break;case b.owner:null!=c&&i.push(c);break;case b.notOwner:null==c?i.push(...this.session.clients):i.push(...this.session.clients.filter(e=>e.id!==c.id))}const a=null!=o&&null!=o.__netid;let l=6+r.length+2+s.byteLength;a&&(l+=1);const d=new ArrayBuffer(l),p=new DataView(d);let u=0;p.setUint8(u,a?P.propComponent:P.prop),u+=1,p.setUint32(u,n.__netid,!0),u+=4,p.setUint8(u,r.length),u+=1;for(let e=0;e<r.length;e++)p.setUint8(u++,r.charCodeAt(e));p.setUint16(u,s.byteLength,!0),u+=2,new Uint8Array(d,u,s.byteLength).set(new Uint8Array(s)),u+=s.byteLength,a&&(p.setUint8(u,o.__netid),u+=1);for(const e of i)null!=e&&this.isRelevant(n,e)&&this.sendWithQueue(n,{connection:e,reliable:t,buffer:d})}defineNetId(e){null==e.__netid&&(e.__netid=this.nextNetId++)}registerReplicatedProperty(e,t,n,r,s,o){if(null==n||null==r||null==s)return;let i=this.replicatedPropertyRegistry.get(n);null==i&&(i=[],this.replicatedPropertyRegistry.set(n,i));const c=o??(s instanceof u?s:void 0),a=i.find(e=>e.target===s&&e.property===r);if(null!=a)return a.replOn=e,a.reliable=t,void(a.component=c);i.push({property:r,replOn:e,reliable:t,target:s,component:c})}sendActorSpawn(e,t=this.session.clients){if(!this.isServer)return;const n=t.filter(t=>this.isRelevant(e,t));this.defineNetId(e);const r=e.__netid;let s=e.constructor.__actorId??e.constructor.name;const o=I.encode(s);let i;null!=e.__netSceneId&&(i=I.encode(e.__netSceneId),i.byteLength>65535&&(console.warn(`Scene actor id is too long to replicate as a startup actor: ${e.__netSceneId}`),i=void 0));const c=i?.byteLength??0,a=6+o.length+12+12+1+4+2+c,l=new ArrayBuffer(a),d=new DataView(l);let p=0;d.setUint8(p,P.spawn),p+=1,d.setUint32(p,r,!0),p+=4,d.setUint8(p,o.length),p+=1,new Uint8Array(l).set(o,p),p+=o.length,d.setFloat32(p,e.position.x,!0),p+=4,d.setFloat32(p,e.position.y,!0),p+=4,d.setFloat32(p,e.position.z,!0),p+=4,d.setFloat32(p,e.rotation.x,!0),p+=4,d.setFloat32(p,e.rotation.y,!0),p+=4,d.setFloat32(p,e.rotation.z,!0),p+=4;let u=p;p+=1,d.setUint32(p,e.owner?.__netid??0),p+=4,d.setUint16(p,c,!0),p+=2,null!=i&&(D(l,p,i),p+=i.byteLength);let f=this.replicatedActors.get(e);null==f&&(f={spawnedAt:Date.now(),connections:[]},this.replicatedActors.set(e,f));for(const t of n){const n=l.slice(0),r=new DataView(n),s=this.resolveActorConnection(e)?.id===t.id?w.autonomousProxy:w.simulatedProxy;r.setUint8(u,s),this.getPreSpawnMessageQueue(e,t),this.session.sendMessage(t,!0,n),f.connections.some(e=>e.id===t.id)||f.connections.push(t)}}sendActorRemove(e){if(!this.isServer)return;const t=new ArrayBuffer(5),n=new DataView(t);let r=0;n.setUint8(r,P.removeActor),r+=1,n.setUint32(r,e.__netid,!0);for(const e of this.session.clients)this.session.sendMessage(e,!0,t)}processRemoveActor(e,t){if(this.isServer||this.session.server?.id!==e.id)return;const n=new DataView(t).getUint32(1,!0),r=this.world.actors.find(e=>e.__netid===n);r&&(this.world.removeActor(r),this.replicatedActors?.delete?.(r),this.replicatedProperties?.delete?.(r))}setOwningConnection(e,t){this.actorConnection.set(e.id,t)}getOwningConnection(e){return this.actorConnection.get(e.id)}getActorsByOwningConnection(e){const t=[];return this.actorConnection.forEach((n,r)=>{if(n.id===e.id){const e=this.world.actors.find(e=>e.id===r);null!=e&&t.push(e)}}),t}resolveActorConnection(e){let t;for(;null==t&&null!=e;)t=this.actorConnection.get(e.id),null==t&&(e=e.owner);return t}isLocallyControlled(e){let t=e;for(;null!=t;){if(t.netRole===w.autonomousProxy)return!0;if(t instanceof U)return t.isLocallyControlled;t=e.owner}return!1}isLocalOwner(e){return this.isLocallyControlled(e)}sendServerTime(e){const t=new ArrayBuffer(9),n=new DataView(t);n.setUint8(0,P.serverTime),n.setBigUint64(1,BigInt(Date.now()),!0),this.session.sendMessage(e,!0,t)}parseServerTime(e){const t=new DataView(e).getBigUint64(1,!0);return Number(t)}getConnectionKey(e){return e.id.toString()}getPreSpawnMessageQueue(e,t){let n=this.actorPreSpawnMessageBuffer.get(e);null==n&&(n=new Map,this.actorPreSpawnMessageBuffer.set(e,n));const r=this.getConnectionKey(t);let s=n.get(r);return null==s&&(s=[],n.set(r,s)),s}shouldQueueMessageUntilActorReady(e,t){const n=this.actorPreSpawnMessageBuffer.get(e);return!!n?.has(this.getConnectionKey(t))||this.isServer&&!this.replicatedActors.has(e)&&this.shouldReplicate(e)}isPropertyMessage(e){const t=new DataView(e).getUint8(0);return t===P.prop||t===P.propComponent}getReplicatedPropertyKey(e,t){return null!=t?.__netid?`component:${t.__netid}:${e}`:`actor:${e}`}sendPropertySnapshot(e,t){const n=this.buildPropertySnapshotEntries(e,t);if(0===n.length)return;const r=this.createPropertySnapshotBuffer(e,n);this.session.sendMessage(t,!0,r)}buildPropertySnapshotEntries(e,t){if(!this.isRelevant(e,t))return[];const n=this.replicatedPropertyRegistry.get(e);if(null==n)return[];const r=[];for(const s of n){if(!this.shouldReplicatePropertyToConnection(e,s.replOn,t))continue;if(null!=s.component&&null==s.component.__netid)continue;const n=this.readReplicatedPropertyValue(s),o=this.serializer.encode(n),i=I.encode(o),c=i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength);r.push({property:s.property,component:s.component,buffer:c})}return r}shouldReplicatePropertyToConnection(e,t,n){const r=this.resolveActorConnection(e);switch(t){case b.all:return!0;case b.owner:return r?.id===n.id;case b.notOwner:return null==r||r.id!==n.id}}readReplicatedPropertyValue(e){const t=e.target[e.property];return A(t)?t.value:t}createPropertySnapshotBuffer(e,t){let n=7;const r=t.map(e=>I.encode(e.property));for(let e=0;e<t.length;e++){const s=t[e];n+=1,null!=s.component&&(n+=1),n+=1+r[e].byteLength+4+s.buffer.byteLength}const s=new ArrayBuffer(n),o=new DataView(s);let i=0;o.setUint8(i,P.propSnapshot),i+=1,o.setUint32(i,e.__netid,!0),i+=4,o.setUint16(i,t.length,!0),i+=2;for(let e=0;e<t.length;e++){const n=t[e],c=r[e],a=null!=n.component;o.setUint8(i,a?$.component:$.actor),i+=1,a&&(o.setUint8(i,n.component.__netid),i+=1),o.setUint8(i,c.byteLength),i+=1,new Uint8Array(s,i,c.byteLength).set(c),i+=c.byteLength,o.setUint32(i,n.buffer.byteLength,!0),i+=4,new Uint8Array(s,i,n.buffer.byteLength).set(new Uint8Array(n.buffer)),i+=n.buffer.byteLength}return s}decodeReplicatedValue(e){let t;if(null!=N)t=N.decode(e);else{t="";const n=new Uint8Array(e);for(let e=0;e<n.length;e++)t+=String.fromCharCode(n[e])}return this.serializer.decode(t,F)}applyReplicatedProperty(e,t,n){A(e[t])?e[t].value=n:e[t]=n}callRepNotify(e,t){const n=e[`onRep_${t}`];"function"==typeof n&&n.call(e)}};L=e([a()],L);export{L as NetService};const Q=new c,B=new i,I=new TextEncoder,N="undefined"!=typeof TextDecoder?new TextDecoder:void 0;function O(e,t,n){const r=new Uint8Array(e,t,n);if(null!=N)return N.decode(r);let s="";for(let e=0;e<r.length;e++)s+=String.fromCharCode(r[e]);return s}function D(e,t,n){new Uint8Array(e,t,n.byteLength).set(n)}const F=new m;/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{inject as n}from"../../inject";import{NetService as t}from"./net-service";import{registerRpcMethod as e,RunsOn as r}from"./rpc";import{BaseActor as o}from"../../actors/actor";import{NetMode as i}from"../net-session";import{ActorComponent as
|
|
1
|
+
import{inject as n}from"../../inject.js";import{NetService as t}from"./net-service.js";import{registerRpcMethod as e,RunsOn as r}from"./rpc.js";import{BaseActor as o}from"../../actors/actor.js";import{NetMode as i}from"../net-session.js";import{ActorComponent as s}from"../../actors/component.js";export function RunOnServer(n=!0){return c(r.server,n)}export function RunOnClient(n=!0){return c(r.client,n)}export function RunOnNotOwner(n=!0){return c(r.notOwner,n)}export function RunOnAll(n=!0){return c(r.all,n)}function c(r,o=!0){return function(...i){if(i.length>=3){const[s,c,u]=i,a=u.value,f=c.toString();let p;return e(s,f),u.value=l(a,f,r,o,()=>(p??(p=n(t)),p)),u}const[s,c]=i,u=c.name.toString();let a;return c.addInitializer(function(){e(Object.getPrototypeOf(this),u),a=n(t)}),l(s,u,r,o,()=>(a??(a=n(t)),a))}}function l(n,t,e,c,l){return function(...u){const a=l();if(!(this instanceof o||this instanceof s))return void console.warn("RPC is defined on a non actor");let f,p;if(this instanceof o)f=this;else if(f=this.actor,p=this,null==f)return void console.warn("Can't call RPC on component before actor is set");let m,v=!1;return a.isServer&&(e===r.all||e===r.server||e===r.notOwner&&!a.isLocalOwner(f)&&a.mode===i.listenServer||e===r.client&&!a.isDedicatedServer&&a.isLocalOwner(f))?v=!0:a.isServer||e!==r.all&&e!==r.client&&e!==r.notOwner||(v=!0),v&&(m=n.apply(this,u)),a&&"function"==typeof a.sendRpc?a.sendRpc(e,c,f,t,u,p):console.warn("Net service is not set up",{netService:a}),m}}/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -25,6 +25,7 @@ export declare class AssetLoader {
|
|
|
25
25
|
private ktx2Loader;
|
|
26
26
|
private textureLoader;
|
|
27
27
|
private audioLoader;
|
|
28
|
+
private animationVariantIds;
|
|
28
29
|
constructor(assetResourceLoader: AssetResourceLoader, assetService: AssetsProvider, shaders: ShaderImpl[]);
|
|
29
30
|
/**
|
|
30
31
|
* @param filePath
|
|
@@ -45,6 +46,12 @@ export declare class AssetLoader {
|
|
|
45
46
|
getModelByAssetName(name: string): Promise<LoadedMesh>;
|
|
46
47
|
getModelByAssetId(id: AssetId): Promise<LoadedMesh>;
|
|
47
48
|
getAnimationClipByAssetId(id: AssetId): Promise<THREE.AnimationClip | null>;
|
|
49
|
+
/**
|
|
50
|
+
* Resolve an animation reference for a concrete target rig without running a
|
|
51
|
+
* retarget solver. A mismatched source clip must already have a generated
|
|
52
|
+
* output recorded by an Animation Retargeter asset.
|
|
53
|
+
*/
|
|
54
|
+
getAnimationClipForTargetByAssetId(id: AssetId, targetRigId?: AssetId): Promise<THREE.AnimationClip | null>;
|
|
48
55
|
getAnimationClipByAssetName(name: string): Promise<THREE.AnimationClip | null>;
|
|
49
56
|
getTextureByAssetName(name: string): Promise<THREE.Texture>;
|
|
50
57
|
getTextureByAssetId(id: AssetId): Promise<THREE.Texture>;
|