Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions source/funkin/input/Controls.hx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class Controls
public var UI_DOWN_P(get, never):Bool;
public var UI_UP_P(get, never):Bool;
public var UI_RIGHT_P(get, never):Bool;
public var UI_LEFT_T(get, never):Bool;
public var UI_DOWN_T(get, never):Bool;
public var UI_UP_T(get, never):Bool;
public var UI_RIGHT_T(get, never):Bool;
public var ACCEPT(get, never):Bool;
public var BACK(get, never):Bool;
public var PAUSE(get, never):Bool;
Expand Down Expand Up @@ -149,6 +153,30 @@ class Controls
return getAction(UIRight).checkPressed();
}

@:noCompletion
inline function get_UI_LEFT_T():Bool
{
return getAction(UILeft).checkTurbo();
}

@:noCompletion
inline function get_UI_DOWN_T():Bool
{
return getAction(UIDown).checkTurbo();
}

@:noCompletion
inline function get_UI_UP_T():Bool
{
return getAction(UIUp).checkTurbo();
}

@:noCompletion
inline function get_UI_RIGHT_T():Bool
{
return getAction(UIRight).checkTurbo();
}

@:noCompletion
inline function get_ACCEPT():Bool
{
Expand Down
7 changes: 7 additions & 0 deletions source/funkin/input/FunkinAction.hx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class FunkinAction

var timestamp(default, null):Int = -1;

var spamming:Bool = false;
var spamTicks:Int = 0;
var lastTicks:Int = -1;

public function new(keys:Array<FlxKey>, buttons:Array<GamepadButton>)
{
this.keys = keys;
Expand All @@ -37,6 +41,9 @@ class FunkinAction
public inline function checkPressed():Bool
return FlxG.game.ticks - timestamp <= FlxG.elapsed * Constants.MS_PER_SEC;

public inline function checkTurbo():Bool
return TurboControl.check(this);

public inline function hasKey(key:FlxKey):Bool
return keys.contains(key);

Expand Down
58 changes: 58 additions & 0 deletions source/funkin/input/TurboControl.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package funkin.input;

@:access(funkin.input.FunkinAction)
class TurboControl
{
static var registry:Map<FunkinAction, TurboControl> = new Map<FunkinAction, TurboControl>();

public static function check(action:FunkinAction):Bool
{
var TurboControl:Null<TurboControl> = registry.get(action);

if (TurboControl == null)
{
TurboControl = new TurboControl(action);
registry.set(action, TurboControl);
}

return TurboControl?.active ?? false;
}

public var active:Bool = false;

var action:FunkinAction;

var spamming:Bool = false;
var spamTimer:Float = 0;

public function new(action:FunkinAction)
{
this.action = action;
FlxG.signals.preUpdate.add(() -> update(FlxG.elapsed));
}

function update(elapsed:Float):Void
{
active = false;

if (action.check())
{
if (spamming && spamTimer >= 0.07)
{
spamTimer = 0;
active = true;
}
else if (!spamming && spamTimer >= 0.5)
spamming = true;
else if (spamTimer <= 0)
active = true;

spamTimer += elapsed;
}
else
{
spamming = false;
spamTimer = 0;
}
}
}
4 changes: 2 additions & 2 deletions source/funkin/ui/freeplay/capsule/CapsuleGroup.hx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class CapsuleGroup extends FlxTypedGroup<CapsuleSprite>
{
super.update(elapsed);

var up:Bool = Controls.instance.UI_UP_P;
var down:Bool = Controls.instance.UI_DOWN_P;
var up:Bool = Controls.instance.UI_UP_T;
var down:Bool = Controls.instance.UI_DOWN_T;

if ((up || down) && !busy)
change(up ? -1 : 1);
Expand Down
8 changes: 4 additions & 4 deletions source/funkin/ui/options/OptionList.hx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class OptionList extends FlxTypedGroup<Option>
{
super.update(elapsed);

final up:Bool = controls.UI_UP_P;
final down:Bool = controls.UI_DOWN_P;
final left:Bool = controls.UI_LEFT_P;
final right:Bool = controls.UI_RIGHT_P;
final up:Bool = controls.UI_UP_T;
final down:Bool = controls.UI_DOWN_T;
final left:Bool = controls.UI_LEFT_T;
final right:Bool = controls.UI_RIGHT_T;
final accept:Bool = controls.ACCEPT;

if (up || down)
Expand Down
4 changes: 2 additions & 2 deletions source/funkin/ui/story/TitleGroup.hx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class TitleGroup extends FlxTypedGroup<TitleText>
{
super.update(elapsed);

var up:Bool = Controls.instance.UI_UP_P;
var down:Bool = Controls.instance.UI_DOWN_P;
var up:Bool = Controls.instance.UI_UP_T;
var down:Bool = Controls.instance.UI_DOWN_T;

if ((up || down) && !busy)
change(up ? -1 : 1);
Expand Down