Skip to content

Commit 982947d

Browse files
updated event methods
1 parent 3268e58 commit 982947d

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

Code/EventSystem/EventHandler.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,22 @@ internal static void EventClear()
4040
DisabledEvents.Clear();
4141
}
4242

43-
internal static void DisableEvent(string evName, ScriptName scriptName)
43+
internal static Result DisableEvent(string evName, ScriptName scriptName)
4444
{
4545
DisabledEvents.Add(evName);
46-
ConnectEvent(evName, scriptName, false);
46+
return ConnectEvent(evName, scriptName, false);
4747
}
4848

49-
internal static void EnableEvent(string evName, bool unsubscribe = false)
49+
internal static bool EnableEvent(string evName, bool unsubscribe = false)
5050
{
5151
DisabledEvents.Remove(evName);
5252
if (unsubscribe && UnsubscribeActions.TryGetValue(evName, out var action))
5353
{
5454
action();
55+
return true;
5556
}
57+
58+
return false;
5659
}
5760

5861
internal static Result ConnectEvent(string evName, ScriptName scriptName, bool allowNonArg = true)

Code/MethodSystem/Methods/EventMethods/DisableEventMethod.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
using JetBrains.Annotations;
22
using SER.Code.ArgumentSystem.Arguments;
33
using SER.Code.ArgumentSystem.BaseArguments;
4+
using SER.Code.Exceptions;
45
using SER.Code.MethodSystem.BaseMethods.Synchronous;
6+
using SER.Code.MethodSystem.MethodDescriptors;
57
using EventHandler = SER.Code.EventSystem.EventHandler;
68

79
namespace SER.Code.MethodSystem.Methods.EventMethods;
810

911
[UsedImplicitly]
10-
public class DisableEventMethod : SynchronousMethod
12+
public class DisableEventMethod : SynchronousMethod, ICanError
1113
{
1214
public override string Description => "Disables the provided event from running.";
1315

@@ -18,6 +20,14 @@ public class DisableEventMethod : SynchronousMethod
1820

1921
public override void Execute()
2022
{
21-
EventHandler.DisableEvent(Args.GetText("eventName"), Script.Name);
23+
if (EventHandler.DisableEvent(Args.GetText("eventName"), Script.Name).HasErrored(out var error))
24+
{
25+
throw new ScriptRuntimeError(this, error);
26+
}
2227
}
28+
29+
public string[] ErrorReasons =>
30+
[
31+
"There exists no event with the provided name."
32+
];
2333
}

Code/MethodSystem/Methods/EventMethods/EnableEventMethod.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
using SER.Code.ArgumentSystem.Arguments;
33
using SER.Code.ArgumentSystem.BaseArguments;
44
using SER.Code.MethodSystem.BaseMethods.Synchronous;
5+
using SER.Code.MethodSystem.MethodDescriptors;
6+
using SER.Code.ValueSystem;
57
using EventHandler = SER.Code.EventSystem.EventHandler;
68

79
namespace SER.Code.MethodSystem.Methods.EventMethods;
810

911
[UsedImplicitly]
10-
public class EnableEventMethod : SynchronousMethod
12+
public class EnableEventMethod : ReturningMethod<BoolValue>, IAdditionalDescription
1113
{
1214
public override string Description => "Enables the provided event to run after being disabled.";
1315

@@ -18,6 +20,8 @@ public class EnableEventMethod : SynchronousMethod
1820

1921
public override void Execute()
2022
{
21-
EventHandler.EnableEvent(Args.GetText("eventName"));
23+
ReturnValue = EventHandler.EnableEvent(Args.GetText("eventName"));
2224
}
25+
26+
public string AdditionalDescription => "Returns true if the event was enabled, false if no event of this name was ever disabled.";
2327
}

0 commit comments

Comments
 (0)