Editing Module:Sandbox/Monster Domosed

Warning: You are not logged in. Once you make an edit, a temporary account will be created for you. Learn more. Log in or create an account to continue receiving notifications after this account expires, and to access other features.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision Your text
Line 2: Line 2:


local data = mw.loadJsonData("Data:ItemData.json")
local data = mw.loadJsonData("Data:ItemData.json")
local ability_data = mw.loadJsonData("Data:AbilityCards.json")


--------------------------------------------------
--------------------------------------------------
Line 25: Line 24:
end
end


-- Returns numeric cost or nil if invalid
local function get_cost(item)
local function get_cost(item)
local cost = tonumber(item["Cost"])
return tonumber(item["Cost"]) or math.huge
if cost == nil then
return nil
end
return cost
end
end


Line 42: Line 36:
--------------------------------------------------
--------------------------------------------------


-- Returns a sorted Lua array of item tables
local function get_sorted_items()
local function get_sorted_items()
local items = {}
local items = {}


for _, item in pairs(data) do
for _, item in pairs(data) do
-- Exclude items with null / missing / non-numeric cost
if is_enabled(item) then
local cost = get_cost(item)
 
if is_enabled(item) and cost ~= nil then
table.insert(items, item)
table.insert(items, item)
end
end
Line 55: Line 47:


table.sort(items, function(a, b)
table.sort(items, function(a, b)
-- 1. Sort by type
local type_a = get_type_rank(a)
local type_a = get_type_rank(a)
local type_b = get_type_rank(b)
local type_b = get_type_rank(b)
-- 1. Sort by type
if type_a ~= type_b then
if type_a ~= type_b then
return type_a < type_b
return type_a < type_b
Line 65: Line 58:
local cost_a = get_cost(a)
local cost_a = get_cost(a)
local cost_b = get_cost(b)
local cost_b = get_cost(b)
if cost_a ~= cost_b then
if cost_a ~= cost_b then
return cost_a < cost_b
return cost_a < cost_b
Line 80: Line 74:
--------------------------------------------------
--------------------------------------------------


-- For other Lua modules
function p._get_enabled_items_sorted()
function p._get_enabled_items_sorted()
return get_sorted_items()
return get_sorted_items()
Line 93: Line 88:


return names
return names
end
--------------------------------------------------
-- Abilities
--------------------------------------------------
local function get_all_abilities()
local abilities = {}
for _, hero in pairs(ability_data) do
if type(hero) == "table" then
for key, ability in pairs(hero) do
if tonumber(key) ~= nil
and type(ability) == "table"
and ability["Name"] ~= nil
then
table.insert(abilities, {
Index = tonumber(key),
Name = ability["Name"]
})
end
end
end
end
return abilities
end
local function get_formatted_abilities(frame)
local abilities = get_all_abilities()
local output = {}
for _, ability in ipairs(abilities) do
table.insert(output, frame:expandTemplate{
title = "AbilityIcon",
args = {
ability["Name"]
}
})
end
return output
end
end


Line 141: Line 94:
--------------------------------------------------
--------------------------------------------------


-- {{#invoke:Sandbox/Monster Domosed|get_list}}
-- {{#invoke:Monster Domosed|get_list}}
-- Newline-separated, sorted
function p.get_list(frame)
function p.get_list(frame)
return table.concat(p._get_enabled_item_names_sorted(), "\n")
local names = p._get_enabled_item_names_sorted()
return table.concat(names, "\n")
end
end


-- {{#invoke:Sandbox/Monster Domosed|get_csv}}
-- {{#invoke:Monster Domosed|get_csv}}
-- Comma-separated, sorted (Python-friendly)
function p.get_csv(frame)
function p.get_csv(frame)
return table.concat(p._get_enabled_item_names_sorted(), ",")
local names = p._get_enabled_item_names_sorted()
return table.concat(names, ",")
end
end


-- {{#invoke:Sandbox/Monster Domosed|get_count}}
-- {{#invoke:Monster Domosed|get_count}}
function p.get_count(frame)
function p.get_count(frame)
return tostring(#p._get_enabled_item_names_sorted())
return tostring(#p._get_enabled_item_names_sorted())
end
-- {{#invoke:Sandbox/Monster Domosed|get_abilities}}
function p.get_abilities(frame)
return table.concat(get_formatted_abilities(frame), "\n")
end
-- {{#invoke:Sandbox/Monster Domosed|get_abilities_csv}}
function p.get_abilities_csv(frame)
return table.concat(get_formatted_abilities(frame), ",")
end
-- {{#invoke:Sandbox/Monster Domosed|get_ability_count}}
function p.get_ability_count(frame)
return tostring(#get_all_abilities())
end
end


return p
return p
Please note that all contributions to The Deadlock Wiki are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Deadlock:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template

Page included on this page: