diff --git a/init.lua b/init.lua index 8e8291e..f95f537 100755 --- a/init.lua +++ b/init.lua @@ -1,4 +1,6 @@ -dofile( "data/scripts/perks/perk.lua" ) +dofile("data/scripts/perks/perk.lua") +dofile("data/scripts/lib/utilities.lua") +dofile("data/scripts/lib/mod_settings.lua") function OnPlayerSpawned( player_entity ) @@ -10,9 +12,68 @@ function OnPlayerSpawned( player_entity ) end GameAddFlagRun( init_check_flag ) - -- Spawn a perk below the 1..2 wall - perk_spawn_random( 771, -96 ) + -- Load mod settings + local perks_amount = ModSettingGet("starting_perk.perks_spawned") + local only_one = ModSettingGet("starting_perk.only_one") - -- Used to take the screenshot - -- perk_spawn( 771, -96, "GENOME_MORE_LOVE" ) + -- Print mod settings to the player + if only_one then + GamePrint("Starting with a choice between " .. to_string(perks_amount) .. " perks") + else + GamePrint("Starting with " .. to_string(perks_amount) .. " free perks") + end + + local x_center = 789 + local y_bottom = -96 + + local gap = 6 + local size = 14 + local offset = gap + size + + -- Find the number of rows + -- Ceil makes it wider instead of taller + local rows = math.ceil(math.sqrt(perks_amount)) + + GamePrint("Spawning rows: "..tostring(rows)) + + -- Draw perk rows + for current_row = 1, rows, 1 do + + -- Find the number of columns + local cols + if perks_amount < rows then + -- Spawn only the leftover amount + cols = perks_amount + else + -- Spawn the full amount + cols = rows + end + + GamePrint("Spawning cols: " .. tostring(cols)) + + -- If there is something to spawn + if cols ~= 0 then + -- Find the total row width + local width = (offset * cols) + size + + -- Find the X position to start spawning perks at + local x_left = x_center - (width / 2) + + -- Draw perk columns + for current_col=1, cols, 1 do + + -- Find the position to spawn each perk at + local x = x_left + (current_col - 1) * offset + local y = y_bottom - (current_row - 1) * offset + + -- Spawn the perk + -- perk_spawn_random(x, y, not only_one) + + -- Used to take the screenshot + perk_spawn( 771, -96, "GENOME_MORE_LOVE" ) + + perks_amount = perks_amount - 1 + end + end + end end diff --git a/mod.xml b/mod.xml index fd6c198..3522ba9 100755 --- a/mod.xml +++ b/mod.xml @@ -1,5 +1,5 @@ diff --git a/settings.lua b/settings.lua new file mode 100644 index 0000000..34a2b35 --- /dev/null +++ b/settings.lua @@ -0,0 +1,37 @@ +dofile("data/scripts/lib/mod_settings.lua") + + +local mod_id = "starting_perk" +mod_settings_version = 1 +mod_settings = { + { + id = "perks_spawned", + ui_name = "Number of perks spawned", + value_default = 1, + value_min = 1, + value_max = 25, + value_display_formatting = " $0 perks", + scope = MOD_SETTING_SCOPE_NEW_GAME, + }, + { + id = "only_one", + ui_name = "Only one", + ui_description = "Despawn the other perks when one is chosen.", + value_default = true, + scope = MOD_SETTING_SCOPE_NEW_GAME, + } +} + + +function ModSettingsUpdate( init_scope ) + local old_version = mod_settings_get_version( mod_id ) -- This can be used to migrate some settings between mod versions. + mod_settings_update( mod_id, mod_settings, init_scope ) +end + +function ModSettingsGuiCount() + return mod_settings_gui_count( mod_id, mod_settings ) +end + +function ModSettingsGui( gui, in_main_menu ) + mod_settings_gui( mod_id, mod_settings, gui, in_main_menu ) +end