From b3184aa5b84b39a2a3734bce1d13fc79859d938f Mon Sep 17 00:00:00 2001 From: CharlesCatYT Date: Tue, 20 Feb 2024 17:52:01 -0500 Subject: [PATCH] SCRIPT EDITOR FINALLY LETS GOOOOOOO --- .github/ISSUE_TEMPLATE/bugs.yml | 3 +- .github/workflows/main.yml | 8 +- Project.xml | 5 + README.md | 9 +- hmm.json | 15 +++ source/Main.hx | 4 + source/backend/Conductor.hx | 6 +- source/backend/Discord.hx | 2 +- source/import.hx | 22 +++- source/psychlua/FunkinLua.hx | 5 +- source/states/MainMenuState.hx | 9 +- source/states/editors/CharacterEditorState.hx | 13 +- source/states/editors/ChartingState.hx | 7 ++ source/substates/ScriptEditorSubstate.hx | 113 ++++++++++++++++++ 14 files changed, 189 insertions(+), 32 deletions(-) create mode 100644 source/substates/ScriptEditorSubstate.hx diff --git a/.github/ISSUE_TEMPLATE/bugs.yml b/.github/ISSUE_TEMPLATE/bugs.yml index bffc334..4bc89a4 100644 --- a/.github/ISSUE_TEMPLATE/bugs.yml +++ b/.github/ISSUE_TEMPLATE/bugs.yml @@ -25,7 +25,8 @@ body: - Lua - Source - Lua and Source - - I am not modding + - I was just compiling + - Idk. validations: required: true diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a23c879..8e0c223 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -50,9 +50,7 @@ jobs: - name: Create Version Tag run: echo "${{github.run_id}}" > VERSION - name: Compile - run: | - haxelib fixrepo - haxelib run lime build Project.xml linux --app-version="4.0.0-${{ github.run_id}}" + run: haxelib run lime build Project.xml linux --app-version="4.0.0-${{ github.run_id}}" - name: Publish Artifact uses: actions/upload-artifact@v2.2.4 with: @@ -115,9 +113,7 @@ jobs: - name: Create Version Tag run: echo "${{github.run_id}}" > VERSION - name: Compile - run: | - haxelib fixrepo - haxelib run lime build mac --app-version="4.0.0-${{ github.run_id}}" + run: haxelib run lime build mac --app-version="4.0.0-${{ github.run_id}}" - name: Publish Artifact uses: actions/upload-artifact@v2.2.4 with: diff --git a/Project.xml b/Project.xml index 868ff87..b06590c 100644 --- a/Project.xml +++ b/Project.xml @@ -20,6 +20,7 @@ + @@ -93,6 +94,10 @@ + + + + diff --git a/README.md b/README.md index 10c075f..04c0042 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Friday Night Funkin' - Vs. Foxa / Foxa Engine +# Friday Night Funkin' - Vs. Foxa / Alleyway Engine Not a Psych fork again... ## Story @@ -83,9 +83,9 @@ If you want to just play the mod and not compile, just use the action builds (ei ## Customization: -if you wish to disable things like *Lua & Haxe Scripts* or *Video Cutscenes*, you can read over to `Project.xml` +if you wish to disable things like *Lua Scripts* or *Video Cutscenes*, you can read over to `Project.xml` -inside `Project.xml`, you will find several variables to customize Vs. Foxa to your liking +inside `Project.xml`, you will find several variables to customize Vs. Foxa / Alleyway Engine to your liking to start you off, disabling Videos should be simple, simply Delete the line `"VIDEOS_ALLOWED"` or comment it out by wrapping the line in XML-like comments, like this `` @@ -153,6 +153,9 @@ _____________________________________ ![Screenshot_3](https://user-images.githubusercontent.com/44785097/144629914-1fe55999-2f18-4cc1-bc70-afe616d74ae5.png) * Working both for Source code modding and Downloaded builds! +### Built-in script editor +* You can now create or edit your Lua/HScript scripts inside the Chart Editor and Character Editor. + ## Story mode menu rework: ![](https://i.imgur.com/UB2EKpV.png) * Added a different BG to every song (less Tutorial) diff --git a/hmm.json b/hmm.json index a08e561..9418541 100644 --- a/hmm.json +++ b/hmm.json @@ -7,6 +7,21 @@ "ref": "develop", "url": "https://github.com/VsFoxaDevs/lime" }, + { + "name": "haxeui-core", + "type": "haxelib", + "version": null + }, + { + "name": "haxeui-openfl", + "type": "haxelib", + "version": null + }, + { + "name": "haxeui-flixel", + "type": "haxelib", + "version": null + }, { "name": "openfl", "type": "git", diff --git a/source/Main.hx b/source/Main.hx index b946d1a..6af5c44 100644 --- a/source/Main.hx +++ b/source/Main.hx @@ -52,6 +52,8 @@ class Main extends Sprite public static var fpsVar:FPS; + public static var instance:Main; + // You can pretty much ignore everything from here on - your code should go in your states. public static function main():Void @@ -70,6 +72,8 @@ class Main extends Sprite #elseif ios Sys.setCwd(lime.system.System.applicationStorageDirectory); #end + + instance = this; if (stage != null) { diff --git a/source/backend/Conductor.hx b/source/backend/Conductor.hx index d4aa11f..d19e946 100644 --- a/source/backend/Conductor.hx +++ b/source/backend/Conductor.hx @@ -14,11 +14,11 @@ typedef BPMChangeEvent = class Conductor { - public static var bpm(default, set):Float = 100; + public static var bpm(default, set):Float = 100; // current bpm public static var crochet:Float = ((60 / bpm) * 1000); // beats in milliseconds public static var stepCrochet:Float = crochet / 4; // steps in milliseconds - public static var songPosition:Float = 0; - public static var offset:Float = 0; + public static var songPosition:Float = 0; // position of the song + public static var offset:Float = 0; // offset of the song //public static var safeFrames:Int = 10; public static var safeZoneOffset:Float = 0; // is calculated in create(), is safeFrames in milliseconds diff --git a/source/backend/Discord.hx b/source/backend/Discord.hx index a70c4d3..8db17ac 100644 --- a/source/backend/Discord.hx +++ b/source/backend/Discord.hx @@ -115,7 +115,7 @@ class DiscordClient _options.details = details; _options.state = state; _options.largeImageKey = 'icon'; - _options.largeImageText = "Engine Version: " + states.MainMenuState.psychEngineVersion; + _options.largeImageText = "Engine Version: " + states.MainMenuState.alleywayEngineVersion; _options.smallImageKey = smallImageKey; // Obtained times are in milliseconds so they are divided so Discord can use it _options.startTimestamp = Std.int(startTimestamp / 1000); diff --git a/source/import.hx b/source/import.hx index 7afe390..0307edf 100644 --- a/source/import.hx +++ b/source/import.hx @@ -1,10 +1,10 @@ #if !macro -//Discord API +// Discord API #if desktop import backend.Discord; #end -//Psych +// Psych/Alleyway #if LUA_ALLOWED import llua.*; import llua.Lua; @@ -12,6 +12,7 @@ import psychlua.*; import psychlua.FunkinLua; #end +// FlxAnimate #if flxanimate import flxanimate.*; #end @@ -20,6 +21,7 @@ import flxanimate.*; import backend.Achievements; #end +// Sys #if sys import sys.*; import sys.io.*; @@ -27,11 +29,18 @@ import sys.io.*; import js.html.*; #end +// math stuff import math.*; import math.Vector3; import math.VectorHelpers; -//import extraflixel.FlxSprite3D; +// HaxeUI +import haxe.ui.*; +import haxe.ui.components.*; +import haxe.ui.containers.*; +import haxe.ui.containers.windows.*; +import haxe.ui.core.*; +import haxe.ui.events.*; import backend.Paths; import backend.Controls; import backend.CoolUtil; @@ -43,14 +52,12 @@ import backend.Conductor; import backend.BaseStage; import backend.Difficulty; import backend.Mods; - import objects.Alphabet; import objects.BGSprite; - import states.PlayState; import states.LoadingState; -//Flixel +// Flixel #if (flixel >= "5.3.0") import flixel.sound.FlxSound; #else @@ -71,6 +78,7 @@ import flixel.group.FlxGroup.FlxTypedGroup; import flixel.addons.display.FlxBackdrop; import flixel.addons.display.FlxGridOverlay; +// HxVLC #if VIDEOS_ALLOWED import hxvlc.flixel.*; import hxvlc.flixel.FlxVideo; @@ -80,8 +88,10 @@ import hxvlc.openfl.*; import flixel.FlxBasic; import flixel.util.FlxAxes; +import substates.ScriptEditorSubstate; import states.editors.ChartingState; +// CPP #if (cpp && windows) import cppthing.CppApi; #end diff --git a/source/psychlua/FunkinLua.hx b/source/psychlua/FunkinLua.hx index f0764d4..e73340a 100644 --- a/source/psychlua/FunkinLua.hx +++ b/source/psychlua/FunkinLua.hx @@ -145,7 +145,8 @@ class FunkinLua { set('ratingName', ''); set('ratingFC', ''); set('version', MainMenuState.psychEngineVersion.trim()); - set('foxaVersion', 'v3.0'); + set('alleywayVersion', MainMenuState.alleywayEngineVersion.trim()); + set('foxaVersion', 'v3.0-SE'); set('inGameOver', false); set('mustHitSection', false); @@ -206,7 +207,7 @@ class FunkinLua { set('splashSkinPostfix', NoteSplash.getSplashSkinPostfix()); set('splashAlpha', ClientPrefs.data.splashAlpha); - // build target (windows, mac, linux, etc.) + // build target (windows, mac, linux, android, etc.) set('buildTarget', getBuildTarget()); for (name => func in customFunctions) diff --git a/source/states/MainMenuState.hx b/source/states/MainMenuState.hx index 2870dc7..ae81d37 100644 --- a/source/states/MainMenuState.hx +++ b/source/states/MainMenuState.hx @@ -43,7 +43,8 @@ typedef MainMenuData = { } class MainMenuState extends MusicBeatState { - public static var psychEngineVersion:String = '0.7.3-foxa'; //This is also used for Discord RPC + public static var psychEngineVersion:String = '0.7.3'; //This is also used for Discord RPC + public static var alleywayEngineVersion:String = '0.2'; public static var curSelected:Int = 0; private var colorRotation:Int = 1; @@ -55,7 +56,7 @@ class MainMenuState extends MusicBeatState { #if html5 "You're on web. Why the FUCK are you on web? You can't get even decent easter eggs, bitch." #elseif debug - "You want logs on debug? I'll give you logs on debug. Out of wood, easter eggs can't display like this." + "You want logs on debug? I'll give you logs on debug. Actually no, we're out of wood, becuz easter eggs can't display like this." #else "500+ Giftcards! (-CharlesCatYT)", "bro became starfire from teen titans go (-Monomouse)", @@ -182,12 +183,12 @@ class MainMenuState extends MusicBeatState { char.antialiasing = ClientPrefs.data.antialiasing; add(char); - final versionShit1:FlxText = new FlxText(12, FlxG.height - 84, 0, 'Alleyway Engine v$psychEngineVersion', 12); + final versionShit1:FlxText = new FlxText(12, FlxG.height - 84, 0, menuJunk.versionText + ' | Alleyway Engine v$alleywayEngineVersion', 12); versionShit1.active = false; versionShit1.scrollFactor.set(); versionShit1.setFormat(Paths.font("vcr.ttf"), 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); add(versionShit1); - final versionShit2:FlxText = new FlxText(12, FlxG.height - 64, 0, menuJunk.versionText, 12); + final versionShit2:FlxText = new FlxText(12, FlxG.height - 64, 0, 'Based off on Psych Engine v$psychEngineVersion', 12); versionShit2.active = false; versionShit2.scrollFactor.set(); versionShit2.setFormat(Paths.font("vcr.ttf"), 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); diff --git a/source/states/editors/CharacterEditorState.hx b/source/states/editors/CharacterEditorState.hx index 784450a..3664b3a 100644 --- a/source/states/editors/CharacterEditorState.hx +++ b/source/states/editors/CharacterEditorState.hx @@ -37,7 +37,7 @@ class CharacterEditorState extends MusicBeatState var cameraZoomText:FlxText; var frameAdvanceText:FlxText; - var testModeButton:FlxButton; + var scriptingButton:FlxButton; var healthBar:Bar; var healthIcon:HealthIcon; @@ -147,12 +147,11 @@ class CharacterEditorState extends MusicBeatState frameAdvanceText.cameras = [camHUD]; add(frameAdvanceText); - testModeButton = new FlxButton(FlxG.width - 360, 25, "Test OFF", () -> + scriptingButton = new FlxButton(FlxG.width - 360, 25, "Edit Script", () -> { - testMode = !testMode; - testModeButton.text = (testMode = !testMode) ? "Test ON" : "Test OFF"; + openScriptEditor(); }); - testModeButton.cameras = [camHUD]; + scriptingButton.cameras = [camHUD]; addHelpScreen(); FlxG.mouse.visible = true; @@ -160,7 +159,7 @@ class CharacterEditorState extends MusicBeatState makeUIMenu(); - add(testModeButton); + add(scriptingButton); updatePointerPos(); updateHealthBar(); @@ -1220,6 +1219,8 @@ class CharacterEditorState extends MusicBeatState animationDropDown.setData(FlxUIDropDownMenu.makeStrIdLabelArray(animList, true)); } + function openScriptEditor() {openSubState(new ScriptEditorSubstate());} + // save var _file:FileReference; function onSaveComplete(_):Void diff --git a/source/states/editors/ChartingState.hx b/source/states/editors/ChartingState.hx index 06e4c16..68e38f7 100644 --- a/source/states/editors/ChartingState.hx +++ b/source/states/editors/ChartingState.hx @@ -564,6 +564,10 @@ class ChartingState extends MusicBeatState player2DropDown.selectedLabel = _song.player2; blockPressWhileScrolling.push(player2DropDown); + var scriptEditor:FlxButton = new FlxButton(player1DropDown.x, player2DropDown.y + 100, "Edit Script", function() { + openScriptEditor(); + }); + #if MODS_ALLOWED var directories:Array = [Paths.mods('stages/'), Paths.mods(Mods.currentModDirectory + '/stages/'), Paths.getSharedPath('stages/')]; for(mod in Mods.getGlobalMods()) @@ -622,6 +626,7 @@ class ChartingState extends MusicBeatState tab_group_song.add(loadEventJson); tab_group_song.add(stepperBPM); tab_group_song.add(stepperSpeed); + tab_group_song.add(scriptEditor); tab_group_song.add(new FlxText(stepperBPM.x, stepperBPM.y - 15, 0, 'Song BPM:')); tab_group_song.add(new FlxText(stepperBPM.x + 100, stepperBPM.y - 15, 0, 'Song Offset:')); tab_group_song.add(new FlxText(stepperSpeed.x, stepperSpeed.y - 15, 0, 'Song Speed:')); @@ -3199,6 +3204,8 @@ class ChartingState extends MusicBeatState return FlxSort.byValues(FlxSort.ASCENDING, Obj1[0], Obj2[0]); } + function openScriptEditor() {openSubState(new ScriptEditorSubstate());} + private function saveEvents() { if(_song.events != null && _song.events.length > 1) _song.events.sort(sortByTime); diff --git a/source/substates/ScriptEditorSubstate.hx b/source/substates/ScriptEditorSubstate.hx new file mode 100644 index 0000000..3207238 --- /dev/null +++ b/source/substates/ScriptEditorSubstate.hx @@ -0,0 +1,113 @@ +package substates; + +import openfl.events.IOErrorEvent; +import openfl.events.Event; +import openfl.net.FileReference; +import flixel.FlxSubState; + +class ScriptEditorSubstate extends FlxSubState +{ + var sample = 'function onCreate()\n\nend'; + var _file:FileReference; + var app:HaxeUIApp; + var WM:WindowManager; + var mainView:Window; + var container:VBox; + var btnContainer:HBox; + var codeEdit:TextArea; + var savebtn:Button; + var closebtn:Button; + + public function new() + { + super(FlxColor.fromRGB(0, 0, 0, 160)); + Toolkit.init(); + } + + override public function create() + { + super.create(); + app = new HaxeUIApp(); + app.ready(function() + { + WM = new WindowManager(); + // var mainView:Component = ComponentBuilder.fromFile("assets/data/main-view.xml"); + mainView = new Window(); + mainView.title = "Editor"; + mainView.left = 20; + mainView.top = 20; + + container = new VBox(); + container.width = 856; + container.height = 480; + codeEdit = new TextArea(); + codeEdit.width = 856; + codeEdit.height = 480; + codeEdit.styleString = "font-size: 18px"; + codeEdit.text = sample; + container.addComponent(codeEdit); + + btnContainer = new HBox(); + savebtn = new Button(); + savebtn.text = "Save"; + savebtn.onClick = (MouseEvent) -> + { + _file = new FileReference(); + _file.addEventListener(#if desktop Event.SELECT #else Event.COMPLETE #end, onSaveComplete); + _file.addEventListener(Event.CANCEL, onSaveCancel); + _file.addEventListener(IOErrorEvent.IO_ERROR, onSaveError); + _file.save(codeEdit.text, "script.lua"); + }; + closebtn = new Button(); + closebtn.text = "Close"; + closebtn.onClick = (MouseEvent) -> + { + WM.closeWindow(mainView); + app.removeComponent(mainView, true); + FlxG.mouse.useSystemCursor = false; + this.close(); + } + + btnContainer.addComponent(savebtn); + btnContainer.addComponent(closebtn); + + mainView.addComponent(container); + mainView.addComponent(btnContainer); + + WM.addWindow(mainView); + + // mainView.set_x(300); + // mainView.set_y(300); + + app.addComponent(mainView); + app.start(); + }); + FlxG.mouse.useSystemCursor = true; + } + + function onSaveComplete(_):Void + { + _file.removeEventListener(Event.COMPLETE, onSaveComplete); + _file.removeEventListener(Event.CANCEL, onSaveCancel); + _file.removeEventListener(IOErrorEvent.IO_ERROR, onSaveError); + _file = null; + FlxG.log.notice("Successfully saved LUA script data."); + } + + function onSaveCancel(_):Void + { + _file.removeEventListener(Event.COMPLETE, onSaveComplete); + _file.removeEventListener(Event.CANCEL, onSaveCancel); + _file.removeEventListener(IOErrorEvent.IO_ERROR, onSaveError); + _file = null; + } + + function onSaveError(_):Void + { + _file.removeEventListener(Event.COMPLETE, onSaveComplete); + _file.removeEventListener(Event.CANCEL, onSaveCancel); + _file.removeEventListener(IOErrorEvent.IO_ERROR, onSaveError); + _file = null; + FlxG.log.error("Problem saving LUA script data"); + } +} \ No newline at end of file