Modulo:Videogioco: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Moroboshi (discussione | contributi)
fix tabella
Moroboshi (discussione | contributi)
fix ordine categorie e inserimento in categoria di errore se valorizzato args e args1
Riga 34:
new_s = mw.ustring.gsub(new_s, " ", " ")
return new_s
end
 
-- ========================================================================
-- Appende una tabella a un'altra tabella
-- ========================================================================
local function append_table(t1, t2)
for cat,_,el in pairsipairs(cat_dictt2) do
t1[#t1+1] = el
end
end
 
Riga 45 ⟶ 54:
local function categorizza(args, base_name, table_name, lowercase, must_exist)
local categories = {}
local name_value = args[base_name] or args[base_name .. '"1'"]
if name_value then
if lowercase then name_value = mw.ustring.lower(name_value) end
local category = get_category(name_value, table_name)
if category then
categories[category#categories+1] = truecategory
elseif must_exist then
errors_msg[#errors_msg+1] = 'Valore non valido per ' .. base_name
end
localif index#categories => 20 then
while true do local index = 2
while true do
name_value = args[base_name .. tostring(index)]
if name_value then
if lowercase then name_value = mw.ustring.lower(name_value) end
local category = get_category(name_value, table_name)
if category then
categories[category#categories+1] = truecategory
elseif must_exist then
errors_msg[#errors_msg+1] = 'Valore non valido per ' .. base_name .. tostring(index)
break end
index = index + 1else
break
end
else index = index + 1
break
end
index = index + 1
end
end
if args[base_name] and args[base_name .. "1"] then
errors_msg[#errors_msg+1] = 'Inserire solo uno di ' .. base_name .. ' e ' .. base_name .. tostring(index)
end
return categories
Riga 82 ⟶ 96:
if current_namespace ~= 0 and not frame.args.debug then return '' end
local categories = {}
append_table(categories.pubblicazione =, categorizza(args, 'pubblicazionesviluppo', 'aziende'))
local anomaly = {}
append_table(categories.sviluppo =, categorizza(args, 'sviluppopubblicazione', 'aziende'))
--if true then return mw.text.jsonEncode(categories) end
categories.pubblicazione = categorizza(args, 'pubblicazione', 'aziende')
append_table(categories.serie =, categorizza(args, 'serie', 'serie'))
if args.anno then
categories.anno = {}
local anno = tonumber(args.anno)
if anno == nil then
errors_msg[#errors_msg+1] = 'anno di pubblicazione non valido'
elseif anno <= 1970 then
categories.anno[#categories+1] = 'Videogiochi fino al 1970'] = true
else
categories.anno[#categories+1] = 'Videogiochi del ' .. args.anno] = true
end
end
categories.tema = categorizza(args, 'tema', 'tema', true)
categories.genere = categorizza(args, 'genere', 'genere', true, true)
categories.piattaforme = categorizza(args, 'piattaforma', 'piattaforma', false, true)
categories.distribuzione = categorizza(args, 'distribuzionedigitale', 'distribuzione', false, true)
local cat_dict = {}
for cat_name,cat_list in pairs(categories) do
for cat,_ in pairs(cat_list) do
cat_dict[cat] = true
end
end
append_table(categories.genere =, categorizza(args, 'genere', 'genere', true, true))
local cat_list = {}
append_table(categories.tema =, categorizza(args, 'tema', 'tema', true))
for cat,_ in pairs(cat_dict) do
append_table(categories.piattaforme =, categorizza(args, 'piattaforma', 'piattaforma', false, true))
cat_list[#cat_list+1] = '[[Categoria:' .. cat .. ']]'
append_table(categories.distribuzione =, categorizza(args, 'distribuzionedigitale', 'distribuzione', false, true))
for cat_nameindex,cat_listcat in pairsipairs(categories) do
cat_listcategories[#cat_list+1index] = '[[Categoria:' .. cat .. ']]'
end
if #errors_msg>0 then
cat_listcategories[#cat_listcategories+1] = '[[Categoria:Errori di compilazione del template Videogioco]]'
end
if #cat_listcategories == 0 then return '' end
return frame.args.debug and mw.text.nowiki(table.concat(cat_listcategories)) or table.concat(cat_listcategories)
end
----------------------------------------------------------------------------------