Skip to content

Instantly share code, notes, and snippets.

@n4ru
Created April 12, 2024 01:36
Show Gist options
  • Save n4ru/885293b844f27e7c90705e4cca9c0f3f to your computer and use it in GitHub Desktop.
Save n4ru/885293b844f27e7c90705e4cca9c0f3f to your computer and use it in GitHub Desktop.
Seed Challenges - Allows seeding challenge runs.
--- STEAMODDED HEADER
--- MOD_NAME: Seed Challenges
--- MOD_ID: seed_challenges
--- MOD_AUTHOR: [thirk]
--- MOD_DESCRIPTION: Allows seeding challenge runs.
----------------------------------------------
------------MOD CODE -------------------------
function G.UIDEF.challenge_list(from_game_over)
G.CHALLENGE_PAGE_SIZE = 10
local challenge_pages = {}
for i = 1, math.ceil(#G.CHALLENGES/G.CHALLENGE_PAGE_SIZE) do
table.insert(challenge_pages, localize('k_page')..' '..tostring(i)..'/'..tostring(math.ceil(#G.CHALLENGES/G.CHALLENGE_PAGE_SIZE)))
end
G.E_MANAGER:add_event(Event({func = (function()
G.FUNCS.change_challenge_list_page{cycle_config = {current_option = 1}}
return true end)}))
local _ch_comp, _ch_tot = 0,#G.CHALLENGES
for k, v in ipairs(G.CHALLENGES) do
if v.id and G.PROFILES[G.SETTINGS.profile].challenge_progress.completed[v.id or ''] then
_ch_comp = _ch_comp + 1
end
end
local t = create_UIBox_generic_options({ back_id = from_game_over and 'from_game_over' or nil, back_func = 'setup_run', back_id = 'challenge_list', contents = {
{n=G.UIT.C, config={align = "cm", padding = 0.0}, nodes={
{n=G.UIT.R, config={align = "cm", padding = 0.1, minh = 7, minw = 4.2}, nodes={
{n=G.UIT.O, config={id = 'challenge_list', object = Moveable()}},
}},
{n=G.UIT.R, config={align = "cm", padding = 0.1}, nodes={
create_option_cycle({id = 'challenge_page',scale = 0.9, h = 0.3, w = 3.5, options = challenge_pages, cycle_shoulders = true, opt_callback = 'change_challenge_list_page', current_option = 1, colour = G.C.RED, no_pips = true, focus_args = {snap_to = true}})
}},
{n=G.UIT.R, config={align = "cm", padding = 0.1}, nodes={
{n=G.UIT.T, config={text = localize{type = 'variable', key = 'challenges_completed', vars = {_ch_comp, _ch_tot}}, scale = 0.4, colour = G.C.WHITE}},
}},
-- Add seeded run options
{n=G.UIT.R, config={align = "cm", padding = 0.05, minh = 0.9}, nodes={
{n=G.UIT.O, config={align = "cm", func = 'toggle_seeded_challenge_run', object = Moveable()}, nodes={
}},
}},
{n=G.UIT.R, config={align = "cm", padding = 0.1}, nodes={
{n=G.UIT.C, config={align = "cm", minw = 2.5, id = 'run_setup_seed'}, nodes={
create_toggle{col = true, label = localize('k_seeded_run'), label_scale = 0.25, w = 0, scale = 0.7, ref_table = G, ref_value = 'run_setup_seed'} or nil
}}
}}
-- end seeded run options
}},
{n=G.UIT.C, config={align = "cm", minh = 9, minw = 11.5}, nodes={
{n=G.UIT.O, config={id = 'challenge_area', object = Moveable()}},
}},
}})
return t
end
G.FUNCS.start_challenge_run = function(e)
local _seed = G.run_setup_seed and G.setup_seed or G.forced_seed or nil
if G.OVERLAY_MENU then G.FUNCS.exit_overlay_menu() end
G.FUNCS.start_run(e, {stake = 1, seed = _seed, challenge = G.CHALLENGES[e.config.id]})
end
function G.FUNCS.toggle_seeded_challenge_run(e)
if e.config.object and not G.run_setup_seed then
e.config.object:remove()
e.config.object = nil
elseif not e.config.object and G.run_setup_seed then
e.config.object = UIBox{
definition = {n=G.UIT.ROOT, config={align = "cm", colour = G.C.CLEAR}, nodes={
{n=G.UIT.C, config={align = "cm", minw = 2.5, padding = 0.05}, nodes={
simple_text_container('ml_disabled_seed',{colour = G.C.UI.TEXT_LIGHT, scale = 0.26, shadow = true}),
}},
{n=G.UIT.C, config={align = "cm", minw = 0.1}, nodes={
create_text_input({max_length = 8, all_caps = true, ref_table = G, ref_value = 'setup_seed', prompt_text = localize('k_enter_seed')}),
{n=G.UIT.C, config={align = "cm", minw = 0.1}, nodes={}},
UIBox_button({label = localize('ml_paste_seed'),minw = 1, minh = 0.6, button = 'paste_seed', colour = G.C.BLUE, scale = 0.3, col = true})
}},
}},
config = {offset = {x=0,y=0}, parent = e, type = 'cm'}
}
e.config.object:recalculate()
end
end
----------------------------------------------
------------MOD CODE END----------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment