Slay the Spire Wiki
No edit summary
Tag: Source edit
No edit summary
Tag: Source edit
(One intermediate revision by the same user not shown)
Line 262: Line 262:
 
local result = '{| style="word-break:break-word; border: 2px solid #5959c0; background-color: #2C2A4E; border-radius: 10px; width: 400px; padding: 10px 20px 10px 20px"'
 
local result = '{| style="word-break:break-word; border: 2px solid #5959c0; background-color: #2C2A4E; border-radius: 10px; width: 400px; padding: 10px 20px 10px 20px"'
 
result = result..'\n|rowspan="2" style="width: 10%;"|[[File:'..image..'|70px]]'
 
result = result..'\n|rowspan="2" style="width: 10%;"|[[File:'..image..'|70px]]'
result = result..'\n|colspan="2" style="padding: 0px 5px 0px 5px" |<div style="font-size: 17px; font-weight:bold; font size: 17px">'..name
+
result = result..'\n|colspan="2" style="padding: 0px 7px 0px 7px" |<div style="font-size: 17px; font-weight:bold; font size: 17px">'..name
 
result = result..'\n|-'
 
result = result..'\n|-'
result = result..'\n|colspan="2" style="vertical-align: top; padding: 0px 5px 4px 5px;"|'..rarityText
+
result = result..'\n|colspan="2" style="vertical-align: top; padding: 0px 7px 0px 7px;"|'..rarityText
 
result = result..'\n|-'
 
result = result..'\n|-'
 
result = result..'\n|colspan="3"|'..text
 
result = result..'\n|colspan="3"|'..text

Revision as of 20:31, 13 September 2020

Documentation for this module may be created at Module:Relics/doc

--Relic equivalent of Module:Cards
--Based on the data in Module:Relics/data - If the information is wrong, edit it there
 
local p = {}
 
local RelicData = mw.loadData( 'Module:Relics/data' )
local Shared = require( 'Module:Shared' )
local Keywords = require( 'Module:Keywords' )
 
function p.getRelic(relicName)
    --If no name is sent, just return nil
    if(relicName == nil or relicName == "") then return nil end
 
    --Loop through all cards, return if the key or the name match
    for i, relic in pairs(RelicData["Relics"]) do
        if relic.Name == relicName then return relic 
        elseif relic.ID == relicName then return relic end
    end
 
    --If not found, return nil
    return nil
end
 
function getValue(theRelic, valName, asString)
    if(asString == nil) then asString = false end
    if(valName == nil or valName == "") then
        return "ERROR: No value chosen"
    else
        valName = string.upper(valName)
    end
 
    local result = nil
 
    if(valName == 'NAME') then
        result = theRelic.Name
    elseif(valName == 'NAMELINK') then
        if(theRelic.Link ~= nil) then
            result = '[['..theRelic.Link..'|'..theRelic.Name..']]'
        else
            result = theRelic.Name
        end
    elseif(valName == "DESCRIPTION") then
        result = theRelic.Description
    elseif(valName == "FULLDESCRIPTION") then
        result = theRelic.Description
        if(result ~= nil) then
            result = Keywords.FillIcons(result)
            result = Keywords.FillKeywords(result)
        end
    elseif(valName == "FLAVOR") then
        result = theRelic.Flavor
    elseif(valName == "IMAGE") then
        result = theRelic.Image
    elseif(valName == 'RARITY') then
        result = theRelic.Rarity
	elseif(valName == "CHARACTER") then
        result = theRelic.Character
    elseif(valName == "EVENT") then
        result = theRelic.EventName
    elseif(valName == 'EVENTICON') then
        result = theRelic.EventIcon
	elseif(valName == "EVENT02") then
        result = theRelic.Event02Name
    elseif(valName == 'EVENT02ICON') then
        result = theRelic.Event02Icon
    elseif(valName == 'TOOLTIP') then
        local name = getValue(theRelic, "NAME")
        local rarity = getValue(theRelic, "RARITY")
        local text = getValue(theRelic, "DESCRIPTION")
        local flavor = getValue(theRelic, "FLAVOR")
        result = ''
        result = result..name
        if rarity ~= nil then
            result = result..' ('..rarity..')'
        end
        if text ~= nil then
            --Add in Icons, but don't include tooltips
            result = result..'\\n'..text
        end
    elseif(valName == 'TOOLTIP2') then
        local image = getValue(theRelic, "IMAGE")
        local name = getValue(theRelic, "NAME")
        local text = getValue(theRelic, "DESCRIPTION")
        local flavor = getValue(theRelic, "FLAVOR")
        result = ''
        if image ~= nil then
            result = result..'[[File:'..image..'|link='..name..'|x40px]] '
        end
        result = result..name
        if text ~= nil then
            --Add in Icons, but don't include tooltips
            text = Keywords.FillIcons(text, "NO")
            result = result..':<br>'..text
        end
        if(flavor ~= nil) then
            result = result.."<br>''"..flavor.."''"
        end
    else
        result = 'ERROR: No such value found'
    end
 
 
    if(asString and result == nil) then result = '' end
    return result
