From 913a102591b39bbd772759d15d7910440d15f19a Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Tue, 14 Nov 2017 21:04:49 +0200 Subject: [PATCH] Option to set aliases for StructurePrefabs --- .../BarotraumaShared/Source/Items/ItemPrefab.cs | 9 --------- .../BarotraumaShared/Source/Map/MapEntityPrefab.cs | 14 ++++++++------ .../BarotraumaShared/Source/Map/Structure.cs | 2 +- .../BarotraumaShared/Source/Map/StructurePrefab.cs | 8 ++++++-- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs b/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs index fff58d0ab..28c2ac22c 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs @@ -60,14 +60,6 @@ namespace Barotrauma private bool canSpriteFlipX; - //if a matching itemprefab is not found when loading a sub, the game will attempt to find a prefab with a matching alias - //(allows changing item names while keeping backwards compatibility with older sub files) - public string[] Aliases - { - get; - private set; - } - public List DeconstructItems { get; @@ -266,7 +258,6 @@ namespace Barotrauma CanUseOnSelf = element.GetAttributeBool("canuseonself", false); - Health = element.GetAttributeFloat("health", 100.0f); Indestructible = element.GetAttributeBool("indestructible", false); FireProof = element.GetAttributeBool("fireproof", false); diff --git a/Barotrauma/BarotraumaShared/Source/Map/MapEntityPrefab.cs b/Barotrauma/BarotraumaShared/Source/Map/MapEntityPrefab.cs index e896eabde..fded3dcf0 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/MapEntityPrefab.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/MapEntityPrefab.cs @@ -87,6 +87,14 @@ namespace Barotrauma get { return price; } } + //If a matching prefab is not found when loading a sub, the game will attempt to find a prefab with a matching alias. + //(allows changing names while keeping backwards compatibility with older sub files) + public string[] Aliases + { + get; + protected set; + } + public static void Init() { MapEntityPrefab ep = new MapEntityPrefab(); @@ -114,12 +122,6 @@ namespace Barotrauma ep.name = "Spawnpoint"; ep.constructor = typeof(WayPoint).GetConstructor(new Type[] { typeof(MapEntityPrefab), typeof(Rectangle) }); list.Add(ep); - - //ep = new MapEntityPrefab(); - //ep.name = "Linked Submarine"; - //ep.Category = 0; - //list.Add(ep); - } public MapEntityPrefab() diff --git a/Barotrauma/BarotraumaShared/Source/Map/Structure.cs b/Barotrauma/BarotraumaShared/Source/Map/Structure.cs index c1d1c3230..b80b788b3 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Structure.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Structure.cs @@ -839,7 +839,7 @@ namespace Barotrauma foreach (MapEntityPrefab ep in MapEntityPrefab.list) { - if (ep.Name == name) + if (ep.Name == name || (ep.Aliases != null && ep.Aliases.Contains(name))) { s = new Structure(rect, (StructurePrefab)ep, submarine); s.Submarine = submarine; diff --git a/Barotrauma/BarotraumaShared/Source/Map/StructurePrefab.cs b/Barotrauma/BarotraumaShared/Source/Map/StructurePrefab.cs index c6a8b0be6..c04ddec6d 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/StructurePrefab.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/StructurePrefab.cs @@ -8,8 +8,6 @@ namespace Barotrauma { partial class StructurePrefab : MapEntityPrefab { - //public static List list = new List(); - //does the structure have a physics body private bool hasBody; @@ -126,6 +124,12 @@ namespace Barotrauma sp.Category = category; sp.Description = element.GetAttributeString("description", ""); + + string aliases = element.GetAttributeString("aliases", ""); + if (!string.IsNullOrWhiteSpace(aliases)) + { + sp.Aliases = aliases.Split(','); + } sp.size = Vector2.Zero; sp.size.X = element.GetAttributeFloat("width", 0.0f);