-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.lua
164 lines (136 loc) · 3.79 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
require("hooks")
require("mime")
require("ltn12")
require("enet")
require("socket")
if arg[2] == "debug" then
require("lldebugger").start()
end
local pkg = require("aqua.package")
pkg.reset()
pkg.addc("3rd-deps/lib")
pkg.addc("bin/lib")
pkg.add("3rd-deps/lua")
pkg.add("aqua")
pkg.add("ncdk")
pkg.add("chartbase")
pkg.add("libchart")
pkg.add("tree/share/lua/5.1")
require("aqua.string")
if arg[2] == "test" then
local ok, err = pcall(require, "luacov.runner")
if ok then
err.init()
end
end
local deco = require("deco")
deco.package_path = love.filesystem.getRequirePath()
deco.read_file = love.filesystem.read
deco.blacklist = {
"3rd-deps",
"tree",
"aqua/byte.lua",
-- "sphere/views",
}
local reqprof = require("reqprof")
if love.filesystem.getInfo("reqprof", "file") then
deco.add(reqprof.ProfileDecorator())
print("enabled reqprof.ProfileDecorator")
end
local typecheck = require("typecheck")
if love.filesystem.getInfo("typecheck", "file") then
typecheck.strict = true
deco.add(require("typecheck.TypeDecorator")())
deco.add(require("typecheck.ClassDecorator")())
print("enabled typecheck.TypeDecorator")
print("enabled typecheck.ClassDecorator")
end
deco.replace_loader()
local ffi = require("ffi")
local source = love.filesystem.getSource()
local sourceBase = love.filesystem.getSourceBaseDirectory()
local root
if source:find("^.+%.love$") then
print("starting from .love file directly")
root = sourceBase
else
print("starting from current directory")
root = source
end
if jit.os == "Windows" then
local winapi = require("winapi")
winapi.putenv("PATH", ("%s;%s"):format(winapi.getenv("PATH"), root .. "/bin/win64"))
winapi.chdir(root)
pkg.addc("bin/win64")
elseif jit.os == "Linux" then
local ldlp = os.getenv("LD_LIBRARY_PATH")
if not ldlp or not ldlp:find("bin/linux64") then
ffi.cdef("int setenv(const char *name, const char *value, int overwrite);")
ffi.C.setenv("LD_LIBRARY_PATH", (ldlp or "") .. ":" .. root .. "/bin/linux64", true)
os.execute(("%q %q &"):format(arg[-2], arg[1]))
return os.exit()
end
ffi.cdef("int chdir(const char *path);")
ffi.C.chdir(root)
pkg.addc("bin/linux64")
elseif jit.os == "OSX" then
local ldlp = os.getenv("DYLD_FALLBACK_LIBRARY_PATH")
if not ldlp or not ldlp:find("bin/mac64") then
ffi.cdef("int setenv(const char *name, const char *value, int overwrite);")
ffi.C.setenv("DYLD_FALLBACK_LIBRARY_PATH", root .. "/bin/mac64", true)
--os.execute(("%q %q &"):format(arg[-2], arg[1]))
--return os.exit()
end
ffi.cdef("int chdir(const char *path);")
ffi.C.chdir(root)
pkg.addc("bin/mac64")
end
love.errhand = require("errhand")
local physfs = require("physfs")
physfs.setWriteDir(root)
if root == sourceBase then
assert(physfs.mount(root, "/", true))
end
require("preload")
local modloader = require("modloader")(root)
modloader:loadMods()
local love_run = require("love_run")
love.load = function() end -- for compatibility with old conf.lua
local defaultLoop = love.loop or love_run()
function love.run()
return function()
return defaultLoop()
end
end
if arg[2] == "test" then
local testing = require("testing")
testing.blacklist = {
".git",
"3rd-deps",
"tree",
"userdata",
}
testing.get_time = love.timer.getTime
testing.test()
os.exit()
end
local delay = require("delay")
delay.set_timer(love.timer.getTime)
local thread = require("thread")
thread.coro(function()
local UpdateController = require("sphere.update.UpdateController")
local updateController = UpdateController()
local needRestart = updateController:updateAsync()
if needRestart then
thread.unload()
thread.waitAsync()
return love.event.quit("restart")
end
local GameController = require("sphere.controllers.GameController")
local game = GameController()
game:load()
local loop = require("loop")
loop:init()
defaultLoop = loop:run()
loop:add(game)
end)()