@dcl/sdk-commands 7.25.0 → 7.25.1-30310486734.commit-5ffe873
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/commands/sdk-server-logs/index.d.ts +24 -0
- package/dist/commands/sdk-server-logs/index.js +313 -0
- package/dist/commands/sdk-server-logs/index.js.map +1 -0
- package/dist/commands/start/explorer-alpha.d.ts +0 -6
- package/dist/commands/start/explorer-alpha.js +0 -45
- package/dist/commands/start/explorer-alpha.js.map +1 -1
- package/dist/commands/start/hammurabi-server.d.ts +19 -0
- package/dist/commands/start/hammurabi-server.js +78 -0
- package/dist/commands/start/hammurabi-server.js.map +1 -0
- package/dist/commands/start/index.d.ts +0 -2
- package/dist/commands/start/index.js +18 -12
- package/dist/commands/start/index.js.map +1 -1
- package/dist/commands/start/server/routes.js +2 -0
- package/dist/commands/start/server/routes.js.map +1 -1
- package/dist/commands/start/server/runtime-env.d.ts +71 -0
- package/dist/commands/start/server/runtime-env.js +226 -0
- package/dist/commands/start/server/runtime-env.js.map +1 -0
- package/dist/commands/start/server/storage-service.d.ts +8 -0
- package/dist/commands/start/server/storage-service.js +156 -0
- package/dist/commands/start/server/storage-service.js.map +1 -0
- package/dist/commands/start/types.d.ts +3 -0
- package/dist/commands/start/utils.d.ts +34 -0
- package/dist/commands/start/utils.js +104 -0
- package/dist/commands/start/utils.js.map +1 -1
- package/dist/commands/storage/env.d.ts +5 -0
- package/dist/commands/storage/env.js +86 -0
- package/dist/commands/storage/env.js.map +1 -0
- package/dist/commands/storage/index.d.ts +26 -0
- package/dist/commands/storage/index.js +142 -0
- package/dist/commands/storage/index.js.map +1 -0
- package/dist/commands/storage/player.d.ts +5 -0
- package/dist/commands/storage/player.js +143 -0
- package/dist/commands/storage/player.js.map +1 -0
- package/dist/commands/storage/scene.d.ts +5 -0
- package/dist/commands/storage/scene.js +105 -0
- package/dist/commands/storage/scene.js.map +1 -0
- package/dist/commands/storage/shared.d.ts +62 -0
- package/dist/commands/storage/shared.js +249 -0
- package/dist/commands/storage/shared.js.map +1 -0
- package/dist/commands/storage/types.d.ts +56 -0
- package/dist/commands/storage/types.js +23 -0
- package/dist/commands/storage/types.js.map +1 -0
- package/dist/components/analytics.d.ts +70 -1
- package/dist/components/analytics.js +3 -2
- package/dist/components/analytics.js.map +1 -1
- package/dist/logic/auth-chain-headers.d.ts +11 -0
- package/dist/logic/auth-chain-headers.js +25 -0
- package/dist/logic/auth-chain-headers.js.map +1 -0
- package/dist/logic/bundle.d.ts +1 -3
- package/dist/logic/bundle.js +55 -45
- package/dist/logic/bundle.js.map +1 -1
- package/dist/logic/config.d.ts +1 -0
- package/dist/logic/config.js +7 -0
- package/dist/logic/config.js.map +1 -1
- package/dist/logic/error.d.ts +1 -1
- package/dist/logic/error.js.map +1 -1
- package/dist/logic/exec.d.ts +1 -0
- package/dist/logic/exec.js +2 -2
- package/dist/logic/exec.js.map +1 -1
- package/dist/logic/lang.js +1 -1
- package/dist/logic/runtime-script.js +4 -5
- package/dist/logic/runtime-script.js.map +1 -1
- package/dist/logic/scene-validations.d.ts +8 -1
- package/dist/logic/scene-validations.js.map +1 -1
- package/package.json +5 -5
- package/dist/logic/runtime-script.ts +0 -267
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import type { IEngine, Entity, EntityState } from '@dcl/ecs'
|
|
3
|
-
import type { ActionRef } from '@dcl/inspector/node_modules/@dcl/asset-packs'
|
|
4
|
-
import { getActionEvents } from '@dcl/inspector/node_modules/@dcl/asset-packs/dist/events'
|
|
5
|
-
|
|
6
|
-
declare global {
|
|
7
|
-
// eslint-disable-next-line no-var
|
|
8
|
-
var __DCL_SCRIPT_INSTANCES__: Map<string, { instance: any; entity: Entity; path: string }>
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
if (!globalThis.__DCL_SCRIPT_INSTANCES__) {
|
|
12
|
-
globalThis.__DCL_SCRIPT_INSTANCES__ = new Map()
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
type ScriptParam = {
|
|
16
|
-
type?: string
|
|
17
|
-
value: unknown
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
type ScriptLayout = {
|
|
21
|
-
params?: Record<string, ScriptParam>
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
type Script = {
|
|
25
|
-
entity: Entity
|
|
26
|
-
path: string
|
|
27
|
-
priority: number
|
|
28
|
-
layout?: string
|
|
29
|
-
module: FunctionalScriptModule | Record<string, unknown>
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
type ScriptWithKey = Script & {
|
|
33
|
-
key: string
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
type FunctionalScriptModule = {
|
|
37
|
-
start?: (src: string, entity: Entity, ...params: unknown[]) => void
|
|
38
|
-
update?: (src: string, entity: Entity, dt: number, ...params: unknown[]) => void
|
|
39
|
-
[key: string]: unknown
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
type ScriptClassInstance = {
|
|
43
|
-
start?: () => void
|
|
44
|
-
update?: (dt: number) => void
|
|
45
|
-
[key: string]: unknown
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
type ScriptClass = new (src: string, entity: Entity, ...params: unknown[]) => ScriptClassInstance
|
|
49
|
-
type ScriptsByPriority = Record<number, ScriptWithKey[]>
|
|
50
|
-
|
|
51
|
-
// compiler-checked literal: the @dcl/ecs d.ts pins EntityState.Removed = 2, so drift fails this build with TS2322; a value import would embed ecs runtime code into every scene bundle
|
|
52
|
-
const ENTITY_STATE_REMOVED: EntityState.Removed = 2
|
|
53
|
-
|
|
54
|
-
function entityIsRemoved(engine: IEngine, entity: Entity) {
|
|
55
|
-
return engine.getEntityState(entity) === ENTITY_STATE_REMOVED
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Get a specific script instance by entity and script path.
|
|
60
|
-
* @param entity - The entity ID
|
|
61
|
-
* @param scriptPath - The script file path
|
|
62
|
-
* @returns The script instance or null if not found
|
|
63
|
-
*/
|
|
64
|
-
export function getScriptInstance(entity: Entity, scriptPath: string): any {
|
|
65
|
-
const key = `${entity}:${scriptPath}`
|
|
66
|
-
const entry = globalThis.__DCL_SCRIPT_INSTANCES__.get(key)
|
|
67
|
-
return entry?.instance || null
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Get all instances of a specific script (across all entities).
|
|
72
|
-
* @param scriptPath - The script file path
|
|
73
|
-
* @returns Array of { entity, instance } objects
|
|
74
|
-
*/
|
|
75
|
-
export function getScriptInstancesByPath(scriptPath: string): Array<{ entity: Entity; instance: any }> {
|
|
76
|
-
const results: Array<{ entity: Entity; instance: any }> = []
|
|
77
|
-
for (const [_, value] of globalThis.__DCL_SCRIPT_INSTANCES__) {
|
|
78
|
-
if (value.path === scriptPath) {
|
|
79
|
-
results.push({ entity: value.entity, instance: value.instance })
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return results
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Get all script instances attached to a specific entity
|
|
87
|
-
* @param entity - The entity ID
|
|
88
|
-
* @returns Array of { path, instance } objects
|
|
89
|
-
*/
|
|
90
|
-
export function getAllScriptInstances(entity: Entity): Array<{ path: string; instance: any }> {
|
|
91
|
-
const results: Array<{ path: string; instance: any }> = []
|
|
92
|
-
for (const [_, value] of globalThis.__DCL_SCRIPT_INSTANCES__) {
|
|
93
|
-
if (value.entity === entity) {
|
|
94
|
-
results.push({ path: value.path, instance: value.instance })
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return results
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Call a method on a script instance (with safety checks).
|
|
102
|
-
* @param entity - The entity ID
|
|
103
|
-
* @param scriptPath - The script file path
|
|
104
|
-
* @param methodName - The method name to call
|
|
105
|
-
* @param args - Arguments to pass to the method
|
|
106
|
-
* @returns The method's return value or undefined if method not found
|
|
107
|
-
*/
|
|
108
|
-
export function callScriptMethod(entity: Entity, scriptPath: string, methodName: string, ...args: any[]): any {
|
|
109
|
-
const instance = getScriptInstance(entity, scriptPath)
|
|
110
|
-
if (instance && typeof instance[methodName] === 'function') {
|
|
111
|
-
return instance[methodName](...args)
|
|
112
|
-
}
|
|
113
|
-
console.error(`Method ${methodName} not found on script ${scriptPath} for entity ${entity}`)
|
|
114
|
-
return undefined
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Creates an ActionCallback function from an ActionRef.
|
|
119
|
-
* The returned function, when called, will trigger the specified action on the entity.
|
|
120
|
-
*
|
|
121
|
-
* @param actionRef - The action reference containing entity and action name
|
|
122
|
-
* @returns A function that triggers the action when called
|
|
123
|
-
*/
|
|
124
|
-
function createActionCallback(actionRef: ActionRef): () => void {
|
|
125
|
-
return () => {
|
|
126
|
-
if (!actionRef.entity || !actionRef.action) {
|
|
127
|
-
console.error('[Script] ActionCallback called with invalid action reference:', actionRef)
|
|
128
|
-
return
|
|
129
|
-
}
|
|
130
|
-
const actionEvents = getActionEvents(actionRef.entity)
|
|
131
|
-
actionEvents.emit(actionRef.action, {})
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Resolves script parameters, converting ActionRef values to ActionCallback functions.
|
|
137
|
-
*
|
|
138
|
-
* @param params - The raw parameters from the script layout
|
|
139
|
-
* @returns Array of resolved parameter values
|
|
140
|
-
*/
|
|
141
|
-
function resolveScriptParams(params: Record<string, ScriptParam>): unknown[] {
|
|
142
|
-
return Object.values(params).map((param) => {
|
|
143
|
-
if (param.type === 'action' && param.value && typeof param.value === 'object') {
|
|
144
|
-
const actionRef = param.value as ActionRef
|
|
145
|
-
return createActionCallback(actionRef)
|
|
146
|
-
}
|
|
147
|
-
return param.value
|
|
148
|
-
})
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Initializes and runs all scripts organized by priority.
|
|
153
|
-
* Supports both functional-style scripts (with start/update functions) and class-based scripts.
|
|
154
|
-
* Scripts are extracted at build time from composites.
|
|
155
|
-
*
|
|
156
|
-
* @internal This function is called automatically by the SDK entry point.
|
|
157
|
-
* Users should not call this function directly.
|
|
158
|
-
*
|
|
159
|
-
* @param engine - The ECS engine instance
|
|
160
|
-
* @param scripts - Scripts with their modules, extracted at build time
|
|
161
|
-
*/
|
|
162
|
-
export function runScripts(engine: IEngine, scripts: Script[]) {
|
|
163
|
-
const scriptsByPriority = groupScriptsByPriority(scripts)
|
|
164
|
-
const classInstances = new Map<string, { instance: ScriptClassInstance; entity: Entity }>()
|
|
165
|
-
const functionScripts = new Map<
|
|
166
|
-
string,
|
|
167
|
-
{ src: string; module: FunctionalScriptModule; entity: Entity; params: unknown[] }
|
|
168
|
-
>()
|
|
169
|
-
|
|
170
|
-
for (const [priority, instances] of Object.entries(scriptsByPriority)) {
|
|
171
|
-
for (const script of instances) {
|
|
172
|
-
if (entityIsRemoved(engine, script.entity)) continue
|
|
173
|
-
|
|
174
|
-
const module = script.module
|
|
175
|
-
if (!module) {
|
|
176
|
-
console.error('[Script] Unknown module:', script.path)
|
|
177
|
-
continue
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const src = script.path.split('/').slice(0, -1).join('/')
|
|
181
|
-
const layout: ScriptLayout = script.layout ? JSON.parse(script.layout) : {}
|
|
182
|
-
const params = resolveScriptParams(layout.params || {})
|
|
183
|
-
const registryKey = `${script.entity}:${script.path}`
|
|
184
|
-
|
|
185
|
-
if (typeof module.start === 'function') {
|
|
186
|
-
try {
|
|
187
|
-
module.start(src, script.entity, ...params)
|
|
188
|
-
} catch (e: unknown) {
|
|
189
|
-
console.error('[Script Error] ' + script.path + ' start() failed:', e)
|
|
190
|
-
throw e
|
|
191
|
-
}
|
|
192
|
-
functionScripts.set(script.key, {
|
|
193
|
-
src,
|
|
194
|
-
module: module as FunctionalScriptModule,
|
|
195
|
-
entity: script.entity,
|
|
196
|
-
params
|
|
197
|
-
})
|
|
198
|
-
globalThis.__DCL_SCRIPT_INSTANCES__.set(registryKey, {
|
|
199
|
-
instance: module,
|
|
200
|
-
entity: script.entity,
|
|
201
|
-
path: script.path
|
|
202
|
-
})
|
|
203
|
-
} else {
|
|
204
|
-
const ScriptClass = Object.values(module).find((exp) => typeof exp === 'function') as ScriptClass | undefined
|
|
205
|
-
if (!ScriptClass) {
|
|
206
|
-
console.error('[Script] No class found in module:', script.path)
|
|
207
|
-
continue
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
try {
|
|
211
|
-
const instance = new ScriptClass(src, script.entity, ...params)
|
|
212
|
-
if (typeof instance.start === 'function') {
|
|
213
|
-
instance.start()
|
|
214
|
-
}
|
|
215
|
-
classInstances.set(script.key, { instance, entity: script.entity })
|
|
216
|
-
globalThis.__DCL_SCRIPT_INSTANCES__.set(registryKey, {
|
|
217
|
-
instance: instance,
|
|
218
|
-
entity: script.entity,
|
|
219
|
-
path: script.path
|
|
220
|
-
})
|
|
221
|
-
} catch (e: unknown) {
|
|
222
|
-
console.error('[Script Error] ' + script.path + ' class initialization failed:', e)
|
|
223
|
-
throw e
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
engine.addSystem((dt: number) => {
|
|
229
|
-
for (const scriptData of instances) {
|
|
230
|
-
try {
|
|
231
|
-
const classInstance = classInstances.get(scriptData.key)
|
|
232
|
-
if (classInstance && !entityIsRemoved(engine, classInstance.entity)) {
|
|
233
|
-
if (typeof classInstance.instance.update === 'function') {
|
|
234
|
-
classInstance.instance.update(dt)
|
|
235
|
-
}
|
|
236
|
-
} else {
|
|
237
|
-
const functionScript = functionScripts.get(scriptData.key)
|
|
238
|
-
if (functionScript && !entityIsRemoved(engine, functionScript.entity)) {
|
|
239
|
-
if (typeof functionScript.module.update === 'function') {
|
|
240
|
-
functionScript.module.update(functionScript.src, functionScript.entity, dt, ...functionScript.params)
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
} catch (e: unknown) {
|
|
245
|
-
console.error('[Script Error] update() failed:', e)
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}, Number(priority))
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
function groupScriptsByPriority(scripts: Script[]): ScriptsByPriority {
|
|
253
|
-
const scriptsByPriority: ScriptsByPriority = {}
|
|
254
|
-
|
|
255
|
-
for (let i = 0; i < scripts.length; i++) {
|
|
256
|
-
const script = scripts[i]
|
|
257
|
-
const key = `${script.entity}:${script.path}:${i}`
|
|
258
|
-
|
|
259
|
-
if (!scriptsByPriority[script.priority]) {
|
|
260
|
-
scriptsByPriority[script.priority] = []
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
scriptsByPriority[script.priority].push({ ...script, key })
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
return scriptsByPriority
|
|
267
|
-
}
|