-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
config.lua
119 lines (95 loc) · 3.28 KB
/
config.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
--=========== Copyright © 2019, Planimeter, All rights reserved. ===========--
--
-- Purpose: Config interface
--
--==========================================================================--
require( "engine.shared.convar" )
local convar = convar
local love = love
local math = math
local tonumber = tonumber
module( "config" )
_conf = _conf or nil
local function createConvars()
convar( "r_window_width", 800, 800, nil,
"Sets the width of the window on load", nil, { "archive" } )
convar( "r_window_height", 600, 600, nil,
"Sets the height of the window on load", nil, { "archive" } )
convar( "r_window_fullscreen", "0", nil, nil,
"Toggles fullscreen mode", nil, { "archive" } )
convar( "r_window_fullscreentype", "desktop", nil, nil,
"Sets the fullscreen type on load", nil, { "archive" } )
convar( "r_window_vsync", "1", nil, nil,
"Toggles vertical synchronization", nil, { "archive" } )
convar( "r_window_borderless", "0", nil, nil,
"Toggles borderless mode", nil, { "archive" } )
convar( "r_window_highdpi", "1", nil, nil,
"Sets the high-dpi mode on load", nil, { "archive" } )
local function updateVolume( convar )
local volume = convar:getNumber()
love.audio.setVolume( volume )
end
convar( "snd_volume", 1, 0, 1,
"Sets the master volume",
updateVolume, { "archive" } )
convar( "snd_desktop", "1", nil, nil,
"Toggles playing sound from the desktop", nil, { "archive" } )
end
function load( c )
love.filesystem.setIdentity( c.identity, c.appendidentity )
convar.readConfig()
setWindow( c )
setSound( c )
createConvars()
_conf = c
end
local function toboolean( v )
local n = tonumber( v )
return n ~= nil and n ~= 0
end
function setWindow( c )
local r_window_width = convar.getConfig( "r_window_width" )
local r_window_height = convar.getConfig( "r_window_height" )
local r_window_fullscreen = convar.getConfig( "r_window_fullscreen" )
local r_window_fullscreentype = convar.getConfig( "r_window_fullscreentype" )
local r_window_vsync = convar.getConfig( "r_window_vsync" )
local r_window_borderless = convar.getConfig( "r_window_borderless" )
local r_window_highdpi = convar.getConfig( "r_window_highdpi" )
if ( r_window_width ) then
c.window.width = math.max( 800, tonumber( r_window_width ) )
end
if ( r_window_height ) then
c.window.height = math.max( 600, tonumber( r_window_height ) )
end
if ( r_window_fullscreen ) then
c.window.fullscreen = toboolean( r_window_fullscreen )
end
if ( r_window_fullscreentype ) then
c.window.fullscreentype = r_window_fullscreentype
end
if ( r_window_vsync ) then
c.window.vsync = toboolean( r_window_vsync )
end
if ( r_window_borderless ) then
c.window.borderless = toboolean( r_window_borderless )
end
if ( r_window_highdpi ) then
c.window.highdpi = toboolean( r_window_highdpi )
end
end
function setSound( c )
c.sound = c.sound or {}
c.sound.volume = 1
c.sound.desktop = true
local snd_volume = convar.getConfig( "snd_volume" )
local snd_desktop = convar.getConfig( "snd_desktop" )
if ( snd_volume ) then
c.sound.volume = tonumber( snd_volume )
end
if ( snd_desktop ) then
c.sound.desktop = toboolean( snd_desktop )
end
end
function getConfig()
return _conf
end