Skip to content

Commit

Permalink
Add binds
Browse files Browse the repository at this point in the history
  • Loading branch information
EmeraldLoc committed Mar 10, 2024
1 parent f503605 commit 6ba3f9b
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 9 deletions.
31 changes: 28 additions & 3 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ TEXTURE_SL_PAINTING = get_texture_info("sl_painting")
TEXTURE_WDW_PAINTING = get_texture_info("wdw_painting")
TEXTURE_TTC_PAINTING = get_texture_info("ttc_painting")

-- binds
BIND_BOOST = 0
BIND_BOMBS = 1
BIND_MAX = 1

-- globals and sync tables
-- this is the round state, this variable tells you what current round it is
gGlobalSyncTable.roundState = ROUND_WAIT_PLAYERS
Expand Down Expand Up @@ -169,6 +174,22 @@ isPaused = false
-- whether or not to use romhack cam
useRomhackCam = true
if mod_storage_load("useRomhackCam") == "false" then useRomhackCam = false end
-- binds
binds = {}

-- boost bind
binds[BIND_BOOST] = {name = "Boost", btn = Y_BUTTON}
if mod_storage_load("bind_" .. tostring(BIND_BOOST)) ~= nil then
binds[BIND_BOOST].btn = tonumber(mod_storage_load("bind_" .. tostring(BIND_BOOST)))
end

-- bomb bind
binds[BIND_BOMBS] = {name = "Bombs", btn = Y_BUTTON}
if mod_storage_load("bind_" .. tostring(BIND_BOMBS)) ~= nil then
binds[BIND_BOMBS].btn = tonumber(mod_storage_load("bind_" .. tostring(BIND_BOMBS)))
end


-- speed boost timer handles boosting
local speedBoostTimer = 0
-- hot potato timer multiplier is when the timer is faster if there's more people in
Expand Down Expand Up @@ -902,7 +923,10 @@ local function mario_update(m)
end

-- handle speed boost, this is a fun if statement
if m.controller.buttonPressed & Y_BUTTON ~= 0 and speedBoostTimer >= 20 * 30 and gPlayerSyncTable[0].state == TAGGER and boosts_enabled() then
if m.controller.buttonPressed & binds[BIND_BOOST].btn ~= 0
and speedBoostTimer >= 20 * 30
and gPlayerSyncTable[0].state == TAGGER
and boosts_enabled() then
speedBoostTimer = 0
end

Expand Down Expand Up @@ -1109,7 +1133,7 @@ local function hud_boost()
elseif speedBoostTimer >= 5 * 30 and speedBoostTimer < 20 * 30 then
text = "Recharging"
else
text = "Boost (Y)"
text = "Boost (" .. button_to_text(binds[BIND_BOOST].btn) .. ")"
end

scale = 0.25
Expand Down Expand Up @@ -1156,8 +1180,9 @@ local function hud_bombs()
if bombCooldown < 2 * 30 then
text = "Reloading"
else
text = "Throw Bomb (Y)"
text = "Throw Bomb (" .. button_to_text(binds[BIND_BOMBS].btn) .. ")"
end
text = "Throw Bomb (" .. button_to_text(binds[BIND_BOMBS].btn) .. ")"

scale = 0.25
width = djui_hud_measure_text(text) * scale
Expand Down
44 changes: 44 additions & 0 deletions misc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,50 @@ function linear_interpolation(input, minRange, maxRange, minInput, maxInput)
return m * input + b
end

function button_to_text(btn)
if btn == A_BUTTON then
return "A"
elseif btn == B_BUTTON then
return "B"
elseif btn == X_BUTTON then
return "X"
elseif btn == Y_BUTTON then
return "Y"
elseif btn == L_TRIG then
return "L"
elseif btn == R_TRIG then
return "R"
elseif btn == Z_TRIG then
return "Z"
elseif btn == START_BUTTON then
return "Start"
elseif btn == U_CBUTTONS then
return "C-Up"
elseif btn == D_CBUTTONS then
return "C-Down"
elseif btn == L_CBUTTONS then
return "C-Left"
elseif btn == R_CBUTTONS then
return "C-Right"
elseif btn == U_JPAD then
return "D-Up"
elseif btn == D_JPAD then
return "D-Down"
elseif btn == L_JPAD then
return "D-Left"
elseif btn == R_JPAD then
return "D-Right"
end

return ""
end

function safetonumber(string, base)
if string == nil then return base end

return tonumber(string, base)
end

-- boost stuff
---@param o Object
function boost_particle_init(o)
Expand Down
90 changes: 85 additions & 5 deletions settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ blacklistAddRequest = false
INPUT_A = 0
INPUT_JOYSTICK = 1

local showBlacklistSettings = false
local showPlayerSettings = false
local showStartSettings = false
local scrollOffset = 0
local joystickCooldown = 0
local screenHeight = djui_hud_get_screen_height()
local bgWidth = 525
local selection = 1
local awaitingInput = nil

