Skip to content

Commit 63828df

Browse files
committed
Got RuleScript Custom Classes Working
1 parent 6100892 commit 63828df

1 file changed

Lines changed: 22 additions & 11 deletions

File tree

engine/source/imaginative/backend/scripting/types/HaxeScript.hx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ package imaginative.backend.scripting.types;
44
import rulescript.RuleScript;
55
import rulescript.interps.RuleScriptInterp;
66
import rulescript.parsers.HxParser;
7-
8-
// import rulescript.types.ScriptedTypeUtil;
7+
import rulescript.types.ScriptedTypeUtil;
98
#end
109

1110
/**
@@ -17,6 +16,16 @@ final class HaxeScript extends Script {
1716
*/
1817
public static final exts:Array<String> = ['haxe', 'hx', 'hscript', 'hsc', 'hxs', 'hxc'];
1918

19+
inline static function getModulePath(name:String):String {
20+
// taken from rulescript test folder since what I was doing just didn't want to work
21+
var path:Array<String> = name.split('.');
22+
var pack:Array<String> = [];
23+
while (path[0].charAt(0) == path[0].charAt(0).toLowerCase()) pack.push(path.shift());
24+
var moduleName:String = null;
25+
if (path.length > 1) moduleName = path.shift();
26+
return pack.length >= 1 ? pack.join('.') + '.' + (moduleName ?? path[0]) : path[0];
27+
}
28+
2029
#if CAN_HAXE_SCRIPT
2130
@:allow(imaginative.backend.scripting.Script)
2231
inline static function init():Void {
@@ -40,17 +49,19 @@ final class HaxeScript extends Script {
4049
rootImport.set(classInst.getClassName().substring(1), classInst.getClassName(true));
4150

4251
// fucks over so much for no reason
43-
/* ScriptedTypeUtil.resolveModule = (name:String) -> {
44-
_log('[HaxeScript] Resolving script for module: $name');
45-
var script:HaxeScript = cast Script.create('lead:content/modules/${name.replace('.', '/')}', TypeHaxe);
46-
if (script.type.dummy) {
47-
_log('[HaxeScript] Failed to resolve module: $name');
48-
script.destroy();
52+
ScriptedTypeUtil.resolveModule = (name:String) -> {
53+
final moduleName:String = getModulePath(name);
54+
// _log('[HaxeScript] Resolving script for module: $moduleName');
55+
final scriptPath:ModPath = Paths.script('lead:content/modules/${moduleName.replace('.', '/')}', TypeHaxe);
56+
if (!scriptPath.isFile) {
57+
// _log('[HaxeScript] Failed to resolve module: $moduleName');
4958
return null;
5059
}
51-
if (!script.filePath.isFile) script.destroy();
52-
return script.filePath.isFile ? script._parser.parseModule(Assets.text(script.filePath)) : null;
53-
} */
60+
final parser = new HxParser();
61+
parser.mode = MODULE;
62+
parser.allowAll();
63+
return parser.parseModule(Assets.text(scriptPath));
64+
}
5465
RuleScript.defaultImports.set('', rootImport);
5566
}
5667

0 commit comments

Comments
 (0)