-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.lua
executable file
·47 lines (40 loc) · 1001 Bytes
/
utils.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
local utils = {}
local os = love.system.getOS()
utils.mobile = os=="Android" or os=="iOS"
function utils.rgb(r, g, b, a)
a = a or 255
return {r/255, g/255, b/255, a/255}
end
local ids = {}
function utils.getId(type)
ids[type] = (ids[type] or 0) + 1
return type.."#"..tostring(ids[type])
end
function utils.centerBox(bX, bY, bW, bH, w, h)
-- center a rect (w, h) inside a box
local x = bX + (bW-w)/2
local y = bY + (bH-h)/2
return x, y
end
local cache = {}
function utils.Font(size, file, hinting)
hinting = hinting or "normal"
local fileN = (file or "DEFAULT")..hinting
if cache[size] then
if cache[size][fileN] then
return cache[size][fileN]
end
end
local f
if file then
f = love.graphics.newFont(file, size, hinting)
else
f = love.graphics.newFont(size, hinting)
end
if not cache[size] then
cache[size] = {}
end
cache[size][fileN] = f
return f
end
return utils