forked from WilhelmW/persistence
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.lua
More file actions
359 lines (343 loc) · 18.6 KB
/
settings.lua
File metadata and controls
359 lines (343 loc) · 18.6 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
dofile_once("data/scripts/lib/mod_settings.lua");
-- dofile_once("data/scripts/debug/keycodes.lua");
-- This file can't access other files from this or other mods in all circumstances.
-- Settings will be automatically saved.
-- Settings don't have access unsafe lua APIs.
-- Use ModSettingGet() in the game to query settings.
-- For some settings (for example those that affect world generation) you might want to retain the current value until a certain point, even
-- if the player has changed the setting while playing.
-- To make it easy to define settings like that, each setting has a "scope" (e.g. MOD_SETTING_SCOPE_NEW_GAME) that will define when the changes
-- will actually become visible via ModSettingGet(). In the case of MOD_SETTING_SCOPE_NEW_GAME the value at the start of the run will be visible
-- until the player starts a new game.
-- ModSettingSetNextValue() will set the buffered value, that will later become visible via ModSettingGet(), unless the setting scope is MOD_SETTING_SCOPE_RUNTIME.
function mod_setting_integer(mod_id, gui, in_main_menu, im_id, setting)
local value = ModSettingGetNextValue(mod_setting_get_id(mod_id,setting));
if type(value) ~= "number" then value = setting.value_default or 0; end
local value_new = GuiSlider(gui, im_id, mod_setting_group_x_offset, 0, setting.ui_name, value, setting.value_min, setting.value_max, setting.value_default, setting.value_display_multiplier or 1, setting.value_display_formatting or "", 64);
value_new = math.floor(value_new);
if value ~= value_new then
ModSettingSetNextValue(mod_setting_get_id(mod_id,setting), value_new, false);
mod_setting_handle_change_callback(mod_id, gui, in_main_menu, setting, value, value_new);
end
mod_setting_tooltip(mod_id, gui, in_main_menu, setting);
end
function mod_setting_number_multiple(mod_id, gui, in_main_menu, im_id, setting)
local _round_to = setting.round_to or 1;
local value = ModSettingGetNextValue(mod_setting_get_id(mod_id,setting)) or setting.value_default;
local value_new = value;
value_new = math.floor( (GuiSlider(gui, im_id, mod_setting_group_x_offset, 0, setting.ui_name, value_new, setting.value_min, setting.value_max, setting.value_default, setting.value_display_multiplier or 1, setting.value_display_formatting or "", 64) / _round_to) + 0.5 ) * _round_to;
if value ~= value_new then
ModSettingSetNextValue(mod_setting_get_id(mod_id,setting), value_new, false);
mod_setting_handle_change_callback(mod_id, gui, in_main_menu, setting, value, value_new);
end
mod_setting_tooltip(mod_id, gui, in_main_menu, setting);
end
mod_id = "persistence" -- This should match the name of your mod's folder.
mod_settings_version = 2; -- This is a magic global that can be used to migrate settings to new mod versions. call mod_settings_get_version() before mod_settings_update() to get the old value.
mod_settings =
{
{
category_id = "encoded_settings",
ui_name = "",
ui_description = "",
settings = {
{ hidden = true, id = "loadout_1", ui_name = "1", ui_description = " ", text_max_length = 512, value_default = "",
allowed_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789, ", scope = MOD_SETTING_SCOPE_RUNTIME, },
{ hidden = true, id = "loadout_2", ui_name = "2", ui_description = " ", text_max_length = 512, value_default = "",
allowed_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789, ", scope = MOD_SETTING_SCOPE_RUNTIME, },
{ hidden = true, id = "loadout_3", ui_name = "3", ui_description = " ", text_max_length = 512, value_default = "",
allowed_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789, ", scope = MOD_SETTING_SCOPE_RUNTIME, },
{ hidden = true, id = "loadout_4", ui_name = "4", ui_description = " ", text_max_length = 512, value_default = "",
allowed_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789, ", scope = MOD_SETTING_SCOPE_RUNTIME, },
{ hidden = true, id = "loadout_5", ui_name = "5", ui_description = " ", text_max_length = 512, value_default = "",
allowed_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789, ", scope = MOD_SETTING_SCOPE_RUNTIME, },
{ hidden = true, id = "loadout_6", ui_name = "6", ui_description = " ", text_max_length = 512, value_default = "",
allowed_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789, ", scope = MOD_SETTING_SCOPE_RUNTIME, },
{ hidden = true, id = "loadout_7", ui_name = "7", ui_description = " ", text_max_length = 512, value_default = "",
allowed_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789, ", scope = MOD_SETTING_SCOPE_RUNTIME, },
{ hidden = true, id = "loadout_8", ui_name = "8", ui_description = " ", text_max_length = 512, value_default = "",
allowed_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789, ", scope = MOD_SETTING_SCOPE_RUNTIME, },
{ hidden = true, id = "loadout_9", ui_name = "9", ui_description = " ", text_max_length = 512, value_default = "",
allowed_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789, ", scope = MOD_SETTING_SCOPE_RUNTIME, },
{ hidden = true, id = "loadout_10", ui_name = "10", ui_description = " ", text_max_length = 512, value_default = "",
allowed_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789, ", scope = MOD_SETTING_SCOPE_RUNTIME, },
{ hidden = true, id = "loadout_11", ui_name = "11", ui_description = " ", text_max_length = 512, value_default = "",
allowed_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789, ", scope = MOD_SETTING_SCOPE_RUNTIME, },
{ hidden = true, id = "loadout_12", ui_name = "12", ui_description = " ", text_max_length = 512, value_default = "",
allowed_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789, ", scope = MOD_SETTING_SCOPE_RUNTIME, },
{ hidden = true, id = "loadout_13", ui_name = "13", ui_description = " ", text_max_length = 512, value_default = "",
allowed_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789, ", scope = MOD_SETTING_SCOPE_RUNTIME, },
{ hidden = true, id = "loadout_14", ui_name = "14", ui_description = " ", text_max_length = 512, value_default = "",
allowed_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789, ", scope = MOD_SETTING_SCOPE_RUNTIME, },
{ hidden = true, id = "loadout_15", ui_name = "15", ui_description = " ", text_max_length = 512, value_default = "",
allowed_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789, ", scope = MOD_SETTING_SCOPE_RUNTIME, },
{ hidden = true, id = "loadout_16", ui_name = "16", ui_description = " ", text_max_length = 512, value_default = "",
allowed_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789, ", scope = MOD_SETTING_SCOPE_RUNTIME, },
{ hidden = true, id = "loadout_17", ui_name = "17", ui_description = " ", text_max_length = 512, value_default = "",
allowed_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789, ", scope = MOD_SETTING_SCOPE_RUNTIME, },
{ hidden = true, id = "loadout_18", ui_name = "18", ui_description = " ", text_max_length = 512, value_default = "",
allowed_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789, ", scope = MOD_SETTING_SCOPE_RUNTIME, },
{ hidden = true, id = "loadout_19", ui_name = "19", ui_description = " ", text_max_length = 512, value_default = "",
allowed_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789, ", scope = MOD_SETTING_SCOPE_RUNTIME, },
{ hidden = true, id = "loadout_20", ui_name = "20", ui_description = " ", text_max_length = 512, value_default = "",
allowed_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789, ", scope = MOD_SETTING_SCOPE_RUNTIME, },
},
},
{
id = "restart_warning",
ui_name = "-- NOTE: These settings will not apply until you start a New Game. --",
not_setting = true,
},
{
category_id = "liteness_settings",
ui_name = "LITENESS",
ui_description = "'Lite-ness' settings (Keep money, etc)",
settings = {
{
id = "money_saved_on_death",
ui_name = "Money Saved on Death",
ui_description = "How much money persists after you do not",
ui_fn = mod_setting_number,
value_default = 25,
value_min = 0,
value_max = 100,
value_display_formatting = " $0 %",
scope = MOD_SETTING_SCOPE_NEW_GAME,
},
{
id = "cap_money_saved_on_death",
ui_name = "MAX Money Saved on Death",
ui_description = "If you think you're earning too quickly (0 is no limit)",
ui_fn = mod_setting_number,
value_default = 0,
value_min = 0,
value_max = 500,
value_display_formatting = " $ $0 k",
scope = MOD_SETTING_SCOPE_NEW_GAME,
},
},
},
{
category_id = "default_settings",
ui_name = "DEFAULTS",
ui_description = "Run defaults",
settings = {
{
id = "gamepad_menu_trigger",
ui_name = "Gamepad Menu Trigger",
ui_description = "Which key the mod listens to in order to trigger the Persistence menu",
value_default = "25",
values = { {"23","A"}, {"24", "B"}, {"25", "X"}, {"26", "Y"}, {"11", "DPAD_UP"}, {"12", "DPAD_DOWN"}, {"13", "DPAD_LEFT"}, {"14", "DPAD_RIGHT"} },
-- value_default = JOY_BUTTON_X,
-- values = { {JOY_BUTTON_A,"A"}, {JOY_BUTTON_B , "B"}, {JOY_BUTTON_X , "X"}, {JOY_BUTTON_Y , "Y"}, {JOY_BUTTON_DPAD_UP , "DPAD_UP"}, {JOY_BUTTON_DPAD_DOWN , "DPAD_DOWN"}, {JOY_BUTTON_DPAD_LEFT , "DPAD_LEFT"}, {JOY_BUTTON_DPAD_RIGHT , "DPAD_RIGHT"} },
scope = MOD_SETTING_SCOPE_RUNTIME,
},
{
id = "always_choose_save_id",
ui_name = "Load-Save behavior",
ui_description = "Manually or automatically load a save (or not)",
value_default = "-1",
values = { {"-1","Manual"}, {"0","Disable mod"}, {"1","Use Slot 1"}, {"2","Use Slot 2"}, {"3","Use Slot 3"}, {"4","Use Slot 4"}, {"5","Use Slot 5"} },
scope = MOD_SETTING_SCOPE_RUNTIME_RESTART,
},
{
id = "allow_stash",
ui_name = "(Manual) Stash use",
ui_description = "Optionally disallow withdrawals, or manual use altogether. Automatic payouts still work.",
value_default = "1",
values = { {"1","Allow"}, {"0","Disable Entirely"}, {"-1","Deposit Only"} },
scope = MOD_SETTING_SCOPE_NEW_GAME,
},
{
id = "start_with_money",
ui_name = "Start with money",
ui_description = "Money to withdraw from your Stash at run start",
ui_fn = mod_setting_number_multiple,
round_to = 25,
value_default = 0,
value_min = 0,
value_max = 5000,
value_display_multiplier = 1,
value_display_formatting = " $ $0",
scope = MOD_SETTING_SCOPE_NEW_GAME,
},
{
id = "holy_mountain_money",
ui_name = "Holy Mountain Reward (Stash)",
ui_description = "Money to withdraw from your Stash at each Holy Mountain, useful if Stash access is disabled as a challenge",
ui_fn = mod_setting_number_multiple,
round_to = 25,
value_default = 0,
value_min = 0,
value_max = 5000,
value_display_multiplier = 1,
value_display_formatting = " $ $0",
scope = MOD_SETTING_SCOPE_NEW_GAME,
},
{
id = "holy_mountain_reward",
ui_name = "Holy Mountain Reward (Bonus)",
ui_description = "Money to reward player for reaching each Holy Mountain",
ui_fn = mod_setting_number_multiple,
round_to = 50,
value_default = 0,
value_min = 0,
value_max = 10000,
value_display_multiplier = 1,
value_display_formatting = " $ $0",
scope = MOD_SETTING_SCOPE_NEW_GAME,
}
},
},
{
category_id = "multiplier_settings",
ui_name = "MULTIPLIERS",
ui_description = "Cost multipliers",
settings = {
{
id = "research_wand_price_multiplier",
ui_name = "Wand Research Price Multiplier",
ui_description = "Price Multiplier to Research a Wand",
ui_fn = mod_setting_number_multiple,
round_to = 0.01,
value_default = 1,
value_min = .1,
value_max = 3,
value_display_multiplier = 100,
value_display_formatting = " $0 %",
scope = MOD_SETTING_SCOPE_NEW_GAME,
},
{
id = "research_spell_price_multiplier",
ui_name = "Spell Research Price Multiplier",
ui_description = "Price Multiplier to Research a Spell",
ui_fn = mod_setting_number_multiple,
round_to = 0.1,
value_default = 10,
value_min = 1,
value_max = 30,
value_display_multiplier = 10,
value_display_formatting = " $0 %",
scope = MOD_SETTING_SCOPE_NEW_GAME,
},
{
id = "buy_wand_price_multiplier",
ui_name = "Buy Wand Price Multiplier",
ui_description = "Price Multiplier to Buy a Wand",
ui_fn = mod_setting_number_multiple,
round_to = 0.01,
value_default = 1,
value_min = .1,
value_max = 3,
value_display_multiplier = 100,
value_display_formatting = " $0 %",
scope = MOD_SETTING_SCOPE_NEW_GAME,
},
{
id = "buy_spell_price_multiplier",
ui_name = "Buy Spell Price Multiplier",
ui_description = "Price Multiplier to Buy a Spell",
ui_fn = mod_setting_number_multiple,
round_to = 0.01,
value_default = 1,
value_min = .1,
value_max = 3,
value_display_multiplier = 100,
value_display_formatting = " $0 %",
scope = MOD_SETTING_SCOPE_NEW_GAME,
},
},
},
{
category_id = "toggle_settings",
ui_name = "TOGGLES",
ui_description = "Feature toggles",
settings = {
{
id = "show_guide_tips",
ui_name = "Show Guide Tooltips in Persistence menus",
ui_description = "Hotkeys, feature explanations, etc...",
value_default = true,
scope = MOD_SETTING_SCOPE_RUNTIME,
},
{
id = "allow_scanner",
ui_name = "Entity Scanner",
ui_description = "The Entity Scanner watches for nearby spells and wands, and indicates wether or not they have been researched.",
value_default = true,
scope = MOD_SETTING_SCOPE_RUNTIME,
},
{
hidden = true, -- Unused, keep for future need?
id = "move_lobby_to_spawn",
ui_name = "Move Lobby to Spawn location",
ui_description = "Lobby is normally Starting Cave. Move Lobby to Spawn instead. Meant for Random runs.",
value_default = false,
scope = MOD_SETTING_SCOPE_NEW_GAME,
},
{
id = "enable_edit_wands_in_lobby",
ui_name = "Allow editing Wands in Lobby",
ui_description = "Only allowed in Holy Mountain / with perk normally",
value_default = false,
scope = MOD_SETTING_SCOPE_NEW_GAME,
},
{
id = "enable_teleport_back_up",
ui_name = "Allow Teleport to Lobby from within Holy Mountain",
ui_description = "Note: There is no return teleport!",
value_default = true,
scope = MOD_SETTING_SCOPE_NEW_GAME,
},
{
id = "enable_menu_in_holy_mountain",
ui_name = "Allow Persistence menu in Holy Mountain",
ui_description = "Allow access to Persistence menu (for stash deposit/withdraw, research, buy) in Holy Mountain",
value_default = true,
scope = MOD_SETTING_SCOPE_NEW_GAME,
},
{
id = "reusable_holy_mountain",
ui_name = "Allow Holy Mountain to be reused",
ui_description = "Definitely a cheat.",
value_default = false,
scope = MOD_SETTING_SCOPE_NEW_GAME,
},
{
id = "global_persistence",
ui_name = "Always allow Persistence menu access",
ui_description = "Because why not?",
value_default = false,
scope = MOD_SETTING_SCOPE_NEW_GAME,
},
},
},
}
-- This function is called to ensure the correct setting values are visible to the game via ModSettingGet(). your mod's settings don't work if you don't have a function like this defined in settings.lua.
-- This function is called:
-- - when entering the mod settings menu (init_scope will be MOD_SETTINGS_SCOPE_ONLY_SET_DEFAULT)
-- - before mod initialization when starting a new game (init_scope will be MOD_SETTING_SCOPE_NEW_GAME)
-- - when entering the game after a restart (init_scope will be MOD_SETTING_SCOPE_RESTART)
-- - at the end of an update when mod settings have been changed via ModSettingsSetNextValue() and the game is unpaused (init_scope will be MOD_SETTINGS_SCOPE_RUNTIME)
function ModSettingsUpdate(init_scope)
local old_version = mod_settings_get_version(mod_id) -- This can be used to migrate some settings between mod versions.
if old_version==1 then
-- need to update money_saved_on_death * 100
money_saved_on_death = ModSettingGet("persistence.money_saved_on_death");
ModSettingSet("persistence.money_saved_on_death", money_saved_on_death * 100, money_saved_on_death==25);
end
mod_settings_update(mod_id, mod_settings, init_scope)
end
-- This function should return the number of visible setting UI elements.
-- Your mod's settings wont be visible in the mod settings menu if this function isn't defined correctly.
-- If your mod changes the displayed settings dynamically, you might need to implement custom logic.
-- The value will be used to determine whether or not to display various UI elements that link to mod settings.
-- At the moment it is fine to simply return 0 or 1 in a custom implementation, but we don't guarantee that will be the case in the future.
-- This function is called every frame when in the settings menu.
function ModSettingsGuiCount()
return mod_settings_gui_count(mod_id, mod_settings)
end
-- This function is called to display the settings UI for this mod. Your mod's settings wont be visible in the mod settings menu if this function isn't defined correctly.
function ModSettingsGui(gui, in_main_menu)
mod_settings_gui(mod_id, mod_settings, gui, in_main_menu)
end