Skip to content

Commit e2bc94a

Browse files
fix comments, remove color utils and add example script framework
1 parent cdba73a commit e2bc94a

File tree

7 files changed

+55
-80
lines changed

7 files changed

+55
-80
lines changed

ExampleScripts/ExampleScript.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace SER.ExampleScripts;
2+
3+
public abstract class ExampleScript
4+
{
5+
public abstract string Name { get; }
6+
7+
public abstract string Content { get; }
8+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace SER.ExampleScripts.Scripts;
2+
3+
public class InviteInfoScript : ExampleScript
4+
{
5+
public override string Name => "InviteBroadcast";
6+
7+
public override string Content =>
8+
"""
9+
# this script is connected to the 'Joined' event, which means that this script will run when a player joins
10+
# this event provides us with the @evPlayer variable with the player who just joined
11+
!-- OnEvent Joined
12+
13+
# this 'Broadcast' method sends a formatted message to the player who just joined
14+
Broadcast @evPlayer 10s "<b><color=#8dfcef><size=35>Welcome {@evPlayer nickname}!</size></color>\n<color=#ebebb9><size=20>This server is using <u>Scripted Events Reloaded</u>, enjoy your stay!</size></color></b>"
15+
""";
16+
}

Helpers/ColorUtils.cs

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

Helpers/Union.cs

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

MethodSystem/Methods/LightMethods/TransitionLightColorMethod.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private static IEnumerator<float> TransitionColor(Room room, Color targetColor,
4646
}
4747

4848
var roomLights = lightsController.Base.transform.parent.GetComponentsInChildren<RoomLight>(true);
49-
var startColorForLight = ColorUtils.AverageColor(
49+
var startColorForLight = AverageColor(
5050
roomLights
5151
.Select(l => l._overrideColorSet ? l._overrideColor : l._initialLightColor)
5252
.Where(c => c != Color.clear)
@@ -72,4 +72,23 @@ private static IEnumerator<float> TransitionColor(Room room, Color targetColor,
7272

7373
room.AllLightControllers.ForEachItem(ctrl => ctrl.OverrideLightsColor = targetColor);
7474
}
75+
76+
private static Color AverageColor(Color[] colors)
77+
{
78+
if (colors.Length == 0)
79+
return Color.clear;
80+
81+
float r = 0f, g = 0f, b = 0f, a = 0f;
82+
83+
foreach (Color color in colors)
84+
{
85+
r += color.r;
86+
g += color.g;
87+
b += color.b;
88+
a += color.a;
89+
}
90+
91+
float count = colors.Length;
92+
return new Color(r / count, g / count, b / count, a / count);
93+
}
7594
}

SER.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,13 @@
138138
<Compile Include="ContextSystem\Structures\TryAddContextRes.cs" />
139139
<Compile Include="ContextSystem\Structures\TryAddTokenRes.cs" />
140140
<Compile Include="EventSystem\EventHandler.cs" />
141+
<Compile Include="ExampleScripts\ExampleScript.cs" />
142+
<Compile Include="ExampleScripts\Scripts\InviteInfoScript.cs" />
141143
<Compile Include="FlagSystem\Flags\CustomCommandFlag.cs" />
142144
<Compile Include="FlagSystem\Flags\OnEventFlag.cs" />
143145
<Compile Include="FlagSystem\ScriptFlagHandler.cs" />
144146
<Compile Include="FlagSystem\Structures\ConsoleType.cs" />
145147
<Compile Include="FlagSystem\Structures\Flag.cs" />
146-
<Compile Include="Helpers\ColorUtils.cs" />
147148
<Compile Include="Helpers\Compiler\CompilerRequiredAttributes.cs" />
148149
<Compile Include="Helpers\Compiler\IsExternalInit.cs.cs" />
149150
<Compile Include="Helpers\Exceptions\AndrzejFuckedUpException.cs" />
@@ -159,7 +160,6 @@
159160
<Compile Include="Helpers\ResultSystem\DynamicTryGet.cs" />
160161
<Compile Include="Helpers\ResultSystem\ITryGet.cs" />
161162
<Compile Include="Helpers\ResultSystem\TryGet.cs" />
162-
<Compile Include="Helpers\Union.cs" />
163163
<Compile Include="MethodSystem\BaseMethods\Method.cs" />
164164
<Compile Include="MethodSystem\BaseMethods\PlayerReturningMethod.cs" />
165165
<Compile Include="MethodSystem\BaseMethods\SynchronousMethod.cs" />

TokenSystem/Tokens/CommentToken.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
using System.Linq;
2+
using SER.ContextSystem.BaseContexts;
3+
using SER.ContextSystem.Contexts;
24
using SER.Helpers.ResultSystem;
35
using SER.ScriptSystem;
6+
using SER.TokenSystem.Structures;
47

58
namespace SER.TokenSystem.Tokens;
69

7-
public class CommentToken : BaseToken
10+
public class CommentToken : BaseToken, IContextableToken
811
{
912
protected override Result InternalParse(Script scr)
1013
{
1114
if (RawRepresentation.FirstOrDefault() == '#') return true;
1215

1316
return "Value is not a comment.";
1417
}
18+
19+
public TryGet<Context> TryGetContext(Script scr)
20+
{
21+
return new NoOperationContext();
22+
}
1523
}

0 commit comments

Comments
 (0)