diff --git a/hmm.json b/hmm.json index 113442b6..884f317b 100644 --- a/hmm.json +++ b/hmm.json @@ -3,62 +3,47 @@ { "name": "lime", "type": "haxelib", - "version": null + "version": "8.0.2" }, { "name": "openfl", "type": "haxelib", - "version": null + "version": "9.2.2" }, { "name": "flixel", "type": "haxelib", - "version": null + "version": "5.3.1" }, { "name": "flixel-addons", "type": "haxelib", - "version": null - }, - { - "name": "flixel-tools", - "type": "haxelib", - "version": null + "version": "3.1.1" }, { "name": "flixel-ui", "type": "haxelib", - "version": null + "version": "2.5.0" }, { "name": "hxcpp", "type": "haxelib", - "version": null + "version": "4.3.2" }, { "name": "tjson", "type": "haxelib", - "version": null - }, - { - "name": "hxjsonast", - "type": "haxelib", - "version": null + "version": "1.4.0" }, { "name": "hxCodec", "type": "haxelib", - "version": null + "version": "3.0.2" }, { "name": "SScript", "type": "haxelib", - "version": "7.0.0" - }, - { - "name": "hxcpp-debug-server", - "type": "haxelib", - "version": null + "version": "7.7.0" }, { "name": "discord_rpc", @@ -77,7 +62,7 @@ { "name": "colyseus", "type": "haxelib", - "version": null + "version": "0.15.2" } ] } diff --git a/source/macro/Macro.hx b/source/macro/Macro.hx new file mode 100644 index 00000000..f088f1e5 --- /dev/null +++ b/source/macro/Macro.hx @@ -0,0 +1,124 @@ +package macro; + +// award for the most useless macro ever goes to sscript + +import haxe.macro.Compiler; +import haxe.macro.ComplexTypeTools; +import haxe.macro.Context; +import haxe.macro.ExprTools; +import haxe.macro.MacroStringTools; +import haxe.macro.Printer; +import haxe.macro.TypeTools; +import haxe.macro.TypedExprTools; +import tea.backend.SScriptVer; +import tea.backend.crypto.Base32; +import haxe.Serializer; +import haxe.Unserializer; +#if sys +import sys.FileSystem; +import sys.io.File; +import sys.io.Process; +#end + +using StringTools; + +typedef SuperlativeSettings = { + public var showMacro:Bool; + public var includeAll:Bool; + public var loopCost:Int; +} + +@:access(hscriptBase.Tools) +class Macro { + public static final defaultSettings:SuperlativeSettings = { + showMacro: false, + includeAll: false, + loopCost: 25 + } + + #if !macro + public static final allClassesAvailable:Map> = hscriptBase.Tools.names.copy(); + #end + + public static var VERSION(default, null):SScriptVer = new SScriptVer(7, 7, 0); + + #if sys + public static var isWindows(default, null):Bool = ~/^win/i.match(Sys.systemName()); + public static var definePath(get, never):String; + #end + + static var credits:Array = ["Special Thanks:", "- CrowPlexus\n",]; + + public static var macroClasses:Array> = [ + Compiler, + Context, + MacroStringTools, + Printer, + ComplexTypeTools, + TypedExprTools, + ExprTools, + TypeTools, + ]; + + macro public static function initiateMacro() { + var settings:SuperlativeSettings = defaultSettings; + #if sys + final defines = Context.getDefines(); + var pushedDefines:Array = []; + var string:String = ""; + for (i => k in defines) { + if (!pushedDefines.contains(i)) { + string += '$i|$k'; + string += '\n'; + pushedDefines.push(i); + } + } + var splitString:Array = string.split('\n'); + if (splitString.length > 1 && string.endsWith('\n')) { + splitString.pop(); + string = splitString.join('\n'); + } + + var path:String = definePath; + File.saveContent(path, new Base32().encodeString(string)); + #end + + if (defines.exists('openflPos') && ( + #if openfl + #if (openfl < "9.2.0") + true + #else + false + #end + #else + true + #end)) + #if (openfl < "9.2.0") Context.fatalError('Your openfl is outdated (${defines.get('openfl')}), please update openfl', + (macro null).pos) #else Context.fatalError('You cannot use \'openflPos\' without targeting openfl', (macro null).pos) #end; + + Compiler.define('loop_unroll_max_cost', Std.string(settings.loopCost)); // Haxe will try to unroll big loops which may cause memory leaks + if (settings.includeAll) + Compiler.define('SUPERLATIVE_INCLUDE_ALL'); + return macro {} + } + + public static function log(?log:String = "") { + #if sys + Sys.println(log); + #else + trace('\n' + log); + #end + } + + #if sys + static function get_definePath():String { + var env:String = if (isWindows) Sys.getEnv('USERPROFILE') else Sys.getEnv('HOME'); + if (isWindows && !env.endsWith('\\')) + env += '\\'; + else if (!isWindows && !env.endsWith('/')) + env += '/'; + + return env + 'defines.cocoa'; + } + #end +} \ No newline at end of file