Skip to content

Commit 6087c71

Browse files
committed
Create non-generic CDmePolygonMeshDataStream for deserializer
1 parent 5b127dc commit 6087c71

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

AttributeList.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,9 @@ public virtual object? this[string name]
272272
if(value != null)
273273
{
274274
var valueType = value.GetType();
275-
if (prop.PropertyType != valueType)
275+
276+
// type must be equal, or a superclass
277+
if (prop.PropertyType != valueType && valueType.IsSubclassOf(prop.PropertyType))
276278
{
277279
throw new InvalidDataException($"class property '{prop.Name}' with type '{prop.PropertyType}' does not match the type '{valueType}' of the value being set, this is likely a mismatch between the real class and the class from the datamodel");
278280
}

Tests/Tests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using DM = Datamodel.Datamodel;
1111
using System.Globalization;
1212
using VMAP;
13-
using Vector3Data = VMAP.CDmePolygonMeshDataStream<System.Numerics.Vector3>;
1413

1514
namespace Datamodel_Tests
1615
{
@@ -322,8 +321,11 @@ private static void Validate_Vmap_Reflection(Datamodel.Datamodel unserialisedVma
322321
Assert.AreEqual(vertexData.size, 8);
323322
Assert.AreEqual(vertexData.streams[0]["semanticName"], "position");
324323

325-
// todo: vertexData.streams[0] is not a instance of CDmePolygonMeshDataStream<Vector3>
326-
// Assert.AreEqual(((Vector3Data)vertexData.streams[0]).semanticName, "position");
324+
var typedPolygonMeshData = (VMAP.CDmePolygonMeshDataStream)vertexData.streams[0];
325+
Assert.AreEqual(typedPolygonMeshData.semanticName, "position");
326+
327+
var typedPolygonMeshDataStream = typedPolygonMeshData.data as Vector3Array;
328+
Assert.IsNotNull(typedPolygonMeshDataStream);
327329

328330
Assert.That(unserialisedVmap.PrefixAttributes["map_asset_references"], Is.Not.Empty);
329331

Tests/ValveMap.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,7 @@ internal class CDmePolygonMeshSubdivisionData : DMElement
359359
public Datamodel.ElementArray streams { get; set; } = [];
360360
}
361361

362-
363-
internal class CDmePolygonMeshDataStream<T> : DMElement
362+
internal class CDmePolygonMeshDataStream : DMElement
364363
{
365364
public string standardAttributeName { get; set; } = string.Empty;
366365
public string semanticName { get; set; } = string.Empty;
@@ -371,5 +370,14 @@ internal class CDmePolygonMeshDataStream<T> : DMElement
371370
/// <summary>
372371
/// An int, vector2, vector3, or vector4 array.
373372
/// </summary>
374-
public required Datamodel.Array<T> data { get; set; }
373+
public System.Collections.IList? data { get; set; }
374+
}
375+
376+
/// <remarks>
377+
/// Note: The deserializer does not support generic types, but the serializer does.
378+
/// </remarks>
379+
/// <typeparam name="T">Int, Vector2, Vector3, or Vector4</typeparam>
380+
internal class CDmePolygonMeshDataStream<T> : CDmePolygonMeshDataStream
381+
{
382+
public new required Datamodel.Array<T> data { get; set; }
375383
}

0 commit comments

Comments
 (0)