Module:UnlockChalDate: Difference between revisions

From SilentBlue.RemyWiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
local p={}
local p={}
local color={
local color={
     [300] = 'style="background:#adff2f;" | ',
     -- [300] = 'style="background:#adff2f;" | ',
     [100] = 'style="background:#adff2f;" | ',
     -- [100] = 'style="background:#adff2f;" | ',
     [50] = 'style="background:#f08080;" | ',
     [150] = 'style="background:#f08080;" | ',
     [10] = 'style="background:#da70d6;" | ',
     [50] = 'style="background:#da70d6;" | ',
     [1] = 'style="background:#da70d6;" | '
     [10] = 'style="background:#da70d6;" | '
}
}
local function tableToString(tbl)
    local result = {}
    for k, v in pairs(tbl) do
        if type(v) == "table" then
            table.insert(result, k .. " = {" .. tableToString(v) .. "}")
        else
            table.insert(result, k .. " = " .. tostring(v))
        end
    end
    return table.concat(result, ", ")
end
local function DateDiffRaw(args)
local function DateDiffRaw(args)
     return tonumber(mw.text.trim(mw.getCurrentFrame():expandTemplate{title='DateDiffRaw',args=args}))
     return tonumber(mw.text.trim(mw.getCurrentFrame():expandTemplate{title='DateDiffRaw',args=args}))
end
end
local function getColor(life, ult)
    return (life == 10 and ult == "y" and 'style="background:#823434;" | ') or
          color[arg]
end
function p.UnlockChalDate(frame)
function p.UnlockChalDate(frame)
     args=frame:getParent().args
     args=frame:getParent().args
     day=DateDiffRaw({args[1],args[2],args[3]})
     day=DateDiffRaw({args[1],args[2],args[3]})
     if day >= 28 then life = 300
     --if day >= 28 then life = 300
     elseif day >= 21 then life = 100
     -- elseif day >= 21 then life = 100
     elseif day >= 14 then life = 150
     if day >= 7 then life = 150
     elseif day >= 7 then life = 50
     elseif day >= 4 then life = 50
     else life = 10 end
     else life = 10 end
     return tableToString(args)
     return getColor(life, args.ult or "n")..'/'..args[2]..'/'..args[3]..' || '..color[life]..life
end
end
return p
return p

Revision as of 11:55, 21 December 2024

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

local p={}
local color={
    -- [300] = 'style="background:#adff2f;" | ',
    -- [100] = 'style="background:#adff2f;" | ',
    [150] = 'style="background:#f08080;" | ',
    [50] = 'style="background:#da70d6;" | ',
    [10] = 'style="background:#da70d6;" | '
}
local function DateDiffRaw(args)
    return tonumber(mw.text.trim(mw.getCurrentFrame():expandTemplate{title='DateDiffRaw',args=args}))
end

local function getColor(life, ult)
    return (life == 10 and ult == "y" and 'style="background:#823434;" | ') or 
           color[arg]
end 

function p.UnlockChalDate(frame)
    args=frame:getParent().args
    day=DateDiffRaw({args[1],args[2],args[3]})
    --if day >= 28 then life = 300
    -- elseif day >= 21 then life = 100
    if day >= 7 then life = 150
    elseif day >= 4 then life = 50
    else life = 10 end
    return getColor(life, args.ult or "n")..'/'..args[2]..'/'..args[3]..' || '..color[life]..life
end
return p