From eccb44a1d5f074e95b07aebca2c6bc5bbfdfdda8 Mon Sep 17 00:00:00 2001 From: Konrad Jamrozik Date: Wed, 12 Jun 2024 22:41:54 -0700 Subject: [PATCH] add Factions and FactionsExtensions classes --- src/game-lib/Model/Factions.cs | 17 +++++++++++++++++ src/game-lib/Model/FactionsExtensions.cs | 7 +++++++ 2 files changed, 24 insertions(+) create mode 100644 src/game-lib/Model/Factions.cs create mode 100644 src/game-lib/Model/FactionsExtensions.cs diff --git a/src/game-lib/Model/Factions.cs b/src/game-lib/Model/Factions.cs new file mode 100644 index 00000000..0576e78f --- /dev/null +++ b/src/game-lib/Model/Factions.cs @@ -0,0 +1,17 @@ +using System.Text.Json.Serialization; + +namespace UfoGameLib.Model; + +public class Factions : List +{ + [JsonConstructor] + public Factions() + { + } + + public Factions(IEnumerable? factions = null) + => AddRange(factions ?? new List()); + + public Factions DeepClone() + => new Factions(this.Select(faction => faction.DeepClone())); +} \ No newline at end of file diff --git a/src/game-lib/Model/FactionsExtensions.cs b/src/game-lib/Model/FactionsExtensions.cs new file mode 100644 index 00000000..ef425de0 --- /dev/null +++ b/src/game-lib/Model/FactionsExtensions.cs @@ -0,0 +1,7 @@ +namespace UfoGameLib.Model; + +public static class FactionsExtensions +{ + public static Factions ToFactions(this IEnumerable factionsEnumerable) + => new Factions(factionsEnumerable); +} \ No newline at end of file