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
/
main.lua
96 lines (81 loc) · 2.25 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
-- we need to require these before fire.save_the_world(), to prevent crashes
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)
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
end
anchor:set_overscan(0.1)
anchor:update()
_G.SCENE.registerEvents {
"update", "keypressed",
"mousepressed", "mousereleased", "mousemoved",
"touchpressed", "touchreleased", "touchmoved"
}
_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 "scenes.main-menu")
end
function love.update(dt)
anchor:update()
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
if _G.FLAGS.show_overscan then
draw_overscan()
end
end