## Manages all the visuals relating to the end force meter
## Runs on a 20hz clock from `controller.animation.player.end_force_management`
## @s = a player

## Initialize objectives
scoreboard objectives add CurrentForce dummy
scoreboard objectives add DisplayCurrForce dummy
scoreboard objectives add DelayPrevDisplay dummy
scoreboard objectives add ShakeTimer dummy
scoreboard players add @s CurrentForce 0
scoreboard players add @s DisplayCurrForce 0
scoreboard players add @s DelayPrevDisplay 0
scoreboard players add @s ShakeTimer 0

## Decrement ShakeTimer every tick. Every time the meter shakes, it waits until ShakeTimer = 0 to shake again
scoreboard players remove @s[scores={ShakeTimer=1..}] ShakeTimer 1

## Makes sure the PreviousForce amount is up to date with CurrentForce
execute if score @s CurrentForce = @s DisplayCurrForce run scoreboard players operation @s PreviousForce = @s DisplayCurrForce
execute if score @s CurrentForce > @s DisplayCurrForce run scoreboard players operation @s DisplayPrevForce = @s DisplayCurrForce

## Delays the previous display from moving whenever there the current force display is in the process of moving
execute unless score @s CurrentForce = @s DisplayCurrForce run scoreboard players set @s DelayPrevDisplay 7
scoreboard players remove @s[scores={DelayPrevDisplay=1..}] DelayPrevDisplay 1

## Runs the easing functions for the Current and Previous displays whenever there is a discrepancy
execute unless score @s CurrentForce = @s DisplayCurrForce run function end_force/player/easer_current
execute unless score @s DisplayPrevForce = @s DisplayCurrForce if score @s DelayPrevDisplay matches 0 run function end_force/player/easer_previous

## When a player doesn't have enough end force to perform an action, their ReqForceAmnt should be set...
## which will trigger this function to indicate to them how much more they need
execute if score @s ReqForceAmnt matches 1.. run function end_force/player/required_amount