Warframe Wiki
Nie podano opisu zmian
Nie podano opisu zmian
Linia 58: Linia 58:
   
 
local function to_precision(value, precision)
 
local function to_precision(value, precision)
return string.format("%." .. precision .. "d", value)
+
return string.format("%." .. precision .. "f", value)
 
end
 
end
 
module_export.to_precision = to_precision
 
module_export.to_precision = to_precision

Wersja z 11:13, 9 sie 2018

Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:Utils/opis

local module_export = {}

local function is_integer(number)
    return number == math.floor(number)
end
module_export.is_integer = is_integer

local function sum(...)
    local sum = 0;
    for i = 1, arg.n do
        sum = sum + arg[i]
    end
    return sum
end
module_export.sum = sum

local function unpack_any_table(t)
    t = t or {} -- nil will throw
    
    local indexed_table = {}
    for k, v in pairs(t) do
        table.insert(indexed_table, v)
    end
    return unpack(indexed_table) 
end
module_export.unpack_any_table = unpack_any_table

local function table_keys(t)
    local keys = {}
    for k, v in pairs(t) do
        table.insert(keys, k)
    end
    return keys
end
module_export.table_keys = table_keys

-- table.concat (doesn't work for some reason) substitue
local function table_concat(t, sep)
    local result = ''
    for i, v in ipairs(t) do
        if(i ~= 1) then
            result = result .. sep     
        end
        result = result .. v
    end
    return result
end
module_export.table_concat = table_concat

local function contains(t, val)
    for i, v in ipairs(t) do
        if v == val then return true end
    end
    
    return false
end
module_export.contains = contains

local function to_precision(value, precision)
    return string.format("%." .. precision .. "f", value)
end
module_export.to_precision = to_precision

local function to_percent(value)
    return to_precision(value * 100, 1) .. "%"
end
module_export.to_percent = to_percent

local function proc_to_polish(proc)
    proc = proc:lower() -- make case insensitive
    
    if proc == "impact" then return "Miażdżące"
    elseif proc == "slash" then return "Tnące"
    elseif proc == "puncture" then return "Przebijające"
    elseif proc == "cold" then return "Zimno"
    elseif proc == "electricity" then return "Elektryczne"
    elseif proc == "heat" then return "Ogień"
    elseif proc == "toxin" then return "Toksyna"
    elseif proc == "blast" then return "Wybuch"
    elseif proc == "corrosive" then return "Żrące"
    elseif proc == "gas" then return "Gaz"
    elseif proc == "magnetic" then return "Magnetyczne"
    elseif proc == "radiation" then return "Radiacja"
    elseif proc == "viral" then return "Wirusowe"
    end
    
    if proc == "tnace" then return "Tnące"
    elseif proc == "miazdzace" then return "Miażdżące"
    elseif proc == "przebijajace" then return "Przebijające"
    elseif proc == "ogien" then return "Ogień"
    elseif proc == "zimno" then return "Zimno"
    elseif proc == "elektryczne" then return "Elektryczne"
    elseif proc == "toksyna" then return "Toksyna"
    elseif proc == "toksyczne" then return "Toksyczne" -- in case
    elseif proc == "wybuch" then return "Wybuch"
    elseif proc == "zrace" then return "Żrące"
    elseif proc == "gaz" then return "Gaz"
    elseif proc == "magnetyczne" then return "Magnetyczne"
    elseif proc == "radiacja" then return "Radiacja"
    elseif proc == "wirusowe" then return "Wirusowe"
    end
end
module_export.proc_to_polish = proc_to_polish

-- Add handling of words ending with -ek
local function make_polish_plural(word, count)
    local y_endings = { "b", "p", "d", "t", "f", "w", "ch", "ł", "m", "n", "r", "s", "z" }
    local i_endings = { "k", "g" }
    local e_endings = { "dzi", "dź", "ci", "ć", "j", "l", "ni", "ń", "si", "ś", "zi", "ź", "dz", "dż", "c", "cz", "rz", "ż", "sz" }
    
    local last_letters = word:sub(-3)
    if count == 1 then return word
    elseif is_integer(count) and count < 5 then
        if last_letters[3] == "a" then
            word = word:sub(1, -1)
            last_letters = word:sub(-3)
        end
        
        if contains(e_endings, last_letters) or contains(e_endings, last_letters:sub(2)) or contains(e_endings, last_letters:sub(3)) then
            return word .. "e"
        elseif contains(i_endings, last_letters:sub(3)) then
            return word .. "i"
        elseif contains(y_endings, last_letters:sub(2)) or contains(y_endings, last_letters:sub(3)) then
            return word .. "y"
        else
            return word .. "a"
        end
    else -- count greater than 4 or fractions
        -- Add more rules
        return word .. "ów"
    end
end
module_export.make_polish_plural = make_polish_plural

return module_export