Diferencia entre revisiones de «Módulo:Calcedibility»
Ir a la navegación
Ir a la búsqueda
(Página creada con «local p = {} --ceh = calculate energy or health function p.ceh(frame) local item = string.lower(frame.args.im) local edibility = tonumber(frame.args.ed) local quality =…») |
|||
Línea 19: | Línea 19: | ||
if ulang == "ES" then | if ulang == "ES" then | ||
--replace space with dot | --replace space with dot | ||
+ | --Problem: ES doesn't add a space for 4 digits | ||
local temp = {mw.ustring.gsub(formattedresult, "%s" , ".")} | local temp = {mw.ustring.gsub(formattedresult, "%s" , ".")} | ||
return temp[1] | return temp[1] |
Revisión del 23:05 26 feb 2023
Description
This module calculates the Energy and Health values for an edible item. It can return a raw, unformatted number to be used as the data-sort-value in a table, or a number formatted appropriately for the language where it's used.
- Note: This module performs special handling of Spanish numbers, inserting a "." instead of a space as a separator for numbers over 1000, in accordance with (most instances of) numbers in the Spanish translation of the game. This differs from the mediawiki standard for displaying numbers in Spanish, which is based on recommendations of the Real Academia Española.
This module can be copy/pasted into all languages without alteration.
Please report any problems or issues with the module on the discussion page for Template:EdibilityGrid.
local p = {}
--ceh = calculate energy or health
function p.ceh(frame)
local item = string.lower(frame.args.im)
local edibility = tonumber(frame.args.ed)
local quality = tonumber(frame.args.q)
local ulang = string.upper(frame.args.ll)
local formattedresult
if edibility == 0 then return 0 end
if item == "energy" then
formattedresult = mw.language.getContentLanguage():formatNum(calcenergy(edibility, quality))
else
formattedresult = mw.language.getContentLanguage():formatNum(calchealth(edibility, quality))
end
if ulang == "ES" then
--replace space with dot
--Problem: ES doesn't add a space for 4 digits
local temp = {mw.ustring.gsub(formattedresult, "%s" , ".")}
return temp[1]
else
return formattedresult
end
end
function calcenergy(edib, qualmult)
return math.floor(math.ceil(edib*2.5) + edib*qualmult)
end
function calchealth(edib, qualmult)
return math.floor(math.floor(math.ceil(edib*2.5) + edib*qualmult) * 0.45)
end
return p