Skip to content

Commit fb77727

Browse files
add more FriendlyName definitions
1 parent b0db0b3 commit fb77727

16 files changed

Lines changed: 53 additions & 28 deletions

File tree

Code/ArgumentSystem/Arguments/VariableArgument.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public DynamicTryGet<Variable> GetConvertSolution(BaseToken token)
2929

3030
public class VariableArgument<T>(string name) : Argument(name) where T : Variable
3131
{
32-
public override string InputDescription => $"A {typeof(T).FriendlyTypeName()}";
32+
public override string InputDescription => $"A {Variable.GetFriendlyName(typeof(T))}";
3333

3434
[UsedImplicitly]
3535
public DynamicTryGet<T> GetConvertSolution(BaseToken token)

Code/Plugin/Commands/HelpSystem/DocsProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ private static string GetMethodHelp(Method method)
462462
if (ret.LiteralReturnTypes.AreKnown(out var types))
463463
{
464464
typeReturn = types
465-
.Select(Value.FriendlyName)
465+
.Select(Value.GetFriendlyName)
466466
.JoinStrings(" or ") + " value";
467467
}
468468
else
@@ -492,7 +492,7 @@ private static string GetMethodHelp(Method method)
492492
if (ret.Returns.AreKnown(out var returnTypes))
493493
{
494494
typeReturn = returnTypes
495-
.Select(Value.FriendlyName)
495+
.Select(Value.GetFriendlyName)
496496
.JoinStrings(" or ") + " value";
497497
}
498498
else

Code/ValueSystem/BoolValue.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ public static implicit operator bool(BoolValue value)
1313
}
1414

1515
public override string StringRep => Value.ToString().ToLower();
16+
17+
public override string FriendlyName => "boolean value";
1618
}

Code/ValueSystem/CollectionValue.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ public static CollectionValue Insert(CollectionValue collection, Value value)
9696
}
9797

9898
throw new CustomScriptRuntimeError(
99-
$"Inserted value '{value}' has to be the same type as the collection ({FriendlyName(type)})."
99+
$"Inserted value '{value}' has to be the same type as the collection ({GetFriendlyName(type)})."
100100
);
101101
}
102-
public CollectionValue Insert(Value val) => CollectionValue.Insert(this, val);
102+
public CollectionValue Insert(Value val) => Insert(this, val);
103103

104104
/// <summary>
105105
/// Removes every match if <paramref name="amountToRemove"/> is -1
@@ -113,7 +113,7 @@ public static CollectionValue Remove(CollectionValue collection, Value value, in
113113

114114
if (type.IsInstanceOfType(value))
115115
{
116-
throw new CustomScriptRuntimeError($"Value {value.FriendlyName()} has to be the same type as the collection ({FriendlyName(type)}).");
116+
throw new CustomScriptRuntimeError($"Value {value.FriendlyName} has to be the same type as the collection ({GetFriendlyName(type)}).");
117117
}
118118

119119
var values = collection.CastedValues.ToList();
@@ -129,16 +129,16 @@ public static CollectionValue Remove(CollectionValue collection, Value value, in
129129

130130
return new CollectionValue(values);
131131
}
132-
public CollectionValue Remove(Value val, int amountToRemove = -1) => CollectionValue.Remove(this, val, amountToRemove);
132+
public CollectionValue Remove(Value val, int amountToRemove = -1) => Remove(this, val, amountToRemove);
133133

134134
public static CollectionValue RemoveAt(CollectionValue collection, int index)
135135
{
136136
return new CollectionValue(collection.CastedValues.Where((_, i) => i != index - 1));
137137
}
138-
public CollectionValue RemoveAt(int index) => CollectionValue.RemoveAt(this, index);
138+
public CollectionValue RemoveAt(int index) => RemoveAt(this, index);
139139

140140
public static bool Contains(CollectionValue collection, Value value) => collection.CastedValues.Contains(value);
141-
public bool Contains(Value val) => CollectionValue.Contains(this, val);
141+
public bool Contains(Value val) => Contains(this, val);
142142

143143
public static CollectionValue operator +(CollectionValue lhs, CollectionValue rhs)
144144
{
@@ -166,6 +166,8 @@ public static CollectionValue RemoveAt(CollectionValue collection, int index)
166166
return new CollectionValue(lhs.CastedValues.Where(val => !rhs.CastedValues.Contains(val)));
167167
}
168168

169+
public override string FriendlyName => "collection value";
170+
169171
public override string ToString()
170172
{
171173
return $"[{string.Join(", ", CastedValues.Select(v => v.ToString()))}]";

Code/ValueSystem/DurationValue.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,6 @@ public override string StringRep
4747
return sb.Remove(sb.Length - 1, 1).ToString();
4848
}
4949
}
50+
51+
public override string FriendlyName => "duration value";
5052
}

