Module:ID table
From Downtime Wiki
Documentation for this module may be created at Module:ID table/doc
local p = {}
function p.main(frame)
local args = frame:getParent().args
local frameArgs = frame.args
return p._main(args, frameArgs)
end
function p._main(args, frameArgs)
local noCat = args.nocat or frameArgs.nocat
if noCat then
return
end
local edition = args.edition or frameArgs.edition -- "java" or "bedrock"
local displayName = args.displayname
local spriteType = args.spritetype -- "block", "entity", "biome", or "env"
local nameId = args.nameid
local aliasId = args.aliasid
local numericId = args.id
local itemForm = args.itemform or args.itemform2 -- "Identical" if block and entity share the same nameid
local form = args.form -- "block" or "item" id only. unset for both. for bedrock: "block" = no /give command
local fluidTags = args.fluidtags
local blockTags = args.blocktags
local itemTags = args.itemtags
local entityTags = args.entityTags
local translationKey = args.translationkey
local translationType = args.translationtype or spriteType
if form == nil then
form = {'block', 'item'}
end
local smw_sub = {}
local subname = (spriteType or 'ID') .. '_' .. (nameId or displayName)
subname = mw.ustring.lower(clean(subname))
:gsub(" ", "_")
local smw_json = {
['Edition'] = edition,
['Display name'] = displayName,
['Type'] = spriteType,
['Resource location'] = nameId,
['Alias ID'] = aliasId,
['Numeric ID'] = numericId,
['Item form'] = itemForm,
['Form'] = form,
['Fluid tags'] = fluidTags,
['Block tags'] = blockTags,
['Item tags'] = itemTags,
['Entity tags'] = entityTags,
['Translation key'] = translationKey,
['Translation type'] = translationType
}
local smw_sub = {
['Edition'] = clean(edition),
['Display name'] = clean(displayName),
['Resource location'] = clean(nameId),
['Resource location JSON'] = mw.text.jsonEncode(clean(smw_json))
}
mw.smw.subobject(smw_sub, subname)
return
end
function clean(data)
local _data = data
if type(_data) == "table" then
for i, v in pairs(_data) do
_data[i] = clean(v)
end
elseif type(_data) == "string" then
local cleaned = mw.text.split(_data, "&#?%w%w%w%w%w?;")[1]
:gsub("<br>", " ")
:gsub("|", " ")
:gsub("[%[%]<>#]","")
cleaned = mw.text.killMarkers(cleaned)
cleaned = mw.text.nowiki(cleaned)
cleaned = mw.text.trim(cleaned)
return cleaned
end
return _data
end
return p