-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.lua
109 lines (93 loc) · 2.97 KB
/
main.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then
require("lldebugger").start()
-- Extra error because it otherwise misses them if they happen during love.load()
function love.errorhandler(msg)
error(msg,2)
end
end
function love.load(args)
--load stuff
require("utils.utils")
-- Boilerplate for types
---@class ClassInfo
---@field name string
---@field super ClassInfo
--has to be done as a table because generics can't be done on an abstract
---@class Class : ClassInfo
---@field class ClassInfo
local c = {}
---@generic T
---@param self T
---@return T
function c:new(...) return self end
local middleclass = require("libs.middleclass")
---@overload fun(): ClassInfo
---@overload fun(parent: ClassInfo): ClassInfo
---@overload fun(name: string, parent?: ClassInfo): ClassInfo
function Class(nameOrParent, parent)
if nameOrParent==nil then
return middleclass("Unnamed")
elseif type(nameOrParent)=="table" then
return middleclass("Unnamed", nameOrParent)
elseif type(nameOrParent)=="string" then
return middleclass(nameOrParent, parent)
end
end
--constants
TILE_SIZE = 71
--globals
Persistant = require("utils.persistant")
Settings = Persistant.settings
Storage = Persistant:get("data")
--make sure which version of CH we're using is saved on disk
require("utils.version")
--love2d state
love.graphics.setFont(love.graphics.newFont("resources/iosevka-aile-regular.ttf", Settings.theme.main.fontSize))
love.graphics.setLineWidth(1)
love.graphics.setPointSize(1)
love.graphics.setLineStyle("rough")
--maximize window
if Storage.fullscreen then
love.window.setFullscreen(true)
else
love.window.maximize()
end
--build ui
MainUI = require("chaoshead.chaoshead"):new()
UiRoot = require("ui.base.root"):new(MainUI)
UiRoot:hookIntoLove()
UiRoot:resize(love.graphics.getWidth(), love.graphics.getHeight())
--bind ui and input
Input = require("chaoshead.input")
Input.parseActions(Settings.bindings)
---It's meant to be overwritten
---@diagnostic disable-next-line duplicate-set-field
Input.inputActivated = function(...)
UiRoot:inputActivated(...)
end
---It's meant to be overwritten
---@diagnostic disable-next-line duplicate-set-field
Input.inputDeactivated = function(...)
UiRoot:inputDeactivated(...)
end
--checks to run at startup
require("chaoshead.startupChecks")
if args[1] then
MainUI.workshop:openEditor(args[1])
end
end
function love.keypressed(key, scancode, isrepeat)
Input.keypressed(key, scancode, isrepeat)
end
function love.keyreleased(key, scancode)
Input.keyreleased(key, scancode)
end
function love.mousepressed(x, y, button, isTouch, presses)
Input.mousepressed(x,y, button, isTouch, presses)
end
function love.mousereleased(x, y, button, isTouch, presses)
Input.mousereleased(x,y, button, isTouch, presses)
end
function love.filedropped(file)
MainUI.workshop:openEditor(file:getFilename())
end