Code/ValueSystem/NumberValue.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ public static implicit operator decimal(NumberValue value)
1313
}
1414

1515
public override string StringRep => Value.ToString();
16+
public override string FriendlyName => "number value";
1617
}

Code/ValueSystem/PlayerValue.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public PlayerValue(IEnumerable<Player> players)
2424

2525
public override int HashCode =>
2626
Players.Select(plr => plr.UserId).GetEnumerableHashCode().HasErrored(out var error, out var val)
27-
? throw new TosoksFuckedUpException(error)
28-
: val;
27+
? throw new TosoksFuckedUpException(error)
28+
: val;
29+
30+
public override string FriendlyName => "player value";
2931
}

Code/ValueSystem/ReferenceValue.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public override bool EqualCondition(Value other)
1616

1717
public override int HashCode => Value.GetHashCode();
1818

19+
public override string FriendlyName => "reference value";
20+
1921
public override string ToString()
2022
{
2123
return $"<{Value.GetType().GetAccurateName()} reference | {Value.GetHashCode()}>";
@@ -25,4 +27,6 @@ public override string ToString()
2527
public class ReferenceValue<T>(T? value) : ReferenceValue(value)
2628
{
2729
public new T Value => (T) base.Value;
30+
31+
public override string FriendlyName => $"reference value of type {typeof(T).GetAccurateName()}";
2832
}

Code/ValueSystem/TextValue.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public static implicit operator string(TextValue value)
3232

3333
public override string StringRep => Value;
3434

35+
public override string FriendlyName => "text value";
36+
3537
public static string ParseValue(string text, Script script) => ExpressionRegex.Replace(text, match =>
3638
{
3739
if (match.Value.StartsWith("~")) return match.Value[1..];
@@ -64,12 +66,17 @@ public static string ParseValue(string text, Script script) => ExpressionRegex.R
6466
});
6567
}
6668

67-
public class DynamicTextValue(string text, Script script) : TextValue(text, script);
69+
public class DynamicTextValue(string text, Script script) : TextValue(text, script)
70+
{
71+
public override string FriendlyName => "dynamic text value";
72+
}
6873

6974
public class StaticTextValue(string text) : TextValue(text, null)
7075
{
7176
public static implicit operator StaticTextValue(string text)
7277
{
7378
return new(text);
7479
}
80+
81+
public override string FriendlyName => "static text value";
7582
}

Code/ValueSystem/TypeOfValue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public TypesOfValue(params Type[] types) : base(types)
3535
}
3636

3737
private readonly Type[] _types;
38-
public override string ToString() => $"{string.Join(" or ", _types.Select(Value.FriendlyName))} value";
38+
public override string ToString() => $"{string.Join(" or ", _types.Select(t => t))} value";
3939
}
4040

4141
public class UnknownTypeOfValue() : TypeOfValue((Type?)null)
@@ -46,7 +46,7 @@ public class UnknownTypeOfValue() : TypeOfValue((Type?)null)
4646
public class SingleTypeOfValue(Type type) : TypeOfValue(type)
4747
{
4848
public readonly Type Type = type;
49-
public override string ToString() => $"{Value.FriendlyName(Type)} value";
49+
public override string ToString() => Value.GetFriendlyName(Type);
5050
}
5151

5252
public class TypeOfValue<T>() : SingleTypeOfValue(typeof(T))

0 commit comments

Comments
 (0)