Skip to content

Commit f41f287

Browse files
committed
Merge branch 'main' into dev
2 parents 6fd7b07 + 02abea0 commit f41f287

File tree

15 files changed

+323
-114
lines changed

15 files changed

+323
-114
lines changed

Code/ContextSystem/Contexts/Control/ElifStatementContext.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public class ElifStatementContext : StatementContext, IStatementExtender, IExten
3131

3232
public override TryAddTokenRes TryAddToken(BaseToken token)
3333
{
34+
if (NumericExpressionReslover.IsValidForExpression(token).HasErrored(out var error))
35+
{
36+
return TryAddTokenRes.Error(error);
37+
}
38+
3439
_condition.Add(token);
3540
return TryAddTokenRes.Continue();
3641
}

Code/ContextSystem/Contexts/Control/IfStatementContext.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public class IfStatementContext : StatementContext, IExtendableStatement, IKeywo
2626

2727
public override TryAddTokenRes TryAddToken(BaseToken token)
2828
{
29+
if (NumericExpressionReslover.IsValidForExpression(token).HasErrored(out var error))
30+
{
31+
return TryAddTokenRes.Error(error);
32+
}
33+
2934
_condition.Add(token);
3035
return TryAddTokenRes.Continue();
3136
}

Code/Examples/ChaosCoinScript.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
namespace SER.Code.Examples;
1+
using JetBrains.Annotations;
22

3-
public class ChaosCoinScript : IExample
3+
namespace SER.Code.Examples;
4+
5+
[UsedImplicitly]
6+
public class ChaosCoinScript : Example
47
{
5-
public string Name => "chaosCoin";
8+
public override string Name => "chaosCoin";
69

7-
public string Content =>
10+
public override string Content =>
811
"""
912
!-- OnEvent FlippingCoin
1013
@@ -16,7 +19,7 @@ public class ChaosCoinScript : IExample
1619
# "coin locked" is a property of this player, storing whether a coin can be used.
1720
# this is because some effects of the coin take time, and we DO NOT want to
1821
# have the coin be used again WHILE a different effect is still ongoing
19-
if {PlayerDataExists @evPlayer "coin locked"}
22+
if {HasPlayerData @evPlayer "coin locked"}
2023
if {GetPlayerData @evPlayer "coin locked"}
2124
Hint @evPlayer 5s "{$hintInfo}You can't use the coin for now!<br><size=20>Come back when the current effect has finished."
2225
IsAllowed false

Code/Examples/DoorRestartScript.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
namespace SER.Code.Examples;
22

3-
public class DoorRestartScript : IExample
3+
public class DoorRestartScript : Example
44
{
5-
public string Name => "doorRestart";
5+
public override string Name => "doorRestart";
66

7-
public string Content =>
7+
public override string Content =>
88
"""
99
# initial cassie announcement
1010
Cassie jingle "ATTENTIONALLPERSONNEL . DOOR CONTROL CONSOLE MALFUNCTION DETECTED . INITIALIZING REACTIVATION SEQUENCE . ATTEMPTING FULL SYSTEM REACTIVATION IN . 3 . 2 . 1" "Attention all personnel. Door control console malfunction detected.<split>Initializing reactivation sequence. Attempting full system reactivation in..."

Code/Examples/Example.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Reflection;
2+
using Cassie.Interpreters;
3+
using JetBrains.Annotations;
4+
using SER.Code.Helpers.ResultSystem;
5+
using SER.Code.ScriptSystem;
6+
7+
namespace SER.Code.Examples;
8+
9+
public abstract class Example
10+
{
11+
public abstract string Name { get; }
12+
public abstract string Content { get; }
13+
14+
[UsedImplicitly]
15+
public static string Verify()
16+
{
17+
var examples = Assembly.GetExecutingAssembly().GetTypes()
18+
.Where(t => !t.IsAbstract && typeof(Example).IsAssignableFrom(t))
19+
.Select(Activator.CreateInstance)
20+
.Cast<Example>()
21+
.ToArray();
22+
23+
foreach (var example in examples)
24+
{
25+
if (Script.CreateAnonymous(example.Name, example.Content).Compile().HasErrored(out var error))
26+
{
27+
return new Result(false, $"in example '{example.Name}'") + error;
28+
}
29+
}
30+
31+
return string.Empty;
32+
}
33+
}

Code/Examples/IExample.cs

Lines changed: 0 additions & 7 deletions
This file was deleted.

Code/Examples/RaveScript.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
namespace SER.Code.Examples;
22

3-
public class RaveScript : IExample
3+
public class RaveScript : Example
44
{
5-
public string Name => "rave";
5+
public override string Name => "rave";
66

7-
public string Content =>
7+
public override string Content =>
88
"""
99
# confirm that @sender variable was created
1010
if {VarExists @sender} == false

Code/Examples/ScanScript.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
namespace SER.Code.Examples;
22

3-
public class ScanScript : IExample
3+
public class ScanScript : Example
44
{
5-
public string Name => "scan";
5+
public override string Name => "scan";
66

7-
public string Content =>
7+
public override string Content =>
88
"""
99
# scan beginning announcement
1010
Cassie jingle "a facility scan is commencing" "A facility scan is commencing..."

Code/Examples/WelcomeScript.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
namespace SER.Code.Examples;
22

3-
public class WelcomeScript : IExample
3+
public class WelcomeScript : Example
44
{
5-
public string Name => "welcome";
5+
public override string Name => "welcome";
66

7-
public string Content =>
7+
public override string Content =>
88
"""
99
# this script is connected to the 'Joined' event, which means that this script will run when a player joins
1010
# this event provides us with the @evPlayer variable with the player who just joined

Code/FileSystem/FileSystem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ public static bool DoesScriptExistByPath(string path)
9595
public static void GenerateExamples()
9696
{
9797
var examples = Assembly.GetExecutingAssembly().GetTypes()
98-
.Where(t => typeof(IExample).IsAssignableFrom(t) && !t.IsAbstract)
99-
.Select(t => t.CreateInstance<IExample>());
98+
.Where(t => typeof(Example).IsAssignableFrom(t) && !t.IsAbstract)
99+
.Select(t => t.CreateInstance<Example>());
100100

101101
var exampleDir = Directory.CreateDirectory(Path.Combine(MainDirPath, "Example Scripts"));
102102
foreach (var example in examples)

0 commit comments

Comments
 (0)