167 lines
4.6 KiB
Haxe
167 lines
4.6 KiB
Haxe
package psychlua;
|
|
|
|
import flixel.FlxCamera;
|
|
import flixel.tweens.FlxEase;
|
|
import flixel.util.FlxColor;
|
|
import openfl.display.BlendMode;
|
|
|
|
using StringTools;
|
|
|
|
@:allow(psychlua.FunkinLua)
|
|
class LuaUtils
|
|
{
|
|
// Better optimized than using some getProperty shit or idk
|
|
static inline function getFlxEaseByString(?ease:String = '')
|
|
{
|
|
return switch (ease.toLowerCase().trim())
|
|
{
|
|
case 'backin': return FlxEase.backIn;
|
|
case 'backinout': return FlxEase.backInOut;
|
|
case 'backout': return FlxEase.backOut;
|
|
case 'bouncein': return FlxEase.bounceIn;
|
|
case 'bounceinout': return FlxEase.bounceInOut;
|
|
case 'bounceout': return FlxEase.bounceOut;
|
|
case 'circin': return FlxEase.circIn;
|
|
case 'circinout': return FlxEase.circInOut;
|
|
case 'circout': return FlxEase.circOut;
|
|
case 'cubein': return FlxEase.cubeIn;
|
|
case 'cubeinout': return FlxEase.cubeInOut;
|
|
case 'cubeout': return FlxEase.cubeOut;
|
|
case 'elasticin': return FlxEase.elasticIn;
|
|
case 'elasticinout': return FlxEase.elasticInOut;
|
|
case 'elasticout': return FlxEase.elasticOut;
|
|
case 'expoin': return FlxEase.expoIn;
|
|
case 'expoinout': return FlxEase.expoInOut;
|
|
case 'expoout': return FlxEase.expoOut;
|
|
case 'quadin': return FlxEase.quadIn;
|
|
case 'quadinout': return FlxEase.quadInOut;
|
|
case 'quadout': return FlxEase.quadOut;
|
|
case 'quartin': return FlxEase.quartIn;
|
|
case 'quartinout': return FlxEase.quartInOut;
|
|
case 'quartout': return FlxEase.quartOut;
|
|
case 'quintin': return FlxEase.quintIn;
|
|
case 'quintinout': return FlxEase.quintInOut;
|
|
case 'quintout': return FlxEase.quintOut;
|
|
case 'sinein': return FlxEase.sineIn;
|
|
case 'sineinout': return FlxEase.sineInOut;
|
|
case 'sineout': return FlxEase.sineOut;
|
|
case 'smoothstepin': return FlxEase.smoothStepIn;
|
|
case 'smoothstepinout': return FlxEase.smoothStepInOut;
|
|
case 'smoothstepout': return FlxEase.smoothStepInOut;
|
|
case 'smootherstepin': return FlxEase.smootherStepIn;
|
|
case 'smootherstepinout': return FlxEase.smootherStepInOut;
|
|
case 'smootherstepout': return FlxEase.smootherStepOut;
|
|
case _: return FlxEase.linear;
|
|
}
|
|
}
|
|
|
|
static inline function blendModeFromString(blend:String):BlendMode
|
|
{
|
|
return switch (blend.toLowerCase().trim())
|
|
{
|
|
case 'add': return ADD;
|
|
case 'alpha': return ALPHA;
|
|
case 'darken': return DARKEN;
|
|
case 'difference': return DIFFERENCE;
|
|
case 'erase': return ERASE;
|
|
case 'hardlight': return HARDLIGHT;
|
|
case 'invert': return INVERT;
|
|
case 'layer': return LAYER;
|
|
case 'lighten': return LIGHTEN;
|
|
case 'multiply': return MULTIPLY;
|
|
case 'overlay': return OVERLAY;
|
|
case 'screen': return SCREEN;
|
|
case 'shader': return SHADER;
|
|
case 'subtract': return SUBTRACT;
|
|
case _: return NORMAL;
|
|
}
|
|
}
|
|
|
|
static inline function cameraFromString(cam:String):FlxCamera
|
|
{
|
|
return switch (cam.toLowerCase())
|
|
{
|
|
case 'camhud' | 'hud': return PlayState.instance.camHUD;
|
|
case 'camother' | 'other': return PlayState.instance.camOther;
|
|
case _: PlayState.instance.camGame;
|
|
}
|
|
}
|
|
|
|
// alias for above, helper function basically
|
|
public static function getCam(obj:String):Dynamic
|
|
{
|
|
if (obj.toLowerCase().trim() == "global")
|
|
return FlxG.game;
|
|
return cameraFromString(obj);
|
|
}
|
|
|
|
public static function luaTrace(lua:#if LUA_ALLOWED State #else Dynamic #end, text:String, ignoreCheck:Bool = false, deprecated:Bool = false,
|
|
color:FlxColor = FlxColor.WHITE)
|
|
{
|
|
#if LUA_ALLOWED
|
|
if (ignoreCheck || getBool(lua, 'luaDebugMode'))
|
|
{
|
|
if (deprecated && !getBool(lua, 'luaDeprecatedWarnings'))
|
|
{
|
|
return;
|
|
}
|
|
PlayState.instance.addTextToDebug(text, color);
|
|
trace(text);
|
|
}
|
|
#end
|
|
}
|
|
|
|
static function getErrorMessage(lua:#if LUA_ALLOWED State #else Dynamic #end, status:Int):String
|
|
{
|
|
#if LUA_ALLOWED
|
|
var v:String = Lua.tostring(lua, -1);
|
|
Lua.pop(lua, 1);
|
|
|
|
if (v != null)
|
|
v = v.trim();
|
|
if (v == null || v == "")
|
|
{
|
|
return switch (status)
|
|
{
|
|
case Lua.LUA_ERRRUN: return "Runtime Error";
|
|
case Lua.LUA_ERRMEM: return "Memory Allocation Error";
|
|
case Lua.LUA_ERRERR: return "Critical Error";
|
|
case _: return "Unknown Error";
|
|
}
|
|
}
|
|
|
|
return v;
|
|
#else
|
|
return null;
|
|
#end
|
|
}
|
|
|
|
public static function isOfTypes(value:Any, types:Array<Dynamic>)
|
|
{
|
|
for (type in types)
|
|
{
|
|
if (Std.isOfType(value, type))
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static function getBool(lua:#if LUA_ALLOWED State #else Dynamic #end, variable:String)
|
|
{
|
|
#if LUA_ALLOWED
|
|
var result:String = null;
|
|
Lua.getglobal(lua, variable);
|
|
result = Convert.fromLua(lua, -1);
|
|
Lua.pop(lua, 1);
|
|
|
|
if (result == null)
|
|
{
|
|
return false;
|
|
}
|
|
return (result == 'true');
|
|
#else
|
|
return false;
|
|
#end
|
|
}
|
|
}
|