end
 
function p.getValue(frame)
    local RelicName = frame.args ~= nil and frame.args[1] or nil
    local ValName = frame.args ~= nil and frame.args[2] or nil
 
    if (RelicName == nil or RelicName == "") then return "ERROR: No relic name chosen" end
 
    local TheRelic = p.getRelic(RelicName)
    if(TheRelic == nil) then return nil end
 
    return getValue(TheRelic, ValName, true)
end
 
function p._getRelicLink(RelicName, OverrideText, TypeOfDisplay)
    if(RelicName == nil or RelicName == "") then return "ERROR: No relic name chosen" end
 
    local TheRelic = p.getRelic(RelicName)
	local name = getValue(TheRelic, 'Name')
    local image = getValue(TheRelic, 'Image')
    local tooltip = getValue(TheRelic, 'Tooltip')
    
    if(TheRelic == nil) then return nil end
 
    local relicLink = ''
    if(OverrideText == nil or OverrideText == '') then
        relicLink = getValue(TheRelic, 'NameLink')
        if(relicLink == "Golden Idol") then
            relicLink = 'Golden Idol (Relic)|Golden Idol'
        end
        relicLink = '[['..relicLink..']]'
    else
        relicLink = getValue(TheRelic, 'NameLink')
        if(relicLink == "Golden Idol") then
            relicLink = 'Golden Idol (Relic)'
        end
        relicLink = '[['..relicLink..'|'..OverrideText..']]'
    end
    
    local result = ''
    
    if(image ~= nil) then
        result =  '[[File:'..image..'|21x23px|middle]] '
        result = result..' '..relicLink
    end
    
    if (TypeOfDisplay == "thumb" or TypeOfDisplay == "thumbnail" or TypeOfDisplay == "Thumb" or TypeOfDisplay == "Thumbnail" or TypeOfDisplay == "t" or TypeOfDisplay == "T") then
            relicLink = getValue(TheRelic, 'NameLink')
            if(relicLink == "Golden Idol") then
                relicLink = 'Golden Idol (Relic)'
             end
            result = '[[File:'..image..'|link='..relicLink..'|67x73px|middle]]'
            
    elseif (TypeOfDisplay == "menu" or TypeOfDisplay == "Menu" or TypeOfDisplay == "M") then
            relicLink = getValue(TheRelic, 'NameLink')
            if(relicLink == "Golden Idol") then
                relicLink = 'Golden Idol (Relic)'
            end
            result = '[[File:'..image..'|link='..relicLink..'|36x34px|middle]]'
    end        
        
    result = '<span class = "relic-tooltip" data-name="'..name..'">'..result..'</span>'
 
    return result
end

