Module:GameData: Difference between revisionsGive feedback
Jump to navigation
Jump to search
Refactor get_prop: use ResourceLookup type for direct routing, unified find_entity, clearer error messages (with help from vergir-bot LLM) |
Remove redundant caching wrappers, mw.loadJsonData already caches (with help from vergir-bot LLM) |
||
| Line 78: | Line 78: | ||
-- Returns raw values for use in templates and expressions. | -- Returns raw values for use in templates and expressions. | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
-- Find an entity by display name or internal key. | -- Find an entity by display name or internal key. | ||
| Line 103: | Line 83: | ||
-- Returns (entity_record, type_string) or (nil, nil). | -- Returns (entity_record, type_string) or (nil, nil). | ||
local function find_entity(identifier) | local function find_entity(identifier) | ||
local resource = | local resource = mw.loadJsonData("Data:ResourceLookup.json")[identifier:lower()] | ||
if resource then | if resource then | ||
local data | local data | ||
if resource.type == "ability" then | if resource.type == "ability" then | ||
data = | data = mw.loadJsonData(p.Dataset.ABILITIES) | ||
elseif resource.type == "hero" then | elseif resource.type == "hero" then | ||
data = | data = mw.loadJsonData(p.Dataset.HEROES) | ||
elseif resource.type == "item" then | elseif resource.type == "item" then | ||
data = | data = mw.loadJsonData(p.Dataset.ITEMS) | ||
end | end | ||
if data and data[resource.key] then | if data and data[resource.key] then | ||
| Line 120: | Line 100: | ||
-- Fallback: try as direct internal key | -- Fallback: try as direct internal key | ||
local datasets = { | local datasets = { | ||
{ | { p.Dataset.ABILITIES, "ability" }, | ||
{ | { p.Dataset.HEROES, "hero" }, | ||
{ | { p.Dataset.ITEMS, "item" }, | ||
} | } | ||
for _, ds in ipairs(datasets) do | for _, ds in ipairs(datasets) do | ||
local data = 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] end | ||
end | end | ||