Editing Module:GameDataGive feedback
Jump to navigation
Jump to search
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
| Latest revision | Your text | ||
| Line 12: | Line 12: | ||
CONVARS = "Data:Convars.json", | CONVARS = "Data:Convars.json", | ||
} | } | ||
-- Returns true if a record represents an active, usable entity. | -- Returns true if a record represents an active, usable entity. | ||
| Line 214: | Line 208: | ||
-- Find an entity by display name or internal key. | -- Find an entity by display name or internal key. | ||
-- Uses ResourceLookup type field to go directly to the right dataset. | -- Uses ResourceLookup type field to go directly to the right dataset. | ||
-- Returns (entity_record, type_string | -- Returns (entity_record, type_string) or (nil, nil). | ||
local function find_entity(identifier) | local function find_entity(identifier) | ||
local resource = mw.loadJsonData("Data:ResourceLookup.json")[identifier:lower()] | local resource = mw.loadJsonData("Data:ResourceLookup.json")[identifier:lower()] | ||
| Line 227: | Line 221: | ||
end | end | ||
if data and data[resource.key] then | if data and data[resource.key] then | ||
return data[resource.key], resource.type | return data[resource.key], resource.type | ||
end | end | ||
end | end | ||
| Line 239: | Line 233: | ||
for _, ds in ipairs(datasets) do | for _, ds in ipairs(datasets) do | ||
local data = mw.loadJsonData(ds[1]) | local data = mw.loadJsonData(ds[1]) | ||
if data[identifier] then return data[identifier], ds[2] | if data[identifier] then return data[identifier], ds[2] end | ||
end | end | ||
return | return nil, nil | ||
end | end | ||
| Line 288: | Line 282: | ||
-- {{#invoke:GameData|get_prop|...}} | -- {{#invoke:GameData|get_prop|...}} | ||
-- Two modes: | -- Two modes: | ||
-- Entity: {{#invoke:GameData|get_prop|ENTITY_NAME|PROPERTY | -- Entity: {{#invoke:GameData|get_prop|ENTITY_NAME|PROPERTY}} | ||
-- Finds entity via ResourceLookup, returns the raw value (no | -- Finds entity via ResourceLookup, returns the raw value (no | ||
-- formatting). Supports dot notation for nested properties | -- formatting). Supports dot notation for nested properties | ||
-- (e.g. "Scale.Value"); tables with a .Value field are unwrapped. | -- (e.g. "Scale.Value"); tables with a .Value field are unwrapped. | ||
-- Convar: {{#invoke:GameData|get_prop|Convar|CONVAR_NAME}} | -- Convar: {{#invoke:GameData|get_prop|Convar|CONVAR_NAME}} | ||
-- Looks up the convar in Data:Convars.json and returns its value, | -- Looks up the convar in Data:Convars.json and returns its value, | ||
| Line 302: | Line 292: | ||
local arg1 = frame.args[1] | local arg1 = frame.args[1] | ||
local arg2 = frame.args[2] | local arg2 = frame.args[2] | ||
if not arg1 then return "" end | if not arg1 then return "" end | ||
| Line 321: | Line 310: | ||
if not prop then return "" end | if not prop then return "" end | ||
local entity, etype | local entity, etype = find_entity(name) | ||
if not entity then | if not entity then | ||
return '<span style="color:red;">Entity not found: ' .. name .. '</span>' | return '<span style="color:red;">Entity not found: ' .. name .. '</span>' | ||
end | end | ||