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

Implement hscript-improved #13304

Closed
Prev Previous commit
Next Next commit
Lua_helper.add_callback() to just set()
  • Loading branch information
TheLeerName committed Sep 19, 2023
commit 6d174c10b7c0f180a98386b3cb0fc2b8da93e5f7
2 changes: 1 addition & 1 deletion source/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Main extends Sprite
game.height = Math.ceil(stageHeight / game.zoom);
}

#if LUA_ALLOWED Lua.set_callbacks_function(cpp.Callable.fromStaticFunction(psychlua.CallbackHandler.call)); #end
#if LUA_ALLOWED llua.Lua.set_callbacks_function(cpp.Callable.fromStaticFunction(psychlua.CallbackHandler.call)); #end
Controls.instance = new Controls();
ClientPrefs.loadDefaultKeys();
addChild(new FlxGame(game.width, game.height, game.initialState, #if (flixel < "5.0.0") game.zoom, #end game.framerate, game.framerate, game.skipSplash, game.startFullscreen));
Expand Down
7 changes: 4 additions & 3 deletions source/backend/Discord.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package backend;
import Sys.sleep;
import discord_rpc.DiscordRpc;
import lime.app.Application;
import psychlua.FunkinLua;

class DiscordClient
{
Expand Down Expand Up @@ -143,12 +144,12 @@ class DiscordClient
#end

#if LUA_ALLOWED
public static function addLuaCallbacks(lua:State) {
Lua_helper.add_callback(lua, "changeDiscordPresence", function(details:String, state:Null<String>, ?smallImageKey:String, ?hasStartTimestamp:Bool, ?endTimestamp:Float) {
public static function addLuaCallbacks(funk:FunkinLua) {
funk.set("changeDiscordPresence", function(details:String, state:Null<String>, ?smallImageKey:String, ?hasStartTimestamp:Bool, ?endTimestamp:Float) {
changePresence(details, state, smallImageKey, hasStartTimestamp, endTimestamp);
});

Lua_helper.add_callback(lua, "changeDiscordClientID", function(?newID:String = null) {
funk.set("changeDiscordClientID", function(?newID:String = null) {
if(newID == null) newID = _defaultID;
clientID = newID;
});
Expand Down
5 changes: 0 additions & 5 deletions source/import.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ import backend.Discord;
#end

//Psych
#if LUA_ALLOWED
import llua.*;
import llua.Lua;
#end

import backend.Paths;
import backend.Controls;
import backend.CoolUtil;
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
public static function implement(funk:FunkinLua)
{
#if LUA_ALLOWED
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(PlayState.instance.modchartSprites.exists(tag))
PlayState.instance.modchartSprites.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(PlayState.instance.modchartSprites.exists(tag)) {
var cock:ModchartSprite = PlayState.instance.modchartSprites.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(PlayState.instance.modchartSprites.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(PlayState.instance.modchartSprites.exists(tag)) {
PlayState.instance.modchartSprites.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(PlayState.instance.modchartSprites.exists(tag)) {
PlayState.instance.modchartSprites.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(PlayState.instance.modchartSprites.exists(tag)) {
PlayState.instance.modchartSprites.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(PlayState.instance.modchartSprites.exists(tag)) {
var shit:ModchartSprite = PlayState.instance.modchartSprites.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(PlayState.instance.modchartSprites.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(PlayState.instance.modchartSprites.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