From 75f6bec8294e5b783368cfd7ae6e45698c326cb3 Mon Sep 17 00:00:00 2001 From: InkyBox <85509162+kittstone@users.noreply.github.com> Date: Mon, 22 May 2023 13:47:07 -0500 Subject: [PATCH] Rerevert Commit Fuck You --- assets/images/editors/charter/event-icons.png | Bin 1295 -> 0 bytes .../event-icons/Alt Animation Toggle.png | Bin 0 -> 436 bytes .../charter/event-icons/BPM Change.png | Bin 0 -> 413 bytes .../charter/event-icons/Camera Movement.png | Bin 0 -> 421 bytes .../charter/event-icons/HScript Call.png | Bin 0 -> 1074 bytes .../editors/charter/event-icons/Unknown.png | Bin 0 -> 413 bytes source/funkin/backend/chart/BaseGameParser.hx | 4 +- source/funkin/backend/chart/ChartData.hx | 41 +------ .../scripting/events/EventGameEvent.hx | 7 ++ source/funkin/backend/system/Conductor.hx | 2 +- source/funkin/backend/system/MainState.hx | 2 + source/funkin/editors/charter/Charter.hx | 5 +- source/funkin/editors/charter/CharterEvent.hx | 108 ++---------------- .../editors/charter/CharterEventGroup.hx | 4 +- .../editors/charter/CharterEventScreen.hx | 20 ++-- .../charter/CharterEventTypeSelection.hx | 13 +-- source/funkin/editors/charter/EventsData.hx | 88 ++++++++++++++ source/funkin/game/PlayState.hx | 38 +++--- 18 files changed, 152 insertions(+), 180 deletions(-) delete mode 100644 assets/images/editors/charter/event-icons.png create mode 100644 assets/images/editors/charter/event-icons/Alt Animation Toggle.png create mode 100644 assets/images/editors/charter/event-icons/BPM Change.png create mode 100644 assets/images/editors/charter/event-icons/Camera Movement.png create mode 100644 assets/images/editors/charter/event-icons/HScript Call.png create mode 100644 assets/images/editors/charter/event-icons/Unknown.png create mode 100644 source/funkin/backend/scripting/events/EventGameEvent.hx create mode 100644 source/funkin/editors/charter/EventsData.hx diff --git a/assets/images/editors/charter/event-icons.png b/assets/images/editors/charter/event-icons.png deleted file mode 100644 index fee6d3d0b95516e036dec12aaf4d4a8c590cea46..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1295 zcmV+q1@QWbP)pJ!AV3xRCwCOm`!XOMHGPF?Cei|nivWKiS)pQB&s-bMB;>~1UHo2 z5F!US^uhs&O0}v)>Y)czsfTiCxl{sI2vwpGB2=mhA%se$DsaGQXq%>P5>;{R{5ZCE zJv+QN_SoxxdYI+@hWdM6CzOqw<9~ zub!XsPZG-yL$AZTiO)AcLu6u=$=dBckW~Xn7E=RpknKY`$H7~479GxBGb#*x*8nhZ zPA)N{g7i}f!S;}QmL`Au_uE#GgIG%E`L4dkM$=C2s%%)ZS^s#B!K6PA) zte2J*viuUv4HvAp{kt{-L~sO&;M_-e0{e231mG9&h1`~m5M5oYnNVIb;pJZ+#sVZI z!{0gq47y8r@of;(X}$VbE225H+bS!XJ)xdwj-76{b#mu0JSv~xEWqR>z|o_@o^^<1 z=TMqArSkx-kX$nWkMV|{w4Me;iEhmCoGjln;rlyP`0(%i9thzb?glU}=rreQpE!{V zYO9MXVR!BXFAAb|V+F8y-MKK}8z0Ga6U36$29MU(2C>MY-{o*)!GrgH-WV;_OH5;*)~#)*Tbf9dqjNw<{NuSV0(Irv*d-%ru^pf&RK}qDv6!H9!q<=+wDpWNrei zetk%id&*6&Ts3TkiX6JOxNm{LJ|$1W$d%RD1$48#Bmg_LB~3&0xL{z4i@d>l@cg7G zOu#}qwOqJ#+ss*i4vzSkz5oUZ0vUuDgy-*Y6@|-12A=Itj(oRvIVr#-%J%|b0M=6_ z?%@EW0e0Mc65{>lNHO0B%)vCqU@BcvX$z@AX^etrs|Za=G((^Svakj4>a|CaP@V>$ zUU=wx$K8(u7aV)A0IN`NX9u1Wt0v}wvYtpIAWEEJyPo^i?%Cj%3}tyrH=2fWLcG?c zt}Q1@W|Jh%NlVl*(CG?!-~dIAN$>g~NW7}4n}|V;05FWdbRHaW`um>eLcny)e zNVtktAh17Lbb~u4pC6 zD<8ZxA&+>O7Y^fjh~OkzpIGORy0o@$7w#p*B#Z84`458natZ|&XcW%!~#nmmJ98NLyiH$kxPqC&;DQu}CYkbLql1 zg~lx=9|IUCI7CGyDY`J62xu_4^1KY8+-gBp^~E$g;VmH@1h@kw;KmT-;qmb4L=3GeeTX z;t32>!kWA^5{*O@%Z#0Pm>J}?*=}A8<2wN~P_@K0q9i4;B-JXpC>2OC7#SED>l&Eq z8X1HbT38tvTNxQ>8yHv_7;N;3ScRe?H$NpatrE9}1A-64fEqO5Hk4%MrWThZ<`!V; XF|~wP!V%dE3U&rhS3j3^P6;OkH}&M2EM}}%y>M1MG8=my~NYkmHj!Zh!C@NXczNs zppciRi(?4K_2h&DTr83jtPWcybvAHJSa@W~k~c379XPOrg+-4~p)D(8!Di(S!6hn5 zDM}1!655*54U((8xOh(RT)m*c!OS8e@qvNiwE}f`~Uy| literal 0 HcmV?d00001 diff --git a/assets/images/editors/charter/event-icons/HScript Call.png b/assets/images/editors/charter/event-icons/HScript Call.png new file mode 100644 index 0000000000000000000000000000000000000000..ab2ff5e1a04ca737e3d5d43429cff665a4ad192f GIT binary patch literal 1074 zcmZ{kdrVVT9LG;rOX=fwy`{Ie7e>O8ftty3g^`U;m+)w4g?79ubW)_0vXF(fKq15F z0tyUq#*j@x0hJ|gYJ9Qi5T_0hGc?G2Z#ZxygJB)W?Y-@N6i9c;k|oQsKYr(%-}ih! z`6cI^oW0rR3`iO&1pq)sLwYW+%GC-N^6R?zm-BduaTsz<0PKhZprHwXAa6B11E3ZM z;CTrEx=sL4clVW?O#ld{v$OK`p-_muB>D5YX!+in+0)@fk9@u^VqqFAUJH{70nq_1 z(ixT#vjBbPJCYY*0{M87>=RZJ+)aa$3MBEu!uul^B3=TBGffksmRZ}j6 ztU~;?YM)K}Z1XGryTYYDDa{93RHRE2@F4TK*wGCt_8U1>r(SlWSB)y-YgwQfrd#2m zEEU}hGcB;U1Yu9e=!1$tD@>MY7A@FJww61rV7leZAq7#0d9yI)O9k5{XL=x}LqV3I zzCz5mO-tHPA}8{EES#;ZpywT``;o|KU{6yCX;^N*1HO z>`1yp;oqquOHrQ%^O~_GvWz#y9-~Pwo)f86 z!gnlf!e4odHKwQJYacjD)GCd=v;maoY^(~C7>(;IFilK{WvjV3r9H*C#j3ZMYZ4mEfW7>~TE6vBfy-)2i*ZU9TUEaQCwCTkxLaJJ8$Y8yZfTI7$CF4YF0 z{iZwdXOk-zqI={mv8A@D&DVAL2*h$tE{5D t{{MkNcv`~)>;9SGsi<_;cI(3)EF2VS{N990fib~ zFff!FFfhDIU|_JC!N4G1FlSew4N!t9$=lt9;eUJonf*W>XMsm#F#`kNVGw3Kp1&dm zD9B#o>Fdh=oK-}K**dg~`8H4}$J50zMC1J031=l63^<(Q|Lp3%TQ4=2jelwVma0j? zo=lum1HJ!p&S27-UGZenmD2Aj1}SRy6?V&;JWd@&9==-RZ4W?d8qT8l&G%4cptHiD0fZzi$pau=N k4JDbmsl_FUxdoVdOf4ana76Yp1NAU?y85}Sb4q9e0IeZ@tN;K2 literal 0 HcmV?d00001 diff --git a/source/funkin/backend/chart/BaseGameParser.hx b/source/funkin/backend/chart/BaseGameParser.hx index 3c56e069..a8b31b87 100644 --- a/source/funkin/backend/chart/BaseGameParser.hx +++ b/source/funkin/backend/chart/BaseGameParser.hx @@ -55,7 +55,7 @@ class BaseGameParser { if (camFocusedBF != (camFocusedBF = section.mustHitSection)) { result.events.push({ time: curTime, - type: CAM_MOVEMENT, + name: "Camera Movement", params: [camFocusedBF ? 1 : 0] }); } @@ -90,7 +90,7 @@ class BaseGameParser { result.events.push({ time: curTime, - type: BPM_CHANGE, + name: "BPM Change", params: [section.bpm] }); } diff --git a/source/funkin/backend/chart/ChartData.hx b/source/funkin/backend/chart/ChartData.hx index 3dd309e7..e81589e7 100644 --- a/source/funkin/backend/chart/ChartData.hx +++ b/source/funkin/backend/chart/ChartData.hx @@ -48,8 +48,8 @@ typedef ChartNote = { } typedef ChartEvent = { + var name:String; var time:Float; - var type:ChartEventType; var params:Array; } @@ -67,43 +67,4 @@ abstract ChartStrumLineType(Int) from Int to Int { * STRUMLINE IS MARKED AS ADDITIONAL - WILL BE PLAYED AS CPU EVEN IF OPPONENT MODE IS ENABLED */ var ADDITIONAL = 2; -} -@:enum -abstract ChartEventType(Int) from Int to Int { - /** - * CUSTOM EVENT - * Params: - * - Function Name (String) - * - Function Parameters... - */ - var CUSTOM = -1; - /** - * NO EVENT, MADE FOR UNKNOWN EVENTS / EVENTS THAT CANNOT BE PARSED - */ - var NONE = 0; - /** - * CAMERA MOVEMENT EVENT - * Params: - * - Target Strumline ID (Int) - */ - var CAM_MOVEMENT = 1; - /** - * BPM CHANGE EVENT - * Params: - * - Target BPM (Float) - */ - var BPM_CHANGE = 2; - /** - * ALT ANIM TOGGLE - * Params: - * - Strum Line which is going to be toggled (Int) - * - Whenever its going to be toggled or not (Bool) - */ - var ALT_ANIM_TOGGLE = 3; - - /** - * Returns all usable event types. - */ - public static inline function getChartEventTypes():Array - return [CUSTOM, CAM_MOVEMENT, BPM_CHANGE, ALT_ANIM_TOGGLE]; } \ No newline at end of file diff --git a/source/funkin/backend/scripting/events/EventGameEvent.hx b/source/funkin/backend/scripting/events/EventGameEvent.hx new file mode 100644 index 00000000..836e44c9 --- /dev/null +++ b/source/funkin/backend/scripting/events/EventGameEvent.hx @@ -0,0 +1,7 @@ +package funkin.backend.scripting.events; + +import funkin.backend.chart.ChartData; + +final class EventGameEvent extends CancellableEvent { + public var event:ChartEvent; +} \ No newline at end of file diff --git a/source/funkin/backend/system/Conductor.hx b/source/funkin/backend/system/Conductor.hx index a35f57c7..d38db2c8 100644 --- a/source/funkin/backend/system/Conductor.hx +++ b/source/funkin/backend/system/Conductor.hx @@ -134,7 +134,7 @@ class Conductor var songTime:Float = 0; var stepTime:Float = 0; - for(e in song.events) if (e.type == BPM_CHANGE && e.params != null && e.params[0] is Float) { + for(e in song.events) if (e.name == "BPM Change" && e.params != null && e.params[0] is Float) { if (e.params[0] == curBPM) continue; var steps = (e.time - songTime) / ((60 / curBPM) * 1000 / 4); stepTime += steps; diff --git a/source/funkin/backend/system/MainState.hx b/source/funkin/backend/system/MainState.hx index 0c03257b..714170f0 100644 --- a/source/funkin/backend/system/MainState.hx +++ b/source/funkin/backend/system/MainState.hx @@ -6,6 +6,7 @@ import sys.FileSystem; import funkin.backend.assets.ModsFolder; import funkin.menus.TitleState; import funkin.menus.BetaWarningState; +import funkin.editors.charter.EventsData; import flixel.FlxState; /** @@ -42,6 +43,7 @@ class MainState extends FlxState { Main.refreshAssets(); ModsFolder.onModSwitch.dispatch(ModsFolder.currentModFolder); DiscordUtil.reloadJsonData(); + EventsData.reloadEvents(); TitleState.initialized = false; diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx index 80759bf3..236a4d74 100644 --- a/source/funkin/editors/charter/Charter.hx +++ b/source/funkin/editors/charter/Charter.hx @@ -405,8 +405,11 @@ class Charter extends UIState { var instPath:String; public function loadSong() { - if (__reload) + if (__reload) { + EventsData.reloadEvents(); PlayState.loadSong(__song, __diff, false, false); + } + Conductor.setupSong(PlayState.SONG); diff --git a/source/funkin/editors/charter/CharterEvent.hx b/source/funkin/editors/charter/CharterEvent.hx index f317c6b8..6c49081a 100644 --- a/source/funkin/editors/charter/CharterEvent.hx +++ b/source/funkin/editors/charter/CharterEvent.hx @@ -1,76 +1,10 @@ package funkin.editors.charter; import funkin.backend.system.Conductor; -import funkin.backend.chart.ChartData.ChartEventType; import funkin.game.HealthIcon; import funkin.backend.chart.ChartData.ChartEvent; class CharterEvent extends UISliceSprite { - public static function getEventInfo(id:ChartEventType):EventDefineInfo { - return switch(id) { - case CUSTOM: - // hscript - { - name: "HScript Call", - params: [ - { - name: "Function Name", - type: TString, - defValue: "myFunc" - }, - { - name: "Function Parameters (String split with commas)", - type: TString, - defValue: "" - } - ] - } - case CAM_MOVEMENT: - { - name: "Camera Movement", - params: [ - { - name: "Camera Target", - type: TStrumLine, - defValue: 0 - } - ] - } - case BPM_CHANGE: - { - name: "BPM Change", - params: [ - { - name: "Target BPM", - type: TFloat(1), - defValue: Conductor.bpm - } - ] - } - case ALT_ANIM_TOGGLE: - { - name: "Alt Animation Toggle", - params: [ - { - name: "Strumline", - type: TStrumLine, - defValue: 0 - }, - { - name: "Enable", - type: TBool, - defValue: true - } - ] - } - default: - { - name: "Unknown", - params: [] - } - }; - } - public var events:Array; public var step:Float; @@ -92,17 +26,19 @@ class CharterEvent extends UISliceSprite { } } - private static function generateDefaultIcon(type:Int) { - var spr = new FlxSprite().loadGraphic(Paths.image('editors/charter/event-icons'), true, 16, 16); - spr.frame = spr.frames.frames[type+1]; - return spr; + private static function generateDefaultIcon(name:String) { + var path:String = Paths.image('editors/charter/event-icons/$name'); + if (!Assets.exists(path)) path = Paths.image('editors/charter/event-icons/Unknown'); + + var spr = new FlxSprite().loadGraphic(path); + return spr; } public static function generateEventIcon(event:ChartEvent) { - return switch(event.type) { + return switch(event.name) { default: - generateDefaultIcon(event.type); - case CAM_MOVEMENT: + generateDefaultIcon(event.name); + case "Camera Movement": // custom icon for camera movement var state = cast(FlxG.state, Charter); if (event.params[0] != null && event.params[0] >= 0 && event.params[0] < state.strumLines.length) { @@ -111,7 +47,7 @@ class CharterEvent extends UISliceSprite { healthIcon.setUnstretchedGraphicSize(32, 32, false); healthIcon; } else - generateDefaultIcon(event.type); + generateDefaultIcon(event.name); } } @@ -136,28 +72,4 @@ class CharterEvent extends UISliceSprite { x = -(bWidth = 37 + (icons.length * 22)); } -} - -typedef EventDefineInfo = { - var name:String; - var params:Array; -} -typedef EventInfo = { - > EventDefineInfo, - var paramValues:Array; -} - -typedef EventParamInfo = { - var name:String; - var type:EventParamType; - var defValue:Dynamic; -} - -enum EventParamType { - TBool; - TInt(?min:Int, ?max:Int, ?step:Float); - TFloat(?min:Int, ?max:Int, ?step:Float, ?precision:Int); - TString; - TArrayOfString; - TStrumLine; } \ No newline at end of file diff --git a/source/funkin/editors/charter/CharterEventGroup.hx b/source/funkin/editors/charter/CharterEventGroup.hx index c631a05a..90719fec 100644 --- a/source/funkin/editors/charter/CharterEventGroup.hx +++ b/source/funkin/editors/charter/CharterEventGroup.hx @@ -1,5 +1,3 @@ package funkin.editors.charter; -class CharterEventGroup extends FlxTypedGroup { - -} \ No newline at end of file +class CharterEventGroup extends FlxTypedGroup {} \ No newline at end of file diff --git a/source/funkin/editors/charter/CharterEventScreen.hx b/source/funkin/editors/charter/CharterEventScreen.hx index b81ee135..8fbc60bd 100644 --- a/source/funkin/editors/charter/CharterEventScreen.hx +++ b/source/funkin/editors/charter/CharterEventScreen.hx @@ -2,6 +2,7 @@ package funkin.editors.charter; import funkin.backend.system.Conductor; import flixel.group.FlxGroup; +import funkin.editors.charter.EventsData; class CharterEventScreen extends UISubstateWindow { public var cam:FlxCamera; @@ -40,11 +41,11 @@ class CharterEventScreen extends UISubstateWindow { add(iconsPanel); addButton = new UIButton(windowSpr.x + 1, windowSpr.y + 31, "", function() { - openSubState(new CharterEventTypeSelection(function(eventType) { + openSubState(new CharterEventTypeSelection(function(eventName) { chartEvent.events.push({ time: Conductor.getTimeForStep(chartEvent.step), params: [], - type: eventType + name: eventName }); changeTab(chartEvent.events.length-1); })); @@ -105,11 +106,10 @@ class CharterEventScreen extends UISubstateWindow { if (id >= 0 && id < chartEvent.events.length) { curEvent = id; var curEvent = chartEvent.events[curEvent]; - var data = CharterEvent.getEventInfo(curEvent.type); - eventName.text = data.name; + eventName.text = curEvent.name; // add new elements var y:Float = eventName.y + eventName.height + 10; - for(k=>param in data.params) { + for(k=>param in EventsData.getEventParams(curEvent.name)) { function addLabel() { var label:UIText = new UIText(eventName.x, y, 0, param.name); y += label.height + 4; @@ -121,30 +121,30 @@ class CharterEventScreen extends UISubstateWindow { case TString: addLabel(); var textBox:UITextBox = new UITextBox(eventName.x, y, cast value); - y += textBox.height + 10; + y += textBox.height + 30; paramsPanel.add(textBox); paramsFields.push(textBox); case TBool: var checkbox = new UICheckbox(eventName.x, y, param.name, cast value); - y += checkbox.height + 10; + y += checkbox.height + 8; paramsPanel.add(checkbox); paramsFields.push(checkbox); case TInt(min, max, step): addLabel(); var numericStepper = new UINumericStepper(eventName.x, y, cast value, step.getDefault(1), 0, min, max); - y += numericStepper.height + 10; + y += numericStepper.height + 30; paramsPanel.add(numericStepper); paramsFields.push(numericStepper); case TFloat(min, max, step, precision): addLabel(); var numericStepper = new UINumericStepper(eventName.x, y, cast value, step.getDefault(1), precision, min, max); - y += numericStepper.height + 10; + y += numericStepper.height + 30; paramsPanel.add(numericStepper); paramsFields.push(numericStepper); case TStrumLine: addLabel(); var dropdown = new UIDropDown(eventName.x, y, 320, 32, [for(k=>s in cast(FlxG.state, Charter).strumLines.members) 'Strumline #${k+1} (${s.strumLine.characters[0]})'], cast value); - y += dropdown.height + 10; + y += dropdown.height + 30; paramsPanel.add(dropdown); paramsFields.push(dropdown); default: diff --git a/source/funkin/editors/charter/CharterEventTypeSelection.hx b/source/funkin/editors/charter/CharterEventTypeSelection.hx index d04a0970..201d9600 100644 --- a/source/funkin/editors/charter/CharterEventTypeSelection.hx +++ b/source/funkin/editors/charter/CharterEventTypeSelection.hx @@ -1,11 +1,11 @@ package funkin.editors.charter; -import funkin.backend.chart.ChartData.ChartEventType; +import funkin.editors.charter.EventsData; class CharterEventTypeSelection extends UISubstateWindow { - var callback:ChartEventType->Void; + var callback:String->Void; - public function new(callback:ChartEventType->Void) { + public function new(callback:String->Void) { super(); this.callback = callback; } @@ -16,11 +16,10 @@ class CharterEventTypeSelection extends UISubstateWindow { var w:Int = winWidth - 20; var lastIndex:Int = 0; - for(k=>eventType in ChartEventType.getChartEventTypes()) { - var type = CharterEvent.getEventInfo(eventType); - add(new UIButton(10, 41 + (32 * k), type.name, function() { + for(k=>eventName in EventsData.eventsList) { + add(new UIButton(10, 41 + (32 * k), eventName, function() { close(); - callback(eventType); + callback(eventName); }, w)); lastIndex = k; diff --git a/source/funkin/editors/charter/EventsData.hx b/source/funkin/editors/charter/EventsData.hx new file mode 100644 index 00000000..e2803c81 --- /dev/null +++ b/source/funkin/editors/charter/EventsData.hx @@ -0,0 +1,88 @@ +package funkin.editors.charter; + +import hscript.Parser; +import hscript.Interp; +import haxe.Json; +import sys.io.File; +import openfl.Assets; +import haxe.io.Path; +import funkin.backend.assets.Paths; + +using StringTools; + +class EventsData { + public static var defaultEventsList:Array = ["HScript Call", "Camera Movement", "BPM Change", "Alt Animation Toggle"]; + public static var defaultEventsParams:Map> = [ + "HScript Call" => [{name: "Function Name", type: TString, defValue: "myFunc"}, {name: "Function Parameters (String split with commas)", type: TString, defValue: ""}], + "Camera Movement" => [{name: "Camera Target", type: TStrumLine, defValue: 0}], + "BPM Change" => [{name: "Target BPM", type: TFloat(1), defValue: 100}], + "Alt Animation Toggle" => [{name: "Strumline", type: TStrumLine, defValue: 0}, {name: "Enable", type: TBool, defValue: true}], + ]; + + public static var eventsList:Array = defaultEventsList.copy(); + public static var eventsParams:Map> = defaultEventsParams.copy(); + + public static function getEventParams(name:String):Array { + return eventsParams.exists(name) ? eventsParams.get(name) : []; + } + + public static function reloadEvents() { + eventsList = defaultEventsList.copy(); + eventsParams = defaultEventsParams.copy(); + + var hscriptInterp:Interp = new Interp(); + hscriptInterp.variables.set("Bool", TBool); + hscriptInterp.variables.set("Int", function (?min:Int, ?max:Int, ?step:Float):EventParamType {return TInt(min, max, step);}); + hscriptInterp.variables.set("Float", function (?min:Int, ?max:Int, ?step:Float, ?precision:Int):EventParamType {return TFloat(min, max, step, precision);}); + hscriptInterp.variables.set("String", TString); + hscriptInterp.variables.set("StrumLine", TStrumLine); + + var hscriptParser:Parser = new Parser(); + hscriptParser.allowJSON = hscriptParser.allowMetadata = false; + + for (file in Paths.getFolderContent('data/events/', true, BOTH)) { + if (Path.extension(file) != "json") continue; + var eventName:String = Path.withoutExtension(Path.withoutDirectory(file)); + + eventsList.push(eventName); + eventsParams.set(eventName, []); + + var fileTxt:String = Assets.getText(file); + if (fileTxt.trim() == "") {continue;} + + try { + var data:Dynamic = Json.parse(fileTxt); + if (data == null || data.params == null) continue; + + var finalParams:Array = []; + for (paramData in cast(data.params, Array)) { + try { + finalParams.push({name: paramData.name, type: hscriptInterp.expr(hscriptParser.parseString(paramData.type)), defValue: paramData.defaultValue}); + } catch (e) {trace('Error parsing event param ${paramData.name} - ${eventName}: $e');} + } + eventsParams.set(eventName, finalParams); + } catch (e) {trace('Error parsing file $file: $e');} + } + + hscriptInterp = null; hscriptParser = null; + } +} + +typedef EventInfo = { + var params:Array; + var paramValues:Array; +} + +typedef EventParamInfo = { + var name:String; + var type:EventParamType; + var defValue:Dynamic; +} + +enum EventParamType { + TBool; + TInt(?min:Int, ?max:Int, ?step:Float); + TFloat(?min:Int, ?max:Int, ?step:Float, ?precision:Int); + TString; + TStrumLine; +} \ No newline at end of file diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index 99c852fd..fe1d2da4 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -1,5 +1,6 @@ package funkin.game; +import funkin.editors.charter.EventsData; import funkin.backend.system.RotatingSpriteGroup; import funkin.editors.charter.Charter; import funkin.savedata.FunkinSave; @@ -550,21 +551,22 @@ class PlayState extends MusicBeatState // dadMidpoint.put(); var camPos:FlxPoint = new FlxPoint(0, 0); - if (!chartingMode || Options.charterEnablePlaytestScripts) { switch(SONG.meta.name) { // case "": // ADD YOUR HARDCODED SCRIPTS HERE! default: - for(content in [ - Paths.getFolderContent('songs/${SONG.meta.name.toLowerCase()}/scripts', true, fromMods ? MODS : BOTH), - Paths.getFolderContent('data/charts/', true, fromMods ? MODS : BOTH)]) { - for(file in content) { - var ext = Path.extension(file).toLowerCase(); - if (Script.scriptExtensions.contains(ext)) - scripts.add(Script.create(file)); - } + function addScript(file:String) { + var ext = Path.extension(file).toLowerCase(); + if (Script.scriptExtensions.contains(ext)) + scripts.add(Script.create(file)); } + + for(content in [Paths.getFolderContent('songs/${SONG.meta.name.toLowerCase()}/scripts', true, fromMods ? MODS : BOTH), Paths.getFolderContent('data/charts/', true, fromMods ? MODS : BOTH)]) + for(file in content) addScript(file); + + for (file in Paths.getFolderContent('data/events/', true, fromMods ? MODS : BOTH)) + if (EventsData.eventsList.contains(Path.withoutExtension(Path.withoutDirectory(file)))) addScript(file); } } @@ -897,7 +899,7 @@ class PlayState extends MusicBeatState // get first camera focus for(e in events) { if (e.time > 10) break; - if (e.type == CAM_MOVEMENT) { + if (e.name == "Camera Movement") { executeEvent(e); break; } @@ -1170,24 +1172,24 @@ class PlayState extends MusicBeatState if (event == null) return; if (event.params == null) return; - switch(event.type) { - case CUSTOM: + if (scripts.event("onEvent", EventManager.get(EventGameEvent).recycle(event)).cancelled) return; + + switch(event.name) { + case "HScript Call": if (event.params[0] is String && event.params[1] is String) { scripts.call(event.params[0], event.params[1].split(',')); } - case CAM_MOVEMENT: + case "Camera Movement": if (event.params[0] is Int) curCameraTarget = event.params[0]; - case BPM_CHANGE: - // automatically handled by conductor - case ALT_ANIM_TOGGLE: + case "BPM Change": // automatically handled by conductor + case "Alt Animation Toggle": if (event.params[0] is Int && event.params[1] is Bool) { var strLine = strumLines.members[event.params[0]]; if (strLine != null) strLine.altAnim = cast event.params[1]; } - // todo!!! - default: + case "Unknown": } }