Do some preparation for touch config screen

This commit is contained in:
Squishy (C6H12O6+NaCl+H2O)
2024-04-21 18:21:52 +07:00
parent 50fdcae8ac
commit 9425b047e2
5 changed files with 107 additions and 65 deletions

View File

@@ -68,16 +68,43 @@ function formatBigNum(number)
else
return
end
local pos = Mod1(string.len(s), 3)
local pos = math.mod1(string.len(s), 3)
return string.sub(s, 1, pos)
.. string.gsub(string.sub(s, pos+1), "(...)", ",%1")
end
function Mod1(n, m)
-- returns a number congruent to n modulo m in the range [1;m] (as opposed to [0;m-1])
function math.clamp(x, min, max)
if max < min then
min, max = max, min
end
return x < min and min or (x > max and max or x)
end
-- Returns a number congruent to n modulo m in the range [1;m] (as opposed to [0;m-1])
function math.mod1(n, m)
return ((n-1) % m) + 1
end
---Round a number with specified unit
---@param n number
---@param u number # Default: 10
---@return number
function math.roundUnit(n,u)
local u = u or 10
return math.floor(n/u+.5)*u
end
---@param t1 table
---@param t2 table
---@return table t
---Merge 2 tables into one<br>(**WARNING**: t2 can **overwrite** some value of t1 if both tables have some same keys!)
function table.merge(t1,t2)
local t
for k, v in pairs(t1) do t[k] = v end
for k, v in pairs(t2) do t[k] = v end
return t
end
function table.contains(table, element)
for _, value in pairs(table) do
if value == element then
@@ -107,13 +134,6 @@ function table.lowest(table)
return lowest
end
function math.clamp(x, min, max)
if max < min then
min, max = max, min
end
return x < min and min or (x > max and max or x)
end
function drawText(text, x, y, size, orientation, color)
if color == nil then color = {1, 1, 1, 1} end
love.graphics.setFont(FONT_tromi)