Skip to content

Commit 035c657

Browse files
rework the text system
1 parent ecbedc4 commit 035c657

File tree

37 files changed

+144
-93
lines changed

37 files changed

+144
-93
lines changed

Code/ArgumentSystem/Arguments/BoolArgument.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@ public class BoolArgument(string name) : Argument(name)
1313
public override string InputDescription => "boolean (true or false) value";
1414

1515
public bool IsFunction { get; init; } = false;
16-
17-
private static TryGet<bool> ParseAsLiteral(BaseToken token)
18-
{
19-
if (token.TryGetLiteralValue<BoolValue>().HasErrored(out var error, out var value))
20-
{
21-
return error;
22-
}
23-
24-
return value.Value;
25-
}
2616

2717
[UsedImplicitly]
2818
public DynamicTryGet<bool> GetConvertSolution(BaseToken token)

Code/ContextSystem/Contexts/VariableDefinition/VariableDefinitionContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ protected override IEnumerator<float> Execute()
132132
}
133133
else if (_parser is not null)
134134
{
135-
Script.AddVariable(Variable.Create(varToken.Name, Value.Parse(_parser())));
135+
Script.AddVariable(Variable.Create(varToken.Name, Value.Parse(_parser(), Script)));
136136
}
137137
else
138138
{

Code/EventSystem/EventHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private static Variable[] InternalGetVariablesFromProperties(List<(object value,
224224
switch (value)
225225
{
226226
case Enum enumValue:
227-
variables.Add(new LiteralVariable<TextValue>(GetName(), enumValue.ToString()));
227+
variables.Add(new LiteralVariable<TextValue>(GetName(), new StaticTextValue(enumValue.ToString())));
228228
continue;
229229
case Player player:
230230
variables.Add(new PlayerVariable(GetName(), new(player)));
@@ -241,7 +241,7 @@ private static Variable[] InternalGetVariablesFromProperties(List<(object value,
241241
continue;
242242
default:
243243
{
244-
variables.Add(Variable.Create(GetName(), Value.Parse(value)));
244+
variables.Add(Variable.Create(GetName(), Value.Parse(value, null)));
245245
continue;
246246
}
247247
}

Code/FileSystem/Structures/Database.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ public TryGet<Value> Get(string key)
116116
return $"Value for key '{key}' is corrupted";
117117
}
118118

119-
return Value.Parse(Player.List.Where(p => playerIds.Contains(p.UserId)));
119+
return Value.Parse(Player.List.Where(p => playerIds.Contains(p.UserId)), null);
120120
}
121121

122-
if (Value.Parse(val.Value) is { } value && value.GetType().GetAccurateName() == val.Type)
122+
if (Value.Parse(val.Value, null) is { } value && value.GetType().GetAccurateName() == val.Type)
123123
{
124124
return value;
125125
}

Code/FlagSystem/Flags/CustomCommandFlag.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public static Result RunAttachedScript(CustomCommand requestingCommand, ScriptEx
219219
}
220220
}
221221

222-
script.AddVariable(new LiteralVariable<TextValue>(name, slice.Value));
222+
script.AddVariable(new LiteralVariable<TextValue>(name, new StaticTextValue(slice.Value)));
223223
}
224224

225225
script.Run(RunContext.Command);

Code/Helpers/Extensions/StringExtensions.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using JetBrains.Annotations;
22
using SER.Code.Helpers.ResultSystem;
3+
using SER.Code.ScriptSystem;
4+
using SER.Code.ValueSystem;
35

46
namespace SER.Code.Helpers.Extensions;
57

@@ -54,4 +56,16 @@ public static string Spaceify(this string str, bool lowerCase = false)
5456

5557
return res;
5658
}
59+
60+
[Pure]
61+
public static StaticTextValue ToStaticTextValue(this string text)
62+
{
63+
return new StaticTextValue(text);
64+
}
65+
66+
[Pure]
67+
public static DynamicTextValue ToDynamicTextValue(this string text, Script script)
68+
{
69+
return new DynamicTextValue(text, script);
70+
}
5771
}

Code/MethodSystem/Methods/CollectionVariableMethods/CollectionFetchMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ public override void Execute()
3232
throw new ScriptRuntimeError(this, error);
3333
}
3434

35-
ReturnValue = Value.Parse(value);
35+
ReturnValue = Value.Parse(value, Script);
3636
}
3737
}

Code/MethodSystem/Methods/DiscordMethods/SendDiscordMessageAndWaitMethod.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using SER.Code.ArgumentSystem.Arguments;
55
using SER.Code.ArgumentSystem.BaseArguments;
66
using SER.Code.Helpers.Exceptions;
7-
using SER.Code.MethodSystem.BaseMethods.Synchronous;
87
using SER.Code.MethodSystem.BaseMethods.Yielding;
98
using SER.Code.MethodSystem.MethodDescriptors;
109
using SER.Code.MethodSystem.Methods.HTTPMethods;
@@ -57,8 +56,9 @@ public override IEnumerator<float> Execute()
5756

5857
try
5958
{
60-
ReturnValue = JObject.Parse(request.downloadHandler.text)["id"]?.Value<string>()
61-
?? throw new Exception();
59+
ReturnValue = new StaticTextValue(
60+
JObject.Parse(request.downloadHandler.text)["id"]?.Value<string>() ?? throw new Exception()
61+
);
6262
}
6363
catch
6464
{

Code/MethodSystem/Methods/DoorMethods/DoorInfoMethod.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ public override void Execute()
4848

4949
ReturnValue = info switch
5050
{
51-
"name" => new TextValue(door.DoorName.ToString()),
52-
"unityname" => new TextValue(door.Base.name),
51+
"name" => new StaticTextValue(door.DoorName.ToString()),
52+
"unityname" => new StaticTextValue(door.Base.name),
5353
"isopen" => new BoolValue(door.IsOpened),
5454
"isclosed" => new BoolValue(!door.IsOpened),
5555
"islocked" => new BoolValue(door.IsLocked),
5656
"isunlocked" => new BoolValue(!door.IsLocked),
5757
"remaininghealth" => new NumberValue(door is BreakableDoor bDoor ? (decimal)bDoor.Health : -1),
5858
"maxhealth" => new NumberValue(door is BreakableDoor bDoor ? (decimal)bDoor.MaxHealth : -1),
59-
"permissions" => new TextValue(door.Permissions.ToString()),
59+
"permissions" => new StaticTextValue(door.Permissions.ToString()),
6060
_ => throw new AndrzejFuckedUpException()
6161
};
6262
}

Code/MethodSystem/Methods/HTTPMethods/AppendJSONMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public override void Execute()
3838

3939
if (value is TextValue textValue)
4040
{
41-
jsonToAddValueTo[key] = textValue.ParsedValue(Script);
41+
jsonToAddValueTo[key] = textValue.Value;
4242
return;
4343
}
4444

0 commit comments

Comments
 (0)