-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsettings.lua
More file actions
175 lines (156 loc) · 5.27 KB
/
settings.lua
File metadata and controls
175 lines (156 loc) · 5.27 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
local _ = dofile_once("data/scripts/lib/mod_settings.lua")
local mod_id = "kaleva_koetus"
local ascension_setting
---@return number
local function get_max_ascension_level()
local setting_max_level = tonumber(ModSettingGet("kaleva_koetus.ascension_highest"))
return setting_max_level and setting_max_level > 0 and setting_max_level or 1 -- At least level 1
end
local function get_ascension_values()
local values = {}
local max_level = get_max_ascension_level()
-- Add unlocked ascension levels
for i = 1, max_level do
table.insert(values, {
tostring(i),
"Ascension " .. i,
})
end
return values
end
local function locate_ascension_setting()
if ascension_setting ~= nil then
return ascension_setting
end
if not mod_settings then
return nil
end
local function search(settings)
for _, setting in ipairs(settings) do
if setting.id == "ascension_current" then
ascension_setting = setting
return true
end
if setting.settings and search(setting.settings) then
return true
end
end
return false
end
for _, category in ipairs(mod_settings) do
if category.settings and search(category.settings) then
break
end
end
return ascension_setting
end
local function update_ascension_setting_values()
local setting = locate_ascension_setting()
if setting then
setting.values = get_ascension_values()
end
end
-- selene: allow(unused_variable)
local function reset_ascension_level()
ascension_setting = nil
update_ascension_setting_values()
end
-- This function is called when the game is initializing settings
function ModSettingsUpdate(init_scope)
local _old_version = mod_settings_get_version(mod_id)
update_ascension_setting_values()
mod_settings_update(mod_id, mod_settings, init_scope)
end
-- This function should return the current value of the setting
function ModSettingsGuiCount()
return mod_settings_gui_count(mod_id, mod_settings)
end
-- This function is called when drawing the settings UI
function ModSettingsGui(gui, in_main_menu)
update_ascension_setting_values()
mod_settings_gui(mod_id, mod_settings, gui, in_main_menu)
end
-- Define mod settings
mod_settings_version = 1
mod_settings = {
{
category_id = "ascension_settings",
ui_name = "Ascension Settings",
ui_description = "Configure ascension level for your run",
settings = {
{
id = "ascension_current",
ui_name = "Ascension Level",
ui_description = "Select the ascension level for this run",
value_default = tostring(get_max_ascension_level()),
values = get_ascension_values(),
scope = MOD_SETTING_SCOPE_NEW_GAME,
},
{
id = "show_ascension_info",
ui_name = "Show Ascension Info",
ui_description = "Display current ascension level and effects during gameplay",
value_default = true,
scope = MOD_SETTING_SCOPE_NEW_GAME,
},
-- {
-- category_id = "debug_settings",
-- ui_name = "Debug Settings",
-- ui_description = "Debug options for testing",
-- foldable = true,
-- _folded = true,
-- settings = {
-- {
-- id = "log_level",
-- ui_name = "Log Level",
-- ui_description = "Select verbosity for Kaleva Koetus logs",
-- value_default = "INFO",
-- values = {
-- { "ERROR", "Error" },
-- { "WARN", "Warn" },
-- { "INFO", "Info" },
-- { "DEBUG", "Debug" },
-- { "VERBOSE", "Verbose" },
-- },
-- scope = MOD_SETTING_SCOPE_RUNTIME,
-- },
-- {
-- id = "single_ascension",
-- ui_name = "Single Ascension",
-- ui_description = "Activate only one ascension",
-- value_default = false,
-- scope = MOD_SETTING_SCOPE_NEW_GAME,
-- },
-- {
-- id = "lock_all",
-- ui_name = "Lock All Ascensions",
-- ui_description = "Instantly lock all ascension levels (for testing)",
-- value_default = "Click to lock ascension",
-- values = { { "ok", "OK" } },
-- scope = MOD_SETTING_SCOPE_RUNTIME,
-- change_fn = function(_mod_id, _gui, _in_main_menu, _setting, _old_value, _new_value)
-- -- Unlock all levels
-- ModSettingSet("kaleva_koetus.ascension_highest", "1")
-- reset_ascension_level()
-- print("[Kaleva Koetus] All ascensions locked!")
-- end,
-- },
-- {
-- id = "unlock_all",
-- ui_name = "Unlock All Ascensions",
-- ui_description = "Instantly unlock all ascension levels (for testing)",
-- value_default = "Click to unlock ascension",
-- values = { { "ok", "OK" } },
-- scope = MOD_SETTING_SCOPE_RUNTIME,
-- change_fn = function(_mod_id, _gui, _in_main_menu, _setting, _old_value, _new_value)
-- -- Unlock all levels
-- ModSettingSet("kaleva_koetus.ascension_highest", "20")
-- reset_ascension_level()
-- print("[Kaleva Koetus] All ascensions unlocked!")
-- end,
-- },
-- },
-- },
},
},
}