* Lua Improvments * fix * fix 2 * fix 3 * fix 4 * fix 5 * fix 6 * Fix 7, please action dont fail * done * done 2 * done 3 * final * last fix * please last fix final * add `curSection` on lua * ready for pr * oops * oop2 * Lua Improvements 2 * Update Project.xml * fixed `lastCalledScript` * Attempt Fix 2 * Attempt fix 3 * shit * done i think * fuck * fuck 2
194 lines
6.0 KiB
Haxe
194 lines
6.0 KiB
Haxe
package psychlua;
|
|
|
|
using StringTools;
|
|
class TextFunctions
|
|
{
|
|
public static function implement(funk:FunkinLua)
|
|
{
|
|
var lua = funk.lua;
|
|
var game:PlayState = PlayState.instance;
|
|
Lua_helper.add_callback(lua, "makeLuaText", function(tag:String, text:String, width:Int, x:Float, y:Float) {
|
|
tag = tag.replace('.', '');
|
|
|
|
LuaUtils.resetTextTag(tag);
|
|
var leText:FlxText = new FlxText(x, y, width, text, 16);
|
|
leText.setFormat(Paths.font("vcr.ttf"), 16, FlxColor.WHITE, CENTER, OUTLINE, FlxColor.BLACK);
|
|
leText.cameras = [game.camHUD];
|
|
leText.scrollFactor.set();
|
|
leText.borderSize = 2;
|
|
game.modchartTexts.set(tag, leText);
|
|
});
|
|
|
|
Lua_helper.add_callback(lua, "setTextString", function(tag:String, text:String) {
|
|
var obj:FlxText = LuaUtils.getTextObject(tag);
|
|
if(obj != null)
|
|
{
|
|
obj.text = text;
|
|
return true;
|
|
}
|
|
FunkinLua.luaTrace("setTextString: Object " + tag + " doesn't exist!", false, false, FlxColor.RED);
|
|
return false;
|
|
});
|
|
Lua_helper.add_callback(lua, "setTextSize", function(tag:String, size:Int) {
|
|
var obj:FlxText = LuaUtils.getTextObject(tag);
|
|
if(obj != null)
|
|
{
|
|
obj.size = size;
|
|
return true;
|
|
}
|
|
FunkinLua.luaTrace("setTextSize: Object " + tag + " doesn't exist!", false, false, FlxColor.RED);
|
|
return false;
|
|
});
|
|
Lua_helper.add_callback(lua, "setTextWidth", function(tag:String, width:Float) {
|
|
var obj:FlxText = LuaUtils.getTextObject(tag);
|
|
if(obj != null)
|
|
{
|
|
obj.fieldWidth = width;
|
|
return true;
|
|
}
|
|
FunkinLua.luaTrace("setTextWidth: Object " + tag + " doesn't exist!", false, false, FlxColor.RED);
|
|
return false;
|
|
});
|
|
Lua_helper.add_callback(lua, "setTextHeight", function(tag:String, height:Float) {
|
|
var obj:FlxText = LuaUtils.getTextObject(tag);
|
|
if(obj != null)
|
|
{
|
|
obj.fieldHeight = height;
|
|
return true;
|
|
}
|
|
FunkinLua.luaTrace("setTextHeight: Object " + tag + " doesn't exist!", false, false, FlxColor.RED);
|
|
return false;
|
|
});
|
|
Lua_helper.add_callback(lua, "setTextAutoSize", function(tag:String, value:Bool) {
|
|
var obj:FlxText = LuaUtils.getTextObject(tag);
|
|
if(obj != null)
|
|
{
|
|
obj.autoSize = value;
|
|
return true;
|
|
}
|
|
FunkinLua.luaTrace("setTextAutoSize: Object " + tag + " doesn't exist!", false, false, FlxColor.RED);
|
|
return false;
|
|
});
|
|
Lua_helper.add_callback(lua, "setTextBorder", function(tag:String, size:Float, color:String, ?style:String = 'outline') {
|
|
var obj:FlxText = LuaUtils.getTextObject(tag);
|
|
if(obj != null)
|
|
{
|
|
CoolUtil.setTextBorderFromString(obj, (size > 0 ? style : 'none'));
|
|
if(size > 0)
|
|
obj.borderSize = size;
|
|
|
|
obj.borderColor = CoolUtil.colorFromString(color);
|
|
return true;
|
|
}
|
|
FunkinLua.luaTrace("setTextBorder: Object " + tag + " doesn't exist!", false, false, FlxColor.RED);
|
|
return false;
|
|
});
|
|
Lua_helper.add_callback(lua, "setTextColor", function(tag:String, color:String) {
|
|
var obj:FlxText = LuaUtils.getTextObject(tag);
|
|
if(obj != null)
|
|
{
|
|
obj.color = CoolUtil.colorFromString(color);
|
|
return true;
|
|
}
|
|
FunkinLua.luaTrace("setTextColor: Object " + tag + " doesn't exist!", false, false, FlxColor.RED);
|
|
return false;
|
|
});
|
|
Lua_helper.add_callback(lua, "setTextFont", function(tag:String, newFont:String) {
|
|
var obj:FlxText = LuaUtils.getTextObject(tag);
|
|
if(obj != null)
|
|
{
|
|
obj.font = Paths.font(newFont);
|
|
return true;
|
|
}
|
|
FunkinLua.luaTrace("setTextFont: Object " + tag + " doesn't exist!", false, false, FlxColor.RED);
|
|
return false;
|
|
});
|
|
Lua_helper.add_callback(lua, "setTextItalic", function(tag:String, italic:Bool) {
|
|
var obj:FlxText = LuaUtils.getTextObject(tag);
|
|
if(obj != null)
|
|
{
|
|
obj.italic = italic;
|
|
return true;
|
|
}
|
|
FunkinLua.luaTrace("setTextItalic: Object " + tag + " doesn't exist!", false, false, FlxColor.RED);
|
|
return false;
|
|
});
|
|
Lua_helper.add_callback(lua, "setTextAlignment", function(tag:String, alignment:String = 'left') {
|
|
var obj:FlxText = LuaUtils.getTextObject(tag);
|
|
if(obj != null)
|
|
{
|
|
obj.alignment = LEFT;
|
|
switch(alignment.trim().toLowerCase())
|
|
{
|
|
case 'right':
|
|
obj.alignment = RIGHT;
|
|
case 'center':
|
|
obj.alignment = CENTER;
|
|
}
|
|
return true;
|
|
}
|
|
FunkinLua.luaTrace("setTextAlignment: Object " + tag + " doesn't exist!", false, false, FlxColor.RED);
|
|
return false;
|
|
});
|
|
|
|
Lua_helper.add_callback(lua, "getTextString", function(tag:String) {
|
|
var obj:FlxText = LuaUtils.getTextObject(tag);
|
|
if(obj != null && obj.text != null)
|
|
{
|
|
return obj.text;
|
|
}
|
|
FunkinLua.luaTrace("getTextString: Object " + tag + " doesn't exist!", false, false, FlxColor.RED);
|
|
return null;
|
|
});
|
|
Lua_helper.add_callback(lua, "getTextSize", function(tag:String) {
|
|
var obj:FlxText = LuaUtils.getTextObject(tag);
|
|
if(obj != null)
|
|
{
|
|
return obj.size;
|
|
}
|
|
FunkinLua.luaTrace("getTextSize: Object " + tag + " doesn't exist!", false, false, FlxColor.RED);
|
|
return -1;
|
|
});
|
|
Lua_helper.add_callback(lua, "getTextFont", function(tag:String) {
|
|
var obj:FlxText = LuaUtils.getTextObject(tag);
|
|
if(obj != null)
|
|
{
|
|
return obj.font;
|
|
}
|
|
FunkinLua.luaTrace("getTextFont: Object " + tag + " doesn't exist!", false, false, FlxColor.RED);
|
|
return null;
|
|
});
|
|
Lua_helper.add_callback(lua, "getTextWidth", function(tag:String) {
|
|
var obj:FlxText = LuaUtils.getTextObject(tag);
|
|
if(obj != null)
|
|
{
|
|
return obj.fieldWidth;
|
|
}
|
|
FunkinLua.luaTrace("getTextWidth: Object " + tag + " doesn't exist!", false, false, FlxColor.RED);
|
|
return 0;
|
|
});
|
|
|
|
Lua_helper.add_callback(lua, "addLuaText", function(tag:String) {
|
|
if(game.modchartTexts.exists(tag)) {
|
|
var shit:FlxText = game.modchartTexts.get(tag);
|
|
LuaUtils.getTargetInstance().add(shit);
|
|
}
|
|
});
|
|
Lua_helper.add_callback(lua, "removeLuaText", function(tag:String, destroy:Bool = true) {
|
|
if(!game.modchartTexts.exists(tag)) {
|
|
return;
|
|
}
|
|
|
|
var pee:FlxText = game.modchartTexts.get(tag);
|
|
if(destroy) {
|
|
pee.kill();
|
|
}
|
|
|
|
LuaUtils.getTargetInstance().remove(pee, true);
|
|
if(destroy) {
|
|
pee.destroy();
|
|
game.modchartTexts.remove(tag);
|
|
}
|
|
});
|
|
}
|
|
} |