-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
500 lines (482 loc) · 19.8 KB
/
main.lua
File metadata and controls
500 lines (482 loc) · 19.8 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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
--- Save Rewinder - main.lua
--
-- Steamodded entry point (for config UI only).
REWINDER = REWINDER or {}
SMODS.Atlas {
key = "modicon",
path = "modicon.png",
px = 32,
py = 32,
}:register()
if SMODS and SMODS.current_mod then
REWINDER.mod = SMODS.current_mod
REWINDER.config = REWINDER.mod.config or {}
local function _loc(key, fallback)
return (localize and localize(key)) or fallback
end
local EXPORT_DIR_INPUT_WIDTH = 8.8
local EXPORT_DIR_VISIBLE_CHARS = 68
local function _left_ellipsis(text, keep_chars)
local s = tostring(text or "")
local keep = tonumber(keep_chars) or 0
if keep <= 0 then return "" end
if #s <= keep then return s end
if keep <= 3 then return string.rep(".", keep) end
return "..." .. string.sub(s, #s - (keep - 4))
end
REWINDER.format_export_dir_display = function(path)
return _left_ellipsis(path, EXPORT_DIR_VISIBLE_CHARS)
end
REWINDER.split_export_dir_display = function(full_path)
local FileIO = require("FileIO")
local profile = FileIO.get_profile and FileIO.get_profile() or "1"
local suffix = "/" .. tostring(profile)
local base = tostring(full_path or "")
-- Strip trailing profile suffix if present
if #base >= #suffix and string.sub(base, -#suffix) == suffix then
base = string.sub(base, 1, #base - #suffix)
end
local base_text = _left_ellipsis(base, EXPORT_DIR_VISIBLE_CHARS - #suffix)
return base_text, suffix
end
-- Builders for repeated config UI structures
local function _section_header(label_key, fallback)
return {
n = G.UIT.R,
config = { align = "cm", padding = 0.05 },
nodes = {
{
n = G.UIT.T,
config = {
text = _loc(label_key, fallback),
colour = G.C.UI.TEXT_LIGHT,
scale = 0.45,
},
},
},
}
end
local function _toggle_row(label_key, fallback, ref_value)
return {
n = G.UIT.R,
config = { align = "cl", padding = 0.02 },
nodes = {
create_toggle({
label = _loc(label_key, fallback),
ref_table = REWINDER.config,
ref_value = ref_value,
}),
},
}
end
local function _rewinder_keybind_label(name)
if REWINDER and REWINDER.keybinds and REWINDER.keybinds.get_binding and REWINDER.keybinds.format_binding then
return REWINDER.keybinds.format_binding(REWINDER.keybinds.get_binding(name))
end
return _loc("rewinder_keybind_none", "[none]")
end
local function _rewinder_keybind_row(name, label_key)
local ref_table = {
name = name,
label = { text = _rewinder_keybind_label(name) },
}
REWINDER._keybind_label_refs = REWINDER._keybind_label_refs or {}
REWINDER._keybind_label_refs[#REWINDER._keybind_label_refs + 1] = ref_table
return {
n = G.UIT.R,
config = { align = "cl", padding = 0.04 },
nodes = {
{
n = G.UIT.C,
config = { align = "cl", padding = 0 },
nodes = {
{
n = G.UIT.T,
config = {
text = _loc(label_key, label_key),
scale = 0.35,
colour = G.C.UI.TEXT_LIGHT,
},
},
},
},
{
n = G.UIT.C,
config = { align = "cr", padding = 0.05 },
nodes = {
UIBox_button({
ref_table = ref_table,
button = "rewinder_change_keybind",
label = {},
dynamic_label = ref_table.label,
minh = 0.32,
minw = 3,
col = true,
scale = 0.3,
colour = G.C.GREY,
}),
},
},
},
}
end
SMODS.current_mod.config_tab = function()
return {
n = G.UIT.ROOT,
config = { r = 0.1, minw = 9, align = "tm", padding = 0.2, colour = G.C.BLACK },
nodes = {
-- Main row with two columns
{
n = G.UIT.R,
config = { padding = 0.1 },
nodes = {
-- Left column: Auto-Save Triggers
{
n = G.UIT.C,
config = { align = "tm", padding = 0.1 },
nodes = {
_section_header("rewinder_section_auto_save", "Auto-Save Triggers"),
_toggle_row("rewinder_save_on_blind", "Save when choosing blind", "save_on_blind"),
_toggle_row("rewinder_save_on_selecting_hand", "Save when selecting hand", "save_on_selecting_hand"),
_toggle_row("rewinder_save_on_round_end", "Save at end of round", "save_on_round_end"),
_toggle_row("rewinder_save_on_shop", "Save in shop", "save_on_shop"),
},
},
-- Right column: Display Options
{
n = G.UIT.C,
config = { align = "tm", padding = 0.1 },
nodes = {
_section_header("rewinder_section_display", "Display Options"),
_toggle_row("rewinder_show_blind_image", "Show blind image", "show_blind_image"),
_toggle_row("rewinder_animate_blind_image", "Blind image effects", "animate_blind_image"),
_toggle_row("rewinder_clamp_infinity_scores", "Clamp infinity scores", "clamp_infinity_scores"),
},
},
},
},
-- Advanced section (full width)
_section_header("rewinder_section_advanced", "Advanced"),
{
n = G.UIT.R,
config = { align = "cm", padding = 0.03 },
nodes = {
{
n = G.UIT.C,
config = { align = "cm", padding = 0.05 },
nodes = {
create_option_cycle({
label = _loc("rewinder_max_antes_per_run", "Max saved antes per run"),
options = {
"1",
"2",
"4",
"6",
"8",
"16",
_loc("rewinder_all_label", "All"),
},
current_option = REWINDER.config.keep_antes or 7,
colour = G.C.BOOSTER,
w = 4,
text_scale = 0.4,
scale = 0.8,
ref_table = REWINDER.config,
ref_value = "keep_antes",
opt_callback = "rewinder_config_change",
}),
},
},
{
n = G.UIT.C,
config = { align = "cm", padding = 0.05 },
nodes = {
create_option_cycle({
label = _loc("rewinder_max_saves_per_type_per_round", "Max saves per type per round"),
options = {
"8",
"16",
"64",
"128",
_loc("rewinder_all_label", "All"),
},
current_option = REWINDER.config.max_saves_per_type_per_round or 2,
colour = G.C.BOOSTER,
w = 4,
text_scale = 0.4,
scale = 0.8,
ref_table = REWINDER.config,
ref_value = "max_saves_per_type_per_round",
opt_callback = "rewinder_config_change",
}),
},
},
},
},
-- Debug toggle and Delete button on same row
{
n = G.UIT.R,
config = { align = "cm", padding = 0.05 },
nodes = {
{
n = G.UIT.C,
config = { align = "cm", padding = 0.1 },
nodes = {
create_toggle({
label = _loc("rewinder_debug_saves", "Debug: verbose logging"),
ref_table = REWINDER.config,
ref_value = "debug_saves",
}),
},
},
{
n = G.UIT.C,
config = { align = "cm", padding = 0.1 },
nodes = {
UIBox_button({
label = { _loc("rewinder_delete_all_saves_button", "Delete all saves") },
button = "rewinder_save_delete_all",
minw = 3,
minh = 0.6,
scale = 0.4,
colour = G.C.RED,
}),
},
},
},
},
},
}
end
REWINDER.keybinds_tab = function()
REWINDER._keybind_label_refs = {}
return {
n = G.UIT.ROOT,
config = { r = 0.1, minw = 9, align = "tm", padding = 0.2, colour = G.C.BLACK },
nodes = {
{
n = G.UIT.R,
config = { align = "cm", padding = 0.05 },
nodes = {
{
n = G.UIT.T,
config = {
text = _loc("rewinder_keybinds_title", "Keybinds"),
colour = G.C.UI.TEXT_LIGHT,
scale = 0.45,
},
},
},
},
_rewinder_keybind_row("step_back", "rewinder_keybind_step_back"),
_rewinder_keybind_row("toggle_saves", "rewinder_keybind_toggle_saves"),
_rewinder_keybind_row("quick_saveload", "rewinder_keybind_quick_saveload"),
{
n = G.UIT.R,
config = { align = "cm", padding = 0.06 },
nodes = {
UIBox_button({
label = { _loc("rewinder_keybind_reset", "Reset to defaults") },
button = "rewinder_reset_keybinds",
minw = 3.6,
minh = 0.6,
scale = 0.35,
colour = G.C.RED,
}),
},
},
{
n = G.UIT.R,
config = { align = "cm", padding = 0.06 },
nodes = {
{
n = G.UIT.T,
config = {
text = _loc("rewinder_keybind_hint", "Click a keybind and press keys. Esc clears it."),
colour = G.C.UI.TEXT_LIGHT,
scale = 0.3,
},
},
},
},
},
}
end
G.FUNCS.rewinder_change_keybind = function(e)
if not e or not e.config or not e.config.ref_table then return end
local name = e.config.ref_table.name
local dynamic_label = e.config.ref_table.label
if dynamic_label then
dynamic_label.text = _loc("rewinder_keybind_waiting", "Waiting for input...")
end
if REWINDER and REWINDER.keybinds and REWINDER.keybinds.record then
REWINDER.keybinds.record({
name = name,
callback = function(keys)
if not keys then
if dynamic_label then dynamic_label.text = "error" end
return
end
if REWINDER.keybinds.update_binding then
-- update_binding merges the new keys into keyboard/controller sub-tables
REWINDER.keybinds.update_binding(name, keys)
elseif REWINDER.keybinds.set_binding then
-- Fallback
REWINDER.keybinds.set_binding(name, keys)
end
if dynamic_label then
-- Get the full updated binding to format correctly
local new_binding = REWINDER.keybinds.get_binding(name)
dynamic_label.text = REWINDER.keybinds.format_binding(new_binding)
end
end,
press_callback = function(keys)
if dynamic_label then
dynamic_label.text = REWINDER.keybinds.format_binding(keys)
end
end,
})
end
end
G.FUNCS.rewinder_reset_keybinds = function()
if REWINDER and REWINDER.keybinds and REWINDER.keybinds.reset_defaults then
REWINDER.keybinds.reset_defaults()
end
if REWINDER and REWINDER._keybind_label_refs then
for _, ref_table in ipairs(REWINDER._keybind_label_refs) do
if ref_table and ref_table.label and ref_table.name then
ref_table.label.text = _rewinder_keybind_label(ref_table.name)
end
end
end
end
SMODS.current_mod.extra_tabs = function()
return {
{
label = _loc("rewinder_tab_keybinds", "Keybinds"),
tab_definition_function = REWINDER.keybinds_tab,
},
{
label = _loc("rewinder_tab_export", "Export"),
tab_definition_function = function()
local ExportService = require("ExportService")
-- Keep input value always as string; nil breaks text-input internals.
if type(REWINDER.config.export_dir) ~= "string" then
REWINDER.config.export_dir = ""
end
if type(REWINDER.config.export_full_seed_non_seeded) ~= "boolean" then
REWINDER.config.export_full_seed_non_seeded = ((tonumber(REWINDER.config.export_seed_mode) or 1) == 2)
end
if type(REWINDER.config.export_include_meta) ~= "boolean" then
REWINDER.config.export_include_meta = false
end
local is_ios = love and love.system and love.system.getOS and love.system.getOS() == "iOS"
local current_path = ExportService.get_export_dir()
local _base_text, _suffix_text = REWINDER.split_export_dir_display(current_path)
local path_ref = {
full_text = current_path,
text = _base_text,
suffix_text = _suffix_text,
}
local export_tab_nodes = {
_section_header("rewinder_export_dir_label", "Export directory"),
{
n = G.UIT.R,
config = { align = "cm", padding = 0.05 },
nodes = {
{
n = G.UIT.C,
config = {
align = "cl",
minw = EXPORT_DIR_INPUT_WIDTH,
maxw = EXPORT_DIR_INPUT_WIDTH,
minh = 0.48,
padding = 0.05,
r = 0.1,
colour = G.C.GREY,
shadow = true,
},
nodes = {
{
n = G.UIT.R,
config = {
align = "cm",
colour = G.C.CLEAR,
minw = EXPORT_DIR_INPUT_WIDTH - 0.28,
maxw = EXPORT_DIR_INPUT_WIDTH - 0.28,
},
nodes = {
{ n = G.UIT.C, config = { minw = 0.14, colour = G.C.CLEAR } },
{
n = G.UIT.T,
config = {
ref_table = path_ref,
ref_value = "text",
colour = G.C.UI.TEXT_LIGHT,
scale = 0.32,
},
},
{
n = G.UIT.T,
config = {
ref_table = path_ref,
ref_value = "suffix_text",
colour = {0.75, 0.75, 0.75, 1},
scale = 0.32,
},
},
{ n = G.UIT.C, config = { minw = 0.14, colour = G.C.CLEAR } },
},
},
},
},
},
},
}
if not is_ios then
export_tab_nodes[#export_tab_nodes + 1] = {
n = G.UIT.R,
config = { align = "cm", padding = 0.03 },
nodes = {
{
n = G.UIT.C,
config = { align = "cm", padding = 0.03 },
nodes = {
UIBox_button({
label = { _loc("rewinder_export_paste", "Paste") },
button = "rewinder_export_paste_dir",
ref_table = { path_ref = path_ref },
minw = 1.7, minh = 0.48, scale = 0.35,
colour = G.C.BLUE,
}),
},
},
{
n = G.UIT.C,
config = { align = "cm", padding = 0.03 },
nodes = {
UIBox_button({
label = { _loc("rewinder_export_reset_dir", "Reset") },
button = "rewinder_export_reset_dir",
ref_table = { path_ref = path_ref },
minw = 1.7, minh = 0.48, scale = 0.35,
colour = G.C.GREY,
}),
},
},
},
}
end
export_tab_nodes[#export_tab_nodes + 1] = _toggle_row("rewinder_export_seed_label", "Show full seed for non-seeded runs", "export_full_seed_non_seeded")
export_tab_nodes[#export_tab_nodes + 1] = { n = G.UIT.R, config = { align = "cm", padding = 0.04 }, nodes = {} }
export_tab_nodes[#export_tab_nodes + 1] = _toggle_row("rewinder_export_include_meta", "Include .meta sidecar", "export_include_meta")
return {
n = G.UIT.ROOT,
config = { r = 0.1, minw = 9.8, align = "tm", padding = 0.2, colour = G.C.BLACK },
nodes = export_tab_nodes,
}
end,
},
}
end
end