function p._getRelicTooltip(TheRelic)
    if(TheRelic == nil or TheRelic == "") then return "ERROR: No relic name chosen" end
 
    local TheRelic = p.getRelic(TheRelic)
	local name = getValue(TheRelic, 'Name')
    local image = getValue(TheRelic, 'Image')
	local rarity = getValue(TheRelic, 'Rarity')
	local rarityText = ''
	local character = getValue(TheRelic, 'Character')
	local event = getValue(TheRelic, 'Event')
	local eventIcon = getValue(TheRelic, 'EventIcon')
	local event02 = getValue(TheRelic, 'Event02')
	local event02Icon = getValue(TheRelic, 'Event02Icon')
	
	--Rarity Colors
		rarityText = '<span style="font-weight:bold; font-size: 13px; '
	--Starter
	if (rarity == "Starter") then
		rarityText = rarityText..'color:#b0b0e8">Starter</span>'
	--Common
	elseif (rarity == "Common") then
		rarityText = rarityText..'color:Grey">Common</span>'
	--Uncommon
	elseif (rarity == "Uncommon") then
		rarityText = rarityText..'color:skyBlue">Uncommon</span>'
	--Rare	
	elseif (rarity == "Rare") then
		rarityText = rarityText..'color:gold">Rare</span>'
	--Boss	
	elseif (rarity == "Boss") then
		rarityText = rarityText..'color:salmon">Boss</span>'
	--Event
	elseif (rarity == "Event") then
		rarityText = rarityText..'color:violet">Event</span>'
	--Shop
	elseif (rarity == "Shop") then
		rarityText = rarityText..'color:lightGreen">Shop</span>'
	--Special
	elseif (rarity == "Special") then
		rarityText = rarityText..'color:#b0b0e8d">Special</span>'
	else
		rarityText = rarityText..'color:#b0b0e8">'..rarity..'</span>'
	end
	
	--Character
	if (character ~= nil) then
		rarityText = rarityText..' • <span style="font-weight:bold; font-size: 13px; '
		--Ironclad	
		if (character == "Ironclad") then
			rarityText = rarityText..'color:indianRed">Ironclad</span>'
		--Silent
		elseif (character == "Silent") then
			rarityText = rarityText..'color:mediumSeaGreen">Silent</span>'
		--Defect
		elseif (character == "Defect") then
			rarityText = rarityText..'color:cornFlowerBlue">Defect</span>'
		--Watcher
		elseif (character == "Watcher") then
			rarityText = rarityText..'color:mediumPurple">Watcher</span>'
		--Other
		else
			rarityText = rarityText..'colore:lavender">'..character..'</span>'
		end
	end
	
	--Event
	if (event ~= nil) then
		--Event Icon
		if (eventIcon ~= nil) then
			rarityText = rarityText..' • [[File:'..eventIcon..'|20px]] '
		end
		--Event Name
		    rarityText= rarityText..'<span style="font-weight:bold; font-size: 13px; color:rosybrown">'..event..'</span>'
	end
	
	--Additional Event
	if (event02 ~= nil) then
		rarityText = rarityText..' / '
		--Event Icon
		if (event02Icon ~= nil) then
			rarityText = rarityText..'[[File:'..event02Icon..'|20px]] '
		end
	--Event Name
    	rarityText = rarityText..'<span style="font-weight:bold; font-size: 13px; color:rosybrown">'..event02..'</span>'
	end
	
	local text = getValue(TheRelic, "DESCRIPTION")
    local flavor = getValue(TheRelic, "FLAVOR")
    
    if(TheRelic == nil) then return nil end
    
    local result = '{| style="word-break:break-word; border: 2px solid #5959c0; background-color: #2C2A4E;  border-radius: 10px; width: 400px; padding: 10px 20px 10px 20px"'
		result = result..'\n|rowspan="2" style="width: 10%;"|[[File:'..image..'|70px]]'
		result = result..'\n|colspan="2" style="padding: 0px 7px 0px 7px" |<div style="font-size: 17px; font-weight:bold; font size: 17px">'..name
		result = result..'\n|-'
		result = result..'\n|colspan="2" style="vertical-align: top; padding: 0px 7px 0px 7px;"|'..rarityText
		result = result..'\n|-'
		result = result..'\n|colspan="3"|'..text
		result = result..'\n|-'
		result = result..'\n|colspan="3"|<div style="font-size: 14px; word-wrap: break-word; font-style: italic; color:#9e9cc9">'..flavor..'</div>'
		result = result..'\n|-'
		result = result..'|}'
 
    return result
end
 
function p.getRelicLink(frame)
    local relicName = frame.args ~= nil and frame.args[1] or nil
    local text = frame.args ~= nil and frame.args.text or nil
    local displayType = frame.args ~= nil and frame.args.displayType or nil
 
    return p._getRelicLink(relicName, text, displayType)
end

function p.getRelicTooltip(frame)
    local relicName = frame.args[1] or frame.args["relic"] or nil
 
    return p._getRelicTooltip(relicName)
end
 
function p._getRelicLink2(RelicName, OverrideText, TypeOfDisplay)
    if(RelicName == nil or RelicName == "") then return "ERROR: No relic name chosen" end
 
    local TheRelic = p.getRelic(RelicName)
    if(TheRelic == nil) then return nil end
 
    local relicLink = ''
    if(OverrideText == nil or OverrideText == '') then
        relicLink = getValue(TheRelic, 'NameLink')
    else
        local link = getValue(TheRelic, 'Link')
        relicLink = '[['..link..'|'..OverrideText..']]'
    end
 
 
    local image = getValue(TheRelic, 'Image')
 
    local result = '<div style="display:block;">'..getValue(TheRelic, 'Tooltip2')..'</div>'
 
    return result
end
 
function p.getRelicLink2(frame)
    local relicName = frame.args ~= nil and frame.args[1] or nil
    local text = frame.args ~= nil and frame.args.text or nil
 
    return p._getRelicLink2(relicName, text)
end
 
return p