From c08c10267d248ec2bf3eee13600145c8b44dc644 Mon Sep 17 00:00:00 2001 From: galactic2005 Date: Thu, 4 Jan 2024 19:48:33 -0600 Subject: [PATCH 1/3] controls rework + whitespace removal --- utbs-lua-v1/scripts/main.lua | 69 ++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/utbs-lua-v1/scripts/main.lua b/utbs-lua-v1/scripts/main.lua index 2869e35..14cef27 100644 --- a/utbs-lua-v1/scripts/main.lua +++ b/utbs-lua-v1/scripts/main.lua @@ -112,7 +112,7 @@ function initializeBattleSystem() -- Register built-in soul modes. registerSoulMode('default', require('mods/utbs-lua-v1/scripts/modes/default')) - + -- Set soul mode and color. setSoulMode('default') end @@ -148,7 +148,7 @@ function openBox(speed) -- Clear any attacks that might be in progress. clearAttacks() - + if soulMode ~= nil and soulMode.onBoxStartOpen ~= nil then soulMode.onBoxStartOpen(self) end @@ -202,7 +202,7 @@ function useAttack(name, data) debugPrint("UTBS: WARNING Cannot use attack '" .. name .. "' because it does not exist. Make sure to register it!") return end - + debugPrint("UTBS: Using attack '" .. name .. "' with data: {" .. data .. "}") attack.spawnAttack(self, data) @@ -295,7 +295,7 @@ function setSoulMode(modeName, forceColor) soulMode = mode - if soulMode.onSwitchToMode ~= nil then + if soulMode.onSwitchToMode ~= nil then soulMode.onSwitchToMode(self) end @@ -493,7 +493,7 @@ function handleUpdate_BoxOpenClose(elapsed) local deltaWidth = (targetBoxWidth - boxW) / elapsed * settings.boxOpenSpeed * boxRelativeOpenSpeed local deltaHeight = (targetBoxHeight - boxH) / elapsed * settings.boxOpenSpeed * boxRelativeOpenSpeed local deltaAlpha = (1.0 - boxA) / elapsed * settings.boxOpenSpeed * boxRelativeOpenSpeed - + boxX = boxX + deltaX boxY = boxY + deltaY boxW = boxW + deltaWidth @@ -505,7 +505,7 @@ function handleUpdate_BoxOpenClose(elapsed) local deltaWidth = (0 - boxW) / elapsed * settings.boxCloseSpeed local deltaHeight = (0 - boxH) / elapsed * settings.boxCloseSpeed local deltaAlpha = (0 - boxA) / elapsed * settings.boxCloseSpeed - + boxX = boxX + deltaX boxY = boxY + deltaY boxW = boxW + deltaWidth @@ -517,7 +517,7 @@ function handleUpdate_BoxOpenClose(elapsed) local deltaWidth = (targetBoxWidth - boxW) / elapsed * settings.boxOpenSpeed * boxRelativeOpenSpeed local deltaHeight = (targetBoxHeight - boxH) / elapsed * settings.boxOpenSpeed * boxRelativeOpenSpeed local deltaAlpha = (1.0 - boxA) / elapsed * settings.boxOpenSpeed * boxRelativeOpenSpeed - + boxX = boxX + deltaX boxY = boxY + deltaY boxW = boxW + deltaWidth @@ -545,7 +545,7 @@ function handleUpdate_BoxOpenClose(elapsed) setProperty('utbsBattleBox.x', boxX) setProperty('utbsBattleBox.y', boxY) setProperty('utbsBattleBox.alpha', boxA) - + -- Ensure the border is visible. setProperty('utbsBattleBoxBorder.scale.x', (boxW + settings.boxBorderWidth) / settings.boxImageSize) setProperty('utbsBattleBoxBorder.scale.y', (boxH + settings.boxBorderWidth) / settings.boxImageSize) @@ -621,7 +621,7 @@ function handleUpdate_Soul(elapsed) local targetColor = soulFlashParams['targetColor'] local targetAlpha = soulFlashParams['targetAlpha'] local baseAlpha = getProperty('utbsBattleBox.alpha') - + local useTargetColor = math.floor(frequency * soulFlashTimer) % 2 == 0 local finalColor = useTargetColor and targetColor or soulColor @@ -634,7 +634,7 @@ function handleUpdate_Soul(elapsed) -- Flash white while invulnerable due to taking damage. local frequency = 20 local targetColor = settings.soulColors['white'] - + local useTargetColor = math.floor(frequency * soulInvulnTimer) % 2 == 0 local finalColor = useTargetColor and targetColor or soulColor @@ -653,25 +653,25 @@ function handleUpdate_Soul(elapsed) soulMode.onSoulInput(self, elapsed, left, down, up, right, action) -- Constrain soul position to bounds. - if soulXPos <= boxLeftBound then + if soulXPos <= boxLeftBound then soulXPos = boxLeftBound isSoulTouchingLeft = true else isSoulTouchingLeft = false end - if soulXPos >= boxRightBound then + if soulXPos >= boxRightBound then soulXPos = boxRightBound isSoulTouchingRight = true else isSoulTouchingRight = false end - if soulYPos <= boxTopBound then + if soulYPos <= boxTopBound then soulYPos = boxTopBound isSoulTouchingTop = true else isSoulTouchingTop = false end - if soulYPos >= boxBottomBound then + if soulYPos >= boxBottomBound then soulYPos = boxBottomBound isSoulTouchingBottom = true else @@ -707,7 +707,7 @@ function handleUpdate_Attacks(elapsed) bullet.x = bullet.x + bullet.velocityX * elapsed bullet.y = bullet.y + bullet.velocityY * elapsed bullet.angle = bullet.angle + bullet.angularVelocity * elapsed - + local fadeAlpha = 1.0 if bullet.fadeInDuration > 0 then @@ -813,31 +813,32 @@ function handleUpdate_Score(wasTextReset) -- Add the damage text = baseScoreText .. " Times Hit: " .. timesHit .. "\n" - + setProperty("scoreTxt.text", text, false) end +function getControl(keyboardControlOptions, gamepadControlOption, useGamepad) + -- support two controls for the action input + if #keyboardControlOptions == 2 then + return getPropertyFromClass('flixel.FlxG', 'keys.pressed.' .. keyboardControlOptions[1]) or getPropertyFromClass('flixel.FlxG', 'keys.pressed.' .. keyboardControlOptions[2]) or + (useGamepad and (getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.DPAD_' .. gamepadControlOption) or getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.LEFT_STICK_DIGITAL_' .. gamepadControlOption))) + end + + return getPropertyFromClass('flixel.FlxG', 'keys.pressed.' .. keyboardControlOptions[1]) or getPropertyFromClass('flixel.FlxG', 'keys.pressed.' .. keyboardControlOptions[2]) or getPropertyFromClass('flixel.FlxG', 'keys.pressed.' .. keyboardControlOptions[3]) or + (useGamepad and (getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.DPAD_' .. gamepadControlOption) or getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.LEFT_STICK_DIGITAL_' .. gamepadControlOption))) +end + function accessControls() - -- TODO: Is there a nicer method? local useGamepad = false if (getPropertyFromClass('flixel.FlxG', 'gamepads.numActiveGamepads') > 0) then useGamepad = true end - local right = getPropertyFromClass('flixel.FlxG', 'keys.pressed.RIGHT') or getPropertyFromClass('flixel.FlxG', 'keys.pressed.D') or getPropertyFromClass('flixel.FlxG', 'keys.pressed.L') or - (useGamepad and (getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.DPAD_RIGHT') or getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.LEFT_STICK_DIGITAL_RIGHT'))) - - local left = getPropertyFromClass('flixel.FlxG', 'keys.pressed.LEFT') or getPropertyFromClass('flixel.FlxG', 'keys.pressed.A') or getPropertyFromClass('flixel.FlxG', 'keys.pressed.J') or - (useGamepad and (getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.DPAD_LEFT') or getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.LEFT_STICK_DIGITAL_LEFT'))) - - local up = getPropertyFromClass('flixel.FlxG', 'keys.pressed.UP') or getPropertyFromClass('flixel.FlxG', 'keys.pressed.W') or getPropertyFromClass('flixel.FlxG', 'keys.pressed.I') or - (useGamepad and (getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.DPAD_UP') or getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.LEFT_STICK_DIGITAL_UP'))) - - local down = getPropertyFromClass('flixel.FlxG', 'keys.pressed.DOWN') or getPropertyFromClass('flixel.FlxG', 'keys.pressed.S') or getPropertyFromClass('flixel.FlxG', 'keys.pressed.K') or - (useGamepad and (getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.DPAD_DOWN') or getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.LEFT_STICK_DIGITAL_DOWN'))) - - local action = getPropertyFromClass('flixel.FlxG', 'keys.pressed.SPACE') or getPropertyFromClass('flixel.FlxG', 'keys.pressed.Z') or - (useGamepad and (getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.A') or getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.A'))) + local left = getControl({'LEFT', 'A', 'J'}, 'LEFT', useGamepad) + local down = getControl({'DOWN', 'S', 'K'}, 'DOWN', useGamepad) + local up = getControl({'UP', 'W', 'I'}, 'UP', useGamepad) + local right = getControl({'RIGHT', 'D', 'L'}, 'RIGHT', useGamepad) + local action = getControl({'SPACE', 'Z'}, 'A', useGamepad) return left, down, up, right, action end @@ -852,10 +853,10 @@ function damagePlayer(damage, applyInvuln) damage = soulMode.onPlayerHit(self, damage) end - + -- Deal damage to the player. setProperty('health', getProperty('health') - (damage / 100.0)); - + if (applyInvuln) then soulInvulnTimer = settings.soulInvulnDuration @@ -928,7 +929,7 @@ function buildState() getSoulPosition = function() return soulXPos, soulYPos end, setSoulPosition = setSoulPosition, - + getSoulAngle = function() return soulAngle end, setSoulAngle = function(angle) soulAngle = angle end, From 395e6e268b777701c171fc854e8fcf124c1d9fda Mon Sep 17 00:00:00 2001 From: galactic2005 Date: Thu, 4 Jan 2024 20:06:27 -0600 Subject: [PATCH 2/3] optimization of control and box property setting in BoxOpenClose(elasped) --- utbs-lua-v1/scripts/main.lua | 71 ++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/utbs-lua-v1/scripts/main.lua b/utbs-lua-v1/scripts/main.lua index 14cef27..e09be0d 100644 --- a/utbs-lua-v1/scripts/main.lua +++ b/utbs-lua-v1/scripts/main.lua @@ -40,6 +40,9 @@ local boxH = 0.0 local boxX = settings.boxX local boxY = settings.boxY +-- Current alpha of the battle box +local boxA = 0.0 + -- -- SOUL STATE VARIABLES -- @@ -391,12 +394,12 @@ end -- function onCreate() - -- Called when the Lua file is loaded. + -- Called when the Lua file is loaded. -- Some variables are not properly initialized yet. end function onCreatePost() - -- Called after the Lua file is loaded and all variables are properly initialized. + -- Called after the Lua file is loaded and all variables are properly initialized. -- NOTE: This gets called multiple times for some reason -_- end @@ -433,7 +436,7 @@ function onUpdateScore(miss) end function onDestroy() - -- triggered when the lua file is ended (Song fade out finished) + -- triggered when the lua file is ended (Song fade out finished) end -- @@ -483,9 +486,17 @@ function handleUpdate_BoxOpenClose(elapsed) return end + local function handleBoxProperties(deltaX, deltaY, deltaWidth, deltaHeight, deltaAlpha) + boxX = boxX + deltaX + boxY = boxY + deltaY + boxW = boxW + deltaWidth + boxH = boxH + deltaHeight + boxA = boxH + deltaAlpha + end + boxX = getProperty('utbsBattleBox.x') boxY = getProperty('utbsBattleBox.y') - local boxA = getProperty('utbsBattleBox.alpha') + boxA = getProperty('utbsBattleBox.alpha') if isBoxOpening then local deltaX = (settings.boxX - boxX) / elapsed * settings.boxOpenSpeed * boxRelativeOpenSpeed @@ -494,11 +505,7 @@ function handleUpdate_BoxOpenClose(elapsed) local deltaHeight = (targetBoxHeight - boxH) / elapsed * settings.boxOpenSpeed * boxRelativeOpenSpeed local deltaAlpha = (1.0 - boxA) / elapsed * settings.boxOpenSpeed * boxRelativeOpenSpeed - boxX = boxX + deltaX - boxY = boxY + deltaY - boxW = boxW + deltaWidth - boxH = boxH + deltaHeight - boxA = boxA + deltaAlpha + handleBoxProperties(deltaX, deltaY, deltaWidth, deltaHeight, deltaAlpha) elseif isBoxClosing then local deltaX = (settings.boxX - boxX) / elapsed * settings.boxCloseSpeed local deltaY = (settings.boxY - boxY) / elapsed * settings.boxCloseSpeed @@ -506,11 +513,7 @@ function handleUpdate_BoxOpenClose(elapsed) local deltaHeight = (0 - boxH) / elapsed * settings.boxCloseSpeed local deltaAlpha = (0 - boxA) / elapsed * settings.boxCloseSpeed - boxX = boxX + deltaX - boxY = boxY + deltaY - boxW = boxW + deltaWidth - boxH = boxH + deltaHeight - boxA = boxA + deltaAlpha + handleBoxProperties(deltaX, deltaY, deltaWidth, deltaHeight, deltaAlpha) elseif isBoxLerping then local deltaX = (settings.boxX - boxX) / elapsed * settings.boxOpenSpeed * boxRelativeOpenSpeed local deltaY = (settings.boxY - boxY) / elapsed * settings.boxOpenSpeed * boxRelativeOpenSpeed @@ -518,11 +521,7 @@ function handleUpdate_BoxOpenClose(elapsed) local deltaHeight = (targetBoxHeight - boxH) / elapsed * settings.boxOpenSpeed * boxRelativeOpenSpeed local deltaAlpha = (1.0 - boxA) / elapsed * settings.boxOpenSpeed * boxRelativeOpenSpeed - boxX = boxX + deltaX - boxY = boxY + deltaY - boxW = boxW + deltaWidth - boxH = boxH + deltaHeight - boxA = boxA + deltaAlpha + handleBoxProperties(deltaX, deltaY, deltaWidth, deltaHeight, deltaAlpha) else if isBoxOpen then boxA = 1.0 @@ -541,17 +540,17 @@ function handleUpdate_BoxOpenClose(elapsed) -- Apply the box size before we apply the position. setProperty('utbsBattleBox.scale.x', boxW / settings.boxImageSize) - setProperty('utbsBattleBox.scale.y', boxH / settings.boxImageSize) + setProperty('utbsBattleBox.scale.y', boxH / settings.boxImageSize) setProperty('utbsBattleBox.x', boxX) - setProperty('utbsBattleBox.y', boxY) - setProperty('utbsBattleBox.alpha', boxA) + setProperty('utbsBattleBox.y', boxY) + setProperty('utbsBattleBox.alpha', boxA) -- Ensure the border is visible. - setProperty('utbsBattleBoxBorder.scale.x', (boxW + settings.boxBorderWidth) / settings.boxImageSize) - setProperty('utbsBattleBoxBorder.scale.y', (boxH + settings.boxBorderWidth) / settings.boxImageSize) - setProperty('utbsBattleBoxBorder.x', boxX) - setProperty('utbsBattleBoxBorder.y', boxY) - setProperty('utbsBattleBoxBorder.alpha', boxA) + setProperty('utbsBattleBoxBorder.scale.x', (boxW + settings.boxBorderWidth) / settings.boxImageSize) + setProperty('utbsBattleBoxBorder.scale.y', (boxH + settings.boxBorderWidth) / settings.boxImageSize) + setProperty('utbsBattleBoxBorder.x', boxX) + setProperty('utbsBattleBoxBorder.y', boxY) + setProperty('utbsBattleBoxBorder.alpha', boxA) -- Set internal bounding box to the displayed box. boxLeftBound = -boxW / 2 + settings.boxBorderWidth @@ -817,18 +816,18 @@ function handleUpdate_Score(wasTextReset) setProperty("scoreTxt.text", text, false) end -function getControl(keyboardControlOptions, gamepadControlOption, useGamepad) - -- support two controls for the action input - if #keyboardControlOptions == 2 then - return getPropertyFromClass('flixel.FlxG', 'keys.pressed.' .. keyboardControlOptions[1]) or getPropertyFromClass('flixel.FlxG', 'keys.pressed.' .. keyboardControlOptions[2]) or +function accessControls() + local function getControl(keyboardControlOptions, gamepadControlOption, useGamepad) + -- support two controls for the action input + if #keyboardControlOptions == 2 then + return getPropertyFromClass('flixel.FlxG', 'keys.pressed.' .. keyboardControlOptions[1]) or getPropertyFromClass('flixel.FlxG', 'keys.pressed.' .. keyboardControlOptions[2]) or + (useGamepad and (getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.DPAD_' .. gamepadControlOption) or getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.LEFT_STICK_DIGITAL_' .. gamepadControlOption))) + end + + return getPropertyFromClass('flixel.FlxG', 'keys.pressed.' .. keyboardControlOptions[1]) or getPropertyFromClass('flixel.FlxG', 'keys.pressed.' .. keyboardControlOptions[2]) or getPropertyFromClass('flixel.FlxG', 'keys.pressed.' .. keyboardControlOptions[3]) or (useGamepad and (getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.DPAD_' .. gamepadControlOption) or getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.LEFT_STICK_DIGITAL_' .. gamepadControlOption))) end - return getPropertyFromClass('flixel.FlxG', 'keys.pressed.' .. keyboardControlOptions[1]) or getPropertyFromClass('flixel.FlxG', 'keys.pressed.' .. keyboardControlOptions[2]) or getPropertyFromClass('flixel.FlxG', 'keys.pressed.' .. keyboardControlOptions[3]) or - (useGamepad and (getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.DPAD_' .. gamepadControlOption) or getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.LEFT_STICK_DIGITAL_' .. gamepadControlOption))) -end - -function accessControls() local useGamepad = false if (getPropertyFromClass('flixel.FlxG', 'gamepads.numActiveGamepads') > 0) then useGamepad = true From ff151634209738f524282483ee66d6e86bc3ff72 Mon Sep 17 00:00:00 2001 From: galactic2005 Date: Thu, 4 Jan 2024 20:28:42 -0600 Subject: [PATCH 3/3] Gamepad fixes --- utbs-lua-v1/scripts/main.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/utbs-lua-v1/scripts/main.lua b/utbs-lua-v1/scripts/main.lua index e09be0d..0361386 100644 --- a/utbs-lua-v1/scripts/main.lua +++ b/utbs-lua-v1/scripts/main.lua @@ -807,7 +807,7 @@ function handleUpdate_Score(wasTextReset) if wasTextReset then baseScoreText = getProperty('scoreTxt.text') -- Trim the last 2 characters. - baseScoreText = string.sub(baseScoreText, 1, string.len(baseScoreText) - 2) + baseScoreText = string.sub(baseScoreText, 1, #baseScoreText - 2) end -- Add the damage @@ -818,14 +818,22 @@ end function accessControls() local function getControl(keyboardControlOptions, gamepadControlOption, useGamepad) - -- support two controls for the action input + local lastActiveOne = 'gamepads.lastActive.pressed.DPAD_' + local lastActiveTwo = 'gamepads.lastActive.pressed.LEFT_STICK_DIGITAL_' + if gamepadControlOption ~= 'LEFT' and gamepadControlOption ~= 'DOWN' and gamepadControlOption ~= 'UP' and gamepadControlOption ~= 'RIGHT' then + -- Support for buttons + lastActiveOne = 'gamepads.lastActive.pressed.' + lastActiveTwo = 'gamepads.lastActive.pressed.' + end + + -- Support two controls for the action input if #keyboardControlOptions == 2 then return getPropertyFromClass('flixel.FlxG', 'keys.pressed.' .. keyboardControlOptions[1]) or getPropertyFromClass('flixel.FlxG', 'keys.pressed.' .. keyboardControlOptions[2]) or - (useGamepad and (getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.DPAD_' .. gamepadControlOption) or getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.LEFT_STICK_DIGITAL_' .. gamepadControlOption))) + (useGamepad and (getPropertyFromClass('flixel.FlxG', lastActiveOne .. gamepadControlOption) or getPropertyFromClass('flixel.FlxG', lastActiveTwo .. gamepadControlOption))) end return getPropertyFromClass('flixel.FlxG', 'keys.pressed.' .. keyboardControlOptions[1]) or getPropertyFromClass('flixel.FlxG', 'keys.pressed.' .. keyboardControlOptions[2]) or getPropertyFromClass('flixel.FlxG', 'keys.pressed.' .. keyboardControlOptions[3]) or - (useGamepad and (getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.DPAD_' .. gamepadControlOption) or getPropertyFromClass('flixel.FlxG', 'gamepads.lastActive.pressed.LEFT_STICK_DIGITAL_' .. gamepadControlOption))) + (useGamepad and (getPropertyFromClass('flixel.FlxG', lastActiveOne .. gamepadControlOption) or getPropertyFromClass('flixel.FlxG', lastActiveTwo .. gamepadControlOption))) end local useGamepad = false