Skylords Reborn
Advertisement
Skylords Reborn

Edit documentation

Description

Provides getter functions to extract data from the data module.

See also


local p = {}
local data = mw.loadData('Module:Card/data')

function p.list()
    local keys={}
    local n=0
    
    for k,_ in pairs(data) do
      n=n+1
      keys[n]=k
    end
    table.sort(
        keys,
        function(a, b)
            return a:lower() < b:lower()
        end
    )
    return keys
end

function p.data()
    return data
end

function p.verified_name(n)
    if data[n] then return n end
    if data[n .. " (Fire)"] then return n .. " (Fire)" end
    if data[n .. " (Frost)"] then return n .. " (Frost)" end
    if data[n .. " (Nature)"] then return n .. " (Nature)" end
    if data[n .. " (Shadow)"] then return n .. " (Shadow)" end
    if data[n .. " (Promo)"] then return n .. " (Promo)" end
    error(n .. " not found in Module:CardData/data (same for affinity variants and promo)")
end

function p.exists(cardname)
    return data[cardname] and true or false
end

function p.card(cardname)
    return data[cardname] or nil
end

function p.card_id(cardname)
	return data[cardname] and data[cardname].card_id or nil
end

function p.description(cardname)
    return data[cardname].description or nil
end

function p.starter_card(cardname)
    return data[cardname].starter_card or false
end

function p.temporary_card(cardname)
    return data[cardname].temporary_card or false
end

function p.type(cardname)
    return data[cardname].type or nil
end

function p.gender(cardname)
	return data[cardname].gender or nil
end

function p.edition(cardname)
	if data[cardname] then return data[cardname].edition or nil end
end