local function on_off_text(bool)
if bool then return "On" else return "Off" end
Expand Down Expand Up @@ -219,6 +217,11 @@ local function set_time_limit(gamemode)
-- I aint redoing it, cuz it works, but this is the most crappy piece of junk
-- i've seen all day

-- Future me, it's March 10th, tag v2.2 is released, and i'm getting ready
-- to release 2.21. What the hell is this. This could've been optimized heavily.
-- I don't think the ranting I did above is justified, its not thaat bad.
-- If it ain't broke, don't fix it

-- set variable based off of dir and speed
if gamemode == TAG then
if direction == CONT_LEFT then
Expand Down Expand Up @@ -387,6 +390,12 @@ local function get_rules(gamemode)
end
end

local function wait_for_button(bindIndex)
if binds[bindIndex] == nil then return end

awaitingInput = bindIndex
end

-- default selections
settingsEntries = {}
-- gamemode entries
Expand All @@ -397,6 +406,8 @@ startEntries = {}
playerEntries = {}
-- blacklisted levels
blacklistEntries = {}
-- binds
bindsEntries = {}

-- help entries
-- generate it here as it is never changed
Expand Down Expand Up @@ -604,6 +615,15 @@ local function reset_settings_selection()
selection = 1
end,
valueText = ">",},
-- binds selection
{name = "Bindings",
permission = PERMISSION_NONE,
input = INPUT_A,
func = function ()
entries = bindsEntries
selection = 1
end,
valueText = ">",},
-- help selection
{name = "Help",
permission = PERMISSION_NONE,
Expand Down Expand Up @@ -863,6 +883,51 @@ local function reset_blacklist_entries()
end
end

local function reset_bind_entries()
local resetBindEntries = false

if entries == bindsEntries then
resetBindEntries = true
end

bindsEntries = {}

for i = 0, BIND_MAX do

local bind = binds[i]
local value = ""

if i == awaitingInput then
value = "Waiting for Press..."
else
value = button_to_text(bind.btn)
end

table.insert(bindsEntries,
{name = bind.name,
permission = PERMISSION_NONE,
input = INPUT_A,
func = function ()
wait_for_button(i)
end,
valueText = value})
end

table.insert(bindsEntries,
{name = "Back",
permission = PERMISSION_NONE,
input = INPUT_A,
func = function ()
entries = settingsEntries
selection = 1
end}
)

if resetBindEntries then
entries = bindsEntries
end
end

local function hud_render()

if not showSettings then
Expand Down Expand Up @@ -891,6 +956,7 @@ local function hud_render()
reset_start_selection()
reset_player_selection()
reset_blacklist_entries()
reset_bind_entries()

local height = 90

Expand Down Expand Up @@ -978,12 +1044,14 @@ local function mario_update(m)
if selection < 1 then selection = #entries end
play_sound(SOUND_MENU_MESSAGE_DISAPPEAR, gGlobalSoundSource)
joystickCooldown = 0.2 * 30
awaitingInput = nil
elseif m.controller.buttonPressed & D_JPAD ~= 0
or (m.controller.stickY < -0.5 and joystickCooldown <= 0) then
selection = selection + 1
if selection > #entries then selection = 1 end
play_sound(SOUND_MENU_MESSAGE_DISAPPEAR, gGlobalSoundSource)
joystickCooldown = 0.2 * 30
awaitingInput = nil
end

if (m.controller.buttonPressed & R_JPAD ~= 0 or (m.controller.stickX > 0.5
Expand All @@ -1010,6 +1078,20 @@ local function mario_update(m)
joystickCooldown = 0.2 * 30
end

if joystickCooldown > 0 then joystickCooldown = joystickCooldown - 1 end

if awaitingInput ~= nil then
if m.controller.buttonPressed ~= 0 then
if button_to_text(m.controller.buttonPressed) == "" then return end
binds[awaitingInput].btn = m.controller.buttonPressed
mod_storage_save("bind_" .. tostring(awaitingInput), tostring(binds[awaitingInput].btn))

awaitingInput = nil
end

return
end

if m.controller.buttonPressed & A_BUTTON ~= 0
and entries[selection].input == INPUT_A then
if has_permission(entries[selection].permission)
Expand All @@ -1021,8 +1103,6 @@ local function mario_update(m)
play_sound(SOUND_MENU_CAMERA_BUZZ, gGlobalSoundSource)
end
end

if joystickCooldown > 0 then joystickCooldown = joystickCooldown - 1 end
end

hook_event(HOOK_ON_HUD_RENDER, hud_render)
Expand Down
2 changes: 1 addition & 1 deletion tag-bobomb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ end
---@param m MarioState
local function mario_update(m)
if gPlayerSyncTable[0].state == TAGGER and gGlobalSyncTable.modifier == MODIFIER_BOMBS and bombCooldown >= 2 * 30 and m.playerIndex == 0 then
if m.controller.buttonDown & Y_BUTTON ~= 0 then
if m.controller.buttonDown & binds[BIND_BOMBS].btn ~= 0 then
bombCooldown = 0
mario_bobomb_use(m)
end
Expand Down

0 comments on commit 6ba3f9b

Please sign in to comment.