Module:GameData: Difference between revisionsGive feedback
Jump to navigation
Jump to search
add comment about subabilities |
get_prop: optional third argument for Street Brawl ability values, falling back to base data when unchanged (with help from vergir-bot LLM) |
||
| Line 12: | Line 12: | ||
CONVARS = "Data:Convars.json", | CONVARS = "Data:Convars.json", | ||
} | } | ||
-- Street Brawl ships a partial overlay of ability properties rather than a full | |||
-- dataset, so it is deliberately kept out of p.Dataset: its top-level keys are | |||
-- sections ("ability-changes", "item-buckets"), not entity records, and it is | |||
-- not usable with get_entities. Only get_prop consults it. | |||
local STREET_BRAWL = "Data:StreetBrawlData.json" | |||
-- Returns true if a record represents an active, usable entity. | -- Returns true if a record represents an active, usable entity. | ||
| Line 98: | Line 104: | ||
-- 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) or (nil, nil). | -- Returns (entity_record, type_string, internal_key) or (nil, 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 111: | Line 117: | ||
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, resource.key | ||
end | end | ||
end | end | ||
| Line 123: | Line 129: | ||
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] end | if data[identifier] then return data[identifier], ds[2], identifier end | ||
end | end | ||
return nil, nil | return nil, nil, nil | ||
end | end | ||
| Line 172: | Line 178: | ||
-- {{#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|VARIANT}} | ||
-- 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. | ||
-- The optional VARIANT selects a game mode variant. "Street Brawl" | |||
-- (case and spacing insensitive) returns the value changed for | |||
-- Street Brawl, falling back to the base value when Street Brawl | |||
-- does not change that property. | |||
-- 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 182: | Line 192: | ||
local arg1 = frame.args[1] | local arg1 = frame.args[1] | ||
local arg2 = frame.args[2] | local arg2 = frame.args[2] | ||
local arg3 = frame.args[3] | |||
if not arg1 then return "" end | if not arg1 then return "" end | ||
| Line 200: | Line 211: | ||
if not prop then return "" end | if not prop then return "" end | ||
local entity, etype = find_entity(name) | local entity, etype, ekey = 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 | |||
-- Street Brawl changes a handful of ability properties. The overlay lists | |||
-- only what changed, so a miss here just means "unchanged" and the base | |||
-- record answers instead. That includes the empty string resolve_prop | |||
-- returns for a table with no Value field: the overlay records are partial, | |||
-- so an overridden table often holds nothing but a nested Scale. | |||
if arg3 and arg3 ~= "" then | |||
local mode = mw.ustring.lower(mw.text.trim(arg3)) | |||
mode = mode:gsub("%s+", "") | |||
if mode ~= "streetbrawl" then | |||
return '<span style="color:red;">Unknown variant: ' .. arg3 .. '</span>' | |||
end | |||
if etype == "ability" then | |||
local changed = mw.loadJsonData(STREET_BRAWL)["ability-changes"][ekey] | |||
if changed then | |||
local value = resolve_prop(changed, prop) | |||
if value ~= nil and value ~= "" then return value end | |||
end | |||
end | |||
end | end | ||