@luminocity/lemonate-engine 26.6.1 → 26.6.3
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/LoadingManager.d.ts +1 -0
- package/dist/lemonate.es.js +127 -12
- package/dist/lemonate.js +171 -56
- package/dist/lemonate.min.js +14 -14
- package/dist/lemonate.umd.js +127 -12
- package/dist/player.zip +0 -0
- package/dist/subsystems/scripting/ScriptEngine.d.ts +3 -0
- package/dist/subsystems/scripting/ScriptRunner.d.ts +3 -0
- package/dist/subsystems/scripting/runtime/RtItem.d.ts +1 -1
- package/package.json +2 -2
package/dist/lemonate.umd.js
CHANGED
|
@@ -11463,7 +11463,7 @@
|
|
|
11463
11463
|
}
|
|
11464
11464
|
}
|
|
11465
11465
|
|
|
11466
|
-
var engine$1 = "26.6.
|
|
11466
|
+
var engine$1 = "26.6.3";
|
|
11467
11467
|
var bullet = "3.26";
|
|
11468
11468
|
var lua = "5.4.3";
|
|
11469
11469
|
var packageVersionInfo = {
|
|
@@ -94899,12 +94899,35 @@
|
|
|
94899
94899
|
if (block.fields && block.fields.length) {
|
|
94900
94900
|
this._initFromFields(block.fields);
|
|
94901
94901
|
}
|
|
94902
|
+
if (block.scripts && block.scripts.length) {
|
|
94903
|
+
this._initFromScripts(block.scripts);
|
|
94904
|
+
}
|
|
94902
94905
|
if (block.blocks && block.blocks.length) {
|
|
94903
94906
|
this._initFromBlocks(block.blocks);
|
|
94904
94907
|
}
|
|
94905
94908
|
}
|
|
94906
94909
|
}
|
|
94907
94910
|
}
|
|
94911
|
+
_initFromScripts(scripts) {
|
|
94912
|
+
for (const script of scripts) {
|
|
94913
|
+
if (!script.fields)
|
|
94914
|
+
continue;
|
|
94915
|
+
for (const field of script.fields) {
|
|
94916
|
+
if (field.type === 'Link' && field.value) {
|
|
94917
|
+
const preparedItem = typeof field.value === 'string' ? { _id: field.value } : field.value;
|
|
94918
|
+
if (preparedItem._id)
|
|
94919
|
+
this._initFromItem(preparedItem);
|
|
94920
|
+
}
|
|
94921
|
+
else if (field.type === 'LinkArray' && Array.isArray(field.value)) {
|
|
94922
|
+
for (const linkValue of field.value) {
|
|
94923
|
+
const preparedItem = typeof linkValue === 'string' ? { _id: linkValue } : linkValue;
|
|
94924
|
+
if (preparedItem && preparedItem._id)
|
|
94925
|
+
this._initFromItem(preparedItem);
|
|
94926
|
+
}
|
|
94927
|
+
}
|
|
94928
|
+
}
|
|
94929
|
+
}
|
|
94930
|
+
}
|
|
94908
94931
|
isItemLoaded(id) {
|
|
94909
94932
|
return this.itemsMap.has(id);
|
|
94910
94933
|
}
|
|
@@ -95722,6 +95745,7 @@
|
|
|
95722
95745
|
scriptItem = undefined;
|
|
95723
95746
|
scriptId = undefined;
|
|
95724
95747
|
injectedFieldsMap = {};
|
|
95748
|
+
referenceId = undefined;
|
|
95725
95749
|
callDepth = 0;
|
|
95726
95750
|
callMutex = new Mutex();
|
|
95727
95751
|
enableMutex = new Mutex();
|
|
@@ -95778,14 +95802,25 @@
|
|
|
95778
95802
|
setNode(node) {
|
|
95779
95803
|
this.injectedFieldsMap["node"] = { type: 'String', value: node };
|
|
95780
95804
|
}
|
|
95805
|
+
setReferenceId(referenceId) {
|
|
95806
|
+
this.referenceId = referenceId;
|
|
95807
|
+
}
|
|
95808
|
+
getReferenceId() {
|
|
95809
|
+
return this.referenceId || this.scriptId || '';
|
|
95810
|
+
}
|
|
95781
95811
|
setInjectedFields(fields) {
|
|
95782
95812
|
for (const field of fields) {
|
|
95783
|
-
if (!
|
|
95784
|
-
|
|
95785
|
-
|
|
95786
|
-
|
|
95787
|
-
|
|
95788
|
-
|
|
95813
|
+
if (!field.name || field.type === 'Separator')
|
|
95814
|
+
continue;
|
|
95815
|
+
const entryType = field.type === 'Link' || field.type === 'LinkArray'
|
|
95816
|
+
? field.type
|
|
95817
|
+
: field.datatype;
|
|
95818
|
+
if (field.name === 'node' && this.injectedFieldsMap['node'])
|
|
95819
|
+
continue;
|
|
95820
|
+
this.injectedFieldsMap[field.name] = {
|
|
95821
|
+
type: entryType,
|
|
95822
|
+
value: field.value
|
|
95823
|
+
};
|
|
95789
95824
|
}
|
|
95790
95825
|
}
|
|
95791
95826
|
getInjectedFields() {
|
|
@@ -96312,6 +96347,7 @@
|
|
|
96312
96347
|
const name = script.getName();
|
|
96313
96348
|
const item = script.getItem();
|
|
96314
96349
|
const runner = new ScriptRunner(this.engine);
|
|
96350
|
+
runner.setReferenceId(instanceId);
|
|
96315
96351
|
runner.setNode(node);
|
|
96316
96352
|
runner.setInjectedFields(meta.fields);
|
|
96317
96353
|
const scriptId = await runner.loadCode(script);
|
|
@@ -99001,11 +99037,11 @@
|
|
|
99001
99037
|
|
|
99002
99038
|
var lua_api_audio = "\nlocal _internal = require('engine/_internal');\n\n--- @module audio\nlocal audio = {}\n\n---Get an FFT analysis from the audio engine. It returns an array of 256 samples\n---@function getAnalysis\nfunction audio.getAnalysis()\n return _internal.sendMessage('audio.getAnalysis')\nend\n\nreturn audio\n";
|
|
99003
99039
|
|
|
99004
|
-
var lua_api_behaviour = "local SceneObject = require('engine/sceneobject')\nlocal Canvas = require('engine/canvas')\nlocal JE = require('engine/json/jsonencoder')()\n\nlocal _behavioursMapByNodeId = {}\nlocal _behavioursMapByScriptId = {}\nlocal _behavioursMapByExecutionOrder = {}\nlocal _executionIndex = 1\n\nlocal Behaviour = Class.new()\n\n-- Put the class in the global scope (Behaviour is the old deprecated name)\n_G.Behaviour = Behaviour\n_G.Entity = Behaviour\n\n--- Constructor hook called when a new Behaviour is created.\n---@private\nfunction Behaviour:__new()\n self._isBehaviour = true\n self._type = \"Behaviour\"\n self._nodeId = nil\n self._scriptName = \"\"\n self._executionIndex = _executionIndex\n self._isActive = true\n self._isInitialized = false\n\n _executionIndex = _executionIndex + 1\n\n -- Adds a default node property\n self:addProperty(\"node\", Property.Node)\nend\n\n--- Destructor hook called before the Behaviour is destroyed.\n---@private\nfunction Behaviour:__destroy()\n print(\"__destroy called for: \", self._nodeId)\nend\n\n--- Get all behaviours attached to a specific node ID.\n---@param nodeId string The ID of the scene graph node\n---@return table A table containing all behaviours attached to the node\nfunction Behaviour.getByNodeId(nodeId)\n local result = {}\n local nodeBehaviours = _behavioursMapByNodeId[nodeId]\n if nodeBehaviours then\n for k,v in pairs(nodeBehaviours) do\n table.insert(result, v.behaviour)\n end\n end\n return result\nend\n\n--- Get a single behaviour attached to a node ID with a specific script name.\n---@param nodeId string The ID of the scene graph node\n---@param scriptName string The script name of the behaviour\n---@return Behaviour|nil The behaviour if found, or nil\nfunction Behaviour.getByNodeIdAndScriptName(nodeId, scriptName)\n local nodeEntities = _behavioursMapByNodeId[nodeId]\n if nodeEntities then\n for k,v in pairs(nodeEntities) do\n if v.scriptName == scriptName then\n return v.behaviour\n end\n end\n end\n return nil\nend\n\n--- Returns the node ID this Behaviour is attached to.\n---@return string|nil Node ID of the attached scene object\nfunction Behaviour:getNodeId()\n return self._nodeId\nend\n\n--- Returns the script name of this Behaviour.\n---@return string Script name\nfunction Behaviour:getScriptName()\n return self._scriptName\nend\n\n--- Returns a table of all properties defined on the behaviour class.\n---@return table A table with fields: name, defaultValue, type, order\nfunction Behaviour:getProperties()\n local props = {}\n local class = self.getClass()\n\n for k,v in pairs(class) do\n if type(v) == 'table' and v._isProperty then\n table.insert(props, { name=k, defaultValue=v.value, type=v.datatype, order=v.order, info=v.info })\n end\n end\n\n for k,v in pairs(class.properties) do\n if type(v) == 'table' and v._isProperty then\n table.insert(props, { name=k, defaultValue=v.value, type=v.datatype, order=v.order, info=v.info })\n end\n end\n\n return props\nend\n\n--- When a script is destroyed, we need to call this to clear the behaviour out of the list\n---@private\nfunction Behaviour:_disposeBehaviour()\n local scripts = _behavioursMapByNodeId[self._nodeId]\n if scripts then\n scripts[self._scriptId] = nil\n end\n\n _behavioursMapByScriptId[self._scriptId] = nil\n _behavioursMapByExecutionOrder[self._executionIndex] = nil\nend\n\n--- Internal setter for a property\n---@private\n---@param name string Property name\n---@param value any Value to set\nfunction Behaviour:_setProperty(name, value)\n self[name] = value\nend\n\n--- Internal method to attach a scene node to this Behaviour\n---@private\n---@param msg table Contains fields: value=nodeId, scriptName, scriptId\nfunction Behaviour:_setNode(msg)\n __assertTrace(type(msg) == 'table', \"_setNode() called with nil or a non-table.\")\n\n if self.node then\n error(\"Node is already set on behaviour!\")\n end\n\n local nodeId = msg.value\n __assertTrace(type(nodeId) == 'string', \"_setNode() needs a nodeId of type string.\")\n\n local node = SceneObject.findById(nodeId)\n __assertTrace(node, \"_setNode() node not found\")\n\n local scriptName = msg.scriptName\n __assertTrace(scriptName, \"_setNode() needs a scriptName\")\n\n local scriptId = msg.scriptId\n __assertTrace(scriptId, \"_setNode() needs a scriptId\")\n\n self.node = node\n self._nodeId = nodeId\n self._scriptName = msg.scriptName\n self._scriptId = scriptId\n\n _behavioursMapByScriptId[scriptId] = self\n _behavioursMapByExecutionOrder[self._executionIndex] = self\n\n if not _behavioursMapByNodeId[nodeId] then\n _behavioursMapByNodeId[nodeId] = {}\n end\n _behavioursMapByNodeId[nodeId][scriptId] = {\n node = node,\n scriptName = scriptName,\n behaviour = self\n }\nend\n\n--- Return the properties of this Behaviour as JSON\n---@private\n---@return string JSON string of properties\nfunction Behaviour:_getPropsJson()\n return JE(self:getProperties())\nend\n\n--- Returns the active state of the behaviour. If the owner item is inactive, so are all attached behaviours\n---@return boolean true, if active, othersise false\nfunction Behaviour:isActive()\n return self._isActive\nend\n\n--- Returns the initialized state of the behaviour. If true, init ran through or there is no init\n---@return boolean true, if initialized, othersise false\nfunction Behaviour:isInitialized()\n return self._isInitialized\nend\n\n--- Clears all registered behaviours (used internally). They are expected to be empty anyway due to scripts\n--- cleaning up behind themselves. This function will assert this\n---@private\nfunction Behaviour._clearBehaviours()\n -- Clear in-place to avoid any stale references to the _behaviours table object\n -- preventing Lua GC from reclaiming behaviour instances.\n for nodeId, nodeBehaviours in pairs(_behavioursMapByNodeId) do\n -- nodeBehaviours is a keyed table (scriptId -> { ... })\n if nodeBehaviours and next(nodeBehaviours) ~= nil then\n -- This warning is useful when scripts forget to dispose their behaviours,\n -- but the check previously used `#nodeBehaviours` which is incorrect for keyed tables.\n print(\"WARNING: Some behaviours did not get cleaned properly. This is an engine bug!\")\n -- Keep clearing anyway to enable GC.\n end\n\n if nodeBehaviours then\n for scriptId in pairs(nodeBehaviours) do\n nodeBehaviours[scriptId] = nil\n end\n end\n\n _behavioursMapByNodeId[nodeId] = nil\n end\n\n -- Also clear the second map that has the behaviours by their script ID directly and the execution order map\n _behavioursMapByScriptId = {}\n _behavioursMapByExecutionOrder = {}\n _executionIndex = 1\nend\n\nfunction Behaviour:_init()\n if type(self.init) == 'function' then\n local ok, err = pcall(self.init, self)\n if not ok then\n print(self._scriptName .. \":init() failed:\", err)\n end\n end\n self._isInitialized = true\n self._isActive = true\nend\n\nfunction Behaviour:_ondisable()\n self._isActive = false\n if type(self.ondisable) == 'function' then\n local ok, err = pcall(self.ondisable, self)\n if not ok then\n print(self._scriptName .. \":ondisable() failed:\", err)\n end\n end\nend\n\nfunction Behaviour:_onenable()\n self._isActive = true\n if type(self.onenable) == 'function' then\n local ok, err = pcall(self.onenable, self)\n if not ok then\n print(self._scriptName .. \":onenable() failed:\", err)\n end\n end\nend\n\nfunction Behaviour:_ondestroy()\n if type(self.ondestroy) == 'function' then\n local ok, err = pcall(self.ondestroy, self)\n if not ok then\n print(self._scriptName .. \":ondestroy() failed:\", err)\n end\n end\n self._isActive = false\n self._isInitialized = false\nend\n\nfunction Behaviour._callHookOnAll(hookName, deltaTime, deltaTimeSmooth)\n local callcount = 0\n\n for _, behaviour in pairs(_behavioursMapByExecutionOrder) do\n local hookFunc = behaviour[hookName]\n if behaviour._isActive and behaviour._isInitialized and type(hookFunc) == 'function' then\n callcount = callcount + 1\n local ok, err = pcall(hookFunc, behaviour, deltaTime, deltaTimeSmooth)\n if not ok then\n print(behaviour._scriptName .. \":\" .. hookName .. \"() failed:\", err)\n end\n end\n end\n\n return callcount\nend\n\nfunction Behaviour._updateAll(deltaTime, deltaTimeSmooth)\n local callcount = 0\n\n callcount = callcount + Behaviour._callHookOnAll(\"preUpdate\", deltaTime, deltaTimeSmooth)\n callcount = callcount + Behaviour._callHookOnAll(\"update\", deltaTime, deltaTimeSmooth)\n callcount = callcount + Behaviour._callHookOnAll(\"lateUpdate\", deltaTime, deltaTimeSmooth)\n\n return callcount\nend\n\nfunction Behaviour._renderAll()\n\n if Canvas.autoClear then\n Canvas.clear()\n end\n\n local callcount = 0\n\n callcount = Behaviour._callHookOnAll(\"prerender\")\n callcount = Behaviour._callHookOnAll(\"render\")\n\n Canvas.commit()\n\n return callcount\nend\n\nfunction Behaviour._renderguiAll()\n return Behaviour._callHookOnAll(\"rendergui\")\nend\n\nfunction Behaviour._setActive(nodes)\n for scriptId, active in pairs(nodes) do\n local behaviour = _behavioursMapByScriptId[scriptId]\n if behaviour then\n behaviour._isActive = active\n else\n print(\"ERROR: Behaviour._setActive() cannot find script: \" .. scriptId)\n end\n end\nend\n\nfunction Behaviour._debugStats()\n local nodeCount = 0\n local behaviourCount = 0\n for _, nodeBehaviours in pairs(_behavioursMapByNodeId) do\n nodeCount = nodeCount + 1\n if nodeBehaviours then\n for _ in pairs(nodeBehaviours) do\n behaviourCount = behaviourCount + 1\n end\n end\n end\n\n return {\n nodeCount = nodeCount,\n behaviourCount = behaviourCount\n }\nend\n\nreturn Behaviour\n";
|
|
99040
|
+
var lua_api_behaviour = "local SceneObject = require('engine/sceneobject')\nlocal Canvas = require('engine/canvas')\nlocal JE = require('engine/json/jsonencoder')()\n\nlocal _behavioursMapByNodeId = {}\nlocal _behavioursMapByScriptId = {}\nlocal _behavioursMapByExecutionOrder = {}\nlocal _executionIndex = 1\n\nlocal Behaviour = Class.new()\n\n-- Put the class in the global scope (Behaviour is the old deprecated name)\n_G.Behaviour = Behaviour\n_G.Entity = Behaviour\n\n--- Constructor hook called when a new Behaviour is created.\n---@private\nfunction Behaviour:__new()\n self._isBehaviour = true\n self._type = \"Behaviour\"\n self._nodeId = nil\n self._scriptName = \"\"\n self._executionIndex = _executionIndex\n self._isActive = true\n self._isInitialized = false\n\n _executionIndex = _executionIndex + 1\n\n -- Adds a default node property\n self:addProperty(\"node\", Property.Node)\nend\n\n--- Destructor hook called before the Behaviour is destroyed.\n---@private\nfunction Behaviour:__destroy()\n print(\"__destroy called for: \", self._nodeId)\nend\n\n--- Get all behaviours attached to a specific node ID.\n---@param nodeId string The ID of the scene graph node\n---@return table A table containing all behaviours attached to the node\nfunction Behaviour.getByNodeId(nodeId)\n local result = {}\n local nodeBehaviours = _behavioursMapByNodeId[nodeId]\n if nodeBehaviours then\n for k,v in pairs(nodeBehaviours) do\n table.insert(result, v.behaviour)\n end\n end\n return result\nend\n\n--- Get a single behaviour attached to a node ID with a specific script name.\n---@param nodeId string The ID of the scene graph node\n---@param scriptName string The script name of the behaviour\n---@return Behaviour|nil The behaviour if found, or nil\nfunction Behaviour.getByNodeIdAndScriptName(nodeId, scriptName)\n local nodeEntities = _behavioursMapByNodeId[nodeId]\n if nodeEntities then\n for k,v in pairs(nodeEntities) do\n if v.scriptName == scriptName then\n return v.behaviour\n end\n end\n end\n return nil\nend\n\n--- Returns the node ID this Behaviour is attached to.\n---@return string|nil Node ID of the attached scene object\nfunction Behaviour:getNodeId()\n return self._nodeId\nend\n\n--- Returns the script name of this Behaviour.\n---@return string Script name\nfunction Behaviour:getScriptName()\n return self._scriptName\nend\n\n--- Returns a table of all properties defined on the behaviour class.\n---@return table A table with fields: name, defaultValue, type, order\nfunction Behaviour:getProperties()\n local propsByName = {}\n local class = self.getClass()\n\n local function addPropertyEntry(name, prop)\n propsByName[name] = {\n name = name,\n defaultValue = prop.value,\n type = prop.datatype,\n order = prop.order,\n info = prop.info,\n minValue = prop.minValue,\n maxValue = prop.maxValue,\n conditions = prop.conditions,\n collapsed = prop.collapsed,\n allowedTypes = prop.allowedTypes,\n }\n end\n\n local SKIP_CLASS_KEYS = {\n metatable = true,\n properties = true,\n super = true,\n new = true,\n getClass = true,\n addProperty = true,\n }\n\n local function collectFromClass(cls)\n if not cls then\n return\n end\n\n collectFromClass(cls.super)\n\n for k, v in pairs(cls.properties) do\n if type(v) == 'table' and v._isProperty then\n addPropertyEntry(k, v)\n end\n end\n\n -- Legacy API: properties assigned directly on the class, e.g. TestEntity.testNode = Property.new(...)\n for k, v in pairs(cls) do\n if type(k) == 'string' and not SKIP_CLASS_KEYS[k] and type(v) == 'table' and v._isProperty and not propsByName[k] then\n addPropertyEntry(k, v)\n end\n end\n end\n\n collectFromClass(class)\n\n local props = {}\n for _, v in pairs(propsByName) do\n table.insert(props, v)\n end\n\n return props\nend\n\n--- When a script is destroyed, we need to call this to clear the behaviour out of the list\n---@private\nfunction Behaviour:_disposeBehaviour()\n local scripts = _behavioursMapByNodeId[self._nodeId]\n if scripts then\n scripts[self._scriptId] = nil\n end\n\n _behavioursMapByScriptId[self._scriptId] = nil\n _behavioursMapByExecutionOrder[self._executionIndex] = nil\nend\n\n--- Internal setter for a property\n---@private\n---@param name string Property name\n---@param value any Value to set\nfunction Behaviour:_setProperty(name, value)\n self[name] = value\nend\n\n--- Internal method to attach a scene node to this Behaviour\n---@private\n---@param msg table Contains fields: value=nodeId, scriptName, scriptId\nfunction Behaviour:_setNode(msg)\n __assertTrace(type(msg) == 'table', \"_setNode() called with nil or a non-table.\")\n\n if self.node then\n error(\"Node is already set on behaviour!\")\n end\n\n local nodeId = msg.value\n __assertTrace(type(nodeId) == 'string', \"_setNode() needs a nodeId of type string.\")\n\n local node = SceneObject.findById(nodeId)\n __assertTrace(node, \"_setNode() node not found\")\n\n local scriptName = msg.scriptName\n __assertTrace(scriptName, \"_setNode() needs a scriptName\")\n\n local scriptId = msg.scriptId\n __assertTrace(scriptId, \"_setNode() needs a scriptId\")\n\n self.node = node\n self._nodeId = nodeId\n self._scriptName = msg.scriptName\n self._scriptId = scriptId\n\n _behavioursMapByScriptId[scriptId] = self\n _behavioursMapByExecutionOrder[self._executionIndex] = self\n\n if not _behavioursMapByNodeId[nodeId] then\n _behavioursMapByNodeId[nodeId] = {}\n end\n _behavioursMapByNodeId[nodeId][scriptId] = {\n node = node,\n scriptName = scriptName,\n behaviour = self\n }\nend\n\n--- Return the properties of this Behaviour as JSON\n---@private\n---@return string JSON string of properties\nfunction Behaviour:_getPropsJson()\n return JE(self:getProperties())\nend\n\n--- Returns the active state of the behaviour. If the owner item is inactive, so are all attached behaviours\n---@return boolean true, if active, othersise false\nfunction Behaviour:isActive()\n return self._isActive\nend\n\n--- Returns the initialized state of the behaviour. If true, init ran through or there is no init\n---@return boolean true, if initialized, othersise false\nfunction Behaviour:isInitialized()\n return self._isInitialized\nend\n\n--- Clears all registered behaviours (used internally). They are expected to be empty anyway due to scripts\n--- cleaning up behind themselves. This function will assert this\n---@private\nfunction Behaviour._clearBehaviours()\n -- Clear in-place to avoid any stale references to the _behaviours table object\n -- preventing Lua GC from reclaiming behaviour instances.\n for nodeId, nodeBehaviours in pairs(_behavioursMapByNodeId) do\n -- nodeBehaviours is a keyed table (scriptId -> { ... })\n if nodeBehaviours and next(nodeBehaviours) ~= nil then\n -- This warning is useful when scripts forget to dispose their behaviours,\n -- but the check previously used `#nodeBehaviours` which is incorrect for keyed tables.\n print(\"WARNING: Some behaviours did not get cleaned properly. This is an engine bug!\")\n -- Keep clearing anyway to enable GC.\n end\n\n if nodeBehaviours then\n for scriptId in pairs(nodeBehaviours) do\n nodeBehaviours[scriptId] = nil\n end\n end\n\n _behavioursMapByNodeId[nodeId] = nil\n end\n\n -- Also clear the second map that has the behaviours by their script ID directly and the execution order map\n _behavioursMapByScriptId = {}\n _behavioursMapByExecutionOrder = {}\n _executionIndex = 1\nend\n\nfunction Behaviour:_init()\n if type(self.init) == 'function' then\n local ok, err = pcall(self.init, self)\n if not ok then\n print(self._scriptName .. \":init() failed:\", err)\n end\n end\n self._isInitialized = true\n self._isActive = true\nend\n\nfunction Behaviour:_ondisable()\n self._isActive = false\n if type(self.ondisable) == 'function' then\n local ok, err = pcall(self.ondisable, self)\n if not ok then\n print(self._scriptName .. \":ondisable() failed:\", err)\n end\n end\nend\n\nfunction Behaviour:_onenable()\n self._isActive = true\n if type(self.onenable) == 'function' then\n local ok, err = pcall(self.onenable, self)\n if not ok then\n print(self._scriptName .. \":onenable() failed:\", err)\n end\n end\nend\n\nfunction Behaviour:_ondestroy()\n if type(self.ondestroy) == 'function' then\n local ok, err = pcall(self.ondestroy, self)\n if not ok then\n print(self._scriptName .. \":ondestroy() failed:\", err)\n end\n end\n self._isActive = false\n self._isInitialized = false\nend\n\nfunction Behaviour._callHookOnAll(hookName, deltaTime, deltaTimeSmooth)\n local callcount = 0\n\n for _, behaviour in pairs(_behavioursMapByExecutionOrder) do\n local hookFunc = behaviour[hookName]\n if behaviour._isActive and behaviour._isInitialized and type(hookFunc) == 'function' then\n callcount = callcount + 1\n local ok, err = pcall(hookFunc, behaviour, deltaTime, deltaTimeSmooth)\n if not ok then\n print(behaviour._scriptName .. \":\" .. hookName .. \"() failed:\", err)\n end\n end\n end\n\n return callcount\nend\n\nfunction Behaviour._updateAll(deltaTime, deltaTimeSmooth)\n local callcount = 0\n\n callcount = callcount + Behaviour._callHookOnAll(\"preUpdate\", deltaTime, deltaTimeSmooth)\n callcount = callcount + Behaviour._callHookOnAll(\"update\", deltaTime, deltaTimeSmooth)\n callcount = callcount + Behaviour._callHookOnAll(\"lateUpdate\", deltaTime, deltaTimeSmooth)\n\n return callcount\nend\n\nfunction Behaviour._renderAll()\n\n if Canvas.autoClear then\n Canvas.clear()\n end\n\n local callcount = 0\n\n callcount = Behaviour._callHookOnAll(\"prerender\")\n callcount = Behaviour._callHookOnAll(\"render\")\n\n Canvas.commit()\n\n return callcount\nend\n\nfunction Behaviour._renderguiAll()\n return Behaviour._callHookOnAll(\"rendergui\")\nend\n\nfunction Behaviour._setActive(nodes)\n for scriptId, active in pairs(nodes) do\n local behaviour = _behavioursMapByScriptId[scriptId]\n if behaviour then\n behaviour._isActive = active\n else\n print(\"ERROR: Behaviour._setActive() cannot find script: \" .. scriptId)\n end\n end\nend\n\nfunction Behaviour._debugStats()\n local nodeCount = 0\n local behaviourCount = 0\n for _, nodeBehaviours in pairs(_behavioursMapByNodeId) do\n nodeCount = nodeCount + 1\n if nodeBehaviours then\n for _ in pairs(nodeBehaviours) do\n behaviourCount = behaviourCount + 1\n end\n end\n end\n\n return {\n nodeCount = nodeCount,\n behaviourCount = behaviourCount\n }\nend\n\nreturn Behaviour\n";
|
|
99005
99041
|
|
|
99006
99042
|
var lua_api_canvas = "\nlocal _internal = require('engine/_internal');\n\n---@module canvas\nlocal canvas = {\n autoClear = false\n}\n\n-- Lua-side command buffer for canvas calls.\nlocal _cmds = {}\n\nlocal function _captureSendMessage(target, payload, buffers)\n table.insert(_cmds, {\n target = target,\n payload = payload,\n buffers = buffers\n })\n return nil\nend\n\nlocal function _runWithCapturedSend(fn, ...)\n local oldSendMessage = _internal.sendMessage\n _internal.sendMessage = _captureSendMessage\n\n local result = { pcall(fn, ...) }\n\n _internal.sendMessage = oldSendMessage\n\n if not result[1] then\n error(result[2])\n end\n\n return table.unpack(result, 2)\nend\n\nlocal function _commitIfNeeded()\n if #_cmds == 0 then\n return { committed = 0 }\n end\n\n local result = _internal.sendMessage('canvas.commit', { cmds = _cmds })\n _cmds = {}\n return result\nend\n\n---If set to true, the canvas will automatically clear once before the render hook is called\n---@param value boolean the flag value\nfunction canvas.setAutoClear(value)\n self.autoClear = value\nend\n\n---Returns the value of the auto clear flag\n---@return boolean the flag value\nfunction canvas.getAutoClear()\n return self.autoClear\nend\n\n---Commit all pending buffered canvas commands.\n---@return table|nil result Optional engine-side debug info.\nfunction canvas.commit()\n return _commitIfNeeded()\nend\n\n---Debug helper: returns count of pending buffered commands in Lua.\n---@return number\nfunction canvas.getPendingCommandCount()\n return #_cmds\nend\n\n---Debug helper: returns current pending buffered commands in Lua.\n---@return table\nfunction canvas.getPendingCommands()\n return _cmds\nend\n\n---Debug helper: returns most recently committed command list on engine side.\n---@return table\nfunction canvas.getLastCommittedCommands()\n _commitIfNeeded()\n return _internal.sendMessage('canvas.getLastCommittedCommands')\nend\n\n---Clear the canvas.\n---@function\nfunction canvas.clear()\n _internal.sendMessage('canvas.clear')\nend\n\n---Returns the width of the canvas in pixels.\n---@function\nfunction canvas.getWidth()\n return _internal.sendMessage('canvas.getWidth')\nend\n\n---Returns the height of the canvas in pixels.\n---@function\nfunction canvas.getHeight()\n return _internal.sendMessage('canvas.getHeight')\nend\n\n---Sets the width of lines in the canvas.\n---@param w number the width to set the lines to.\nfunction canvas.setLineWidth(w)\n _internal.sendMessage('canvas.setLineWidth', { w=w })\nend\n\n---Sets the type of endings applied to the ends of a line.\n---@param cap string the type of corner to create on a line. One of \"butt\", \"round\", \"square\".\nfunction canvas.setLineCap(cap)\n _internal.sendMessage('canvas.setLineCap', { cap=cap })\nend\n\n---Sets the type of corner created when two lines meet.\n---@param join string the type of connection to create between two lines. One of \"bevel\", \"round\", or \"miter\".\nfunction canvas.setLineJoin(join)\n _internal.sendMessage('canvas.setLineJoin', { join=join })\nend\n\n---Sets the maximum miter length. Miter length is the distance between the inner corner and the outer corner of the join.\n---@param limit number the maximum miter length. When the miter length exceeds this value, the corner is trimmed.\nfunction canvas.setMiterLimit(limit)\n _internal.sendMessage('canvas.setMiterLimit', { limit=limit })\nend\n\n---Sets the color of the stroke (outline) for shapes drawn on the canvas.\n---@param r number Red channel value (0–255)\n---@param g number Green channel value (0–255)\n---@param b number Blue channel value (0–255)\n---@param a number Alpha channel value (0–1)\nfunction canvas.setStrokeColor(r, g, b, a)\n _internal.sendMessage('canvas.setStrokeColor', { r=r, g=g, b=b, a=a })\nend\n\n---Sets the color that is used to fill in shapes and text when they are drawn on the canvas.\n---@param r number Red channel value (0–255)\n---@param g number Green channel value (0–255)\n---@param b number Blue channel value (0–255)\n---@param a number Alpha channel value (0–1)\nfunction canvas.setFillColor(r, g, b, a)\n _internal.sendMessage('canvas.setFillColor', { r=r, g=g, b=b, a=a })\nend\n\n---Sets the color to use for shadows.\n---@param r number Red channel value (0–255)\n---@param g number Green channel value (0–255)\n---@param b number Blue channel value (0–255)\n---@param a number Alpha channel value (0–1)\nfunction canvas.setShadowColor(r, g, b, a)\n _internal.sendMessage('canvas.setShadowColor', { r=r, g=g, b=b, a=a })\nend\n\n---Sets the blur level for shadows.\n---@param level number the level of blur to be applied to shadows (in pixels).\nfunction canvas.setShadowBlurLevel(level)\n _internal.sendMessage('canvas.setShadowBlurLevel', { level=level })\nend\n\n---Sets the blur level for shadows.\n---@param x number the vertical offset of the shadow in pixels.\n---@param y number the horizontal offset of the shadow in pixels.\nfunction canvas.setShadowOffset(x, y)\n _internal.sendMessage('canvas.setShadowOffset', { x=x, y=y })\nend\n\n---Begins a new path.\n---@function\nfunction canvas.beginPath()\n _internal.sendMessage('canvas.beginPath')\nend\n\n---Close the current path by connecting the last and first point in the path, creating a loop.\n---@function\nfunction canvas.closePath()\n _internal.sendMessage('canvas.closePath')\nend\n\n---Determines if the specified point is in the current path.\n---@param x number x-coordinate of the point to check.\n---@param y number y-coordinate of the point to check.\n---@return boolean indicating if the point is in the path or not.\nfunction canvas.isPointInPath(x, y)\n return _internal.sendMessage('canvas.isPointInPath', { x=x, y=y })\nend\n\n---Sets the clipping path to the current drawing path.\n---@function\nfunction canvas.clip()\n _internal.sendMessage('canvas.clip')\nend\n\n---Draws the outline of a shape or path using the current stroke style, line width and styles.\n---@function\nfunction canvas.stroke()\n _internal.sendMessage('canvas.stroke')\nend\n\n---Fills a shape or path with the current fill style.\n---@function\nfunction canvas.fill()\n _internal.sendMessage('canvas.fill')\nend\n\n---Moves the current drawing position to the specified coordinates.\n---@param x number x-coordinate of the new current drawing position.\n---@param y number y-coordinate of the new current drawing position.\nfunction canvas.moveTo(x, y)\n _internal.sendMessage('canvas.moveTo', { x=x, y=y })\nend\n\n---Draws a straight line from the current position to the specified coordinates.\n---@param x number the x-coordinate to draw the line to.\n---@param y number the y-coordinate to draw the line to.\nfunction canvas.lineTo(x, y)\n _internal.sendMessage('canvas.lineTo', { x=x, y=y })\nend\n\n---Sets the type of compositing operation to apply when drawing new shapes.\n---@param operation string the compositing operation to use, possible values are:\n---\"source-over\", \"source-in\", \"source-out\", \"source-atop\", \"destination-over\",\n---\"destination-in\", \"destination-out\", \"destination-atop\", \"lighter\", \"copy\", \"xor\".\nfunction canvas.setCompositeOperation(operation)\n _internal.sendMessage('canvas.setCompositeOperation', { operation=operation })\nend\n\n---Sets the transparency value that is applied to all rendering operations.\n---@param value number a value between 0.0 (fully transparent) and 1.0 (fully opaque).\nfunction canvas.setGlobalAlpha(value)\n _internal.sendMessage('canvas.setGlobalAlpha', { value=value })\nend\n\n---Creates a rectangle path which is only drawn after calling stroke() or fill().\n---@param x number x-coordinate of the rectangle upper-left corner.\n---@param y number y-coordinate of the rectangle upper-left corner.\n---@param w number width of the rectangle.\n---@param h number height of the rectangle.\nfunction canvas.pathRect(x, y, w, h)\n _internal.sendMessage('canvas.pathRect', { x=x, y=y, w=w, h=h })\nend\n\n---Adds a rounded rectangle to the current path. Must be followed by stroke() or fill().\n---@param x number x-coordinate of the rectangle upper-left corner.\n---@param y number y-coordinate of the rectangle upper-left corner.\n---@param w number width of the rectangle.\n---@param h number height of the rectangle.\n---@param radius number|table corner radius applied to all four corners (uniform), or a table\n---of 1–4 values to set individual corner radius in the order [top-left, top-right,\n---bottom-right, bottom-left], following the HTML Canvas API specification.\nfunction canvas.roundRect(x, y, w, h, radius)\n _internal.sendMessage('canvas.roundRect', { x=x, y=y, w=w, h=h, radius=radius })\nend\n\n---Draw a rectangle outline using the current stroke style.\n---@param x number x-coordinate of the rectangle upper-left corner.\n---@param y number y-coordinate of the rectangle upper-left corner.\n---@param w number width of the rectangle.\n---@param h number height of the rectangle.\nfunction canvas.strokeRect(x, y, w, h)\n _internal.sendMessage('canvas.strokeRect', { x=x, y=y, w=w, h=h })\nend\n\n---Draw a rectangle with a filled interior using the current fill style,\n---@param x number x-coordinate of the rectangle upper-left corner.\n---@param y number y-coordinate of the rectangle upper-left corner.\n---@param w number width of the rectangle.\n---@param h number height of the rectangle.\nfunction canvas.fillRect(x, y, w, h)\n _internal.sendMessage('canvas.fillRect', { x=x, y=y, w=w, h=h })\nend\n\n---Clears the specified rectangle by setting its pixels to transparent.\n---@param x number x-coordinate of the rectangle upper-left corner.\n---@param y number y-coordinate of the rectangle upper-left corner.\n---@param w number width of the rectangle.\n---@param h number height of the rectangle.\nfunction canvas.clearRect(x, y, w, h)\n _internal.sendMessage('canvas.clearRect', { x=x, y=y, w=w, h=h })\nend\n\n---Draws a circle with given parameters. Must be followed by stroke() or fill().\n---@param x number x-coordinates of the center of the circle.\n---@param y number y-coordinates of the center of the circle.\n---@param r number the radius of the circle\nfunction canvas.circle(x, y, r)\n _internal.sendMessage('canvas.circle', { x=x, y=y, r=r })\nend\n\n---Draws an arc with given parameters. Must be followed by stroke() or fill().\n---@param x number x-coordinates of the center of the circle.\n---@param y number y-coordinates of the center of the circle.\n---@param r number the radius of the circle.\n---@param startAngle number the starting angle in radians.\n---@param endAngle number the ending angle, in radians.\n---@param anticlockwise boolean a flag which specifies whether the drawing should be counterclockwise or clockwise.\nfunction canvas.arc(x, y, r, startAngle, endAngle, anticlockwise)\n _internal.sendMessage('canvas.arc', { x=x, y=y, r=r, startAngle=startAngle,\n endAngle=endAngle, anticlockwise=anticlockwise })\nend\n\n---Adds a quadratic Bézier curve to the path with given control point and end point.\n---@param cpx number x-coordinate of the control point.\n---@param cpy number y-coordinate of the control point.\n---@param x number x-coordinate of the end point.\n---@param y number y-coordinate of the end point.\nfunction canvas.quadraticCurve(cpx, cpy, x, y)\n _internal.sendMessage('canvas.quadraticCurve', { cpx=cpx, cpy=cpy, x=x, y=y })\nend\n\n---Draws a bezier curve from the current position to the specified point, using the specified control points.\n---@param cp1x number x-coordinate of the first control point.\n---@param cp1y number y-coordinate of the first control point.\n---@param cp2x number x-coordinate of the second control point.\n---@param cp2y number y-coordinate of the second control point.\n---@param x number x-coordinate of the end point.\n---@param y number y-coordinate of the end point.\nfunction canvas.bezierCurve(cp1x, cp1y, cp2x, cp2y, x, y)\n _internal.sendMessage('canvas.bezierCurve', { cp1x=cp1x, cp1y=cp1y,\n cp2x=cp2x, cp2y=cp2y,\n x=x, y=y })\nend\n\n---@class Gradient\n---A class to internally link gradient objects from the Lua environment to Lumino codebase.\n---A Gradient object can be create using @{createLinearGradient} or @{createRadialGradient}\n---@private\nlocal Gradient = {}\n\n---Creates a new gradient object with the given index\n---@param idx number index of the gradient object\n---@private\nfunction Gradient:new(idx)\n -- Store the gradient object in a field of the class instance metatable\n local obj = { idx = idx}\n Class.__setmetatable(obj, self)\n self.__index = self\n -- Return the instance\n return obj\nend\n\n---Hook that runs before an object is deleted by the garbage collector.\n---It calls a function to delete the gradient object in JS\n---@private\nfunction Gradient:__gc()\n -- Keep deletion ordering deterministic when gradient operations are buffered.\n _commitIfNeeded()\n _internal.sendMessage('canvas.deleteGradient', { gradientIdx = self.idx })\nend\n-- Add the Gradient class to the Canvas namespace\ncanvas.Gradient = Gradient\n\n---Sets a gradient object to active.\n---@param gradient Gradient a gradient object\nfunction canvas.setGradientActive(gradient)\n if gradient.idx >= 0 then\n _internal.sendMessage('canvas.setGradientActive', { gradientIdx = gradient.idx })\n end\nend\n\n---Adds a new stop, defined by an offset and a color, to a gradient object.\n---@param gradient Gradient a gradient object\n---@param offset number a value between 0.0 and 1.0 where the new color stop is positioned.\n---@param r number Red channel value (0–255)\n---@param g number Green channel value (0–255)\n---@param b number Blue channel value (0–255)\n---@param a number Alpha channel value (0–1)\nfunction canvas.colorStop(gradient, offset, r, g, b, a)\n _internal.sendMessage('canvas.colorStop', { gradientIdx=gradient.idx, offset=offset, r=r, g=g, b=b, a=a })\nend\n\n---Creates a linear gradient object.\n---@param x1 number the x-coordinate of the start point of the gradient\n---@param y1 number the y-coordinate of the start point of the gradient\n---@param x2 number the x-coordinate of the end point of the gradient\n---@param y2 number the y-coordinate of the end point of the gradient\n---@return Gradient a new gradient object\n---@usage local gradient = Canvas.createLinearGradient(0, 0, 50, 0)\nfunction canvas.createLinearGradient(x1, y1, x2, y2)\n local idx = _internal.sendMessage('canvas.createLinearGradient', { x1=x1, y1=y1,\n x2=x2, y2=y2 })\n local gradient = Gradient:new(idx)\n return gradient\nend\n\n---Creates a radial gradient object.\n---@param x1 number x-coordinate of the start circle\n---@param y1 number y-coordinate of the start circle\n---@param r1 number radius of the start circle\n---@param x2 number x-coordinate of the end circle\n---@param y2 number y-coordinate of the end circle\n---@param r2 number radius of the end circle\n---@return Gradient a new gradient object\nfunction canvas.createRadialGradient(x1, y1, r1, x2, y2, r2)\n local idx = _internal.sendMessage('canvas.createRadialGradient', { x1=x1, y1=y1, r1=r1,\n x2=x2, y2=y2, r2=r2})\n local gradient = Gradient:new(idx)\n return gradient\nend\n\n---Returns an array with strings of all available fonts. This will list all custom loaded fonts through Loader.loadFont and\n---fonts registered in Canvas Fonts in your project. It will also probe for common system fonts although the list might not be complete.\n---It is strongly recommended to use only custom uploaded fonts to have reliable results on all platforms.\n---@return table an array with all the available fonts as strings\nfunction canvas.getAvailableFonts()\n return _internal.sendMessage('canvas.getAvailableFonts')\nend\n\n---Sets a font style.\n---@param font string The font style to be set, in the format of 'font-style font-size font-family'. Example: 'italic 20px Arial'.\nfunction canvas.setFont(font)\n _internal.sendMessage('canvas.setFont', { font=font })\nend\n\n---Sets the current text alignment\n---@param align string The new text alignment to be set. One of 'start', 'end', 'left', 'right', or 'center'.\nfunction canvas.setTextAlign(align)\n _internal.sendMessage('canvas.setTextAlign', { align=align })\nend\n\n---Sets the text baseline used when drawing text.\n---@param baseline string The text baseline to set. One of 'alphabetic', 'top', 'hanging', 'middle', 'ideographic', or 'bottom'.\nfunction canvas.setTextBaseline(baseline)\n _internal.sendMessage('canvas.setTextBaseline', { baseline=baseline })\nend\n\n---Measures the width of the specified text in pixels.\n---@param text string The text to measure.\nfunction canvas.measureTextWidth(text)\n return _internal.sendMessage('canvas.measureTextWidth', { text=text })\nend\n\n---Draws and fills a given text string at the specified coordinates.\n---@param text string The text string to be drawn and filled.\n---@param x number The x-coordinate where the text will be drawn.\n---@param y number The y-coordinate where the text will be drawn.\nfunction canvas.fillText(text, x, y)\n _internal.sendMessage('canvas.fillText', { text=text, x=x, y=y })\nend\n\n---Draws the outline of the given text at the specified coordinates.\n---@param text string The text string to be drawn.\n---@param x number The x-coordinate where the text will be drawn.\n---@param y number The y-coordinate where the text will be drawn.\nfunction canvas.strokeText(text, x, y)\n _internal.sendMessage('canvas.strokeText', { text=text, x=x, y=y })\nend\n\n-- -TODO: ImageData is not yet ready for deployment because using it for pixel manipulation would be\n-- -inefficient and slow due to the need for JSON communication with JavaScript. While JSON\n-- -communication is necessary for the security of the application, it is not well-suited for tasks\n-- -that require frequent or high-volume data transfer. It is better to use ImageData for low\n-- -frequency tasks such as updating UI and handling events, rather than trying to use it for more\n-- -demanding tasks that may be slowed down by the use of JSON objects.\n\n-- --- Image class to link imageData objects in the canvas to Lua\n-- ---@class imageData\n-- local Image = {}\n\n-- --- Creates a new Image object with the given index\n-- ---@param idx number index of the imageData object in the canvas\n-- function Image:new(idx)\n-- local obj = {}\n-- Class.__setmetatable(obj, self)\n-- self.__index = self\n-- self.idx = idx\n-- return obj\n-- end\n-- canvas.Image = Image\n\n-- ---Creates a new, blank Image object with the specified dimensions.\n-- ---All of the pixels in the new object are transparent black.\n-- ---@param width number the width of the Image object\n-- ---@param height number the height of the Image object\n-- ---@return Image a new Image object\n-- function canvas.createImage(width, height)\n-- local idx = _internal.sendMessage('canvas.createImage', { width=width, height=height })\n-- local image = Image:new(idx)\n-- return image\n-- end\n\n-- ---Write the RGBA channels of an Image object\n-- ---@param r number the r channel of the Image object\n-- ---@param g number the g channel of the Image object\n-- ---@param b number the b channel of the Image object\n-- ---@param a number the a channel of the Image object\n-- function canvas.writeImageChannels(image, r, g, b, a)\n-- _internal.sendMessage('canvas.writeImageChannels', { imageIdx=image.idx, r=r, g=g, b=b, a=a })\n-- end\n\n-- ---Draws an image given by an url at the specified position and dimensions.\n-- ---@param url string\n-- ---@param x number\n-- ---@param y number\n-- ---@param width number\n-- ---@param height number\n-- function canvas.drawImageFromUrl(url, x, y, width, height)\n-- _internal.sendMessage('canvas.drawImageFromUrl', { url=url, x=x, y=y, width=width, height=height })\n-- end\n\n-- ---Repeats a given image on the canvas with a given pattern.\n-- ---@param image imageSource an image object\n-- ---@param repeat string one of repeat, repeat-x, repeat-y, no-repeat\n-- function canvas.imagePattern(image, repeatPattern)\n-- _internal.sendMessage('canvas.pattern', { image=image, repeatPattern=repeatPattern })\n-- end\n\n---Draws the image data at the given coordinates.\n---@param image Texture the image data to paint\n---@param x number x-coordinate of the top left corner where the image data will be painted\n---@param y number y-coordinate of the top left corner where the image data will be painted\n---@param width number width of the image on screen (optional)\n---@param height number height of the image on screen (optional)\n---@param mode number mode to use for stretching. possible values are 0 = stretch, 1 = fit, 2 = cover\nfunction canvas.drawImage(image, x, y, width, height, mode)\n __assertTrace(image and image._isTexture, \"image is not a Texture object\")\n _internal.sendMessage('canvas.drawImage', { image= image._handle, x=x, y=y, width=width, height=height, mode=mode })\nend\n\n---Draws the image data at the given coordinates.\n---@param image Texture the image data to paint\n---@param x number x-coordinate of the top left corner where the image data will be painted\n---@param y number y-coordinate of the top left corner where the image data will be painted\n---@param width number width of the image on screen (optional)\n---@param height number height of the image on screen (optional)\nfunction canvas.drawSubImage(image, x, y, width, height, sourceX, sourceY, sourceWidth, sourceHeight)\n __assertTrace(image and image._isTexture, \"image is not a Texture object\")\n _internal.sendMessage('canvas.drawSubImage', { image= image._handle,\n x=x, y=y, width=width, height=height,\n sourceX=sourceX, sourceY=sourceY, sourceWidth=sourceWidth, sourceHeight=sourceHeight })\nend\n\n--- Scales the canvas by the specified factors along the x and y axes.\n--- Transformations are applied relative to the canvas origin (0,0).\n--- To scale around a different point, use `translate()` to move the origin before scaling.\n---@param x number Scale factor along the x-axis.\n---@param y number Scale factor along the y-axis.\nfunction canvas.scale(x, y)\n _internal.sendMessage('canvas.scale', { x=x, y=y })\nend\n\n--- Rotates the canvas by the specified angle in radians.\n--- Rotation is performed around the canvas origin (0,0).\n--- To rotate around a different point, translate the canvas to that point before calling rotate().\n---@param a number Angle in radians.\nfunction canvas.rotate(a)\n _internal.sendMessage('canvas.rotate', { a=a })\nend\n\n\n--- Moves (translates) the canvas origin by the specified amounts.\n--- All subsequent drawing and transformations (scale, rotate, etc.) are relative to the new origin.\n---@param x number Amount to translate along the x-axis.\n---@param y number Amount to translate along the y-axis.\nfunction canvas.translate(x, y)\n _internal.sendMessage('canvas.translate', { x=x, y=y })\nend\n\n---Applies a 2D transformation matrix to the canvas.\n---@param horizontal_scale number The amount to scale horizontally.\n---@param horizontal_skew number The amount of horizontal skew.\n---@param vertical_skew number The amount of vertical skew.\n---@param vertical_scale number The amount to scale vertically.\n---@param horizontal_translation number The amount of horizontal translation.\n---@param vertical_translation number The amount of vertical translation.\nfunction canvas.transform(horizontal_scale, horizontal_skew, vertical_skew,\n vertical_scale, horizontal_translation, vertical_translation)\n _internal.sendMessage('canvas.transform', { a=horizontal_scale, b=horizontal_skew,\n c=vertical_skew, d=vertical_scale,\n e=horizontal_translation, f=vertical_translation })\nend\n\n---Resets the current canvas transform to the identity matrix and then invokes the transform() function with the given parameters.\n---@param horizontal_scale number The amount to scale horizontally.\n---@param horizontal_skew number The amount of horizontal skew.\n---@param vertical_skew number The amount of vertical skew.\n---@param vertical_scale number The amount to scale vertically.\n---@param horizontal_translation number The amount of horizontal translation.\n---@param vertical_translation number The amount of vertical translation.\nfunction canvas.resetAndSetTransform(horizontal_scale, horizontal_skew, vertical_skew,\n vertical_scale, horizontal_translation, vertical_translation)\n _internal.sendMessage('canvas.resetAndSetTransform', { a=horizontal_scale, b=horizontal_skew,\n c=vertical_skew, d=vertical_scale,\n e=horizontal_translation, f=vertical_translation })\nend\n\n---Reset the transformation matrix to the identity matrix.\n---@function\nfunction canvas.resetTransform()\n _internal.sendMessage('canvas.resetTransform')\nend\n\n---Pushes the current canvas state to a stack so that you can restore it.\n---This can be useful for performing multiple transformations or styles on the canvas, and\n---then restoring it to its original state. The canvas state in fact includes current transformation matrix\n---stroke and fill styles, shadow styles, and other attributes. To restore the canvas state you call\n---the restoreState() function.\n---@function\nfunction canvas.saveState()\n _internal.sendMessage('canvas.saveState')\nend\n\n---Pops the the most recently saved canvas from the saved state stack and restores it.\n---@function\nfunction canvas.restoreState()\n _internal.sendMessage('canvas.restoreState')\nend\n\n--- Resets the canvas to its default state, clearing the canvas and restoring all\n--- context -properties (transforms, styles, clipping region, etc.) to their\n--- defaults. Reset() is more thorough than -calling clear() alone, which only\n--- erases pixels but leaves context state intact.\n---@function\nfunction canvas.reset()\n _internal.sendMessage('canvas.reset')\nend\n\n-- Automatically wrap canvas methods for buffering, so non-query calls are queued\n-- and query/result-producing calls force an immediate commit first.\nlocal _passthroughMethods = {\n commit = true,\n getPendingCommandCount = true,\n getPendingCommands = true,\n}\n\nlocal _immediateMethods = {\n getLastCommittedCommands = true,\n getWidth = true,\n getHeight = true,\n isPointInPath = true,\n createLinearGradient = true,\n createRadialGradient = true,\n getAvailableFonts = true,\n measureTextWidth = true,\n}\n\nfor name, fn in pairs(canvas) do\n if type(fn) == \"function\" and name ~= \"Gradient\" then\n if _passthroughMethods[name] then\n -- keep as-is\n elseif _immediateMethods[name] then\n canvas[name] = function(...)\n _commitIfNeeded()\n return fn(...)\n end\n else\n canvas[name] = function(...)\n return _runWithCapturedSend(fn, ...)\n end\n end\n end\nend\n\nreturn canvas\n";
|
|
99007
99043
|
|
|
99008
|
-
var lua_api_class = "\nlocal Class = {}\n\nClass.__setmetatable = setmetatable\n_G.setmetatable = function()\n error(\"Do not use setmetatable. Use Class.new() instead!\")\nend\n\n-- Put the class in the global scope\n_G.Class = Class\n\nfunction Class.new(self, super)\n if self ~= Class then\n -- new was called with dot syntax, so we need to move self to super.\n super = self\n end\n\n local class, metatable, properties = {}, {}, {}\n class.metatable = metatable\n class.properties = properties\n\n function metatable:__index(key)\n local prop = properties[key]\n if prop then\n return prop:get()\n elseif class[key] ~= nil then\n return class[key]\n elseif class.__customIndex then\n return class.__customIndex(self, key)\n elseif super then\n return super.metatable.__index(self, key)\n else\n return nil\n end\n end\n\n function metatable:__newindex(key, value)\n local prop = properties[key]\n if prop then\n prop:set(value)\n elseif class.__customNewIndex then\n class.__customNewIndex(self, key, value)\n else\n if (super and super.metatable.__customnewindex(self, key, value)) then\n return\n end\n rawset(self, key, value)\n end\n end\n\n function metatable:__customnewindex(key, value)\n if class.__customNewIndex then\n class.__customNewIndex(self, key, value)\n return true\n elseif super then\n return super.metatable.__customnewindex(self, key, value)\n end\n return false\n end\n\n function class:getClass()\n return class\n end\n\n function class.new(self, ...)\n local obj = Class.__setmetatable({}, class.metatable)\n\n if obj.__new then\n if self ~= class then\n -- new was called with dot syntax\n obj:__new(self, ...)\n else\n obj:__new(...)\n end\n end\n\n return obj\n end\n\n function tableLength(T)\n local count = 0\n for _ in pairs(T) do\n count = count + 1\n end\n return count\n end\n\n function class:addProperty(key, propType, defaultValue, options)\n options = options or {}\n if type(options) == 'string' then\n options = { info=options }\n end\n\n if class.properties[key] then\n error(\"A property with the name '\" .. key .. \"' already exists!\");\n return;\n end\n class.properties[key] = Property.new(propType, defaultValue, tableLength(class.properties), options);\n end\n\n return class\nend\n\nreturn Class\n";
|
|
99044
|
+
var lua_api_class = "\nlocal Class = {}\n\nClass.__setmetatable = setmetatable\n_G.setmetatable = function()\n error(\"Do not use setmetatable. Use Class.new() instead!\")\nend\n\n-- Put the class in the global scope\n_G.Class = Class\n\nfunction Class.new(self, super)\n if self ~= Class then\n -- new was called with dot syntax, so we need to move self to super.\n super = self\n end\n\n local class, metatable, properties = {}, {}, {}\n class.metatable = metatable\n class.properties = properties\n class.super = super\n\n function metatable:__index(key)\n local prop = properties[key]\n if prop then\n return prop:get()\n elseif class[key] ~= nil then\n return class[key]\n elseif class.__customIndex then\n return class.__customIndex(self, key)\n elseif super then\n return super.metatable.__index(self, key)\n else\n return nil\n end\n end\n\n function metatable:__newindex(key, value)\n local prop = properties[key]\n if prop then\n prop:set(value)\n elseif class.__customNewIndex then\n class.__customNewIndex(self, key, value)\n else\n if (super and super.metatable.__customnewindex(self, key, value)) then\n return\n end\n rawset(self, key, value)\n end\n end\n\n function metatable:__customnewindex(key, value)\n if class.__customNewIndex then\n class.__customNewIndex(self, key, value)\n return true\n elseif super then\n return super.metatable.__customnewindex(self, key, value)\n end\n return false\n end\n\n function class:getClass()\n return class\n end\n\n function class.new(self, ...)\n local obj = Class.__setmetatable({}, class.metatable)\n\n if obj.__new then\n if self ~= class then\n -- new was called with dot syntax\n obj:__new(self, ...)\n else\n obj:__new(...)\n end\n end\n\n return obj\n end\n\n function tableLength(T)\n local count = 0\n for _ in pairs(T) do\n count = count + 1\n end\n return count\n end\n\n function class:addProperty(key, propType, defaultValue, options)\n options = options or {}\n if type(options) == 'string' then\n options = { info=options }\n end\n\n if class.properties[key] then\n error(\"A property with the name '\" .. key .. \"' already exists!\");\n return;\n end\n class.properties[key] = Property.new(propType, defaultValue, tableLength(class.properties), options);\n end\n\n return class\nend\n\nreturn Class\n";
|
|
99009
99045
|
|
|
99010
99046
|
var lua_api_console = "\nlocal _internal = require('engine/_internal');\n\n--- @module console\nlocal console = {}\n\n-- Add Console to the global scope\n_G.Console = console\n\n---Output log message\n---@param text string\nfunction console.log(text)\n _internal.sendMessage('console.log', { text=text })\nend\n\n---Output debug message\n---@param text string\nfunction console.debug(text)\n _internal.sendMessage('console.debug', { text=text })\nend\n\n---Output warning message\n---@param text string\nfunction console.warning(text)\n _internal.sendMessage('console.warning', { text=text })\nend\n\n---Output error message\n---@param text string\nfunction console.error(text)\n _internal.sendMessage('console.error', { text=text })\nend\n\n---Output inspector to the console that allows inspecting the value with a UI\n---@param value any\nfunction console.inspect(value)\n _internal.sendMessage('console.inspect', { value=value })\nend\n\nreturn console\n";
|
|
99011
99047
|
|
|
@@ -99089,7 +99125,7 @@
|
|
|
99089
99125
|
|
|
99090
99126
|
var lua_api_promise = "\nlocal handle = require 'engine/handle'\nlocal _internal = require 'engine/_internal'\nlocal Console = require 'engine/console'\n\n---@class Promise\nlocal Promise = {}\nPromise.__index = Promise\n\n-- Put the class in the global scope\n_G.Promise = Promise\n\nlocal _managedPromises = {}\nlocal _handleMap = {}\n\nfunction Promise:__init()\n _managedPromises = {}\n _handleMap = {}\nend\n\nfunction Promise.new(self, executorOrHandle)\n\n if self ~= Promise then\n executorOrHandle = self\n end\n\n self = Class.__setmetatable({}, Promise)\n self._type = \"Promise\"\n self._isPromise = true\n self.status = \"pending\"\n self.value = nil\n self.reason = nil\n self.onFulfilled = {}\n self.onRejected = {}\n\n table.insert(_managedPromises, self)\n\n if type(executorOrHandle) == \"string\" then\n self._handle = executorOrHandle\n _handleMap[self._handle] = self\n return self\n elseif type(executorOrHandle) ~= \"function\" then\n error(\"Promise.new() expects a function or a string handle\")\n end\n\n local function resolve(value)\n if self.status ~= \"pending\" then\n return\n end\n\n if value == self then\n return reject(\"Cannot resolve promise with itself\")\n end\n\n -- If value is a Promise, adopt its state\n if type(value) == \"table\" and value._isPromise then\n value:next(resolve, reject)\n return\n end\n\n self.status = \"fulfilled\"\n self.value = value\n coroutine.yield({ __engine_call=true }, \"promiseDone\", self._handle)\n end\n\n local function reject(reason)\n if self.status ~= \"pending\" then return end\n self.status = \"rejected\"\n self.reason = reason\n coroutine.yield({ __engine_call=true }, \"promiseDone\", self._handle)\n end\n\n self._handle = _internal.randomHex8()\n _handleMap[self._handle] = self\n\n local co = coroutine.create(function()\n executorOrHandle(resolve, reject)\n end)\n coroutine.yield({ __engine_call=true }, \"promise\", self._handle, co)\n\n return self\nend\n\nfunction Promise._processQueue()\n local processed = 0\n\n repeat\n processed = 0\n local i = 1\n while i <= #_managedPromises do\n local promise = _managedPromises[i]\n\n if promise == nil then\n table.remove(_managedPromises, i)\n elseif promise.status == \"fulfilled\" then\n for _, callback in ipairs(promise.onFulfilled) do\n callback(promise.value)\n end\n if promise._handle then _handleMap[promise._handle] = nil end\n table.remove(_managedPromises, i) -- removes and shifts\n processed = processed + 1\n elseif promise.status == \"rejected\" then\n local caught = false\n for _, callback in ipairs(promise.onRejected) do\n callback(promise.reason)\n caught = true\n end\n if not caught then\n Console.error(\"Uncaught rejection! -> \" .. promise.reason);\n end\n if promise._handle then _handleMap[promise._handle] = nil end\n table.remove(_managedPromises, i)\n processed = processed + 1\n else\n i = i + 1\n end\n end\n until processed == 0\nend\n\nfunction Promise:next(onFulfilled, onRejected)\n return Promise.new(function(resolve, reject)\n local function handleFulfilled(value)\n if type(onFulfilled) == \"function\" then\n local ok, result = pcall(onFulfilled, value)\n if ok then\n if type(result) == \"table\" and result._isPromise then\n result:next(resolve, reject)\n else\n resolve(result)\n end\n else\n reject(result)\n end\n else\n resolve(value)\n end\n end\n\n local function handleRejected(reason)\n if type(onRejected) == \"function\" then\n local ok, result = pcall(onRejected, reason)\n if ok then\n if type(result) == \"table\" and result._isPromise then\n result:next(resolve, reject)\n else\n resolve(result)\n end\n else\n reject(result)\n end\n else\n reject(reason)\n end\n end\n\n if self.status == \"fulfilled\" then\n handleFulfilled(self.value)\n elseif self.status == \"rejected\" then\n handleRejected(self.reason)\n else\n table.insert(self.onFulfilled, handleFulfilled)\n table.insert(self.onRejected, handleRejected)\n end\n end)\nend\n\nfunction Promise:catch(onRejected)\n return self:next(nil, onRejected)\nend\n\nfunction Promise.all(self, promises)\n\n if self ~= Promise then\n promises = self\n end\n\n return Promise.new(function(resolve, reject)\n local results = {}\n local remaining = #promises\n\n for i, p in ipairs(promises) do\n p:next(function(value)\n results[i] = value\n remaining = remaining - 1\n if remaining == 0 then\n resolve(results)\n end\n end, function(err)\n reject(err)\n end)\n end\n\n if remaining == 0 then\n resolve(table.unpack(results))\n end\n end)\nend\n\n-- Engine calls this to resolve or reject promises externally\n-- res = { handle = \"0xABC\", type = \"resolved\" or \"rejected\", value = ... }\nfunction Promise._externalResult(res)\n local promise = _handleMap[res._handle]\n if not promise or promise.status ~= \"pending\" then return end\n\n if res.type == \"resolved\" then\n if type(res.value) == 'table' and res.value._isHandle then\n res.value = handle.createObject(res.value)\n end\n promise.status = \"fulfilled\"\n promise.value = res.value\n\n elseif res.type == \"rejected\" then\n promise.status = \"rejected\"\n promise.reason = res.error\n end\n\n Promise._processQueue()\n\nend\n\nfunction Promise.awaitAll(self, promises)\n if self ~= Promise then\n promises = self\n end\n\n return await(Promise.all(promises))\nend\n\nfunction Promise:await()\n return await(self)\nend\n\nfunction Promise._debugStats()\n local handleCount = 0\n for _ in pairs(_handleMap) do\n handleCount = handleCount + 1\n end\n\n local pendingCount = 0\n local fulfilledCount = 0\n local rejectedCount = 0\n for i = 1, #_managedPromises do\n local p = _managedPromises[i]\n if p then\n if p.status == \"pending\" then\n pendingCount = pendingCount + 1\n elseif p.status == \"fulfilled\" then\n fulfilledCount = fulfilledCount + 1\n elseif p.status == \"rejected\" then\n rejectedCount = rejectedCount + 1\n end\n end\n end\n\n return {\n managedCount = #_managedPromises,\n pendingCount = pendingCount,\n fulfilledCount = fulfilledCount,\n rejectedCount = rejectedCount,\n handleCount = handleCount\n }\nend\n\nreturn Promise\n";
|
|
99091
99127
|
|
|
99092
|
-
var lua_api_property = "\nlocal Class = require('engine/class')\nlocal Tools = require('engine/tools')\n\nlocal Property = Class.new()\n\n-- Put the class in the global scope\n_G.Property = Property\n\nProperty.String = \"string\"\nProperty.Number = \"number\"\nProperty.Bool = \"bool\"\nProperty.Boolean = \"bool\"\nProperty.Node = \"node\"\nProperty.Separator = \"separator\"\n\nProperty.Datatypes = {
|
|
99128
|
+
var lua_api_property = "\nlocal Class = require('engine/class')\nlocal Tools = require('engine/tools')\n\nlocal Property = Class.new()\n\n-- Put the class in the global scope\n_G.Property = Property\n\nProperty.String = \"string\"\nProperty.Number = \"number\"\nProperty.Bool = \"bool\"\nProperty.Boolean = \"bool\"\nProperty.Node = \"node\"\nProperty.Link = \"link\"\nProperty.Separator = \"separator\"\nProperty.NumberArray = \"numberarray\"\nProperty.StringArray = \"stringarray\"\nProperty.BoolArray = \"boolarray\"\nProperty.BooleanArray = \"boolarray\"\nProperty.NodeArray = \"nodearray\"\nProperty.LinkArray = \"linkarray\"\n\nProperty.Datatypes = {\n Property.String, Property.Number, Property.Bool,\n Property.Node, Property.Link, Property.Separator,\n Property.NumberArray, Property.StringArray, Property.BoolArray,\n Property.NodeArray, Property.LinkArray,\n}\n\n--- Hook for the Class to call when a new object is created\n---@param datatype string type of property\n---@param value any initial value of the property\n---@param order number a number used for odering the properties\n---@param options table options for the property\n---@param options.info string an info text that can be displayed as tooltip in the editor UI\n---@param options.minValue number a minimum possible value for the property\n---@param options.maxValue number a maximum possible value for the property\n---@param options.conditions table a conditions object to determine, if that field should be visible in the UI\n---@param options.collapsed boolean when true, separator sections start collapsed in the editor\n---@param options.allowedTypes string[] when set on Link properties, restricts which item types can be linked\n---@private\nfunction Property:__new(datatype, value, order, options)\n\n if not Tools.isValueInTable(Property.Datatypes, datatype) then\n error(\"Invalid datatype for property: \" .. tostring(datatype));\n end\n\n options = options or {}\n\n self._isProperty = true\n self._type = \"Property\"\n self.datatype = datatype\n self.value = value\n self.order = order or 0\n self.info = options.info\n self.minValue = options.minValue\n self.maxValue = options.maxValue\n self.conditions = options.conditions\n self.collapsed = options.collapsed\n self.allowedTypes = options.allowedTypes\nend\n\n--- Set the value of the property\n---@param value any value of the property\nfunction Property:set(value)\n self.value = value\nend\n\n--- Get the value of the property\n---@return any value of the property\nfunction Property:get()\n return self.value\nend\n\n--- If the property has a value of type Node, this will call behaviour() on the node and return its value.\n--- Otherwise it will return nil\n---@param scriptName string name of the script item\n---@return Behaviour the behaviour if found or nil\nfunction Property:behaviour(scriptName)\n if self.datatype ~= Property.Node or not self.value then\n return nil\n end\n\n return self.value:behaviour(scriptName)\nend\n\n--- If the property has a value of type Node, this will call getEntityByScriptName() on the node and return its value.\n--- Otherwise it will return nil\n---@deprecated\n---@param scriptName string name of the script item\n---@return Behaviour the behaviour if found or nil\nfunction Property:entity(scriptName)\n if self.datatype ~= Property.Node or not self.value then\n return nil\n end\n\n return self.value:behaviour(scriptName)\nend\n\nreturn Property\n";
|
|
99093
99129
|
|
|
99094
99130
|
var lua_api_renderer = "\nlocal _internal = require('engine/_internal');\nlocal handle = require 'engine/handle'\n\n--- @module renderer\nlocal renderer = {}\n\nlocal _data = {}\n\nfunction renderer.__setData(data)\n _data = data;\nend\n\n--- Get width of the output in pixels\n---@return number width\nfunction renderer.getWidth()\n return _data.width or 0\nend\n\n--- Get height of the output in pixels\n---@return number height\nfunction renderer.getHeight()\n return _data.height or 0\nend\n\n---Sets a uniform value inside a background shader\n---@param name string\n---@param value string\nfunction renderer.setBackgroundShaderUniform(name, value)\n if value == nil then\n return\n end\n local valueType = 'float';\n if type(value) == 'object' then\n valueType = value._type\n end\n _internal.sendMessage('renderer.setBackgroundShaderUniform', { name=name, value=value, type=valueType })\nend\n\n---Tests which objects are at the specified pixel position on screen\n---@param camera Camera the camera to use. If nil, the main camera of the scene will be used. if that does not exist, the first found camera will be used. If no camera exists at all, the function will throw an error\n---@param x number x position\n---@param y number y position\n---@param findAll boolean set to true, to get all objects at the position, otherwise only the first is returned\n---@return table list of intersections with the ray if findAll is true or a single result or nil if nothing was found.\nfunction renderer.raycast(camera, x, y, findAll)\n local results = _internal.sendMessage('renderer.raycast', { camera=camera, x=x, y=y, findAll=findAll })\n if results then\n if findAll then\n for k, v in pairs(results) do\n v.object = handle.createObject(v.object)\n end\n else\n results.object = handle.createObject(results.object)\n end\n end\n return results;\nend\n\nreturn renderer\n";
|
|
99095
99131
|
|
|
@@ -100315,7 +100351,16 @@
|
|
|
100315
100351
|
// TODO!
|
|
100316
100352
|
}
|
|
100317
100353
|
findById(params) {
|
|
100318
|
-
|
|
100354
|
+
const id = params.id;
|
|
100355
|
+
if (!id)
|
|
100356
|
+
return null;
|
|
100357
|
+
const itemInstance = this.loadingManager.get(id, this.refId);
|
|
100358
|
+
if (!itemInstance) {
|
|
100359
|
+
console.warn(`Item.findById: item ${id} is not loaded yet`);
|
|
100360
|
+
return null;
|
|
100361
|
+
}
|
|
100362
|
+
this._addLoadedItemInstance(itemInstance);
|
|
100363
|
+
return this.runtime.makeObjectHandle(itemInstance);
|
|
100319
100364
|
}
|
|
100320
100365
|
getId(params) {
|
|
100321
100366
|
return this.runtime.getObjectOfType(params.obj, Item)?.getId();
|
|
@@ -104735,8 +104780,16 @@
|
|
|
104735
104780
|
let payload;
|
|
104736
104781
|
if (entry.type === "String" && key === "node")
|
|
104737
104782
|
payload = this.packMessage({ scriptName: scriptItemName, value: value, scriptId: scriptId });
|
|
104783
|
+
else if (entry.type === "Link")
|
|
104784
|
+
payload = await this._packLinkFieldValue(value, scriptRunner.getReferenceId());
|
|
104785
|
+
else if (entry.type === "LinkArray")
|
|
104786
|
+
payload = await this._packLinkArrayFieldValue(value, scriptRunner.getReferenceId());
|
|
104787
|
+
else if (entry.type === "NodeArray")
|
|
104788
|
+
payload = this.packMessage(Array.isArray(value) ? value : []);
|
|
104738
104789
|
else
|
|
104739
104790
|
payload = this.packMessage(value);
|
|
104791
|
+
if (!payload)
|
|
104792
|
+
continue;
|
|
104740
104793
|
const funcName = `__set_object_${key}`;
|
|
104741
104794
|
if (this.functionExists(scriptId, funcName))
|
|
104742
104795
|
await this.callFunctionWithObject(scriptId, funcName, payload);
|
|
@@ -104748,11 +104801,55 @@
|
|
|
104748
104801
|
}
|
|
104749
104802
|
}
|
|
104750
104803
|
}
|
|
104804
|
+
async _resolveLinkHandle(value, referenceId) {
|
|
104805
|
+
let preparedItem;
|
|
104806
|
+
if (typeof value === 'string') {
|
|
104807
|
+
preparedItem = await this.itemRepo.loadItem(value, { recursive: true });
|
|
104808
|
+
}
|
|
104809
|
+
else if (value && value._id) {
|
|
104810
|
+
if (value.type)
|
|
104811
|
+
preparedItem = value;
|
|
104812
|
+
else
|
|
104813
|
+
preparedItem = await this.itemRepo.loadItem(value._id, { recursive: true });
|
|
104814
|
+
}
|
|
104815
|
+
else {
|
|
104816
|
+
return null;
|
|
104817
|
+
}
|
|
104818
|
+
if (!preparedItem)
|
|
104819
|
+
return null;
|
|
104820
|
+
const loadingManager = this.engine.loadingManager;
|
|
104821
|
+
const ItemType = loadingManager.typeNameToType(preparedItem.type);
|
|
104822
|
+
let itemInstance = loadingManager.get(preparedItem._id, referenceId);
|
|
104823
|
+
if (!itemInstance)
|
|
104824
|
+
itemInstance = await loadingManager.load(referenceId, preparedItem, ItemType, { waitUntilFinished: true });
|
|
104825
|
+
if (!itemInstance)
|
|
104826
|
+
return null;
|
|
104827
|
+
return this.scriptRuntime.makeObjectHandle(itemInstance);
|
|
104828
|
+
}
|
|
104829
|
+
async _packLinkFieldValue(value, referenceId) {
|
|
104830
|
+
const handle = await this._resolveLinkHandle(value, referenceId);
|
|
104831
|
+
return handle ? this.packMessage(handle) : null;
|
|
104832
|
+
}
|
|
104833
|
+
async _packLinkArrayFieldValue(values, referenceId) {
|
|
104834
|
+
if (!Array.isArray(values))
|
|
104835
|
+
return null;
|
|
104836
|
+
const handles = [];
|
|
104837
|
+
for (const value of values) {
|
|
104838
|
+
if (value == null)
|
|
104839
|
+
continue;
|
|
104840
|
+
const handle = await this._resolveLinkHandle(value, referenceId);
|
|
104841
|
+
if (handle)
|
|
104842
|
+
handles.push(handle);
|
|
104843
|
+
}
|
|
104844
|
+
return this.packMessage(handles);
|
|
104845
|
+
}
|
|
104751
104846
|
_prepareCode(code, scriptItemId, injectedFields = undefined) {
|
|
104752
104847
|
let varCode = "";
|
|
104753
104848
|
let injectedVarsNumLines = 0;
|
|
104754
104849
|
if (injectedFields) {
|
|
104755
104850
|
for (const field of injectedFields) {
|
|
104851
|
+
if (field.type === 'separator')
|
|
104852
|
+
continue;
|
|
104756
104853
|
switch (field.type) {
|
|
104757
104854
|
case 'node':
|
|
104758
104855
|
if (field.name === 'node')
|
|
@@ -104761,8 +104858,26 @@
|
|
|
104761
104858
|
varCode += `function __set_object_${field.name}(object, data, len) if type(object.${field.name}) == 'table' then object.${field.name}:set(__api_sceneobject:findById(__api_internal.fetchAndUnpack(data, len))) else object.${field.name} = __api_sceneobject:findById(__api_internal.fetchAndUnpack(data, len)) end end\n`;
|
|
104762
104859
|
injectedVarsNumLines++;
|
|
104763
104860
|
break;
|
|
104861
|
+
case 'link':
|
|
104862
|
+
varCode += `function __set_object_${field.name}(object, data, len) local __handle = require('engine/handle'); local item = __handle.createObject(__api_internal.fetchAndUnpack(data, len)); if type(object.${field.name}) == 'table' and object.${field.name}.set then object.${field.name}:set(item) else object.${field.name} = item end end\n`;
|
|
104863
|
+
injectedVarsNumLines++;
|
|
104864
|
+
break;
|
|
104865
|
+
case 'numberarray':
|
|
104866
|
+
case 'stringarray':
|
|
104867
|
+
case 'boolarray':
|
|
104868
|
+
varCode += `function __set_object_${field.name}(object, data, len) object.${field.name} = __api_internal.fetchAndUnpack(data, len) end\n`;
|
|
104869
|
+
injectedVarsNumLines++;
|
|
104870
|
+
break;
|
|
104871
|
+
case 'nodearray':
|
|
104872
|
+
varCode += `function __set_object_${field.name}(object, data, len) local ids = __api_internal.fetchAndUnpack(data, len); local nodes = {}; for i, id in ipairs(ids or {}) do nodes[i] = __api_sceneobject:findById(id) end; object.${field.name} = nodes end\n`;
|
|
104873
|
+
injectedVarsNumLines++;
|
|
104874
|
+
break;
|
|
104875
|
+
case 'linkarray':
|
|
104876
|
+
varCode += `function __set_object_${field.name}(object, data, len) local __handle = require('engine/handle'); local handles = __api_internal.fetchAndUnpack(data, len); local items = {}; for i, h in ipairs(handles or {}) do items[i] = __handle.createObject(h) end; object.${field.name} = items end\n`;
|
|
104877
|
+
injectedVarsNumLines++;
|
|
104878
|
+
break;
|
|
104764
104879
|
default:
|
|
104765
|
-
varCode += `function __set_object_${field.name}(object, data, len) if type(object.${field.name}) == 'table' then object.${field.name}:set(__api_internal.fetchAndUnpack(data, len)) else object.${field.name} = __api_internal.fetchAndUnpack(data, len) end end\n`;
|
|
104880
|
+
varCode += `function __set_object_${field.name}(object, data, len) if type(object.${field.name}) == 'table' and object.${field.name}.set then object.${field.name}:set(__api_internal.fetchAndUnpack(data, len)) else object.${field.name} = __api_internal.fetchAndUnpack(data, len) end end\n`;
|
|
104766
104881
|
injectedVarsNumLines++;
|
|
104767
104882
|
break;
|
|
104768
104883
|
}
|
package/dist/player.zip
CHANGED
|
Binary file
|
|
@@ -126,6 +126,9 @@ export declare class ScriptEngine {
|
|
|
126
126
|
_importLib(scriptItemId: any, path: any, scriptItemName: any): Promise<any>;
|
|
127
127
|
_disposeBehaviour(scriptId: string): Promise<void>;
|
|
128
128
|
_injectValues(scriptId: string, scriptItemName: string, scriptRunner: ScriptRunner): Promise<void>;
|
|
129
|
+
_resolveLinkHandle(value: any, referenceId: string): Promise<any>;
|
|
130
|
+
_packLinkFieldValue(value: any, referenceId: string): Promise<Uint8Array<ArrayBufferLike> | null>;
|
|
131
|
+
_packLinkArrayFieldValue(values: any, referenceId: string): Promise<Uint8Array<ArrayBufferLike> | null>;
|
|
129
132
|
_prepareCode(code: string, scriptItemId: string, injectedFields?: any[] | undefined): {
|
|
130
133
|
preparedCode: string;
|
|
131
134
|
breakpointsOffset: number;
|
|
@@ -8,6 +8,7 @@ export declare class ScriptRunner {
|
|
|
8
8
|
scriptItem: ScriptItem | undefined;
|
|
9
9
|
scriptId: string | undefined;
|
|
10
10
|
injectedFieldsMap: any;
|
|
11
|
+
referenceId: string | undefined;
|
|
11
12
|
callDepth: number;
|
|
12
13
|
callMutex: Mutex;
|
|
13
14
|
enableMutex: Mutex;
|
|
@@ -22,6 +23,8 @@ export declare class ScriptRunner {
|
|
|
22
23
|
getScriptItemName(): string;
|
|
23
24
|
getCode(): string | null;
|
|
24
25
|
setNode(node: any): void;
|
|
26
|
+
setReferenceId(referenceId: string): void;
|
|
27
|
+
getReferenceId(): string;
|
|
25
28
|
setInjectedFields(fields: any): void;
|
|
26
29
|
getInjectedFields(): any;
|
|
27
30
|
loadCode(script: ScriptItem): Promise<string>;
|
|
@@ -3,7 +3,7 @@ import { ScriptRuntime } from "../ScriptRuntime";
|
|
|
3
3
|
export declare class RtItem extends RtBase {
|
|
4
4
|
constructor(runtime: ScriptRuntime);
|
|
5
5
|
findByName(params: RuntimeParams): void;
|
|
6
|
-
findById(params: RuntimeParams):
|
|
6
|
+
findById(params: RuntimeParams): any;
|
|
7
7
|
getId(params: RuntimeParams): string | undefined;
|
|
8
8
|
getName(params: RuntimeParams): any;
|
|
9
9
|
getType(params: RuntimeParams): string | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luminocity/lemonate-engine",
|
|
3
|
-
"version": "26.6.
|
|
3
|
+
"version": "26.6.3",
|
|
4
4
|
"productName": "Lemonate Engine",
|
|
5
5
|
"repository": "https://codeberg.org/Luminocity/lemonate-engine",
|
|
6
6
|
"homepage": "https://lemonate.io",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@gltf-transform/core": "^4.0.1",
|
|
45
45
|
"@gltf-transform/extensions": "^4.0.1",
|
|
46
|
-
"@luminocity/lemonate-gateway": "8.
|
|
46
|
+
"@luminocity/lemonate-gateway": "8.4.0",
|
|
47
47
|
"@msgpack/msgpack": "3.1.1",
|
|
48
48
|
"@recast-navigation/three": "^0.42.0",
|
|
49
49
|
"@sparkjsdev/spark": "^0.1.10",
|