-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutil.lua
More file actions
44 lines (37 loc) · 942 Bytes
/
util.lua
File metadata and controls
44 lines (37 loc) · 942 Bytes
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
-- Miscellaneous utility functions
function json.decodefile(file)
return json.decode(love.filesystem.read(file))
end
-- Check if a table is empty
function tableEmpty(self)
for _, _ in pairs(self) do
return false
end
return true
end
-- Split a string into a table on newlines
function splitNewline(str)
local tbl = {}
for s in str:gmatch("[^\r\n]+") do
table.insert(tbl, s)
end
return tbl
end
-- Axis-aligned bounding boxes (AABB) collision detection implementation
function checkCollision(x1,y1,w1,h1, x2,y2,w2,h2)
return x1 < x2+w2
and x2 < x1+w1
and y1 < y2+h2
and y2 < y1+h1
end
-- Clamp implementation (clamp x within min and max)
function math.clamp(x, min, max)
if x < min then return min end
if x > max then return max end
return x
end
-- Dummy translation function
-- (Future proofing for when a translation system is implemented)
function S(text, ...)
return string.format(text, ...)
end