Client LuaCsForBarotrauma
CoreEntityPrefab.cs
2 using Microsoft.Xna.Framework;
3 using System;
4 using System.Collections.Generic;
5 using System.Collections.Immutable;
6 using System.Linq;
7 using System.Reflection;
8 using System.Text;
9 
10 namespace Barotrauma
11 {
13  {
15 
16  private readonly ConstructorInfo constructor;
17 
18  private CoreEntityPrefab(
19  Identifier identifier,
20  ConstructorInfo constructor,
21  bool resizeHorizontal = false,
22  bool resizeVertical = false,
23  bool linkable = false,
24  IEnumerable<Identifier> allowedLinks = null,
25  IEnumerable<string> aliases = null)
26  : base(identifier)
27  {
28  System.Diagnostics.Debug.Assert(constructor != null);
29  this.constructor = constructor;
30  this.Name = TextManager.Get($"EntityName.{identifier}");
31  this.Description = TextManager.Get($"EntityDescription.{identifier}");
32  this.ResizeHorizontal = resizeHorizontal;
33  this.ResizeVertical = resizeVertical;
34  this.Linkable = linkable;
35  this.AllowedLinks = (allowedLinks ?? Enumerable.Empty<Identifier>()).ToImmutableHashSet();
36  this.Aliases = (aliases ?? Enumerable.Empty<string>()).Concat(identifier.Value.ToEnumerable()).ToImmutableHashSet();
37  }
38 
39  public static CoreEntityPrefab HullPrefab { get; private set; }
40  public static CoreEntityPrefab GapPrefab { get; private set; }
41  public static CoreEntityPrefab WayPointPrefab { get; private set; }
42  public static CoreEntityPrefab SpawnPointPrefab { get; private set; }
43 
44  public static void InitCorePrefabs()
45  {
47  "hull".ToIdentifier(),
48  typeof(Hull).GetConstructor(new Type[] { typeof(Rectangle) }),
49  resizeHorizontal: true,
50  resizeVertical: true,
51  linkable: true,
52  allowedLinks: new Identifier[] { "hull".ToIdentifier() });
53  Prefabs.Add(HullPrefab, false);
54 
56  "gap".ToIdentifier(),
57  typeof(Gap).GetConstructor(new Type[] { typeof(Rectangle) }),
58  resizeHorizontal: true,
59  resizeVertical: true);
60  Prefabs.Add(GapPrefab, false);
61 
63  "waypoint".ToIdentifier(),
64  typeof(WayPoint).GetConstructor(new Type[] { typeof(MapEntityPrefab), typeof(Rectangle) }));
65  Prefabs.Add(WayPointPrefab, false);
66 
68  "spawnpoint".ToIdentifier(),
69  typeof(WayPoint).GetConstructor(new Type[] { typeof(MapEntityPrefab), typeof(Rectangle) }));
70  Prefabs.Add(SpawnPointPrefab, false);
71  }
72 
73  protected override void CreateInstance(Rectangle rect)
74  {
75  if (this == WayPointPrefab || this == SpawnPointPrefab)
76  {
77  object[] lobject = new object[] { this, rect };
78  constructor.Invoke(lobject);
79  }
80  else
81  {
82  object[] lobject = new object[] { rect };
83  constructor.Invoke(lobject);
84  }
85  }
86 
87 
88  public override Sprite Sprite => null;
89 
90  public override string OriginalName => Name.Value;
91 
92  public override LocalizedString Name { get; }
93 
94  public override ImmutableHashSet<Identifier> Tags { get; } = Enumerable.Empty<Identifier>().ToImmutableHashSet();
95 
96  public override ImmutableHashSet<Identifier> AllowedLinks { get; }
97 
98  public override MapEntityCategory Category => MapEntityCategory.Structure;
99 
100  public override ImmutableHashSet<string> Aliases { get; }
101 
102  public override void Dispose()
103  {
104  throw new InvalidOperationException(
105  $"{nameof(CoreEntityPrefab)}.{nameof(Dispose)} should never be called");
106  }
107  }
108 }
static readonly PrefabCollection< CoreEntityPrefab > Prefabs
override ImmutableHashSet< Identifier > AllowedLinks
static CoreEntityPrefab SpawnPointPrefab
static CoreEntityPrefab GapPrefab
override LocalizedString Name
static CoreEntityPrefab HullPrefab
override MapEntityCategory Category
static CoreEntityPrefab WayPointPrefab
override ImmutableHashSet< Identifier > Tags
override void CreateInstance(Rectangle rect)
override ImmutableHashSet< string > Aliases
readonly Identifier Identifier
Definition: Prefab.cs:34