-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildingQueries.cs
More file actions
97 lines (89 loc) · 3.23 KB
/
BuildingQueries.cs
File metadata and controls
97 lines (89 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// SPDX-License-Identifier: MIT
using System.Collections.Generic;
using System.Linq;
using Godot;
/// <summary>
/// Query helpers for common building lookups and UI-friendly arrays.
/// Stateless utility that operates on provided snapshots.
/// </summary>
public class BuildingQueries
{
public List<IProductionBuilding> GetProductionBuildings(IEnumerable<Building> buildings)
{
return buildings?.OfType<IProductionBuilding>().ToList() ?? new List<IProductionBuilding>();
}
public Godot.Collections.Array<Building> GetProductionBuildingsForUI(IEnumerable<Building> buildings)
{
var arr = new Godot.Collections.Array<Building>();
if (buildings == null) return arr;
foreach (var b in buildings)
{
if (b is IProductionBuilding && b != null && GodotObject.IsInstanceValid(b) && !b.IsQueuedForDeletion())
{
arr.Add(b);
}
}
return arr;
}
public List<Building> GetByDefinitionId(IEnumerable<Building> buildings, string definitionId)
{
if (buildings == null || string.IsNullOrEmpty(definitionId)) return new List<Building>();
return buildings.Where(b => b != null && GodotObject.IsInstanceValid(b) && b.DefinitionId == definitionId).ToList();
}
public Godot.Collections.Array<Building> GetByDefinitionIdForUI(IEnumerable<Building> buildings, string definitionId)
{
var arr = new Godot.Collections.Array<Building>();
if (buildings == null || string.IsNullOrEmpty(definitionId)) return arr;
foreach (var b in buildings)
{
if (b != null && GodotObject.IsInstanceValid(b) && !b.IsQueuedForDeletion() && b.DefinitionId == definitionId)
{
arr.Add(b);
}
}
return arr;
}
public List<T> GetByType<T>(IEnumerable<Building> buildings) where T : Building
{
return buildings?.OfType<T>().ToList() ?? new List<T>();
}
public Godot.Collections.Array<T> GetByTypeForUI<[MustBeVariant] T>(IEnumerable<Building> buildings) where T : Building
{
var arr = new Godot.Collections.Array<T>();
if (buildings == null) return arr;
foreach (var b in buildings.OfType<T>())
{
if (b != null && GodotObject.IsInstanceValid(b) && !b.IsQueuedForDeletion())
{
arr.Add(b);
}
}
return arr;
}
public Godot.Collections.Array<Building> GetAllBuildingsForUI(IEnumerable<Building> buildings)
{
var arr = new Godot.Collections.Array<Building>();
if (buildings == null) return arr;
foreach (var b in buildings)
{
if (b != null && GodotObject.IsInstanceValid(b) && !b.IsQueuedForDeletion())
{
arr.Add(b);
}
}
return arr;
}
public Godot.Collections.Array<City> GetCitiesForUI(IEnumerable<City> cities)
{
var arr = new Godot.Collections.Array<City>();
if (cities == null) return arr;
foreach (var c in cities)
{
if (c != null && GodotObject.IsInstanceValid(c) && !c.IsQueuedForDeletion())
{
arr.Add(c);
}
}
return arr;
}
}