function p.editions(cardname)
	local e = {}
	local function c(arr,v) for _,vv in ipairs(arr) do if v==vv then return false end end return true end
	if data[cardname] then e[#e+1] = data[cardname].edition end
	if data[cardname..' (Fire)'] and c(e, data[cardname..' (Fire)'].edition) then e[#e+1] = data[cardname..' (Fire)'].edition end
	if data[cardname..' (Frost)'] and c(e, data[cardname..' (Frost)'].edition) then e[#e+1] = data[cardname..' (Frost)'].edition end
	if data[cardname..' (Nature)'] and c(e, data[cardname..' (Nature)'].edition) then e[#e+1] = data[cardname..' (Nature)'].edition end
	if data[cardname..' (Shadow)'] and c(e, data[cardname..' (Shadow)'].edition) then e[#e+1] = data[cardname..' (Shadow)'].edition end
	if data[cardname..' (Promo)'] and c(e, data[cardname..' (Promo)'].edition) then e[#e+1] = data[cardname..' (Promo)'].edition end
	return e
end

function p.rarity(cardname)
    return data[cardname].rarity or nil
end

function p.booster_locations(cardname)
	return data[cardname].booster_locations or nil
end

function p.boosters(cardname)
	local res,b = {},{}
	local loc = data[cardname].booster_locations
	local fac = p.faction(cardname)

	if loc == 'None' then return {} end

	if loc then
		if type(loc) == 'table' then 
			for k,v in ipairs(loc) do
				b[v] = true
			end
		else
			b[loc] = true
		end
	end
	
	if fac == 'Fire' then
		b['Fire'] = true
		b['Bandit'] = true
		b['Fire/Frost'] = true
		b['Twilight'] = true
	elseif fac == 'Frost' then
		b['Frost'] = true
		b['Fire/Frost'] = true
		b['Lost Souls'] = true
		b['Stonekin'] = true
	elseif fac == 'Nature' then
		b['Nature'] = true
		b['Amii'] = true
		b['Stonekin'] = true
		b['Twilight'] = true
	elseif fac == 'Shadow' then
		b['Shadow'] = true
		b['Amii'] = true
		b['Bandit'] = true
		b['Lost Souls'] = true
	elseif fac ~= 'Neutral' then
		b[fac] = true
	end

	for k,v in pairs(b) do
		res[#res+1] = k
	end

	table.sort(res)
	table.insert(res, 1, 'General')

	return res
end

function p.affinity(cardname)
	return data[cardname] and data[cardname].affinity or nil
end

function p.affinity_variants(cardname)
    local affs = {}
    if data[cardname .. " (Fire)"] then affs[#affs+1] = "Fire" end
    if data[cardname .. " (Frost)"] then affs[#affs+1] = "Frost" end
    if data[cardname .. " (Nature)"] then affs[#affs+1] = "Nature" end
    if data[cardname .. " (Shadow)"] then affs[#affs+1] = "Shadow" end
    return affs[1] and affs or nil
end

function p.orbs(cardname)
    return data[cardname].orbs or nil
end

function p.factions(cardname, inp_orbs)
    local check_factions = {
        FrostFire = {'Fire', 'Frost'},
        NatureFire = {'Fire', 'Nature'},
        ShadowFire = {'Fire', 'Shadow'},
        FrostNature = {'Nature', 'Frost'},
        FrostShadow = {'Shadow', 'Frost'},
        NatureShadow = {'Shadow', 'Nature'},
    }
    local orbs = inp_orbs or data[cardname]["orbs"]
    local hash,res={},{}
    for _,v in ipairs(orbs) do
        if v ~= "Neutral" and not hash[v] then
            res[#res+1] = v
            hash[v] = true
        end
    end
    if not res[1] then res[1] = "Neutral" end
    if not res[2] then res[2] = res[1] end

    return check_factions[res[1]..res[2]] or res
end

function p.faction(cardname)
    local res = p.factions(cardname)

    if res[1] == res[2] then
        return res[1]
    end

    local faction = res[1] .. res[2]

    if faction == 'FireNature' then
        return 'Twilight'
    elseif faction == 'NatureFrost' then
        return 'Stonekin'
    elseif faction == 'ShadowFrost' then
        return 'Lost Souls'
    elseif faction == 'FireShadow' then
        return 'Bandit'
    elseif faction == 'ShadowNature' then
        return 'Amii'
    else
        return 'Error: ' .. faction
    end
end

function p.construction_time(cardname)
    return data[cardname].construction_time or nil
end

function p.movement_speed(cardname)
    return data[cardname].movement_speed or nil
end

function p.power_cost(cardname)
    return data[cardname].power_cost or nil
end

function p.weapon_type(cardname)
    return data[cardname].weapon_type or nil
end

function p.charges(cardname)
    return data[cardname].charges or nil
end

function p.squadsize(cardname)
    return data[cardname].squadsize or nil
end

function p.class(cardname)
    return data[cardname].class or nil
end

function p.counter(cardname)
    return data[cardname].counter or nil
end

function p.size(cardname)
    return data[cardname].size or nil
end

function p.damage(cardname)
    return data[cardname].damage or nil
end

function p.health(cardname)
    return data[cardname].health or nil
end

function p.general_upgrade_text(cardname)
    return data[cardname].general_upgrade_text
end

function p.upgrade_locations(cardname)
    return data[cardname].upgrade_locations
end

function p.map_drops(mapname, difficulty)
    local t = {}
    for k, v in pairs(data) do
        if type(v.upgrade_locations) == 'table' and v.upgrade_locations[difficulty] == mapname then
            t[#t+1] = k
        end
    end
    table.sort(t, function(a, b) return a:lower() < b:lower() end)
    return t
end

function p.abilities(cardname)
    -- TODO
    return data[cardname] and data[cardname].abilities or nil
end

function p.abilities_all(cardname)
    local t, res, hash, aff_hash, variants = {}, {}, {}, {}, {}
    if data[cardname] then for _,v in ipairs(data[cardname]["abilities"]) do t[#t+1] = v end end
    if data[cardname .. " (Fire)"] then for _,v in ipairs(data[cardname .. " (Fire)"]["abilities"]) do t[#t+1] = v; aff_hash[#t] = 'Fire' end end
    if data[cardname .. " (Frost)"] then for _,v in ipairs(data[cardname .. " (Frost)"]["abilities"]) do t[#t+1] = v; aff_hash[#t] = 'Frost' end end
    if data[cardname .. " (Nature)"] then for _,v in ipairs(data[cardname .. " (Nature)"]["abilities"]) do t[#t+1] = v; aff_hash[#t] = 'Nature' end end
    if data[cardname .. " (Shadow)"] then for _,v in ipairs(data[cardname .. " (Shadow)"]["abilities"]) do t[#t+1] = v; aff_hash[#t] = 'Shadow' end end
    if data[cardname .. " (Promo)"] then for _,v in ipairs(data[cardname .. " (Promo)"]["abilities"]) do t[#t+1] = v end end
    if t then
        for k,v in ipairs(t) do
            if not hash[v["name"]] and v["affinity_dependency"] then
                res[#res+1] = v
                variants[v["name"]] = aff_hash[k]
                hash[v["name"]] = true
            end
        end
        for k,v in ipairs(t) do
            if not hash[v["name"]] and not v["affinity_dependency"] then
                res[#res+1] = v
                hash[v["name"]] = true
            end
        end
    end
    return res, variants
end

function p.upgrades(cardname)
    -- TODO
    return data[cardname].upgrades or nil
end

return p
Advertisement