Files
FNF-i486-Engine/source/psychlua/CustomSubstate.hx
Vinegar (Moxie) d7a31ab061 feat: rewrite Lua and HScript to be more modular
* Rewrote Lua by separating most of its classes and such into its own things so other classes can make use of them
* Made HScript better by being able to open multiple instances, and should work better then the old one that was held together by sticks and glue
* Made HScript less reliant on Lua (still needs it to function currently)
* Removed Smokeyys Animate Atlas in favor of FlxAnimate (it used more ram, and could only load 2018 atlases)
* Bump version internally due to breaking changes introduced
* TODO: Add more extensive HScript support and both need thorough testing, and add backwards compatibility
2025-08-07 17:51:11 -04:00

102 lines
2.8 KiB
Haxe

package psychlua;
import flixel.FlxObject;
class CustomSubstate extends MusicBeatSubstate
{
public static var name:String = 'unnamed';
public static var instance:CustomSubstate;
#if LUA_ALLOWED
public static function implement(funk:FunkinLua)
{
var lua = funk.lua;
Lua_helper.add_callback(lua, "openCustomSubstate", openCustomSubstate);
Lua_helper.add_callback(lua, "closeCustomSubstate", closeCustomSubstate);
Lua_helper.add_callback(lua, "insertToCustomSubstate", insertToCustomSubstate);
}
#end
public static function openCustomSubstate(name:String, ?pauseGame:Bool = false)
{
if(pauseGame)
{
FlxG.camera.followLerp = 0;
PlayState.instance.persistentUpdate = false;
PlayState.instance.persistentDraw = true;
PlayState.instance.paused = true;
if(FlxG.sound.music != null) {
FlxG.sound.music.pause();
PlayState.instance.vocals.pause();
}
}
PlayState.instance.openSubState(new CustomSubstate(name));
}
public static function closeCustomSubstate()
{
if(instance != null)
{
PlayState.instance.closeSubState();
return true;
}
return false;
}
public static function insertToCustomSubstate(tag:String, ?pos:Int = -1)
{
if(instance != null)
{
var tagObject:FlxObject = cast (MusicBeatState.getVariables().get(tag), FlxObject);
if(tagObject != null)
{
if(pos < 0) instance.add(tagObject);
else instance.insert(pos, tagObject);
return true;
}
}
return false;
}
override function create()
{
instance = this;
// PlayState.instance.setOnHScript('customSubstate', instance);
// PlayState.instance.callOnScripts('onCustomSubstateCreate', [name]);
PlayState.instance.callOnLuas('onCustomSubstateCreate', [name]);
super.create();
// PlayState.instance.callOnScripts('onCustomSubstateCreatePost', [name]);
PlayState.instance.callOnLuas('onCustomSubstateCreatePost', [name]);
}
public function new(name:String)
{
CustomSubstate.name = name;
// PlayState.instance.setOnHScript('customSubstateName', name);
super();
cameras = [FlxG.cameras.list[FlxG.cameras.list.length - 1]];
}
override function update(elapsed:Float)
{
// PlayState.instance.callOnScripts('onCustomSubstateUpdate', [name, elapsed]);
PlayState.instance.callOnLuas('onCustomSubstateUpdate', [name, elapsed]);
super.update(elapsed);
// PlayState.instance.callOnScripts('onCustomSubstateUpdatePost', [name, elapsed]);
PlayState.instance.callOnLuas('onCustomSubstateUpdatePost', [name, elapsed]);
}
override function destroy()
{
// PlayState.instance.callOnScripts('onCustomSubstateDestroy', [name]);
PlayState.instance.callOnLuas('onCustomSubstateDestroy', [name]);
instance = null;
name = 'unnamed';
// PlayState.instance.setOnHScript('customSubstate', null);
// PlayState.instance.setOnHScript('customSubstateName', name);
super.destroy();
}
}