Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"Infront",
"jignored",
"LOCKON",
"lscript",
"luajit",
"PAGEUP",
"preprocesor",
Expand Down
5 changes: 3 additions & 2 deletions Project.hxp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ class EngineAsset {
// script related
if (scriptSupport.exists()) {
canHaxeScript.enable();
canLuaScript.enable();
if (!isLinux()) // can't finish compiling for some reason, causes action to go on forever
canLuaScript.enable();

disableDCE.enable();
scriptedStates.enable();
Expand Down Expand Up @@ -279,7 +280,7 @@ class EngineAsset {
addHaxelib('moonchart', 'git');

if ( canHaxeScript.exists()) addHaxelib('hscript-improved', 'git');
if ( canLuaScript .exists()) addHaxelib('linc_luajit', 'git');
if ( canLuaScript .exists()) addHaxelib('lscript', 'git');
if ( discordRPC .exists()) addHaxelib('hxdiscord_rpc');
if (allowVideos .exists()) addHaxelib('hxvlc', 'git');
if (knowsVersionID.exists()) addHaxelib('thx.semver');
Expand Down
2 changes: 1 addition & 1 deletion engine/assets
Submodule assets updated 45 files
+0 −4 .gitignore
+1 −1 content/difficulties/readme.md
+1 −1 content/levels/Week 2.hx
+1 −1 content/levels/Week 5.hx
+1 −1 content/levels/Weekend 1.hx
+0 −2 content/levels/global.hx
+1 −1 content/levels/readme.md
+1 −1 content/objects/characters/boyfriend.json
+4 −0 content/objects/icons/bf-pixel.yaml
+0 −23 content/objects/icons/boyfriend-pixel.json
+0 −31 content/objects/icons/boyfriend.json
+0 −23 content/objects/icons/dad.json
+0 −31 content/objects/icons/darnell.json
+0 −31 content/objects/icons/face.json
+0 −23 content/objects/icons/gf.json
+0 −31 content/objects/icons/mom.json
+0 −31 content/objects/icons/monster.json
+0 −31 content/objects/icons/pico.json
+0 −23 content/objects/icons/senpai.json
+4 −0 content/objects/icons/senpai.yaml
+0 −23 content/objects/icons/spirit.json
+4 −0 content/objects/icons/spirit.yaml
+0 −31 content/objects/icons/spooky.json
+0 −31 content/objects/icons/tankman.json
+0 −8 content/scripts/readme.md
+0 −2 content/scripts/songs/global.hx
+1 −1 content/songs/Test/meta.json
+2 −6 content/songs/readme.md
+4 −4 content/states/TestState.hx
+1 −1 content/states/readme.md
+ fonts/PhantomMuff/difficulty font.ttf
+ fonts/PhantomMuff/empty letters.ttf
+ fonts/PhantomMuff/full letters.ttf
+0 −2 fonts/PhantomMuff/readme.txt
+ images/credits/concow.png
+ images/credits/zyflx.png
+ images/gameplay/arrows/funkin.png
+0 −69 images/gameplay/arrows/funkin.xml
+ images/gameplay/arrows/noteStrumline.png
+55 −0 images/gameplay/arrows/noteStrumline.xml
+ images/gameplay/arrows/notes.png
+7 −0 images/gameplay/arrows/notes.xml
+ images/ui/icons/bf-pixel.png
+ images/ui/icons/bf.png
+1 −1 music/readme.md
192 changes: 188 additions & 4 deletions engine/source/imaginative/backend/scripting/types/LuaScript.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package imaginative.backend.scripting.types;

#if CAN_LUA_SCRIPT
import lscript.LScript;
#end

/**
Expand All @@ -13,28 +14,211 @@ final class LuaScript extends Script {
public static final exts:Array<String> = ['lua'];

#if CAN_LUA_SCRIPT
public var lscript:LScript;

@:access(imaginative.backend.Console.formatLogInfo)
static function getScriptImports(script:LuaScript):Map<String, Dynamic> {
return [
// Lime + OpenFL //
'Assets' => openfl.utils.Assets,
'Application' => lime.app.Application,
'window' => lime.app.Application.current.window,

// Flixel //
'FlxBasic' => FlxBasic,
'FlxCamera' => FlxCamera,
'FlxG' => FlxG,
'FlxObject' => FlxObject,
'FlxSprite' => FlxSprite,
'FlxState' => FlxState,
'FlxSubState' => FlxSubState,
'FlxTypeText' => FlxTypeText,
'FlxGroup' => FlxGroup,
'FlxSpriteGroup' => FlxSpriteGroup,
'FlxTypedGroup' => FlxTypedGroup,
'FlxTypedSpriteGroup' => FlxTypedSpriteGroup,
'FlxAngle' => FlxAngle,
'FlxMath' => FlxMath,
'FlxPoint' => Type.resolveClass('flixel.math.FlxPoint_HSC'),
'FlxRect' => FlxRect,
'FlxVelocity' => FlxVelocity,
'FlxSound' => FlxSound,
'FlxSoundGroup' => FlxSoundGroup,
'FlxText' => FlxText,
'FlxEase' => FlxEase,
'FlxTween' => FlxTween,
'FlxAxes' => Type.resolveClass('flixel.util.FlxAxes_HSC'),
'FlxColor' => Type.resolveClass('flixel.util.FlxColor_HSC'),
'FlxGradient' => FlxGradient,
'FlxSave' => FlxSave,
'FlxTypedSignal' => Type.resolveClass('flixel.util.FlxTypedSignal_HSC'),
'FlxSkewedSprite' => flixel.addons.effects.FlxSkewedSprite,
'FlxBackdrop' => flixel.addons.display.FlxBackdrop,
'FlxSort' => FlxSort,
'FlxTimer' => FlxTimer,
'OneOfFour' => Type.resolveClass('flixel.util.typeLimit.OneOfFour_HSC'),
'OneOfThree' => Type.resolveClass('flixel.util.typeLimit.OneOfThree_HSC'),
'OneOfTwo' => Type.resolveClass('flixel.util.typeLimit.OneOfTwo_HSC'),
'FlxArrayUtil' => FlxArrayUtil,
'FlxColorTransformUtil' => FlxColorTransformUtil,
'FlxDestroyUtil' => FlxDestroyUtil,
'FlxSpriteUtil' => FlxSpriteUtil,
'FlxStringUtil' => FlxStringUtil,

// Engine //
'Controls' => Controls,
'PlayConfig' => PlayConfig,
'Conductor' => Conductor,
'BeatGroup' => BeatGroup,
'BeatSpriteGroup' => BeatSpriteGroup,
'BeatTypedGroup' => BeatTypedGroup,
'BeatTypedSpriteGroup' => BeatTypedSpriteGroup,
'BeatState' => BeatState,
'BeatSubState' => BeatSubState,
'TypeXY' => TypeXY,
'Position' => Position,
'Script' => Script,
'ScriptGroup' => ScriptGroup,
'ScriptedState' => imaginative.backend.scripting.states.ScriptedState,
'ScriptedSubState' => imaginative.backend.scripting.states.ScriptedSubState,
'GlobalScript' => GlobalScript,
'HaxeScript' => HaxeScript,
'InvalidScript' => InvalidScript,
'LuaScript' => LuaScript,
'Main' => Main,
#if MOD_SUPPORT
'Modding' => Modding,
#end
'ModType' => Type.resolveClass('imaginative.backend.system.Paths.ModType_HSC'),
'ModPath' => Type.resolveClass('imaginative.backend.system.Paths.ModPath_HSC'),
'Paths' => Paths,
'Settings' => Settings,
'DifficultyHolder' => DifficultyHolder,
'LevelHolder' => LevelHolder,
'FlxWindow' => FlxWindow,
'mainWindow' => FlxWindow.direct,
'ArrowField' => ArrowField,
'Note' => Note,
'Strum' => Strum,
'SpriteText' => SpriteText,
'SpriteTextLine' => SpriteTextLine,
'SpriteTextCharacter' => SpriteTextCharacter,
'HealthIcon' => HealthIcon,
'WindowBounds' => WindowBounds,
'AnimationContext' => Type.resolveClass('imaginative.objects.BaseSprite.AnimationContext_HSC'),
'BaseSprite' => BaseSprite,
'BeatSprite' => BeatSprite,
'Character' => Character,
'PlayState' => PlayState,
'FunkinUtil' => FunkinUtil,
'ParseUtil' => ParseUtil,
'PlatformUtil' => PlatformUtil,
'SpriteUtil' => SpriteUtil,

// Extra //
#if KNOWS_VERSION_ID
'Version' => Type.resolveClass('thx.semver.Version_HSC'),
#end

// Custom Functions //
'addInfrontOf' => (obj:FlxBasic, from:FlxBasic, ?into:FlxTypedGroup<Dynamic>) ->
return SpriteUtil.addInfrontOf(obj, from, into),
'addBehind' => (obj:FlxBasic, from:FlxBasic, ?into:FlxTypedGroup<Dynamic>) ->
return SpriteUtil.addBehind(obj, from, into),

'print' => (value:Dynamic) ->
_log(Console.formatLogInfo(value, LogMessage, script.pathing.format(), FromLua)),
'log' => (value:Dynamic, level:String = LogMessage) ->
_log(Console.formatLogInfo(value, level, script.pathing.format(), FromLua)),

'disableScript' => () ->
script.active = false
script.active = false,

// self //
'__this__' => script
];
}

@:allow(imaginative.backend.scripting.Script.create)
override function new(file:ModPath, ?code:String) {
log('Lua scripting isn\'t supported... yet.', SystemMessage);
override function new(file:ModPath, ?code:String)
super(file, code);

override function renderScript(file:ModPath, ?code:String):Void {
super.renderScript(file, code);
lscript = new LScript(this.code);
}

@:access(imaginative.backend.Console.formatLogInfo)
override function loadCodeString(code:String):Void {
try {
for (name => thing in getScriptImports(this))
set(name, thing);
canRun = true;
return;
} catch(error:haxe.Exception)
_log(Console.formatLogInfo(error.message, ErrorMessage, pathing.format()), ErrorMessage);
canRun = false;
}

/**
* Load's code from string.
* @param code The script code.
* @param vars Variables to input into the lua script instance.
* @param funcToRun Function to run inside the lua script instance.
* @param funcArgs Arguments to run for said function.
* @return `LuaScript` ~ The lua script instance from string.
*/
public static function loadCodeFromString(code:String, ?vars:Map<String, Dynamic>, ?funcToRun:String, ?funcArgs:Array<Dynamic>):LuaScript {
var script:LuaScript = new LuaScript('', code);
for (name => thing in vars)
script.set(name, thing);
script.load();
script.call(funcToRun, funcArgs ?? []);
return script;
}

override function load():Void {
super.load();
if (!loaded && canRun) {
try {
lscript.execute();
loaded = true;
call('new');
} catch(error:haxe.Exception)
log('Error while trying to execute script: ${error.message}', ErrorMessage);
}
}

override function get_parent():Dynamic
return lscript.parent;
override function set_parent(value:Dynamic):Dynamic
return lscript.parent = value;

override public function set(variable:String, value:Dynamic):Void
lscript.setVar(variable, value);
override public function get(variable:String, ?def:Dynamic):Dynamic
return lscript.getVar(variable) ?? def;

override public function call(func:String, ?args:Array<Dynamic>):Dynamic
return lscript.callFunc(func, args ?? []);
override public function event<SC:ScriptEvent>(func:String, event:SC):SC {
event.returnCall = call(func, [event]);
return event;
}

override public function destroy() {
if (lscript.luaState != null) {
llua.Lua.close(lscript.luaState);
lscript.luaState = null;
}
if (lscript != null)
lscript = null;
super.destroy();
}
#else
@:allow(imaginative.backend.scripting.Script.create)
override function new(file:ModPath, ?_:String) {
log('Lua scripting isn\'t supported in this build.', SystemMessage);
log(#if linux 'LScript doesn\'t compile on linux for some reason.' #else 'Lua scripting isn\'t supported in this build.' #end, SystemMessage);
super(file, null);
}
#end
Expand Down
2 changes: 1 addition & 1 deletion extras
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Be weary of any issues you may encounter.
### Libraries Used
[CNE Devs](https://github.com/CodenameCrew): [`flixel`](https://github.com/CodenameCrew/cne-flixel) and [`flixel-addons`](https://github.com/CodenameCrew/cne-flixel-addons) forks, [`hscript-improved`](https://github.com/CodenameCrew/hscript-improved) and one of this engine's inspirations!

[SuperPowers04](https://github.com/superpowers04): [`linc_luajit`](https://github.com/superpowers04/linc_luajit), for all my lua needs.
[SrtHero278](https://github.com/SrtHero278): [`lscript`](https://github.com/SrtHero278/lscript), for all my lua needs.

[Guillaume Desquesnes](https://github.com/elnabo): [`json2object`](https://github.com/elnabo/json2object), a great json parser! Oh and I'm using [FunkinCrew](https://github.com/FunkinCrew/json2object)'s fork btw.

Expand Down
6 changes: 3 additions & 3 deletions setup/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"url": "https://github.com/CodenameCrew/hscript-improved"
},
{
"name": "linc_luajit", "version": "git",
"url": "https://github.com/superpowers04/linc_luajit"
"name": "lscript", "version": "git",
"url": "https://github.com/SrtHero278/lscript"
},
{"name": "hxdiscord_rpc"},
{
Expand All @@ -49,7 +49,7 @@
"description": "include haxe scripting support"
},
{
"name": "linc_luajit",
"name": "lscript",
"description": "include lua scripting support"
},
{
Expand Down
Loading