diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..7150b43 Binary files /dev/null and b/.DS_Store differ diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 430dd74..7d8d5e3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -81,25 +81,26 @@ jobs: path: export/release/macos/bin # MacOS On ARM (M1 to M4 chips) Will be commented until we figure it out. - # MacOS-ARM-Build: - # runs-on: macos-latest + MacOS-ARM-Build: + runs-on: macos-latest - # steps: - # - uses: actions/checkout@v4.1.7 + steps: + - uses: actions/checkout@v4.1.7 - # - uses: krdlab/setup-haxe@master - # with: - # haxe-version: 4.3.4 - # - name: Install Haxelib - # run: | - # haxelib setup ~/haxelib - # chmod +x ./compile/workflow/unix.sh - # sh ./compile/workflow/unix.sh - # haxelib list - # - name: Compile MacOS ARM - # run: haxelib run lime build mac -arm64 - # - name: Publish Artifact - # uses: actions/upload-artifact@v4 - # with: - # name: Universe-MacOS-ARM - # path: export/release/macos/bin + - uses: krdlab/setup-haxe@master + with: + haxe-version: 4.3.4 + - name: Install Haxelib + run: | + haxelib setup ~/haxelib + chmod +x ./compile/workflow/unix.sh + sh ./compile/workflow/unix.sh + haxelib list + haxelib install lime 8.2.2 && haxelib set lime 8.2.2 + - name: Compile MacOS ARM + run: haxelib run lime build mac -arm64 + - name: Publish Artifact + uses: actions/upload-artifact@v4 + with: + name: Universe-MacOS-ARM + path: export/release/macos/bin diff --git a/Project.xml b/Project.xml index f242a31..1a17883 100644 --- a/Project.xml +++ b/Project.xml @@ -2,7 +2,12 @@ - +
+ +
+
+ +
@@ -45,23 +50,17 @@ - - - - - - @@ -143,9 +142,8 @@ - - - + + @@ -157,7 +155,7 @@ - + diff --git a/assets/.DS_Store b/assets/.DS_Store new file mode 100644 index 0000000..15d0a7a Binary files /dev/null and b/assets/.DS_Store differ diff --git a/assets/preload/.DS_Store b/assets/preload/.DS_Store new file mode 100644 index 0000000..54edfb5 Binary files /dev/null and b/assets/preload/.DS_Store differ diff --git a/assets/preload/images/.DS_Store b/assets/preload/images/.DS_Store new file mode 100644 index 0000000..b29ee7b Binary files /dev/null and b/assets/preload/images/.DS_Store differ diff --git a/assets/preload/uescript/.DS_Store b/assets/preload/uescript/.DS_Store new file mode 100644 index 0000000..7fa4103 Binary files /dev/null and b/assets/preload/uescript/.DS_Store differ diff --git a/assets/shared/.DS_Store b/assets/shared/.DS_Store new file mode 100644 index 0000000..ae7613d Binary files /dev/null and b/assets/shared/.DS_Store differ diff --git a/assets/shared/images/.DS_Store b/assets/shared/images/.DS_Store new file mode 100644 index 0000000..70df296 Binary files /dev/null and b/assets/shared/images/.DS_Store differ diff --git a/compile/.DS_Store b/compile/.DS_Store new file mode 100644 index 0000000..f4ae30c Binary files /dev/null and b/compile/.DS_Store differ diff --git a/compile/Test_Build_Mac.sh b/compile/Test_Build_Mac.sh new file mode 100644 index 0000000..fca271d --- /dev/null +++ b/compile/Test_Build_Mac.sh @@ -0,0 +1,2 @@ +lime test mac -DTEST_BUILD +read -n1 -r -p "Press any key to continue..." key diff --git a/compile/workflow/unix.sh b/compile/workflow/unix.sh index 3c3d90b..3df0362 100644 --- a/compile/workflow/unix.sh +++ b/compile/workflow/unix.sh @@ -1,9 +1,14 @@ -haxelib install lime 8.1.3 && haxelib set lime 8.1.3 -haxelib install openfl 9.2.2 && haxelib set openfl 9.2.2 -haxelib install flixel 5.6.2 && haxelib set flixel 5.6.2 +haxelib install lime 8.2.2 && haxelib set lime 8.2.2 +haxelib install openfl 9.4.1 && haxelib set openfl 9.4.1 +haxelib install flixel 5.5.0 && haxelib set flixel 5.5.0 haxelib install flixel-addons 3.2.0 && haxelib set flixel-addons 3.2.0 haxelib install flixel-ui 2.5.0 && haxelib set flixel-ui 2.5.0 haxelib install hxvlc 1.9.3 && haxelib set hxvlc 1.9.3 +haxelib install polymod +haxelib git jsonpatch https://github.com/EliteMasterEric/jsonpatch f9b83215acd586dc28754b4ae7f69d4c06c3b4d3 +haxelib git jsonpath https://github.com/EliteMasterEric/jsonpath 7a24193717b36393458c15c0435bb7c4470ecdda +haxelib git thx.core https://github.com/fponticelli/thx.core 2bf2b992e06159510f595554e6b952e47922f128 +haxelib git thx.semver https://github.com/fponticelli/thx.semver bdb191fe7cf745c02a980749906dbf22719e200b haxelib run lime setup flixel haxelib run lime setup @@ -13,5 +18,4 @@ haxelib install hxcpp-debug-server haxelib install hxdiscord_rpc haxelib git hxcpp https://github.com/moxie-coder/hxcpp-compiled -haxelib git linc_luajit https://github.com/superpowers04/linc_luajit -haxelib git hscript-improved https://github.com/CodenameCrew/hscript-improved \ No newline at end of file +haxelib git linc_luajit https://github.com/superpowers04/linc_luajit \ No newline at end of file diff --git a/compile/workflow/windows.bat b/compile/workflow/windows.bat index 3c3d90b..3df0362 100644 --- a/compile/workflow/windows.bat +++ b/compile/workflow/windows.bat @@ -1,9 +1,14 @@ -haxelib install lime 8.1.3 && haxelib set lime 8.1.3 -haxelib install openfl 9.2.2 && haxelib set openfl 9.2.2 -haxelib install flixel 5.6.2 && haxelib set flixel 5.6.2 +haxelib install lime 8.2.2 && haxelib set lime 8.2.2 +haxelib install openfl 9.4.1 && haxelib set openfl 9.4.1 +haxelib install flixel 5.5.0 && haxelib set flixel 5.5.0 haxelib install flixel-addons 3.2.0 && haxelib set flixel-addons 3.2.0 haxelib install flixel-ui 2.5.0 && haxelib set flixel-ui 2.5.0 haxelib install hxvlc 1.9.3 && haxelib set hxvlc 1.9.3 +haxelib install polymod +haxelib git jsonpatch https://github.com/EliteMasterEric/jsonpatch f9b83215acd586dc28754b4ae7f69d4c06c3b4d3 +haxelib git jsonpath https://github.com/EliteMasterEric/jsonpath 7a24193717b36393458c15c0435bb7c4470ecdda +haxelib git thx.core https://github.com/fponticelli/thx.core 2bf2b992e06159510f595554e6b952e47922f128 +haxelib git thx.semver https://github.com/fponticelli/thx.semver bdb191fe7cf745c02a980749906dbf22719e200b haxelib run lime setup flixel haxelib run lime setup @@ -13,5 +18,4 @@ haxelib install hxcpp-debug-server haxelib install hxdiscord_rpc haxelib git hxcpp https://github.com/moxie-coder/hxcpp-compiled -haxelib git linc_luajit https://github.com/superpowers04/linc_luajit -haxelib git hscript-improved https://github.com/CodenameCrew/hscript-improved \ No newline at end of file +haxelib git linc_luajit https://github.com/superpowers04/linc_luajit \ No newline at end of file diff --git a/example_mods/.DS_Store b/example_mods/.DS_Store new file mode 100644 index 0000000..32342f8 Binary files /dev/null and b/example_mods/.DS_Store differ diff --git a/new_example_mods/.DS_Store b/new_example_mods/.DS_Store new file mode 100644 index 0000000..0f14f0a Binary files /dev/null and b/new_example_mods/.DS_Store differ diff --git a/new_example_mods/test_folder/.DS_Store b/new_example_mods/test_folder/.DS_Store new file mode 100644 index 0000000..a1a6c85 Binary files /dev/null and b/new_example_mods/test_folder/.DS_Store differ diff --git a/new_example_mods/test_folder/_polymod_icon.png b/new_example_mods/test_folder/_polymod_icon.png new file mode 100644 index 0000000..825cc0e Binary files /dev/null and b/new_example_mods/test_folder/_polymod_icon.png differ diff --git a/new_example_mods/test_folder/_polymod_meta.json b/new_example_mods/test_folder/_polymod_meta.json new file mode 100644 index 0000000..bd70ebe --- /dev/null +++ b/new_example_mods/test_folder/_polymod_meta.json @@ -0,0 +1,6 @@ +{ + "title":"Test Mod", + "description":"This mod is for testing the polymod mod loader framework", + "api_version":"1.0.0", + "mod_version":"1.0.0" +} \ No newline at end of file diff --git a/new_example_mods/test_folder/assets/images/AnnaBelleAnnoyed.png b/new_example_mods/test_folder/assets/images/AnnaBelleAnnoyed.png new file mode 100644 index 0000000..8a12dba Binary files /dev/null and b/new_example_mods/test_folder/assets/images/AnnaBelleAnnoyed.png differ diff --git a/new_example_mods/test_folder/yuh.json b/new_example_mods/test_folder/yuh.json deleted file mode 100644 index 4186449..0000000 --- a/new_example_mods/test_folder/yuh.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "value": "key" -} \ No newline at end of file diff --git a/source/.DS_Store b/source/.DS_Store new file mode 100644 index 0000000..c7689db Binary files /dev/null and b/source/.DS_Store differ diff --git a/source/ClientPrefs.hx b/source/ClientPrefs.hx index 44c923f..5f913eb 100644 --- a/source/ClientPrefs.hx +++ b/source/ClientPrefs.hx @@ -41,6 +41,7 @@ class SaveVariables public var splashAlpha:Float = 0.6; // UE + public var enabledMods:Array> = []; // Format: [modID, modName] public var universeEngineCPREF:Bool = true; // this is to check if you running universe engine! public var keystrokes:Bool = true; public var keyA:Float = 0.3; diff --git a/source/HealthIcon.hx b/source/HealthIcon.hx index 1112357..b6d9fbc 100644 --- a/source/HealthIcon.hx +++ b/source/HealthIcon.hx @@ -44,13 +44,19 @@ class HealthIcon extends FlxSprite imageFile = name; var file:Dynamic = Paths.image(name); + var imageRatio:Int = Math.round(width / height); // The ratio for the image, used to divide the image. loadGraphic(file); //Load stupidly first for getting the file size + var framesArray:Array = [0, 1]; // The amount of animation frames + var w2 = width; loadGraphic(file, true, Math.floor(width / 2), Math.floor(height)); //Then load it fr - iconOffsets[0] = (width - 150) / 2; - iconOffsets[1] = (width - 150) / 2; + for (i in 0...imageRatio) + { + iconOffsets[i] = (width - 150) / imageRatio; + framesArray[i] = i; + } updateHitbox(); - animation.add(char, [0, 1], 0, false, isPlayer); + animation.add(char, framesArray, 0, false, isPlayer); animation.play(char); this.char = char; diff --git a/source/Main.hx b/source/Main.hx index 8287bc0..246d245 100644 --- a/source/Main.hx +++ b/source/Main.hx @@ -10,8 +10,7 @@ import openfl.display.FPS; import openfl.display.Sprite; import openfl.events.Event; import openfl.display.StageScaleMode; -import codename.modding.ModsFolder; -import codename.backend.system.Logs; +import sys.logger.Logs; //crash handler stuff #if CRASH_HANDLER @@ -25,20 +24,24 @@ import sys.io.File; import sys.io.Process; #end -import codename.backend.assets.AssetsLibraryList; +#if MODS_ALLOWED +import modding.PolymodHandler as Modding; +#end using StringTools; class Main extends Sprite { - var gameWidth:Int = 1280; // Width of the game in pixels (might be less / more in actual pixels depending on your zoom). - var gameHeight:Int = 720; // Height of the game in pixels (might be less / more in actual pixels depending on your zoom). - var initialState:Class = TitleState; // The FlxState the game starts with. - var zoom:Float = -1; // If -1, zoom is automatically calculated to fit the window dimensions. - var framerate:Int = 60; // How many frames per second the game should run at. - var skipSplash:Bool = true; // Whether to skip the flixel splash screen that appears in release mode. - var startFullscreen:Bool = false; // Whether to start the game in fullscreen on desktop targets - var modToLoad:String = null; + var game = { + width: 1280, + height: 720, + initialState: TitleState, + zoom: -1.0, + fps: 60, + skipSplash: true, + startFullscreen: false, + }; + var gameArgs:Array = []; // Used for allowing mods to define custom commandline arguments. public static var fpsVar:FPS; public static var noTerminalColor:Bool = false; @@ -79,23 +82,26 @@ class Main extends Sprite private function setupGame():Void { + gameArgs = Sys.args(); + trace(gameArgs); var stageWidth:Int = Lib.current.stage.stageWidth; var stageHeight:Int = Lib.current.stage.stageHeight; - if (zoom == -1) + if (game.zoom == -1) { - var ratioX:Float = stageWidth / gameWidth; - var ratioY:Float = stageHeight / gameHeight; - zoom = Math.min(ratioX, ratioY); - gameWidth = Math.ceil(stageWidth / zoom); - gameHeight = Math.ceil(stageHeight / zoom); + var ratioX:Float = stageWidth / game.width; + var ratioY:Float = stageHeight / game.height; + game.zoom = Math.min(ratioX, ratioY); + game.width = Math.ceil(stageWidth / game.zoom); + game.height = Math.ceil(stageHeight / game.zoom); } - - Paths.assetsTree = new AssetsLibraryList(); Logs.init(); + #if MODS_ALLOWED + Modding.initMods(); + #end ClientPrefs.loadDefaultStuff(); - addChild(new FlxGame(gameWidth, gameHeight, initialState, framerate, framerate, skipSplash, startFullscreen)); + addChild(new FlxGame(game.width, game.height, game.initialState, game.fps, game.fps, game.skipSplash, game.startFullscreen)); #if !mobile fpsVar = new FPS(10, 3, 0xFFFFFF); @@ -115,15 +121,6 @@ class Main extends Sprite #if CRASH_HANDLER Lib.current.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onCrash); #end - - #if GLOBAL_SCRIPT - codename.scripting.GlobalScript.init(); - #end - - ModsFolder.init(); - #if MOD_SUPPORT - ModsFolder.switchMod(modToLoad = ClientPrefs.data.lastLoadedMod); - #end } // Code was entirely made by sqirra-rng for their fnf engine named "Izzy Engine", big props to them!!! diff --git a/source/MainMenuState.hx b/source/MainMenuState.hx index d5a9f10..3860580 100644 --- a/source/MainMenuState.hx +++ b/source/MainMenuState.hx @@ -349,12 +349,12 @@ class MainMenuState extends MusicBeatState MusicBeatState.switchState(new FreeplayState()); #if MODS_ALLOWED case 'mods': - openSubState(new codename.substates.ModSwitchMenu()); + MusicBeatState.switchState(new ModsMenuState()); #end case 'awards': MusicBeatState.switchState(new AchievementsMenuState()); case 'credits': - MusicBeatState.switchState(new credits.CreditsState()); + MusicBeatState.switchState(new credits.PECreditsState()); case 'options': LoadingState.loadAndSwitchState(new options.SelectThing()); } diff --git a/source/MusicBeatState.hx b/source/MusicBeatState.hx index ca35c17..173db82 100644 --- a/source/MusicBeatState.hx +++ b/source/MusicBeatState.hx @@ -15,9 +15,6 @@ import flixel.FlxState; import flixel.FlxCamera; import flixel.FlxBasic; import flixel.sound.FlxSound; -// scripting -import codename.scripting.ScriptPack; -import codename.scripting.DummyScript; #if sys import sys.FileSystem; import sys.io.File; @@ -42,9 +39,6 @@ class MusicBeatState extends modchart.modcharting.ModchartMusicBeatState inline function get_controls():Controls return PlayerSettings.player1.controls; - // scripting - public var stateScripts:ScriptPack; - public var scriptsAllowed:Bool = true; public static var lastScriptName:String = null; @@ -55,19 +49,11 @@ class MusicBeatState extends modchart.modcharting.ModchartMusicBeatState public function new(scriptsAllowed:Bool = true, ?scriptName:String) { super(); - this.scriptsAllowed = #if SOFTCODED_STATES scriptsAllowed #else false #end; - - if (lastStateName != (lastStateName = Type.getClassName(Type.getClass(this)))) - { - lastScriptName = null; - } - this.scriptName = scriptName != null ? scriptName : lastScriptName; - lastScriptName = this.scriptName; } - function loadScript() + function loadScript() // Stubbed untill later, this will be re-used for loading polymod scripts. { - var className = Type.getClassName(Type.getClass(this)); +/* var className = Type.getClassName(Type.getClass(this)); if (stateScripts == null) (stateScripts = new ScriptPack(className)).setParent(this); if (scriptsAllowed) @@ -88,7 +74,7 @@ class MusicBeatState extends modchart.modcharting.ModchartMusicBeatState } else stateScripts.reload(); - } + } */ } override function create() @@ -108,10 +94,12 @@ class MusicBeatState extends modchart.modcharting.ModchartMusicBeatState FlxTransitionableState.skipNextTransOut = false; } - public function call(name:String, ?args:Array, ?defaultVal:Dynamic):Dynamic { - // calls the function on the assigned script + public function call(name:String, ?args:Array, ?defaultVal:Dynamic):Dynamic { // Stubbed untill polymod loader finished. + /* // calls the function on the assigned script if(stateScripts != null) return stateScripts.call(name, args); + return defaultVal; */ + return defaultVal; } @@ -140,9 +128,6 @@ class MusicBeatState extends modchart.modcharting.ModchartMusicBeatState if (FlxG.save.data != null) FlxG.save.data.fullscreen = FlxG.fullscreen; - if (FlxG.keys.justPressed.F5) - loadScript(); - call("update", [elapsed]); super.update(elapsed); diff --git a/source/MusicBeatSubstate.hx b/source/MusicBeatSubstate.hx index 777af68..bd31d6b 100644 --- a/source/MusicBeatSubstate.hx +++ b/source/MusicBeatSubstate.hx @@ -1,6 +1,5 @@ package; -import codename.scripting.ScriptPack; import Conductor.BPMChangeEvent; import flixel.FlxG; import flixel.FlxSubState; @@ -10,11 +9,6 @@ import flixel.FlxSprite; class MusicBeatSubstate extends FlxSubState { - /** - * Current injected script attached to the state. To add one, create a file at path "data/states/stateName" (ex: "data/states/PauseMenuSubstate.hx") - */ - public var stateScripts:ScriptPack; - public var scriptsAllowed:Bool = true; public var scriptName:String = null; diff --git a/source/Paths.hx b/source/Paths.hx index c73ec3b..32cd891 100644 --- a/source/Paths.hx +++ b/source/Paths.hx @@ -23,10 +23,6 @@ import haxe.Json; import flash.media.Sound; import flixel.graphics.frames.FlxFramesCollection; import flixel.animation.FlxAnimationController; -import codename.backend.assets.AssetsLibraryList; - -import codename.scripting.HScript; -import codename.backend.Script; using StringTools; @@ -40,8 +36,6 @@ class Paths public static var noteSkinFramesMap:Map = new Map(); public static var noteSkinAnimsMap:Map = new Map(); - public static var assetsTree:AssetsLibraryList; - #if MODS_ALLOWED public static var ignoreModFolders:Array = [ 'characters', @@ -63,9 +57,9 @@ class Paths ]; #end - static public function getFolderDirectories(key:String, addPath:Bool = false, source:codename.backend.assets.AssetsLibraryList.AssetSource = BOTH):Array + static public function getFolderDirectories(key:String, addPath:Bool = false):Array // Stubbed for later polymod use { - if (!key.endsWith("/")) + /* if (!key.endsWith("/")) key += "/"; var content = assetsTree.getFolders('assets/$key', source); if (addPath) @@ -73,12 +67,13 @@ class Paths for (k => e in content) content[k] = '$key$e'; } - return content; + return content; */ + return []; } - static public function getFolderContent(key:String, addPath:Bool = false, source:codename.backend.assets.AssetsLibraryList.AssetSource = BOTH):Array + static public function getFolderContent(key:String, addPath:Bool = false):Array // Stubbed for later polymod use { - // designed to work both on windows and web + /* // designed to work both on windows and web if (!key.endsWith("/")) key += "/"; var content = assetsTree.getFiles('assets/$key', source); @@ -87,7 +82,8 @@ class Paths for (k => e in content) content[k] = '$key$e'; } - return content; + return content; */ + return []; } public static var defaultSkin = 'NOTE_assets' + Note.getNoteSkinPostfix(); @@ -494,21 +490,6 @@ class Paths return ""; } - inline static public function hscript(key:String, ?library:String, isAssetsPath:Bool = false) { - var scriptPath = isAssetsPath ? key : cne_getPath(key, library); - if (!OpenFlAssets.exists(scriptPath)) { - var p:String; - for(ex in Script.scriptExtensions) { - p = '$scriptPath.$ex'; - if (OpenFlAssets.exists(p)) { - scriptPath = p; - break; - } - } - } - return scriptPath; - } - public static function returnSound(path:String, key:String, ?library:String) { #if MODS_ALLOWED diff --git a/source/PlayState.hx b/source/PlayState.hx index 7b550e5..05e3323 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -3525,6 +3525,8 @@ class PlayState extends MusicBeatState { if (healthBar.percent < 20) iconP1.animation.curAnim.curFrame = 1; + if (iconP2.animation.curAnim.numFrames == 3) + iconP2.animation.curAnim.curFrame = 2; else iconP1.animation.curAnim.curFrame = 0; } @@ -3552,6 +3554,8 @@ class PlayState extends MusicBeatState { if (healthBar.percent > 80) iconP2.animation.curAnim.curFrame = 1; + if (iconP1.animation.curAnim.numFrames == 3) + iconP1.animation.curAnim.curFrame = 2; else iconP2.animation.curAnim.curFrame = 0; } diff --git a/source/codename/backend/Script.hx b/source/codename_ref/backend/Script.hx similarity index 100% rename from source/codename/backend/Script.hx rename to source/codename_ref/backend/Script.hx diff --git a/source/codename/backend/assets/AssetsLibraryList.hx b/source/codename_ref/backend/assets/AssetsLibraryList.hx similarity index 100% rename from source/codename/backend/assets/AssetsLibraryList.hx rename to source/codename_ref/backend/assets/AssetsLibraryList.hx diff --git a/source/codename/backend/assets/IModsAssetLibrary.hx b/source/codename_ref/backend/assets/IModsAssetLibrary.hx similarity index 100% rename from source/codename/backend/assets/IModsAssetLibrary.hx rename to source/codename_ref/backend/assets/IModsAssetLibrary.hx diff --git a/source/codename/backend/assets/ModsFolderLibrary.hx b/source/codename_ref/backend/assets/ModsFolderLibrary.hx similarity index 100% rename from source/codename/backend/assets/ModsFolderLibrary.hx rename to source/codename_ref/backend/assets/ModsFolderLibrary.hx diff --git a/source/codename/backend/assets/ScriptedAssetLibrary.hx b/source/codename_ref/backend/assets/ScriptedAssetLibrary.hx similarity index 100% rename from source/codename/backend/assets/ScriptedAssetLibrary.hx rename to source/codename_ref/backend/assets/ScriptedAssetLibrary.hx diff --git a/source/codename/backend/import.hx b/source/codename_ref/backend/import.hx similarity index 100% rename from source/codename/backend/import.hx rename to source/codename_ref/backend/import.hx diff --git a/source/codename/backend/options/ArrayTools.hx b/source/codename_ref/backend/options/ArrayTools.hx similarity index 100% rename from source/codename/backend/options/ArrayTools.hx rename to source/codename_ref/backend/options/ArrayTools.hx diff --git a/source/codename/backend/options/OptionsScreen.hx b/source/codename_ref/backend/options/OptionsScreen.hx similarity index 100% rename from source/codename/backend/options/OptionsScreen.hx rename to source/codename_ref/backend/options/OptionsScreen.hx diff --git a/source/codename/backend/options/OptionsTree.hx b/source/codename_ref/backend/options/OptionsTree.hx similarity index 100% rename from source/codename/backend/options/OptionsTree.hx rename to source/codename_ref/backend/options/OptionsTree.hx diff --git a/source/codename/backend/options/TreeMenu.hx b/source/codename_ref/backend/options/TreeMenu.hx similarity index 100% rename from source/codename/backend/options/TreeMenu.hx rename to source/codename_ref/backend/options/TreeMenu.hx diff --git a/source/codename/backend/options/import.hx b/source/codename_ref/backend/options/import.hx similarity index 100% rename from source/codename/backend/options/import.hx rename to source/codename_ref/backend/options/import.hx diff --git a/source/codename/backend/options/type/OptionType.hx b/source/codename_ref/backend/options/type/OptionType.hx similarity index 100% rename from source/codename/backend/options/type/OptionType.hx rename to source/codename_ref/backend/options/type/OptionType.hx diff --git a/source/codename/backend/options/type/PortraitOption.hx b/source/codename_ref/backend/options/type/PortraitOption.hx similarity index 100% rename from source/codename/backend/options/type/PortraitOption.hx rename to source/codename_ref/backend/options/type/PortraitOption.hx diff --git a/source/codename/backend/options/type/TextOption.hx b/source/codename_ref/backend/options/type/TextOption.hx similarity index 100% rename from source/codename/backend/options/type/TextOption.hx rename to source/codename_ref/backend/options/type/TextOption.hx diff --git a/source/codename/backend/shaders/CustomShader.hx b/source/codename_ref/backend/shaders/CustomShader.hx similarity index 100% rename from source/codename/backend/shaders/CustomShader.hx rename to source/codename_ref/backend/shaders/CustomShader.hx diff --git a/source/codename/backend/shaders/FunkinShader.hx b/source/codename_ref/backend/shaders/FunkinShader.hx similarity index 100% rename from source/codename/backend/shaders/FunkinShader.hx rename to source/codename_ref/backend/shaders/FunkinShader.hx diff --git a/source/codename/backend/system/import.hx b/source/codename_ref/backend/system/import.hx similarity index 100% rename from source/codename/backend/system/import.hx rename to source/codename_ref/backend/system/import.hx diff --git a/source/codename/backend/utils/CoolUtil.hx b/source/codename_ref/backend/utils/CoolUtil.hx similarity index 100% rename from source/codename/backend/utils/CoolUtil.hx rename to source/codename_ref/backend/utils/CoolUtil.hx diff --git a/source/codename/backend/utils/FileAttributeWrapper.hx b/source/codename_ref/backend/utils/FileAttributeWrapper.hx similarity index 100% rename from source/codename/backend/utils/FileAttributeWrapper.hx rename to source/codename_ref/backend/utils/FileAttributeWrapper.hx diff --git a/source/codename/backend/utils/LogUtils.hx b/source/codename_ref/backend/utils/LogUtils.hx similarity index 100% rename from source/codename/backend/utils/LogUtils.hx rename to source/codename_ref/backend/utils/LogUtils.hx diff --git a/source/codename/backend/utils/NativeAPI.hx b/source/codename_ref/backend/utils/NativeAPI.hx similarity index 100% rename from source/codename/backend/utils/NativeAPI.hx rename to source/codename_ref/backend/utils/NativeAPI.hx diff --git a/source/codename/backend/utils/ScriptUtils.hx b/source/codename_ref/backend/utils/ScriptUtils.hx similarity index 100% rename from source/codename/backend/utils/ScriptUtils.hx rename to source/codename_ref/backend/utils/ScriptUtils.hx diff --git a/source/codename/backend/utils/native/Windows.hx b/source/codename_ref/backend/utils/native/Windows.hx similarity index 100% rename from source/codename/backend/utils/native/Windows.hx rename to source/codename_ref/backend/utils/native/Windows.hx diff --git a/source/codename/import.hx b/source/codename_ref/import.hx similarity index 71% rename from source/codename/import.hx rename to source/codename_ref/import.hx index 4c2c109..39f6435 100644 --- a/source/codename/import.hx +++ b/source/codename_ref/import.hx @@ -3,5 +3,4 @@ package ue; #if !macro import codename.backend.*; import codename.backend.assets.*; -import codename.modding.ModsFolder; #end \ No newline at end of file diff --git a/source/codename/modding/ModsFolder.hx b/source/codename_ref/modding/ModsFolder.hx similarity index 100% rename from source/codename/modding/ModsFolder.hx rename to source/codename_ref/modding/ModsFolder.hx diff --git a/source/codename/scripting/DummyScript.hx b/source/codename_ref/scripting/DummyScript.hx similarity index 100% rename from source/codename/scripting/DummyScript.hx rename to source/codename_ref/scripting/DummyScript.hx diff --git a/source/codename/scripting/GlobalScript.hx b/source/codename_ref/scripting/GlobalScript.hx similarity index 100% rename from source/codename/scripting/GlobalScript.hx rename to source/codename_ref/scripting/GlobalScript.hx diff --git a/source/codename/scripting/HScript.hx b/source/codename_ref/scripting/HScript.hx similarity index 100% rename from source/codename/scripting/HScript.hx rename to source/codename_ref/scripting/HScript.hx diff --git a/source/codename/scripting/ModState.hx b/source/codename_ref/scripting/ModState.hx similarity index 100% rename from source/codename/scripting/ModState.hx rename to source/codename_ref/scripting/ModState.hx diff --git a/source/codename/scripting/ModSubState.hx b/source/codename_ref/scripting/ModSubState.hx similarity index 100% rename from source/codename/scripting/ModSubState.hx rename to source/codename_ref/scripting/ModSubState.hx diff --git a/source/codename/scripting/ScriptPack.hx b/source/codename_ref/scripting/ScriptPack.hx similarity index 100% rename from source/codename/scripting/ScriptPack.hx rename to source/codename_ref/scripting/ScriptPack.hx diff --git a/source/codename/scripting/import.hx b/source/codename_ref/scripting/import.hx similarity index 100% rename from source/codename/scripting/import.hx rename to source/codename_ref/scripting/import.hx diff --git a/source/codename/states/MainState.hx b/source/codename_ref/states/MainState.hx similarity index 100% rename from source/codename/states/MainState.hx rename to source/codename_ref/states/MainState.hx diff --git a/source/codename/substates/ModSwitchMenu.hx b/source/codename_ref/substates/ModSwitchMenu.hx similarity index 100% rename from source/codename/substates/ModSwitchMenu.hx rename to source/codename_ref/substates/ModSwitchMenu.hx diff --git a/source/credits/.DS_Store b/source/credits/.DS_Store new file mode 100644 index 0000000..dda4cb8 Binary files /dev/null and b/source/credits/.DS_Store differ diff --git a/source/credits/BaseCreditsState.hx b/source/credits/BaseCreditsState.hx new file mode 100644 index 0000000..7b37999 --- /dev/null +++ b/source/credits/BaseCreditsState.hx @@ -0,0 +1,6 @@ +package credits.old; + +class BaseCreditsState extends MusicBeatState +{ + // Stubbed for now. +} \ No newline at end of file diff --git a/source/credits/PECreditsState.hx b/source/credits/PECreditsState.hx new file mode 100644 index 0000000..1b0c276 --- /dev/null +++ b/source/credits/PECreditsState.hx @@ -0,0 +1,609 @@ +package credits; + +#if desktop +import Discord.DiscordClient; +#end +import flash.text.TextField; +import flixel.FlxG; +import flixel.FlxSprite; +import flixel.addons.display.FlxGridOverlay; +import flixel.group.FlxGroup.FlxTypedGroup; +import flixel.math.FlxMath; +import flixel.text.FlxText; +import flixel.util.FlxColor; +import flixel.tweens.FlxTween; +import flixel.tweens.FlxEase; +#if MODS_ALLOWED +import sys.FileSystem; +import sys.io.File; +#end +import lime.utils.Assets; +import flixel.addons.display.FlxBackdrop; +import flixel.addons.display.FlxGridOverlay; + +using StringTools; +/** +* The original Credits State from PE, used in snapshot y25v01a +*/ +class PECreditsState extends MusicBeatState +{ + var curSelected:Int = -1; + + private var grpOptions:FlxTypedGroup; + private var iconArray:Array = []; + private var creditsStuff:Array> = []; + + var bg:FlxSprite; + var descText:FlxText; + var intendedColor:Int; + var colorTween:FlxTween; + var descBox:AttachedSprite; + + var offsetThing:Float = -75; + + var pisspoop:Array>; + + override function create() + { + #if desktop + // Updating Discord Rich Presence + DiscordClient.changePresence("In the Credits Menu", null); + #end + + persistentUpdate = true; + if (ClientPrefs.data.darkmode) + { + bg = new FlxSprite(0, 0).loadGraphic(Paths.image("aboutMenu", "preload")); + add(bg); + bg.screenCenter(); + } + else + { + bg = new FlxSprite().loadGraphic(Paths.image('menuDesat')); + add(bg); + bg.screenCenter(); + } + + var grid:FlxBackdrop = new FlxBackdrop(FlxGridOverlay.createGrid(80, 80, 160, 160, true, 0x33FFFFFF, 0x0)); + grid.velocity.set(20, 20); + grid.alpha = 0; + FlxTween.tween(grid, {alpha: 1}, 0.5, {ease: FlxEase.quadOut}); + add(grid); + + grpOptions = new FlxTypedGroup(); + add(grpOptions); + + #if MODS_ALLOWED + var path:String = 'modsList.txt'; + if (FileSystem.exists(path)) + { + var leMods:Array = CoolUtil.coolTextFile(path); + for (i in 0...leMods.length) + { + if (leMods.length > 1 && leMods[0].length > 0) + { + var modSplit:Array = leMods[i].split('|'); + if (!Paths.ignoreModFolders.contains(modSplit[0].toLowerCase()) && !modsAdded.contains(modSplit[0])) + { + if (modSplit[1] == '1') + pushModCreditsToList(modSplit[0]); + else + modsAdded.push(modSplit[0]); + } + } + } + } + + var arrayOfFolders:Array = Paths.getModDirectories(); + arrayOfFolders.push(''); + for (folder in arrayOfFolders) + { + pushModCreditsToList(folder); + } + #end + + if (!ClientPrefs.data.hideOriCredits) + { + pisspoop = [ + // Name - Icon name - Description - Link - BG Color + ['Universe Engine DEVs'], + [ + 'Video Bot', + 'videobot', + 'First DEV, In charge of the HX files', + 'https://linktr.ee/videobot', + '14FFFF' + ], + [ + 'CharGoldenYT', + 'char', + "I guess I'll join the team - Me\nThird DEV In charge of HX Files, and the POLYMOD MOD LOADER!", + 'https://bsky.app/profile/vschar-official.com', + 'FFA600' + ], + [''], + ['Former UE DEVs'], + [ + 'Daveberry', + 'dave', + 'Former DEV, (No Longer) In charge of the LUA, HX files and other', + 'https://daveberry.netlify.app/', + '008BFF' + ], + [ + 'BaranMuzu', + 'baranmuzu', + 'Former DEV, (No Longer) In charge of the LUA files and other', + 'https://linktr.ee/baranmuzu', + 'BE9877' + ], + [''], + ['UE Borrowed Code'], + ['Edwhak', 'Edwhak', 'Modchart Tool', 'https://www.youtube.com/@EDWHAK', '00FF00'], + [ + 'Rozebud', + 'rozebud', + "Chart Editor's Lil' Buddies", + 'https://x.com/helpme_thebigt', + '6D2F83' + ], + [ + ' SilverSpringing', + 'invis', + 'Combo Counter', + 'https://gamebanana.com/members/1823951', + '00FFFF' + ], + [ + ' Unholywanderer', + 'invis', + 'Smooth HP', + 'https://gamebanana.com/members/1908754', + '00FFFF' + ], + [ + ' Kiruwu', + 'invis', + 'Weekend 1 Port', + 'https://gamebanana.com/mods/512609', + 'B3715F' + ], + [ + ' Spelo', + 'invis', + 'Play Both Sides', + 'https://www.youtube.com/watch?v=xmUQUi8rd9M', + 'FFFFFF' + ], + [''], + ['UE Special Thanks'], + [ + 'Blitz', + 'Blitz', + 'Universe Logo And Playtester', + 'https://www.youtube.com/@fireballfurby', + '00FFFF' + ], + [ + 'An Ammar', + 'Ammar', + 'Hype Mode, Detached Health Bar, Playtester', + 'https://gamebanana.com/mods/381804', + '00FF00' + ], + [ + 'Dinus Game', + 'Dinus Game', + 'freakyMenu Universe Engine music. Also made the design of the Fancy Main Menu', + 'https://gamebanana.com/members/2053946', + '27FF27' + ], + [ + 'idiotxd', + 'idiotxd', + 'His own freakyMenu music and Universe Banner', + 'https://x.com/IdiottLool', + '5656FF' + ], + [ + 'JordanSantiago', + 'jor', + 'Most of the code of UE comes from JS', + 'https://gamebanana.com/tools/13575', + '32CD32' + ], + [''], + ["UE PR's"], + [ + 'MoxieCoder', + 'moxie', + "Lua Jit Fork superpowers04 PR", + 'https://x.com/moxie_specalist', + '00FFFF' + ], + [ + ' soushimiya', + 'invis', + "Crediting Rozebud", + 'https://github.com/soushimiya', + 'FFFFFF' + ], + [''], + ['Psych Engine Team'], + [ + 'Shadow Mario', + 'shadowmario', + 'Main Programmer of Psych Engine', + 'https://twitter.com/Shadow_Mario_', + '444444' + ], + [ + 'RiverOaken', + 'river', + 'Main Artist/Animator of Psych Engine', + 'https://twitter.com/RiverOaken', + 'B42F71' + ], + [ + 'shubs', + 'shubs', + 'Additional Programmer of Psych Engine', + 'https://twitter.com/yoshubs', + '5E99DF' + ], + [''], + ['Former Engine Members'], + [ + 'bb-panzu', + 'bb', + 'Ex-Programmer of Psych Engine', + 'https://twitter.com/bbsub3', + '3E813A' + ], + [""], + ['Engine Contributors'], + [ + 'iFlicky', + 'flicky', + 'Composer of Psync and Tea Time\nMade the Dialogue Sounds', + 'https://twitter.com/flicky_i', + '9E29CF' + ], + [ + 'SqirraRNG', + 'sqirra', + 'Crash Handler and Base code for\nChart Editor\'s Waveform', + 'https://twitter.com/gedehari', + 'E1843A' + ], + [ + 'EliteMasterEric', + 'mastereric', + 'Runtime Shaders support', + 'https://twitter.com/EliteMasterEric', + 'FFBD40' + ], + [ + 'PolybiusProxy', + 'proxy', + '.MP4 Video Loader Library (hxCodec)', + 'https://twitter.com/polybiusproxy', + 'DCD294' + ], + [ + 'KadeDev', + 'kade', + 'Fixed some cool stuff on Chart Editor\nand other PRs', + 'https://twitter.com/kade0912', + '64A250' + ], + [ + 'Keoiki', + 'keoiki', + 'Note Splash Animations', + 'https://twitter.com/Keoiki_', + 'D2D2D2' + ], + [ + "superpowers04", + "superpowers04", + "LUA JIT Fork", + "https://x.com/superpowers04", + "B957ED" + ], + [ + 'Smokey', + 'smokey', + 'Sprite Atlas Support', + 'https://twitter.com/Smokey_5_', + '483D92' + ], + [""], + ["Funkin' Crew"], + [ + "ninjamuffin99", + "ninjamuffin99", + "Programmer of Friday Night Funkin'", + "https://x.com/ninja_muffin99", + "CF2D2D" + ], + [ + "PhantomArcade", + "phantomarcade", + "Animator of Friday Night Funkin'", + "https://x.com/PhantomArcade3K", + "FADC45" + ], + [ + "evilsk8r", + "evilsk8r", + "Artist of Friday Night Funkin'", + "https://x.com/evilsk8r", + "5ABD4B" + ], + [ + "kawaisprite", + "kawaisprite", + "Composer of Friday Night Funkin'", + "https://x.com/kawaisprite", + "378FC7" + ], + ]; + } + else + { // prevents crash lol + pisspoop = [ + [ + '', + 'invis', + 'this is just here to prevent crash when theres no credits lol', + '', + '000000' + ] + ]; + } + + for (i in pisspoop) + { + creditsStuff.push(i); + } + + for (i in 0...creditsStuff.length) + { + var isSelectable:Bool = !unselectableCheck(i); + var optionText:Alphabet = new Alphabet(FlxG.width / 2, 300, creditsStuff[i][0], !isSelectable); + optionText.isMenuItem = true; + optionText.targetY = i; + optionText.changeX = false; + optionText.snapToPosition(); + grpOptions.add(optionText); + + if (isSelectable) + { + if (creditsStuff[i][5] != null) + { + Paths.currentModDirectory = creditsStuff[i][5]; + } + + var icon:AttachedSprite = new AttachedSprite('credits/' + creditsStuff[i][1]); + icon.xAdd = optionText.width + 10; + icon.sprTracker = optionText; + + // using a FlxGroup is too much fuss! + iconArray.push(icon); + add(icon); + Paths.currentModDirectory = ''; + + if (curSelected == -1) + curSelected = i; + } + else + optionText.alignment = CENTERED; + } + + descBox = new AttachedSprite(); + descBox.makeGraphic(1, 1, FlxColor.BLACK); + descBox.xAdd = -10; + descBox.yAdd = -10; + descBox.alphaMult = 0.6; + descBox.alpha = 0.6; + add(descBox); + + descText = new FlxText(50, FlxG.height + offsetThing - 25, 1180, "", 32); + descText.setFormat(Paths.font("funkin.ttf"), 32, FlxColor.WHITE, CENTER /*, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK*/); + descText.scrollFactor.set(); + // descText.borderSize = 2.4; + descBox.sprTracker = descText; + add(descText); + + bg.color = getCurrentBGColor(); + intendedColor = bg.color; + changeSelection(); + super.create(); + } + + var quitting:Bool = false; + var holdTime:Float = 0; + + override function update(elapsed:Float) + { + if (FlxG.sound.music.volume < 0.7) + { + FlxG.sound.music.volume += 0.5 * FlxG.elapsed; + } + + if (!quitting) + { + if (creditsStuff.length > 1) + { + var shiftMult:Int = 1; + if (FlxG.keys.pressed.SHIFT) + shiftMult = 3; + + var upP = controls.UI_UP_P; + var downP = controls.UI_DOWN_P; + + if (upP) + { + changeSelection(-shiftMult); + holdTime = 0; + } + if (downP) + { + changeSelection(shiftMult); + holdTime = 0; + } + + if (controls.UI_DOWN || controls.UI_UP) + { + var checkLastHold:Int = Math.floor((holdTime - 0.5) * 10); + holdTime += elapsed; + var checkNewHold:Int = Math.floor((holdTime - 0.5) * 10); + + if (holdTime > 0.5 && checkNewHold - checkLastHold > 0) + { + changeSelection((checkNewHold - checkLastHold) * (controls.UI_UP ? -shiftMult : shiftMult)); + } + } + } + + if (controls.ACCEPT && (creditsStuff[curSelected][3] == null || creditsStuff[curSelected][3].length > 4)) + { + CoolUtil.browserLoad(creditsStuff[curSelected][3]); + } + if (controls.BACK) + { + if (colorTween != null) + { + colorTween.cancel(); + } + FlxG.sound.play(Paths.sound('cancelMenu')); + MusicBeatState.switchState(new MainMenuState()); + quitting = true; + } + } + + for (item in grpOptions.members) + { + if (!item.bold) + { + var lerpVal:Float = CoolUtil.boundTo(elapsed * 12, 0, 1); + if (item.targetY == 0) + { + var lastX:Float = item.x; + item.screenCenter(X); + item.x = FlxMath.lerp(lastX, item.x - 70, lerpVal); + } + else + { + item.x = FlxMath.lerp(item.x, 200 + -40 * Math.abs(item.targetY), lerpVal); + } + } + } + super.update(elapsed); + } + + var moveTween:FlxTween = null; + + function changeSelection(change:Int = 0) + { + FlxG.sound.play(Paths.sound('scrollMenu'), 0.4); + do + { + curSelected += change; + if (curSelected < 0) + curSelected = creditsStuff.length - 1; + if (curSelected >= creditsStuff.length) + curSelected = 0; + } + while (unselectableCheck(curSelected)); + + var newColor:Int = getCurrentBGColor(); + if (newColor != intendedColor) + { + if (colorTween != null) + { + colorTween.cancel(); + } + intendedColor = newColor; + colorTween = FlxTween.color(bg, 1, bg.color, intendedColor, { + onComplete: function(twn:FlxTween) + { + colorTween = null; + } + }); + } + + var bullShit:Int = 0; + + for (item in grpOptions.members) + { + item.targetY = bullShit - curSelected; + bullShit++; + + if (!unselectableCheck(bullShit - 1)) + { + item.alpha = 0.6; + if (item.targetY == 0) + { + item.alpha = 1; + } + } + } + + descText.text = creditsStuff[curSelected][2]; + descText.y = FlxG.height - descText.height + offsetThing - 60; + + if (moveTween != null) + moveTween.cancel(); + moveTween = FlxTween.tween(descText, {y: descText.y + 75}, 0.25, {ease: FlxEase.sineOut}); + + descBox.setGraphicSize(Std.int(descText.width + 20), Std.int(descText.height + 25)); + descBox.updateHitbox(); + } + + #if MODS_ALLOWED + private var modsAdded:Array = []; + + function pushModCreditsToList(folder:String) + { + if (modsAdded.contains(folder)) + return; + + var creditsFile:String = null; + if (folder != null && folder.trim().length > 0) + creditsFile = Paths.mods(folder + '/data/credits.txt'); + else + creditsFile = Paths.mods('data/credits.txt'); + + if (FileSystem.exists(creditsFile)) + { + var firstarray:Array = File.getContent(creditsFile).split('\n'); + for (i in firstarray) + { + var arr:Array = i.replace('\\n', '\n').split("::"); + if (arr.length >= 5) + arr.push(folder); + creditsStuff.push(arr); + } + creditsStuff.push(['']); + } + modsAdded.push(folder); + } + #end + + function getCurrentBGColor() + { + var bgColor:String = creditsStuff[curSelected][4]; + if (!bgColor.startsWith('0x')) + { + bgColor = '0xFF' + bgColor; + } + return Std.parseInt(bgColor); + } + + private function unselectableCheck(num:Int):Bool + { + return creditsStuff[num].length <= 1; + } +} \ No newline at end of file diff --git a/source/credits/CreditsState.hx b/source/credits/old/CreditsState.hx similarity index 100% rename from source/credits/CreditsState.hx rename to source/credits/old/CreditsState.hx diff --git a/source/credits/FNFCredits.hx b/source/credits/old/FNFCredits.hx similarity index 100% rename from source/credits/FNFCredits.hx rename to source/credits/old/FNFCredits.hx diff --git a/source/credits/PECredits.hx b/source/credits/old/PECredits.hx similarity index 100% rename from source/credits/PECredits.hx rename to source/credits/old/PECredits.hx diff --git a/source/credits/UECredits.hx b/source/credits/old/UECredits.hx similarity index 100% rename from source/credits/UECredits.hx rename to source/credits/old/UECredits.hx diff --git a/source/credits/import.hx b/source/credits/old/import.hx similarity index 100% rename from source/credits/import.hx rename to source/credits/old/import.hx diff --git a/source/import.hx b/source/import.hx index eb1af41..ee7d9de 100644 --- a/source/import.hx +++ b/source/import.hx @@ -1,7 +1,5 @@ #if !macro // Fix for haxe 4.3+ import Paths; - -import codename.backend.assets.AssetsLibraryList; -import codename.backend.Script; -import codename.backend.system.Logs; +import sys.logger.Logs; +using StringTools; #end \ No newline at end of file diff --git a/source/modding/ModFolder.hx b/source/modding/ModFolder.hx new file mode 100644 index 0000000..ae3ca3f --- /dev/null +++ b/source/modding/ModFolder.hx @@ -0,0 +1,13 @@ +package modding; + +class ModFolder +{ + public var id:String; // The assosciated mod id polymod uses for this mod folder + public var name:String; // To make sure there are no folder conflicts.. somehow. + public var enabled:Bool = true; // Whether this mod is enabled + + public function new(id:String, name:String, enabled:Bool) + { + this.id = id; this.name = name; this.enabled = enabled; + } +} \ No newline at end of file diff --git a/source/modding/PolymodHandler.hx b/source/modding/PolymodHandler.hx new file mode 100644 index 0000000..891b098 --- /dev/null +++ b/source/modding/PolymodHandler.hx @@ -0,0 +1,231 @@ +package modding; + +import haxe.PosInfos; +#if MODS_ALLOWED +import polymod.Polymod; +import polymod.Polymod.PolymodError; +import polymod.util.DefineUtil.getDefineString; +import polymod.util.DefineUtil.getDefineBool; + +import modding.ModFolder; +import modding.ScriptContext; +import modding.ScriptContext.ModScriptContexts; + +import sys.FileSystem as Fs; +import sys.io.File; // Just in case, may get removed later if unused. + +class PolymodHandler { + static var modRoot:String = #if TEST_BUILD "../../../new_example_mods" #else "mods" #end; + static var apiVersion:String = "1.0.0"; // This should match the current engine version. + + static var curMods_folder:Array = []; + static var raw_curMods:Array = []; + static var scriptContexts:Array = []; + + static var customAssetLibrary:Map = [ + #if VIDEOS_ALLOWED "videos" => "./videos", #end + "songs" => "./songs", + "shared" => "shared", + "week2" => "./week1", + "week3" => "./week2", + "week4" => "./week3", + "week5" => "./week4", + "week6" => "./week5", + "week7" => "./week7", + "shaders" => "./shaders" + ]; + + public static function initMods() + { + curMods_folder = []; + raw_curMods = []; + scriptContexts = []; + + trace("Let's have a mod load.. /ref"); + + raw_curMods = Polymod.scan({ + modRoot: modRoot, + apiVersionRule: '>=$apiVersion', + errorCallback: function(e:PolymodError) errorCallback(e) + }); + + var modDirs:Array = []; + for (mod in raw_curMods) + { + modDirs.push(mod.id); + } + + Polymod.init({ + modRoot: modRoot, + apiVersionRule: '>=$apiVersion', + errorCallback: function(e:PolymodError) errorCallback(e), + frameworkParams: { + assetLibraryPaths: customAssetLibrary + }, + dirs: modDirs + }); + + try + { + for (mod in raw_curMods) + { + if (ClientPrefs.data.enabledMods.length > 0) + { + for (modMeta in ClientPrefs.data.enabledMods) + { + if (mod.id != modMeta[0]) + { + if (mod.title != modMeta[1]) + { + fireModDisable(mod.id); + } + fireModDisable(mod.id); + } + else + { + Logs.traceNew("Loaded mod: `" + mod.title + '`[${mod.id}]', INFO); + curMods_folder.push(new ModFolder(mod.id, mod.title, true)); + + //scriptContexts.push(initScriptContexts(mod.modPath, mod.id)); + } + } + } + else + { + Logs.traceNew("Loaded mod: `" + mod.title + '`[${mod.id}]', INFO); + curMods_folder.push(new ModFolder(mod.id, mod.title, true)); + + //scriptContexts.push(initScriptContexts(mod.modPath, mod.id)); + } + } + } + catch(e:Dynamic) + { + Logs.traceNew("Mod loading didn't work! `" + Std.string(e) + "`", ERROR); + } + + trace("Loading finished! Final loaded mods: " + Std.string(curMods_folder.length) + ' / ${raw_curMods.length}'); + } + + static function errorCallback(e:PolymodError, ?infos:Null):Void + { + if (e.severity == NOTICE) + { + Logs.traceNew(e.message, INFO, infos); + } + + if (e.severity == WARNING) + { + Logs.traceNew(e.message, WARNING, infos); + } + + if (e.severity == ERROR) + { + Logs.traceNew(e.message, ERROR, infos); + } + } + + static function initScriptContexts(path:String, id:String):ModScriptContexts + { + var scriptContexts:Array = []; + var p = path + '/game'; + if (Fs.exists(p)) + { + var f = Fs.readDirectory(p); + var sbd:Array = []; + for (file in f) + { + if (Fs.isDirectory(p + '/$file')) + { + sbd.push(file); + } + else + { + scriptContexts.push(new ScriptContext(p, file)); + } + } + } + + return new ModScriptContexts(id, scriptContexts); + } + + static function getScriptContexts(mod_id:String):ModScriptContexts + { + for (contexts in scriptContexts) + { + if (contexts.mod_id == mod_id) + return contexts; + } + + trace("Couldn't find that mod id!"); + return null; + } + + /* + * This is here so that mod scripts can find the folder they're currently in + */ + public static function getScriptContext(sFileName:String, id:String):ScriptContext + { + var contexts = getScriptContexts(id); + + for (script in contexts.contexts) + { + if (script.script == sFileName) + return script; + } + + trace("Not a validly loaded script!"); + return null; + } + + public static function get_modByID(id:String):ModMetadata + { + for (mod in raw_curMods) + { + if (mod.id == id) + { + return mod; + } + } + + trace("Couldn't find a mod with that ID!"); + return null; + } + + public static function get_enabledModByID(id:String):ModFolder + { + for (mod in curMods_folder) + { + if (mod.id == id) + return mod; + } + + trace("Couldn't find a mod with that ID!"); + return null; + } + + /* + * ONLY USE THIS FUNCTION AFTER INIT HAS FINISHED. + */ + public static function disableMod(id:String):Bool return fireModDisable(id, false); + + static function fireModDisable(id:String, isInitPhase:Bool = true):Bool + { + if (!isInitPhase) trace('Disabling mod `${get_modByID(id).title}[$id]'); + + Polymod.unloadMod(id); + scriptContexts.remove(getScriptContexts(id)); + return curMods_folder.remove(get_enabledModByID(id)); + } + + public static function enableMod(id:String) + { + var tempMods:Array = Polymod.loadMod(id); + var mod:ModMetadata = get_modByID(id); + scriptContexts.push(initScriptContexts(mod.modPath, mod.id)); + curMods_folder.push(new ModFolder(mod.id, mod.title, true)); + + trace("Enabled mod: `" + mod.title + '`[$id]'); + } +} +#end \ No newline at end of file diff --git a/source/modding/ScriptContext.hx b/source/modding/ScriptContext.hx new file mode 100644 index 0000000..d830342 --- /dev/null +++ b/source/modding/ScriptContext.hx @@ -0,0 +1,27 @@ +package modding; + +class ScriptContext +{ + public var folder:String; + public var script:String; + + /* + * f - Folder + * s - Script + */ + public function new(f:String, s:String) + { + folder = f; script = s; + } +} + +class ModScriptContexts +{ + public var mod_id:String; + public var contexts:Array; + + public function new(id:String, cs:Array) + { + mod_id = id; contexts = cs; + } +} \ No newline at end of file diff --git a/source/sys/LuaIterator.hx b/source/sys/LuaIterator.hx new file mode 100644 index 0000000..c227c29 --- /dev/null +++ b/source/sys/LuaIterator.hx @@ -0,0 +1,51 @@ +package sys; + +/* +* This class recreates the functionality of a lua iterator +*/ +class LuaIterator +{ + var min:Float; + var max:Float; + var step:Float; + + /** + Iterates from `min` (inclusive) to `max` (exclusive) by `step`. + + If `max <= min`, the iterator will not act as a countdown. + If `step` is a whole number, but `min` and/or `max` aren't, `min` and/or `max` will be `Math.floor()`'d + **/ + public inline function new(min:Float, max:Float, step:Float = 1) + { + this.min = min; + this.max = max; + this.step = step; + + if (Std.int(step) == step) + { + min = Math.floor(min); + max = Math.floor(max); + } + } + + /** + Returns true if the iterator has other items, false otherwise. + **/ + public inline function hasNext():Bool + { + var nextCalc:Float = min + step; + + return nextCalc < max; + } + + /** + Moves to the next item of the iterator. + + If this is called while hasNext() is false, the result is unspecified. + **/ + public inline function next():Float + { + var nextCalc:Float = min + step; + return (min = nextCalc); + } +} \ No newline at end of file diff --git a/source/codename/backend/system/Logs.hx b/source/sys/logger/AnsiColors.hx similarity index 62% rename from source/codename/backend/system/Logs.hx rename to source/sys/logger/AnsiColors.hx index 9e13a3a..2079c87 100644 --- a/source/codename/backend/system/Logs.hx +++ b/source/sys/logger/AnsiColors.hx @@ -1,80 +1,4 @@ -package codename.backend.system; - -import haxe.Log; -import haxe.PosInfos; -import lime.app.Application; -using codename.backend.system.Logs.LogTools; - -class LogTools -{ - public static inline function levelToString(level:Level):String - { - switch (level) - { - case INFO: - return AnsiColors.LightPurple + '[ INFO ]'; - case WARNING: - return AnsiColors.LightYellow + '[ WARNING ]'; - case ERROR: - return AnsiColors.Error + '[ ERROR ]'; - default: - return '[ MISC ]'; - } - } -} - -class Logs -{ - public static var nativeTrace = Log.trace; - - public static function init() - { - Log.trace = traceOverride; - } - - static function levelToInt(l:Level):Int - { - switch(l) - { - case INFO: - return 0; - case MISC: - return 1; - case NONE: - return 2; - case WARNING: - return 3; - case ERROR: - return 4; - } - } - - static function traceOverride(v:Dynamic, ?infos:PosInfos):Void traceNew(v, NONE, infos); - - public static function traceNew(v:Dynamic, level:Level = NONE, ?infos:PosInfos):Void - { - var str = '${level.levelToString()} : ' + Log.formatOutput(v, infos).replace('\n\n', '\n').replace('\n', '\n${level.levelToString()} : ${infos.fileName}:${infos.lineNumber}: ') + AnsiColors.Reset; - #if js - if (js.Syntax.typeof(untyped console) != "undefined" && (untyped console).log != null) - (untyped console).log(str); - #elseif lua - untyped __define_feature__("use._hx_print", _hx_print(str)); - #elseif sys - Sys.println(str); - #else - throw new haxe.exceptions.NotImplementedException() - #end - } -} - -enum abstract Level(Int) -{ - var INFO = 0; - var MISC = 1; - var NONE = 2; - var WARNING = 3; - var ERROR = 4; -} +package sys.logger; // Thank you @notbilly in the Haxe Discord for the color codes! enum abstract AnsiColors(String) to String { diff --git a/source/sys/logger/Level.hx b/source/sys/logger/Level.hx new file mode 100644 index 0000000..fcebf8c --- /dev/null +++ b/source/sys/logger/Level.hx @@ -0,0 +1,10 @@ +package sys.logger; + +enum abstract Level(Int) +{ + var INFO = 0; + var MISC = 1; + var NONE = 2; + var WARNING = 3; + var ERROR = 4; +} \ No newline at end of file diff --git a/source/sys/logger/LogTools.hx b/source/sys/logger/LogTools.hx new file mode 100644 index 0000000..3bc776e --- /dev/null +++ b/source/sys/logger/LogTools.hx @@ -0,0 +1,22 @@ +package sys.logger; + +import sys.logger.AnsiColors; +import sys.logger.Level; + +class LogTools +{ + public static inline function levelToString(level:Level):String + { + switch (level) + { + case INFO: + return AnsiColors.LightPurple + '[ INFO ]'; + case WARNING: + return AnsiColors.LightYellow + '[ WARNING ]'; + case ERROR: + return AnsiColors.Error + '[ ERROR ]'; + default: + return '[ MISC ]'; + } + } +} \ No newline at end of file diff --git a/source/sys/logger/Logs.hx b/source/sys/logger/Logs.hx new file mode 100644 index 0000000..7ccbd06 --- /dev/null +++ b/source/sys/logger/Logs.hx @@ -0,0 +1,52 @@ +package sys.logger; // This is MY log script, so it's under charengine :3c - CharGoldenYT + +import haxe.Log; +import haxe.PosInfos; +import lime.app.Application; +import sys.logger.AnsiColors; +using sys.logger.LogTools; +import sys.logger.Level; + +class Logs +{ + public static var nativeTrace = Log.trace; + + public static function init() + { + Log.trace = traceOverride; + } + + static function levelToInt(l:Level):Int + { + switch(l) + { + case INFO: + return 0; + case MISC: + return 1; + case NONE: + return 2; + case WARNING: + return 3; + case ERROR: + return 4; + } + } + + static function traceOverride(v:Dynamic, ?infos:PosInfos):Void traceNew(v, NONE, infos); + + public static function traceNew(v:Dynamic, level:Level = NONE, ?infos:PosInfos):Void + { + var str = '${level.levelToString()} : ' + Log.formatOutput(v, infos).replace('\n\n', '\n').replace('\n', '\n${level.levelToString()} : ${infos.fileName}:${infos.lineNumber}: ') + AnsiColors.Reset; + #if js + if (js.Syntax.typeof(untyped console) != "undefined" && (untyped console).log != null) + (untyped console).log(str); + #elseif lua + untyped __define_feature__("use._hx_print", _hx_print(str)); + #elseif sys + Sys.println(str); + #else + throw new haxe.exceptions.NotImplementedException() + #end + } +} \ No newline at end of file