Module:Sandbox/GameTag
Jump to navigation
Jump to search
doc is in Template:Sandbox/GameTag/doc.
[view] [edit] [history] [refresh]The above documentation is transcluded from Module:Sandbox/GameTag/doc.
local p = {}
--local all = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'Module:Sandbox/GameTag/Data.json' } )
local all = mw.loadData("Module:Sandbox/GameTag/data")
local i18n = {
['WrongID'] = "'''Unkown ID or it has no tag'''[[Category:Unknow ID]]",
['WrongTag'] = "'''Unkown Tag'''[[Category:Unkown Tag]]",
['WrongType'] = "'''Unknown tag type[[Category:Unknown tag type]]'''",
['Different Group'] = "'''Wrong Category[[Category:Wrong Category Tag]]'''"
}
function p.main(f)
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
end
--'blocks','items','entity_types','fluids','game_events'
local objtype
if args[1] == 'block' or args[1] == 'blocks' then
objtype='blocks'
end
if args[1] == 'item' or args[1] == 'items' then
objtype='items'
end
if args[1] == 'entity_type' or args[1] == 'entity_types' or args[1] == 'entity'then
objtype='entity_types'
end
if args[1] == 'fluid' or args[1] == 'fluids' then
objtype='fluids'
end
if args[1] == 'game_event' or args[1] == 'game_events' then
objtype='game_events'
end
if not all['tag_ori'][args[1]] and not objtype then
return i18n['WrongType']
end
local outtable = {}
local sptable = {}
local id = ''
local diff = false
local err = ''
local id = string.gsub(string.lower(args[2] or ''),' ','_')
if args['tagpage'] == '1' or args['tagpage'] == 'y' or args['tagpage'] == 'true' then
if all['tag_ori'][objtype][id] then
for i,v in ipairs(all['tag_ori'][objtype][id]) do
if string.find(v,'#') == 1 then
table.insert(outtable,
--[[#blocks flowers|#flowers]]
table.concat({
'[[#',
objtype,
' ',
string.sub(v,12),
'|#',
string.sub(v,12),
']]'
})
)
else
table.insert(outtable,string.sub(v,11))
end
end
else
return i18n['WrongTag']
end
return table.concat(outtable,', ')
else
if string.find(args[2],',') then
sptable=mw.text.split(args[2],',')
id = string.gsub(string.lower(mw.text.trim(sptable[1])),' ','_')
for i,v in ipairs(sptable) do --all['ID'][objtype][id]
v = string.gsub(string.lower(mw.text.trim(sptable[i])),' ','_')
if all['ID'][objtype][id] and all['ID'][objtype][v] then
for i1,v1 in ipairs(all['ID'][objtype][id]) do
if v1 ~= all['ID'][objtype][v][i1] then
diff = diff or true
err = v
end
end
else
return i18n['WrongID'].."'''"..id.."-"..v.."'''"
end
end
if diff then
return i18n['Different Group'].."'''"..err.."'''"
end
end
if all['ID'][objtype][id] then
for i,v in ipairs(all['ID'][objtype][id]) do
table.insert(outtable,v)
end
return table.concat(outtable,',')
else
return i18n['WrongID'].."'''"..id.."'''"
end
end
end
return p