From c77de481f9348a227e00c5339e5a47205d7a9b32 Mon Sep 17 00:00:00 2001 From: Angel Date: Sun, 25 May 2025 20:47:44 +0200 Subject: [PATCH 1/2] fix setting element props using an element derived value --- AttributeList.cs | 4 ++-- Tests/ValveMap.cs | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/AttributeList.cs b/AttributeList.cs index 1761300..d0648aa 100644 --- a/AttributeList.cs +++ b/AttributeList.cs @@ -273,8 +273,8 @@ public virtual object? this[string name] { var valueType = value.GetType(); - // type must be equal, or a superclass - if (prop.PropertyType != valueType && valueType.IsSubclassOf(prop.PropertyType)) + // types must be equal, or a superclass + if (prop.PropertyType != typeof(Element) && valueType.IsSubclassOf(prop.PropertyType)) { 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"); } diff --git a/Tests/ValveMap.cs b/Tests/ValveMap.cs index f8fe7e5..8ce70c5 100644 --- a/Tests/ValveMap.cs +++ b/Tests/ValveMap.cs @@ -180,7 +180,7 @@ internal class CMapSelectionSet : DMElement { public Datamodel.ElementArray Children { get; } = []; public string SelectionSetName { get; set; } = string.Empty; - public CObjectSelectionSetDataElement SelectionSetData { get; set; } = []; + public DMElement SelectionSetData { get; set; } = []; public CMapSelectionSet() { } public CMapSelectionSet(string name) @@ -195,6 +195,12 @@ internal class CObjectSelectionSetDataElement : DMElement public Datamodel.ElementArray selectedObjects { get; set; } = []; } +internal class CFaceSelectionSetDataElement : DMElement +{ + public Datamodel.IntArray faces { get; set; } = []; + public Datamodel.ElementArray meshes { get; set; } = []; +} + internal class CMapEntity : BaseEntity { From fc535dfdf9adee467a93b0a116affcfc1f2a0c71 Mon Sep 17 00:00:00 2001 From: Angel Date: Sun, 25 May 2025 22:54:01 +0200 Subject: [PATCH 2/2] fix constructor order this fixes the element getting owner set to null --- ICodec.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ICodec.cs b/ICodec.cs index 0c6ff35..cef6071 100644 --- a/ICodec.cs +++ b/ICodec.cs @@ -256,12 +256,11 @@ public static bool TryConstructCustomElement(Dictionary types, Dat object uninitializedObject = RuntimeHelpers.GetUninitializedObject(derivedType); - elementConstructor.Invoke(uninitializedObject, [dataModel, elem_name, elem_id, elem_class]); - // this will initialize values such as // public Datamodel.ElementArray Children { get; } = []; customClassInitializer.Invoke(uninitializedObject, []); + elementConstructor.Invoke(uninitializedObject, [dataModel, elem_name, elem_id, elem_class]); elem = (Element?)uninitializedObject; return true;