This repository has been archived by the owner on Mar 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.lua
148 lines (129 loc) · 3.62 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
-- we need to require these before fire.save_the_world(), to prevent crashes
--hue
require "cpml"
require "iqm"
require "love3d".import(false)
local anchor = require "anchor"
local fire = require "fire"
fire.save_the_world()
_G.EVENT = require "signal".new()
_G.SCENE = require "gamestate"
function love.load(args)
local screen = "scenes.splash"
local check_screen = false
for _, v in pairs(args) do
if v == "--debug" then
_G.FLAGS.debug_mode = true
end
if v == "--hud" then
_G.FLAGS.show_perfhud = true
end
if v == "--screen" then
check_screen = true
end
if check_screen and not v:find("%-%-") then
screen = string.format("scenes.%s", v)
check_screen = false
end
end
if _G.FLAGS.debug_mode then
_G.imgui = require "imgui"
_G.imgui.PushStyleColor("WindowBg", 0.0, 0.0, 0.0, 0.98)
_G.imgui.PushStyleColor("ScrollbarBg", 0.2, 0.25, 0.3, 0.0)
_G.imgui.PushStyleColor("ScrollbarGrab", 1.0, 1.0, 1.0, 0.3)
_G.imgui.PushStyleColor("ScrollbarGrabHovered", 1.0, 0.85, 1.0, 0.5)
_G.imgui.PushStyleColor("ScrollbarGrabActive", 1.0, 0.5, 0.69, 0.4)
_G.imgui.PushStyleColor("CheckMark", 0.15, 0.0, 1.0, 0.91)
_G.imgui.PushStyleColor("FrameBg", 0.94, 1.0, 1.0, 0.16)
_G.imgui.PushStyleColor("Text", 1.0, 1.0, 1.0, 1.0)
_G.imgui.PushStyleColor("PlotHistogram", 0.78, 0.21, 0.21, 1.0)
else
_G.imgui = setmetatable({}, { __index = function()
return function() end
end })
end
anchor:set_overscan(0.1)
anchor:update()
_G.SCENE.registerEvents {
"update", "keypressed", "keyreleased", "wheelmoved",
"mousepressed", "mousereleased", "mousemoved",
"touchpressed", "touchreleased", "touchmoved",
"textinput"
}
_G.DEFAULT_PREFERENCES = {
fullscreen = false,
vsync = true,
msaa = true,
master_volume = 1.0,
bgm_volume = 1.0,
sfx_volume = 1.0,
language = "en"
}
_G.PREFERENCES = {}
-- Load preferences
if love.filesystem.isFile("preferences.json") then
local json = require "dkjson"
local file = love.filesystem.read("preferences.json")
local decode = json.decode(file)
-- copy default prefs first, in case some have been added.
for k, v in pairs(_G.DEFAULT_PREFERENCES) do
_G.PREFERENCES[k] = v
end
for k, v in pairs(decode) do
_G.PREFERENCES[k] = v
end
else
for k, v in pairs(_G.DEFAULT_PREFERENCES) do
_G.PREFERENCES[k] = v
end
end
local w, h, mode = love.window.getMode()
mode.msaa = _G.PREFERENCES.msaa and 4 or 1
mode.vsync = _G.PREFERENCES.vsync
mode.fullscreen = _G.PREFERENCES.fullscreen
love.window.setMode(w, h, mode)
_G.SCENE.switch(require(screen))
end
function love.quit()
if _G.imgui then
_G.imgui.ShutDown()
end
end
function love.update(dt)
anchor:update()
if _G.imgui then
_G.imgui.NewFrame()
end
if _G.FLAGS.debug_mode and not love.mouse.getRelativeMode() then
if imgui.BeginMainMenuBar() then
local top = _G.SCENE.current()
if top.menu then
top:menu()
end
imgui.EndMainMenuBar()
end
end
end
local function draw_overscan()
love.graphics.setColor(180, 180, 180, 200)
love.graphics.setLineStyle("rough")
love.graphics.line(anchor:left(), anchor:center_y(), anchor:right(), anchor:center_y())
love.graphics.line(anchor:center_x(), anchor:top(), anchor:center_x(), anchor:bottom())
love.graphics.setColor(255, 255, 255, 255)
love.graphics.rectangle("line", anchor:bounds())
end
function love.draw()
local top = _G.SCENE.current()
if not top.draw then
fire.print("no draw function on the top screen.", 0, 0, "red")
else
top:draw()
end
love.graphics.setColor(255, 255, 255)
if _G.imgui then
_G.imgui.Render()
end
if _G.FLAGS.show_overscan then
draw_overscan()
end
end