-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Konrad Jamrozik
committed
Jul 6, 2024
1 parent
3fc9002
commit 8da8e97
Showing
8 changed files
with
70 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Collections.Immutable; | ||
using System.Reflection; | ||
using System.Text.Json.Serialization; | ||
using Lib.Contracts; | ||
using Lib.Json; | ||
|
||
namespace UfoGameLib.Controller; | ||
|
||
[JsonConverter(typeof(StringJsonConverter<PlayerActionName>))] | ||
public class PlayerActionName | ||
{ | ||
private readonly string _name; | ||
|
||
private static readonly ImmutableList<string> ValidNames = GetValidNames(); | ||
|
||
private static ImmutableList<string> GetValidNames() | ||
{ | ||
// Get the assembly that contains the PlayerAction class | ||
Assembly assembly = Assembly.GetAssembly(typeof(PlayerAction))!; | ||
|
||
// Get all types in the assembly that inherit from PlayerAction | ||
var derivedTypes = assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(PlayerAction))); | ||
|
||
return derivedTypes.Select(t => t.Name).ToImmutableList(); | ||
} | ||
|
||
public PlayerActionName(string name) | ||
{ | ||
Contract.Assert( | ||
ValidNames.Contains(name), | ||
$"The type name '{name}' is not a valid name of PlayerAction-derived class."); | ||
_name = name; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return $"{_name}"; | ||
} | ||
|
||
// public static implicit operator string(PlayerActionName playerActionName) | ||
// { | ||
// return playerActionName._name; | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters