Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small lua improvements #15088

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
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: 21 additions & 7 deletions source/psychlua/FunkinLua.hx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ class FunkinLua {
var runningScripts:Array<String> = [];
for (script in game.luaArray)
runningScripts.push(script.scriptName);

for (script in game.hscriptArray)
runningScripts.push(script.origin);

return runningScripts;
});
Expand Down Expand Up @@ -287,6 +290,9 @@ class FunkinLua {
Lua_helper.add_callback(lua, "getVar", function(varName:String) {
return MusicBeatState.getVariables().get(varName);
});
Lua_helper.add_callback(lua, "removeVar", function(varName:String) {
return MusicBeatState.getVariables().remove(varName);
});

Lua_helper.add_callback(lua, "addLuaScript", function(luaFile:String, ?ignoreAlreadyRunning:Bool = false) {
var luaPath:String = findScript(luaFile);
Expand Down Expand Up @@ -385,10 +391,16 @@ class FunkinLua {

FlxG.sound.music.pause();
FlxG.sound.music.volume = 0;
if(game != null && game.vocals != null)
{
game.vocals.pause();
game.vocals.volume = 0;
if(game != null) {
if (game.vocals != null) {
game.vocals.pause();
game.vocals.volume = 0;
}

if (game.opponentVocals != null) {
game.opponentVocals.pause();
game.opponentVocals.volume = 0;
}
}
FlxG.camera.followLerp = 0;
});
Expand Down Expand Up @@ -461,7 +473,7 @@ class FunkinLua {
if(tag != null)
{
var variables = MusicBeatState.getVariables();
tag = 'tween_' + LuaUtils.formatVariable(tag);
tag = LuaUtils.formatVariable('tween_$tag');
variables.set(tag, FlxTween.tween(penisExam, values, duration, {
type: myOptions.type,
ease: myOptions.ease,
Expand Down Expand Up @@ -847,20 +859,22 @@ class FunkinLua {
Lua_helper.add_callback(lua, "getScreenPositionX", function(variable:String, ?camera:String = 'game') {
var split:Array<String> = variable.split('.');
var obj:FlxSprite = LuaUtils.getObjectDirectly(split[0]);
var cam:FlxCamera = LuaUtils.cameraFromString(camera);
if(split.length > 1) {
obj = LuaUtils.getVarInArray(LuaUtils.getPropertyLoop(split), split[split.length-1]);
}
if(obj != null) return obj.getScreenPosition().x;
if(obj != null) return obj.getScreenPosition(cam).x;

return 0;
});
Lua_helper.add_callback(lua, "getScreenPositionY", function(variable:String, ?camera:String = 'game') {
var split:Array<String> = variable.split('.');
var obj:FlxSprite = LuaUtils.getObjectDirectly(split[0]);
var cam:FlxCamera = LuaUtils.cameraFromString(camera);
if(split.length > 1) {
obj = LuaUtils.getVarInArray(LuaUtils.getPropertyLoop(split), split[split.length-1]);
}
if(obj != null) return obj.getScreenPosition().y;
if(obj != null) return obj.getScreenPosition(cam).y;

return 0;
});
Expand Down
2 changes: 1 addition & 1 deletion source/psychlua/HScript.hx
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class HScript extends Iris
{
if(funk == null) funk = parentLua;

if(parentLua != null) funk.addLocalCallback(name, func);
if(funk != null) funk.addLocalCallback(name, func);
else FunkinLua.luaTrace('createCallback ($name): 3rd argument is null', false, false, FlxColor.RED);
});
#end
Expand Down
1 change: 1 addition & 0 deletions source/psychlua/LuaUtils.hx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class LuaUtils

public static function getLuaTween(options:Dynamic)
{
if (options == null) options = {}
return {
type: getTweenTypeByString(options.type),
startDelay: options.startDelay,
Expand Down
4 changes: 2 additions & 2 deletions source/psychlua/ReflectionFunctions.hx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ReflectionFunctions
var myClass:Dynamic = Type.resolveClass(classVar);
if(myClass == null)
{
FunkinLua.luaTrace('getPropertyFromClass: Class $classVar not found', false, false, FlxColor.RED);
FunkinLua.luaTrace('setPropertyFromClass: Class $classVar not found', false, false, FlxColor.RED);
return null;
}

Expand Down Expand Up @@ -227,7 +227,7 @@ class ReflectionFunctions

if(myType == null)
{
FunkinLua.luaTrace('createInstance: Variable $variableToSave is already being used and cannot be replaced!', false, false, FlxColor.RED);
FunkinLua.luaTrace('createInstance: Class $className not found.', false, false, FlxColor.RED);
return false;
}

Expand Down