mirror of
https://github.com/celisej567/LibBSP.git
synced 2026-01-04 06:10:07 +03:00
Add constructor to Patch to copy another Patch using any given format.
This commit is contained in:
@@ -14,16 +14,13 @@ using System.Reflection;
|
||||
namespace LibBSP {
|
||||
#if UNITY
|
||||
using Vector2 = UnityEngine.Vector2;
|
||||
using Vector3 = UnityEngine.Vector3;
|
||||
#if !OLDUNITY
|
||||
using Vertex = UnityEngine.UIVertex;
|
||||
#endif
|
||||
#elif GODOT
|
||||
using Vector2 = Godot.Vector2;
|
||||
using Vector3 = Godot.Vector3;
|
||||
#else
|
||||
using Vector2 = System.Numerics.Vector2;
|
||||
using Vector3 = System.Numerics.Vector3;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
@@ -140,11 +137,11 @@ namespace LibBSP {
|
||||
if (Type == 0) {
|
||||
return new Vector2(BitConverter.ToInt16(Data, 4), BitConverter.ToInt16(Data, 6));
|
||||
} else {
|
||||
return new Vector2(float.NaN, float.NaN);
|
||||
return new Vector2(0, 0);
|
||||
}
|
||||
}
|
||||
default: {
|
||||
return new Vector2(float.NaN, float.NaN);
|
||||
return new Vector2(0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -366,6 +363,52 @@ namespace LibBSP {
|
||||
Parent = parent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Patch"/> by copying the fields in <paramref name="source"/>, using
|
||||
/// <paramref name="parent"/> to get <see cref="LibBSP.MapType"/> and <see cref="LumpInfo.version"/>
|
||||
/// to use when creating the new <see cref="Patch"/>.
|
||||
/// If the <paramref name="parent"/>'s <see cref="BSP"/>'s <see cref="LibBSP.MapType"/> is different from
|
||||
/// the one from <paramref name="source"/>, it does not matter, because fields are copied by name.
|
||||
/// </summary>
|
||||
/// <param name="source">The <see cref="Patch"/> to copy.</param>
|
||||
/// <param name="parent">
|
||||
/// The <see cref="ILump"/> to use as the <see cref="Parent"/> of the new <see cref="Patch"/>.
|
||||
/// Use <c>null</c> to use the <paramref name="source"/>'s <see cref="Parent"/> instead.
|
||||
/// </param>
|
||||
public Patch(Patch source, ILump parent) : this() {
|
||||
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)];
|
||||
}
|
||||
}
|
||||
|
||||
ShaderIndex = source.ShaderIndex;
|
||||
Type = source.Type;
|
||||
|
||||
if (Type == 0) {
|
||||
Dimensions = source.Dimensions;
|
||||
Flags = source.Flags;
|
||||
} else if (Type == 1) {
|
||||
NumVertices = source.NumVertices;
|
||||
NumVertexIndices = source.NumVertexIndices;
|
||||
FirstVertexIndex = source.FirstVertexIndex;
|
||||
}
|
||||
|
||||
FirstVertex = source.FirstVertex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Factory method to parse a <c>byte</c> array into a <see cref="Lump{Patch}"/>.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user