Skip to content

Commit

Permalink
Lua_helper.add_callback(lua, -> funk.set(
Browse files Browse the repository at this point in the history
  • Loading branch information
mcagabe19 committed Aug 20, 2024
1 parent 1f15374 commit 1ddfc5f
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 243 deletions.
14 changes: 7 additions & 7 deletions source/backend/Achievements.hx
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ class Achievements {
#end

#if LUA_ALLOWED
public static function addLuaCallbacks(lua:State)
public static function addLuaCallbacks(funk:psychlua.FunkinLua)
{
Lua_helper.add_callback(lua, "getAchievementScore", function(name:String):Float
funk.set("getAchievementScore", function(name:String):Float
{
if(!achievements.exists(name))
{
Expand All @@ -277,7 +277,7 @@ class Achievements {
}
return getScore(name);
});
Lua_helper.add_callback(lua, "setAchievementScore", function(name:String, ?value:Float = 1, ?saveIfNotUnlocked:Bool = true):Float
funk.set("setAchievementScore", function(name:String, ?value:Float = 1, ?saveIfNotUnlocked:Bool = true):Float
{
if(!achievements.exists(name))
{
Expand All @@ -286,7 +286,7 @@ class Achievements {
}
return setScore(name, value, saveIfNotUnlocked);
});
Lua_helper.add_callback(lua, "addAchievementScore", function(name:String, ?value:Float = 1, ?saveIfNotUnlocked:Bool = true):Float
funk.set("addAchievementScore", function(name:String, ?value:Float = 1, ?saveIfNotUnlocked:Bool = true):Float
{
if(!achievements.exists(name))
{
Expand All @@ -295,7 +295,7 @@ class Achievements {
}
return addScore(name, value, saveIfNotUnlocked);
});
Lua_helper.add_callback(lua, "unlockAchievement", function(name:String):Dynamic
funk.set("unlockAchievement", function(name:String):Dynamic
{
if(!achievements.exists(name))
{
Expand All @@ -304,7 +304,7 @@ class Achievements {
}
return unlock(name);
});
Lua_helper.add_callback(lua, "isAchievementUnlocked", function(name:String):Dynamic
funk.set("isAchievementUnlocked", function(name:String):Dynamic
{
if(!achievements.exists(name))
{
Expand All @@ -313,7 +313,7 @@ class Achievements {
}
return isUnlocked(name);
});
Lua_helper.add_callback(lua, "achievementExists", function(name:String) return achievements.exists(name));
funk.set("achievementExists", function(name:String) return achievements.exists(name));
}
#end
}
Expand Down
6 changes: 3 additions & 3 deletions source/backend/Discord.hx
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ class DiscordClient
#end

#if LUA_ALLOWED
public static function addLuaCallbacks(lua:State)
public static function addLuaCallbacks(funk:psychlua.FunkinLua)
{
Lua_helper.add_callback(lua, "changeDiscordPresence", changePresence);
Lua_helper.add_callback(lua, "changeDiscordClientID", function(?newID:String) {
funk.set("changeDiscordPresence", changePresence);
funk.set("changeDiscordClientID", function(?newID:String) {
if(newID == null) newID = _defaultID;
clientID = newID;
});
Expand Down
6 changes: 3 additions & 3 deletions source/backend/Language.hx
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ class Language
#end

#if LUA_ALLOWED
public static function addLuaCallbacks(lua:State) {
Lua_helper.add_callback(lua, "getTranslationPhrase", function(key:String, ?defaultPhrase:String, ?values:Array<Dynamic> = null) {
public static function addLuaCallbacks(funk:psychlua.FunkinLua) {
"getTranslationPhrase", function(key:String, ?defaultPhrase:String, ?values:Array<Dynamic> = null) {
return getPhrase(key, defaultPhrase, values);
});

Lua_helper.add_callback(lua, "getFileTranslation", function(key:String) {
"getFileTranslation", function(key:String) {
return getFileTranslation(key);
});
}
Expand Down
7 changes: 3 additions & 4 deletions source/psychlua/CustomSubstate.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ class CustomSubstate extends MusicBeatSubstate
#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);
funk.set("openCustomSubstate", openCustomSubstate);
funk.set("closeCustomSubstate", closeCustomSubstate);
funk.set("insertToCustomSubstate", insertToCustomSubstate);
}
#end

Expand Down
29 changes: 14 additions & 15 deletions source/psychlua/DeprecatedFunctions.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ class DeprecatedFunctions
{
public static function implement(funk:FunkinLua)
{
var lua:State = funk.lua;
// DEPRECATED, DONT MESS WITH THESE SHITS, ITS JUST THERE FOR BACKWARD COMPATIBILITY
Lua_helper.add_callback(lua, "addAnimationByIndicesLoop", function(obj:String, name:String, prefix:String, indices:String, framerate:Int = 24) {
funk.set("addAnimationByIndicesLoop", function(obj:String, name:String, prefix:String, indices:String, framerate:Int = 24) {
FunkinLua.luaTrace("addAnimationByIndicesLoop is deprecated! Use addAnimationByIndices instead", false, true);
return LuaUtils.addAnimByIndices(obj, name, prefix, indices, framerate, true);
});

Lua_helper.add_callback(lua, "objectPlayAnimation", function(obj:String, name:String, forced:Bool = false, ?startFrame:Int = 0) {
funk.set("objectPlayAnimation", function(obj:String, name:String, forced:Bool = false, ?startFrame:Int = 0) {
FunkinLua.luaTrace("objectPlayAnimation is deprecated! Use playAnim instead", false, true);
if(PlayState.instance.getLuaObject(obj,false) != null) {
PlayState.instance.getLuaObject(obj,false).animation.play(name, forced, false, startFrame);
Expand All @@ -30,7 +29,7 @@ class DeprecatedFunctions
}
return false;
});
Lua_helper.add_callback(lua, "characterPlayAnim", function(character:String, anim:String, ?forced:Bool = false) {
funk.set("characterPlayAnim", function(character:String, anim:String, ?forced:Bool = false) {
FunkinLua.luaTrace("characterPlayAnim is deprecated! Use playAnim instead", false, true);
switch(character.toLowerCase()) {
case 'dad':
Expand All @@ -44,12 +43,12 @@ class DeprecatedFunctions
PlayState.instance.boyfriend.playAnim(anim, forced);
}
});
Lua_helper.add_callback(lua, "luaSpriteMakeGraphic", function(tag:String, width:Int, height:Int, color:String) {
funk.set("luaSpriteMakeGraphic", function(tag:String, width:Int, height:Int, color:String) {
FunkinLua.luaTrace("luaSpriteMakeGraphic is deprecated! Use makeGraphic instead", false, true);
if(MusicBeatState.getVariables().exists(tag))
MusicBeatState.getVariables().get(tag).makeGraphic(width, height, CoolUtil.colorFromString(color));
});
Lua_helper.add_callback(lua, "luaSpriteAddAnimationByPrefix", function(tag:String, name:String, prefix:String, framerate:Int = 24, loop:Bool = true) {
funk.set("luaSpriteAddAnimationByPrefix", function(tag:String, name:String, prefix:String, framerate:Int = 24, loop:Bool = true) {
FunkinLua.luaTrace("luaSpriteAddAnimationByPrefix is deprecated! Use addAnimationByPrefix instead", false, true);
if(MusicBeatState.getVariables().exists(tag)) {
var cock:ModchartSprite = MusicBeatState.getVariables().get(tag);
Expand All @@ -59,7 +58,7 @@ class DeprecatedFunctions
}
}
});
Lua_helper.add_callback(lua, "luaSpriteAddAnimationByIndices", function(tag:String, name:String, prefix:String, indices:String, framerate:Int = 24) {
funk.set("luaSpriteAddAnimationByIndices", function(tag:String, name:String, prefix:String, indices:String, framerate:Int = 24) {
FunkinLua.luaTrace("luaSpriteAddAnimationByIndices is deprecated! Use addAnimationByIndices instead", false, true);
if(MusicBeatState.getVariables().exists(tag)) {
var strIndices:Array<String> = indices.trim().split(',');
Expand All @@ -74,13 +73,13 @@ class DeprecatedFunctions
}
}
});
Lua_helper.add_callback(lua, "luaSpritePlayAnimation", function(tag:String, name:String, forced:Bool = false) {
funk.set("luaSpritePlayAnimation", function(tag:String, name:String, forced:Bool = false) {
FunkinLua.luaTrace("luaSpritePlayAnimation is deprecated! Use playAnim instead", false, true);
if(MusicBeatState.getVariables().exists(tag)) {
MusicBeatState.getVariables().get(tag).animation.play(name, forced);
}
});
Lua_helper.add_callback(lua, "setLuaSpriteCamera", function(tag:String, camera:String = '') {
funk.set("setLuaSpriteCamera", function(tag:String, camera:String = '') {
FunkinLua.luaTrace("setLuaSpriteCamera is deprecated! Use setObjectCamera instead", false, true);
if(MusicBeatState.getVariables().exists(tag)) {
MusicBeatState.getVariables().get(tag).cameras = [LuaUtils.cameraFromString(camera)];
Expand All @@ -89,15 +88,15 @@ class DeprecatedFunctions
FunkinLua.luaTrace("Lua sprite with tag: " + tag + " doesn't exist!");
return false;
});
Lua_helper.add_callback(lua, "setLuaSpriteScrollFactor", function(tag:String, scrollX:Float, scrollY:Float) {
funk.set("setLuaSpriteScrollFactor", function(tag:String, scrollX:Float, scrollY:Float) {
FunkinLua.luaTrace("setLuaSpriteScrollFactor is deprecated! Use setScrollFactor instead", false, true);
if(MusicBeatState.getVariables().exists(tag)) {
MusicBeatState.getVariables().get(tag).scrollFactor.set(scrollX, scrollY);
return true;
}
return false;
});
Lua_helper.add_callback(lua, "scaleLuaSprite", function(tag:String, x:Float, y:Float) {
funk.set("scaleLuaSprite", function(tag:String, x:Float, y:Float) {
FunkinLua.luaTrace("scaleLuaSprite is deprecated! Use scaleObject instead", false, true);
if(MusicBeatState.getVariables().exists(tag)) {
var shit:ModchartSprite = MusicBeatState.getVariables().get(tag);
Expand All @@ -107,7 +106,7 @@ class DeprecatedFunctions
}
return false;
});
Lua_helper.add_callback(lua, "getPropertyLuaSprite", function(tag:String, variable:String) {
funk.set("getPropertyLuaSprite", function(tag:String, variable:String) {
FunkinLua.luaTrace("getPropertyLuaSprite is deprecated! Use getProperty instead", false, true);
if(MusicBeatState.getVariables().exists(tag)) {
var killMe:Array<String> = variable.split('.');
Expand All @@ -122,7 +121,7 @@ class DeprecatedFunctions
}
return null;
});
Lua_helper.add_callback(lua, "setPropertyLuaSprite", function(tag:String, variable:String, value:Dynamic) {
funk.set("setPropertyLuaSprite", function(tag:String, variable:String, value:Dynamic) {
FunkinLua.luaTrace("setPropertyLuaSprite is deprecated! Use setProperty instead", false, true);
if(MusicBeatState.getVariables().exists(tag)) {
var killMe:Array<String> = variable.split('.');
Expand All @@ -140,12 +139,12 @@ class DeprecatedFunctions
FunkinLua.luaTrace("setPropertyLuaSprite: Lua sprite with tag: " + tag + " doesn't exist!");
return false;
});
Lua_helper.add_callback(lua, "musicFadeIn", function(duration:Float, fromValue:Float = 0, toValue:Float = 1) {
funk.set("musicFadeIn", function(duration:Float, fromValue:Float = 0, toValue:Float = 1) {
FlxG.sound.music.fadeIn(duration, fromValue, toValue);
FunkinLua.luaTrace('musicFadeIn is deprecated! Use soundFadeIn instead.', false, true);

});
Lua_helper.add_callback(lua, "musicFadeOut", function(duration:Float, toValue:Float = 0) {
funk.set("musicFadeOut", function(duration:Float, toValue:Float = 0) {
FlxG.sound.music.fadeOut(duration, toValue);
FunkinLua.luaTrace('musicFadeOut is deprecated! Use soundFadeOut instead.', false, true);
});
Expand Down
Loading

0 comments on commit 1ddfc5f

Please sign in to comment.