1+ using CustomPlayerEffects ;
2+ using JetBrains . Annotations ;
3+ using Respawning . Waves ;
4+ using SER . Code . ArgumentSystem . BaseArguments ;
5+ using SER . Code . Extensions ;
6+ using SER . Code . Helpers . ResultSystem ;
7+ using SER . Code . TokenSystem . Tokens ;
8+ using SER . Code . TokenSystem . Tokens . Interfaces ;
9+ using SER . Code . ValueSystem ;
10+
11+ namespace SER . Code . ArgumentSystem . Arguments ;
12+
13+ public class WaveTypeArgument ( string name ) : Argument ( name )
14+ {
15+ public static readonly Type [ ] WaveTypes = typeof ( SpawnableWaveBase ) . Assembly . GetTypes ( )
16+ . Where ( t =>
17+ t . IsSubclassOf ( typeof ( SpawnableWaveBase ) ) &&
18+ ! t . IsAbstract
19+ )
20+ . ToArray ( ) ;
21+
22+ public override string InputDescription =>
23+ "One of the following wave types:\n "
24+ + WaveTypes . Select ( t => $ "> { t . Name . LowerFirst ( ) } ") . JoinStrings ( "\n " ) ;
25+
26+ [ UsedImplicitly ]
27+ public DynamicTryGet < SpawnableWaveBase > GetConvertSolution ( BaseToken token )
28+ {
29+ if ( ! InternalConvert ( token . GetBestTextRepresentation ( Script ) ) . HasErrored ( out var error , out var type ) )
30+ {
31+ return type ;
32+ }
33+
34+ if ( token is not IValueToken valToken || valToken . CapableOf < LiteralValue > ( out var get ) )
35+ {
36+ return error ;
37+ }
38+
39+ return new ( get ( ) . OnSuccess ( lVal => InternalConvert ( lVal . StringRep ) ) ) ;
40+ }
41+
42+ private static TryGet < SpawnableWaveBase > InternalConvert ( string name )
43+ {
44+ if ( WaveTypes . FirstOrDefault ( t => string . Equals ( t . Name , name , StringComparison . OrdinalIgnoreCase ) ) is { } type )
45+ {
46+ return type . CreateInstance < SpawnableWaveBase > ( ) ;
47+ }
48+
49+ return "Value is not a valid wave type." ;
50+ }
51+ }
0 commit comments