mirror of
https://github.com/Dadido3/noita-mapcap.git
synced 2024-11-22 21:17:33 +00:00
parent
e8c6c8bb8f
commit
40f31011e8
@ -34,12 +34,32 @@ NoitaComponent.__index = NoitaComponent
|
|||||||
-- JSON Implementation --
|
-- JSON Implementation --
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
|
-- Set of component keys that would return an "invalid type" error when called with ComponentGetValue2().
|
||||||
|
-- This is more or less to get around console error spam that otherwise can't be prevented when iterating over component members.
|
||||||
|
-- Only used inside the JSON marshaler, until there is a better solution.
|
||||||
|
local componentValueKeysWithInvalidType = {}
|
||||||
|
|
||||||
---MarshalJSON implements the JSON marshaler interface.
|
---MarshalJSON implements the JSON marshaler interface.
|
||||||
---@return string
|
---@return string
|
||||||
function NoitaComponent:MarshalJSON()
|
function NoitaComponent:MarshalJSON()
|
||||||
|
-- Get list of members, but with correct type (instead of string values).
|
||||||
|
local membersTable = self:GetMembers()
|
||||||
|
local members = {}
|
||||||
|
if membersTable then
|
||||||
|
for k, v in pairs(membersTable) do
|
||||||
|
if not componentValueKeysWithInvalidType[k] then
|
||||||
|
members[k] = self:GetValue(k) -- Try to get value with correct type. Assuming nil is an error, but this is not always the case... meh.
|
||||||
|
end
|
||||||
|
if members[k] == nil then
|
||||||
|
componentValueKeysWithInvalidType[k] = true
|
||||||
|
--members[k] = v -- Fall back to string value of self:GetMembers().
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local resultObject = {
|
local resultObject = {
|
||||||
typeName = self:GetTypeName(),
|
typeName = self:GetTypeName(),
|
||||||
members = self:GetMembers(),
|
members = members,
|
||||||
--objectMembers = component:ObjectGetMembers
|
--objectMembers = component:ObjectGetMembers
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,9 +439,11 @@ end
|
|||||||
|
|
||||||
---Returns one or many values matching the type or subtypes of the requested field in a component subobject.
|
---Returns one or many values matching the type or subtypes of the requested field in a component subobject.
|
||||||
---Reports error and returns nil if the field type is not supported or 'object_name' is not a metaobject.
|
---Reports error and returns nil if the field type is not supported or 'object_name' is not a metaobject.
|
||||||
|
---
|
||||||
|
---Reporting errors means that it spams the stdout with messages, instead of using the lua error handling. Thanks Nolla.
|
||||||
---@param objectName string
|
---@param objectName string
|
||||||
---@param fieldName string
|
---@param fieldName string
|
||||||
---@return any
|
---@return any|nil
|
||||||
function NoitaComponent:ObjectGetValue(objectName, fieldName)
|
function NoitaComponent:ObjectGetValue(objectName, fieldName)
|
||||||
return ComponentObjectGetValue2(self.ID, objectName, fieldName)
|
return ComponentObjectGetValue2(self.ID, objectName, fieldName)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user