1
Fork 0
mirror of https://github.com/Steffo99/noita-starting-perk.git synced 2024-10-16 05:27:27 +00:00

Implement mod configuration

This commit is contained in:
Steffo 2021-09-10 22:53:48 +02:00
parent 3c30b3c2c4
commit b7b261848c
Signed by: steffo
GPG key ID: 6965406171929D01
3 changed files with 104 additions and 6 deletions

View file

@ -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

View file

@ -1,5 +1,5 @@
<Mod
name="Random starting perk"
name="Starting perk"
description="Start every run with a perk from the Holy Mountain pool."
request_no_api_restrictions="0"
>

37
settings.lua Normal file
View file

@ -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