-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.lua
More file actions
65 lines (57 loc) · 1.65 KB
/
dev.lua
File metadata and controls
65 lines (57 loc) · 1.65 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
local M = {}
function isModuleAvailable(name)
if package.loaded[name] then
return true
else
for _, searcher in ipairs(package.searchers or package.loaders) do
local loader = searcher(name)
if type(loader) == 'function' then
package.preload[name] = loader
return true
end
end
return false
end
end
-- function M.printInfo()
-- local infoString = 'W='..love.graphics.getWidth()..'; H='..love.graphics.getHeight()..'; SN='..love.window.getPixelScale()
-- if isModuleAvailable('ui.conf') then
-- infoString = infoString .. '; S=' .. require('ui.conf').scale()
-- end
-- print(string.rep('-', #infoString))
-- print(infoString)
-- print(string.rep('-', #infoString))
-- end
function M.displayInfo(...)
local flags
if ... then
flags = {...}
else
flags = {'dimension','mouse', 'fps'}
end
local flagDict = {}
for _, flag in ipairs(flags) do
flagDict[flag] = true
end
local w, h = love.graphics.getWidth(), love.graphics.getHeight()
local s = love.window.getPixelScale()
local x, y = love.mouse.getPosition()
local lineSpace = 6
local infoWidth = w - lineSpace
local curY = 0
function stepY()
curY = curY + love.graphics.getFont():getHeight() + lineSpace
return curY
end
curY = -stepY() + lineSpace
if flagDict['dimension'] then
love.graphics.printf('W='..w..'; H='..h..'; S='.. s, 0, stepY(), infoWidth, 'right')
end
if flagDict['mouse'] then
love.graphics.printf('mX='..x..' mY='..y, 0, stepY(), infoWidth, 'right')
end
if flagDict['fps'] then
love.graphics.printf('FPS=' .. love.timer.getFPS(), 0, stepY(), infoWidth, 'right')
end
end
return M