-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.lua
195 lines (156 loc) · 4.48 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
io.stdout:setvbuf("no")
local imgui = require("imgui")
local UIHelper = require("src.classes.UIHelper"):new()
local editor = require("src.classes.Editor"):new('yay')
local projector = require("lasagna.projector")
local nogame, pong
--
-- LOVE callbacks
--
-- this gets merged into the sandboxes
-- therefore, we are exposing the gift of sandsmas here
local sandsmas = {
sandsmas = {
editor = editor,
imgui = imgui,
}
}
function love.load(arg)
nogame = projector:new("project/nogame/main.lua", sandsmas)
pong = projector:new("project/pong/main.lua", sandsmas)
local testfunc = function() end
UIHelper:AddMenu("File/New", testfunc)
UIHelper:AddMenu("File/Open", testfunc)
UIHelper:AddMenu("File/Save", testfunc)
UIHelper:AddMenu("File/Save As...", testfunc)
UIHelper:AddMenu("Edit/This", testfunc)
UIHelper:AddMenu("Edit/Thing", testfunc)
UIHelper:AddMenu("Help/About", testfunc)
end
function love.update(dt)
imgui.NewFrame()
nogame:update(dt)
pong:update(dt)
-- reverse the hierarchy stack so things are roughly in hierarchial view
editor.inspector:ClearSelection()
for _, uid in ipairs(editor.hierarchy.chrono_selection) do
editor.inspector:AddSelection(editor.hierarchy.objects[uid])
end
end
function love.draw()
local wx, wy, x, y
UIHelper:RenderMenu()
imgui.SetNextWindowPos(0, 0)
imgui.SetNextWindowSize(love.graphics.getWidth(), love.graphics.getHeight())
if UIHelper:Begin("DockArea", nil, { "NoResize", "NoMove", "NoBringToFrontOnFocus" }) then
imgui.BeginDockspace()
imgui.SetNextDock("Right")
if imgui.BeginDock("Inspector") then
editor.inspector:Render()
end
imgui.EndDock()
imgui.SetNextDock("Left")
if imgui.BeginDock("Project") then
imgui.Text("Project")
end
imgui.EndDock()
if imgui.BeginDock("Console") then
editor.console:Render()
end
imgui.EndDock()
imgui.SetNextDock("Top")
if imgui.BeginDock("Hierarchy") then
editor.hierarchy:Render()
end
imgui.EndDock()
imgui.SetNextDock("Right")
if imgui.BeginDock("Scene") then
nogame.env.love.store.window.focus = imgui.IsWindowFocused()
local x, y = imgui.GetWindowPos()
local w, h = imgui.GetWindowSize()
nogame.env.love.window.setPosition(x, y)
nogame.env.love.window.setMode(w, h)
UIHelper:PushPostRender(function()
nogame:draw()
end)
end
imgui.EndDock()
if imgui.BeginDock("Game") then
-- pong game goes here when active
end
imgui.EndDock()
imgui.EndDockspace()
end
UIHelper:End()
love.graphics.clear(100, 100, 100, 255)
local mx, my = love.mouse.getPosition()
if imgui.Begin(pong.env.love.window.getTitle() .. " | " .. mx .. "\\" .. my .. "###GameWindow") then
pong.env.love.store.window.focus = imgui.IsWindowFocused()
local x, y = imgui.GetWindowPos()
local w, h = imgui.GetWindowSize()
local titleHeight = 19
y = y + titleHeight
h = h - titleHeight
pong.env.love.window.setPosition(x, y)
pong.env.love.window.setMode(w, h)
UIHelper:PushPostRender(function()
pong:draw()
end)
end
imgui.End()
imgui.Render()
UIHelper:PostRender()
end
function love.quit()
imgui.ShutDown()
end
--
-- User inputs
--
function love.textinput(t)
imgui.TextInput(t)
if not imgui.GetWantCaptureKeyboard() then
end
end
function love.keypressed(key, scan, isRepeat)
imgui.KeyPressed(key)
if not imgui.GetWantCaptureKeyboard() then
if key == "escape" then
love.event.quit()
elseif key == "y" then
editor.console:Log('error', "too many dannies")
else
pong.env.love.keypressed(key, scan, isRepeat)
end
end
end
function love.keyreleased(key)
imgui.KeyReleased(key)
if not imgui.GetWantCaptureKeyboard() then
end
end
function love.mousemoved(x, y, dx, dy, istouch)
imgui.MouseMoved(x, y)
pong:mousemoved(x, y, dx, dy, istouch)
if not imgui.GetWantCaptureMouse() then
end
end
function love.mousepressed(x, y, button)
imgui.MousePressed(button)
if not imgui.GetWantCaptureMouse() then
end
end
function love.mousereleased(x, y, button)
imgui.MouseReleased(button)
if not imgui.GetWantCaptureMouse() then
end
end
function love.mousefocus( focus )
-- don't send mousefocus to the game because
-- they don't actually receive focus when we do
end
function love.wheelmoved(x, y)
imgui.WheelMoved(y)
if not imgui.GetWantCaptureMouse() then
end
end