init.lua
5.34 KB
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
-- TE4 - T-Engine 4
-- Copyright (C) 2009 - 2018 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
--- @script init.lua
-- load some utility functions
dofile("/engine/utils.lua")
dofile("/engine/colors.lua")
-- load resolver functions for entities cloning
dofile("/engine/resolvers.lua")
require "config"
require "engine.Game"
require "engine.version"
require "engine.interface.GameMusic"
require "engine.KeyBind"
require "engine.Savefile"
require "engine.SavefilePipe"
require "engine.Tiles"
require "engine.PlayerProfile"
engine.Tiles.prefix = "/data/gfx/"
-- Setup the user directory
engine.homepath = fs.getUserPath()..fs.getPathSeparator()..fs.getHomePath()..fs.getPathSeparator().."4.0"
fs.setWritePath(fs.getUserPath())
fs.mkdir(fs.getHomePath())
fs.mkdir(fs.getHomePath().."/4.0/")
fs.mkdir(fs.getHomePath().."/4.0/profiles/")
fs.mkdir(fs.getHomePath().."/4.0/settings/")
fs.setPathAllowed(engine.homepath, true)
fs.setPathAllowed(fs.getRealPath("/addons/"), true)
if fs.getRealPath("/dlcs/") then fs.setPathAllowed(fs.getRealPath("/dlcs/"), true) end
fs.setPathAllowed(fs.getRealPath("/modules/"), true)
-- Last resort, add currently mounted paths, as readonly, so taht reset mounts work
for _, path in ipairs(fs.getSearchPath()) do fs.setPathAllowed(path) end
fs.doneSettingPathAllowed()
fs.setWritePath(engine.homepath)
-- Loads default config & user config
fs.mount(engine.homepath, "/")
config.loadString[[
audio.music_volume = 40
audio.effects_volume = 100
audio.enable = true
aa_text = true
fbo_active = true
shaders_active = true
shaders_kind_distort = true
shaders_kind_adv = true
shaders_kind_volumetric = false
screen_zoom = 1
particles_density = 100
background_saves = true
mouse_cursor = true
display_fps = 30
gamma_correction = 120
font_scale = 100
mouse_move = true
censor_boot = true
chat.filter = {}
chat.ignores = {}
addons = {}
allow_online_events = true
upgrades { v1_0_5=true }
]]
for i, file in ipairs(fs.list("/settings/")) do
if file:find(".cfg$") then
config.load("/settings/"..file)
end
end
if config.settings.force_safeboot then
util.removeForceSafeBoot()
core.display.forceSafeMode()
end
if core.display.safeMode() then
config.settings.aa_text = false
config.settings.fbo_active = false
config.settings.shaders_active = false
config.settings.particles_density = 5
config.settings.background_saves = false
config.settings.mouse_cursor = false
config.settings.display_fps = 10
config.settings.window = {size='800x600 Windowed'}
end
-- Default resolution as big as possible
if not config.settings.window or not config.settings.window.size then
local list = core.display.getModesList()
table.sort(list, function(a, b) return a.w > b.w end)
local r = list[1] or {w=800, h=600}
print("[RESOLUTION] no configured resolution, defaulting to biggest possible: ", r.w, r.h)
config.settings.window = config.settings.window or {}
--local x, y = math.max(800, math.floor(r.w * 0.75)), math.max(600, math.floor(r.h*0.75))
local x, y = r.w, r.h
config.settings.window.size = x.."x"..y.." Fullscreen"
end
-- Move around
if config.settings.window.pos then
core.display.setWindowPos(config.settings.window.pos.x, config.settings.window.pos.y)
else
local px, py = core.display.windowPos()
config.settings.window = config.settings.window or {}
config.settings.window.pos = {x=px, y=py}
end
-- Audio
core.sound.enable(config.settings.audio.enable)
-- Load default keys
engine.KeyBind:load("move,hotkeys,inventory,actions,interface,debug")
-- Load remaps
if fs.exists("/keybinds2.cfg") then
engine.KeyBind:loadRemap("/keybinds2.cfg")
end
fs.umount(engine.homepath)
-- Steam cloud saves, disabled until the user chooses otherwise
if core.steam and not config.settings.steam_cloud_choose then
print("[STEAM] Disabling cloud saves until the user elects to use them")
core.steam.cloudEnable(false)
end
-- Setup a default key handler
local key = engine.KeyBind.new()
key:setCurrent()
-- Load the game module
game = false
-- Setup resolution
engine.Game:setResolution(config.settings.window.size, true)
core.display.setTextBlended(config.settings.aa_text)
-- core.display.setGamma(config.settings.gamma_correction / 100)
if not config.settings.fbo_active then core.display.disableFBO() print("Disabling FBO") end
if not config.settings.shaders_active then core.shader.disable() print("Disabling Shaders") end
-- Webcore local request resolver
dofile("/engine/webcore.lua")
-- Load profile configs
core.profile.createThread()
profile = engine.PlayerProfile.new()
profile:start()
-- Create a savefile pipe
savefile_pipe = engine.SavefilePipe.new()
-- Setup FPS
core.game.setFPS(config.settings.display_fps)
if config.settings.disable_discord then core.discord = nil end
if core.discord then core.discord.init() end
util.showMainMenu(true)