Difference between revisions of "Module:FindId"
Jump to navigation
Jump to search
m (Remove '.' from names) |
Demcookies (talk | contribs) (Fix hyphenateName function to include commas (fixes e.g. Ice, Ice, Ice)) |
||
| (One intermediate revision by one other user not shown) | |||
| Line 5: | Line 5: | ||
enchantment = 'Module:Enchantment_ids/data', | enchantment = 'Module:Enchantment_ids/data', | ||
item = 'Module:Item_ids/data', | item = 'Module:Item_ids/data', | ||
| − | location = 'Module: | + | location = 'Module:Location_ids/data', |
monster = 'Module:Monster_ids/data' | monster = 'Module:Monster_ids/data' | ||
} | } | ||
| Line 22: | Line 22: | ||
local function hyphenateName(name) | local function hyphenateName(name) | ||
local lName = name:lower() | local lName = name:lower() | ||
| − | return lName:gsub('^%s*(.-)%s*$', '%1'):gsub("'", ""):gsub("%-%s" or "%-", ""):gsub("%s+", "_ | + | return lName:gsub('^%s*(.-)%s*$', '%1'):gsub("[',%-%.]", ""):gsub("%-%s" or "%-", ""):gsub("%s+", "_") |
end | end | ||
Latest revision as of 14:46, 30 May 2025
local p = {}
local idListNames = {
ability = 'Module:Ability_ids/data',
enchantment = 'Module:Enchantment_ids/data',
item = 'Module:Item_ids/data',
location = 'Module:Location_ids/data',
monster = 'Module:Monster_ids/data'
}
local loadedIdLists = {}
function p.loadData(listType)
local listName = idListNames[listType]
if loadedIdLists[listName] == nil then
loadedIdLists[listName] = mw.loadData(listName)
end
return loadedIdLists[listName]
end
local function hyphenateName(name)
local lName = name:lower()
return lName:gsub('^%s*(.-)%s*$', '%1'):gsub("[',%-%.]", ""):gsub("%-%s" or "%-", ""):gsub("%s+", "_")
end
local function findId(hName, idType)
local idList = p.loadData(idType)
local id = idList[hName]
if id then
return id
end
return "id not found"
end
function p.findId(frame)
local args = frame:getParent().args
return p._item(args)
end
function p._findId(args)
local hName = hyphenateName(args[1])
local idType = args[2]
local id
id = findId(hName, idType)
return id
end
return p