Skip to content

Commit

Permalink
allow scripts to run in substates
Browse files Browse the repository at this point in the history
  • Loading branch information
Vortex2Oblivion committed Nov 8, 2024
1 parent 06984a8 commit dcc790b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
6 changes: 3 additions & 3 deletions source/states/MusicBeatState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MusicBeatState extends #if MODCHARTING_TOOLS modcharting.ModchartMusicBeat
override public function create() {
super.create();
#if sys
var statePath:String = Type.getClassName(Type.getClass(FlxG.state)).replace(".", "/");
var statePath:String = Type.getClassName(Type.getClass(this)).replace(".", "/");
if (sys.FileSystem.exists('mods/${Options.getData("curMod")}/classes/${statePath}.hx')) {
stateScript = new HScript('mods/${Options.getData("curMod")}/classes/${statePath}.hx');
}
Expand Down Expand Up @@ -150,11 +150,11 @@ class MusicBeatState extends #if MODCHARTING_TOOLS modcharting.ModchartMusicBeat
Application.current.window.title = windowNamePrefix + windowNameSuffix #if debug + ' (DEBUG)' #end;
}

private function updateBeat():Void {
public function updateBeat():Void {
curBeat = Math.floor(curStep / Conductor.timeScale[1]);
}

private function updateCurStep():Void {
public function updateCurStep():Void {
var lastChange:BPMChangeEvent = {
stepTime: 0,
songTime: 0,
Expand Down
50 changes: 28 additions & 22 deletions source/substates/MusicBeatSubstate.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,38 @@ import lime.app.Application;
import flixel.input.FlxInput.FlxInputState;
import flixel.FlxSprite;
import flixel.FlxBasic;
import openfl.Lib;
import game.Conductor;
import utilities.PlayerSettings;
import utilities.Controls;
import game.Conductor.BPMChangeEvent;
import flixel.FlxG;
import flixel.FlxSubState;
import modding.scripts.languages.HScript;

class MusicBeatSubstate extends FlxSubState
{
private var lastBeat:Float = 0;
private var lastStep:Float = 0;
class MusicBeatSubstate extends FlxSubState {
public var lastBeat:Float = 0;
public var lastStep:Float = 0;

private var curStep:Int = 0;
private var curBeat:Int = 0;
private var controls(get, never):Controls;
public var curStep:Int = 0;
public var curBeat:Int = 0;
public var controls(get, never):Controls;

public var stateScript:HScript;

inline function get_controls():Controls
return PlayerSettings.player1.controls;

override function update(elapsed:Float)
{
override public function create() {
super.create();
#if sys
var statePath:String = Type.getClassName(Type.getClass(this)).replace(".", "/");
if (sys.FileSystem.exists('mods/${Options.getData("curMod")}/classes/${statePath}.hx')) {
stateScript = new HScript('mods/${Options.getData("curMod")}/classes/${statePath}.hx');
}
#end
}

override function update(elapsed:Float) {
var oldStep:Int = curStep;

updateCurStep();
Expand All @@ -37,7 +47,7 @@ class MusicBeatSubstate extends FlxSubState

super.update(elapsed);

if(FlxG.stage != null)
if (FlxG.stage != null)
FlxG.stage.frameRate = flixel.math.FlxMath.bound(Options.getData("maxFPS"), 0.1, 1000);

if (!Options.getData("antialiasing")) {
Expand All @@ -49,36 +59,32 @@ class MusicBeatSubstate extends FlxSubState
}, true);
}

if(FlxG.keys.checkStatus(FlxKey.fromString(Options.getData("fullscreenBind", "binds")), FlxInputState.JUST_PRESSED))
if (FlxG.keys.checkStatus(FlxKey.fromString(Options.getData("fullscreenBind", "binds")), FlxInputState.JUST_PRESSED))
FlxG.fullscreen = !FlxG.fullscreen;

Application.current.window.title = MusicBeatState.windowNamePrefix + MusicBeatState.windowNameSuffix;
Application.current.window.title = MusicBeatState.windowNamePrefix + MusicBeatState.windowNameSuffix #if debug + ' (DEBUG)' #end;
}

private function updateCurStep():Void
{
public function updateCurStep():Void {
var lastChange:BPMChangeEvent = {
stepTime: 0,
songTime: 0,
bpm: 0
}
for (i in 0...Conductor.bpmChangeMap.length)
{
for (i in 0...Conductor.bpmChangeMap.length) {
if (Conductor.songPosition > Conductor.bpmChangeMap[i].songTime)
lastChange = Conductor.bpmChangeMap[i];
}

curStep = lastChange.stepTime + Math.floor((Conductor.songPosition - lastChange.songTime) / Conductor.stepCrochet);
}

public function stepHit():Void
{
public function stepHit():Void {
if (curStep % 4 == 0)
beatHit();
}

public function beatHit():Void
{
//do literally nothing dumbass
public function beatHit():Void {
// do literally nothing dumbass
}
}

0 comments on commit dcc790b

Please sign in to comment.