From eec690e4e2e11032e75fa9ea6c24d4ed53a4e8e3 Mon Sep 17 00:00:00 2001 From: wfowler Date: Sun, 18 Apr 2021 22:03:27 -0600 Subject: [PATCH] Add constructor to BrushSide to copy another BrushSide using any given format. --- LibBSP/Source/Structs/BSP/BrushSide.cs | 43 ++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/LibBSP/Source/Structs/BSP/BrushSide.cs b/LibBSP/Source/Structs/BSP/BrushSide.cs index 9983557..ac5695e 100644 --- a/LibBSP/Source/Structs/BSP/BrushSide.cs +++ b/LibBSP/Source/Structs/BSP/BrushSide.cs @@ -160,7 +160,7 @@ namespace LibBSP { return BitConverter.ToSingle(Data, 0); } default: { - return float.NaN; + return 0; } } } @@ -484,7 +484,46 @@ namespace LibBSP { Data = data; Parent = parent; } - + + /// + /// Creates a new by copying the fields in , using + /// to get and + /// to use when creating the new . + /// If the 's 's is different from + /// the one from , it does not matter, because fields are copied by name. + /// + /// The to copy. + /// + /// The to use as the of the new . + /// Use null to use the 's instead. + /// + public BrushSide(BrushSide source, ILump parent) { + Parent = parent; + + if (parent != null && parent.Bsp != null) { + if (source.Parent != null && source.Parent.Bsp != null && source.Parent.Bsp.version == parent.Bsp.version && source.LumpVersion == parent.LumpInfo.version) { + Data = new byte[source.Data.Length]; + Array.Copy(source.Data, Data, source.Data.Length); + return; + } else { + Data = new byte[GetStructLength(parent.Bsp.version, parent.LumpInfo.version)]; + } + } else { + if (source.Parent != null && source.Parent.Bsp != null) { + Data = new byte[GetStructLength(source.Parent.Bsp.version, source.Parent.LumpInfo.version)]; + } else { + Data = new byte[GetStructLength(MapType.Undefined, 0)]; + } + } + + PlaneIndex = source.PlaneIndex; + TextureIndex = source.TextureIndex; + FaceIndex = source.FaceIndex; + DisplacementIndex = source.DisplacementIndex; + IsBevel = source.IsBevel; + IsThin = source.IsThin; + } + /// /// Factory method to parse a byte array into a . ///