Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b54aa36
fix tests
Angel-foxxo May 18, 2025
f2c986c
fix quaternion test failing due to culture mismatch
Angel-foxxo May 18, 2025
96c5a6b
further make everything use invariant culture
Angel-foxxo May 18, 2025
5c5ad6d
also fix reading, fix all tests
Angel-foxxo May 18, 2025
8521657
reflection based deserialisation, binary only for now
Angel-foxxo May 18, 2025
a026367
match vmap field names
Angel-foxxo May 19, 2025
c3dfe42
small improvements plus fix tests
Angel-foxxo May 20, 2025
4b9afab
finish reflection based deserialisation (add for text codec)
Angel-foxxo May 21, 2025
19ad0a0
bump ver
Angel-foxxo May 21, 2025
b4adf7c
make some files follow nullability
Angel-foxxo May 22, 2025
cfc8340
more
Angel-foxxo May 22, 2025
20c36ba
finish nullable
Angel-foxxo May 22, 2025
5d5bf7a
fix nonsense
Angel-foxxo May 22, 2025
b71a6f8
actually stupidity seems to not be so stupid
Angel-foxxo May 22, 2025
0c487f3
modernise code
Angel-foxxo May 22, 2025
52fac05
handle loading using reflection nicer
Angel-foxxo May 22, 2025
ff86824
Remove deferredmode argument from Load<T>
kristiker May 23, 2025
3358086
Unduplicate some code
kristiker May 23, 2025
0cfecab
Bring back naming convention attribute
kristiker May 23, 2025
a7f5618
fr fr tests
kristiker May 23, 2025
71f6ab0
Support getter only properties such as ElementArray in typed deserial…
kristiker May 23, 2025
5b127dc
Add note for `CDmePolygonMeshDataStream<T>`
kristiker May 23, 2025
6087c71
Create non-generic CDmePolygonMeshDataStream for deserializer
kristiker May 24, 2025
b675e83
Validate element types
kristiker May 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 53 additions & 25 deletions Arrays.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,39 @@ namespace Datamodel
[DebuggerDisplay("Count = {Inner.Count}")]
public abstract class Array<T> : IList<T>, IList
{
internal class DebugView
internal class DebugView(Array<T> arr)
{
public DebugView(Array<T> arr)
{
Arr = arr;
}
Array<T> Arr;
readonly Array<T> Arr = arr;

[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public T[] Items { get { return Arr.Inner.ToArray(); } }
public T[] Items { get { return [.. Arr.Inner]; } }
}

protected List<T> Inner;

public virtual AttributeList Owner
public virtual AttributeList? Owner
{
get => _Owner;
internal set
{
_Owner = value;
}
}
AttributeList _Owner;
AttributeList? _Owner;

protected Datamodel OwnerDatamodel => Owner?.Owner;
protected Datamodel? OwnerDatamodel => Owner?.Owner;

internal Array()
{
Inner = new List<T>();
Inner = [];
}

internal Array(IEnumerable<T> enumerable)
{
if (enumerable != null)
Inner = new List<T>(enumerable);
Inner = [.. enumerable];
else
Inner = new List<T>();
Inner = [];
}

internal Array(int capacity)
Expand Down Expand Up @@ -94,40 +90,52 @@ public void CopyTo(T[] array, int offset)

public object SyncRoot => throw new NotImplementedException();

object IList.this[int index] { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
object? IList.this[int index] { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

public bool Remove(T item) => Inner.Remove(item);

public IEnumerator<T> GetEnumerator() => Inner.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => Inner.GetEnumerator();

#region IList
int IList.Add(object value)
int IList.Add(object? value)
{
Add((T)value);
if (value is not null)
Add((T)value);
return Count;
}

bool IList.Contains(object value)
bool IList.Contains(object? value)
{
if (value is null)
return false;
return Contains((T)value);
}

int IList.IndexOf(object value)
int IList.IndexOf(object? value)
{
if (value is null)
throw new InvalidOperationException("Trying to get the index of a null object");

return IndexOf((T)value);
}

void IList.Insert(int index, object value)
void IList.Insert(int index, object? value)
{
if (value is null)
throw new InvalidOperationException("Trying to insert a null object");

Insert(index, (T)value);
}

bool IList.IsFixedSize { get { return false; } }
bool IList.IsReadOnly { get { return false; } }

void IList.Remove(object value)
void IList.Remove(object? value)
{
if (value is null)
throw new InvalidOperationException("Trying to remove a null object");

Remove((T)value);
}

Expand Down Expand Up @@ -156,7 +164,7 @@ public ElementArray(int capacity)
/// </summary>
internal IEnumerable<Element> RawList { get { foreach (var elem in Inner) yield return elem; } }

public override AttributeList Owner
public override AttributeList? Owner
{
get => base.Owner;
internal set
Expand All @@ -172,7 +180,12 @@ internal set
if (elem == null) continue;
if (elem.Owner == null)
{
Inner[i] = OwnerDatamodel.ImportElement(elem, Datamodel.ImportRecursionMode.Stubs, Datamodel.ImportOverwriteMode.Stubs);
var importedElement = OwnerDatamodel.ImportElement(elem, Datamodel.ImportRecursionMode.Stubs, Datamodel.ImportOverwriteMode.Stubs);

if(importedElement is not null)
{
Inner[i] = importedElement;
}
}
else if (elem.Owner != OwnerDatamodel)
throw new ElementOwnershipException();
Expand All @@ -186,12 +199,21 @@ protected override void Insert_Internal(int index, Element item)
if (item != null && OwnerDatamodel != null)
{
if (item.Owner == null)
item = OwnerDatamodel.ImportElement(item, Datamodel.ImportRecursionMode.Recursive, Datamodel.ImportOverwriteMode.Stubs);
{
var importedElement = OwnerDatamodel.ImportElement(item, Datamodel.ImportRecursionMode.Recursive, Datamodel.ImportOverwriteMode.Stubs);

if(importedElement is not null)
{
item = importedElement;
}
}
else if (item.Owner != OwnerDatamodel)
{
throw new ElementOwnershipException();
}
}

base.Insert_Internal(index, item);
base.Insert_Internal(index, item!);
}

public override Element this[int index]
Expand All @@ -203,13 +225,19 @@ public override Element this[int index]
{
try
{
elem = Inner[index] = elem.Owner.OnStubRequest(elem.ID);
elem = Inner[index] = elem.Owner.OnStubRequest(elem.ID)!;
}
catch (Exception err)
{
throw new DestubException(this, index, err);
}
}

if (elem is null)
{
throw new InvalidOperationException("Element at specified index is null");
}

return elem;
}
set => base[index] = value;
Expand Down
27 changes: 15 additions & 12 deletions Attribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Numerics;

using AttrKVP = System.Collections.Generic.KeyValuePair<string, object>;
using AttrKVP = System.Collections.Generic.KeyValuePair<string, object?>;

namespace Datamodel
{
Expand All @@ -16,7 +16,7 @@ class Attribute
/// </summary>
/// <param name="name">The name of the Attribute, which must be unique to its owner.</param>
/// <param name="value">The value of the Attribute, which must be of a supported Datamodel type.</param>
public Attribute(string name, AttributeList owner, object value)
public Attribute(string name, AttributeList owner, object? value)
{
ArgumentNullException.ThrowIfNull(name);

Expand Down Expand Up @@ -48,7 +48,7 @@ public Attribute(string name, AttributeList owner, long defer_offset)
/// <summary>
/// Gets the Type of this Attribute's Value.
/// </summary>
public Type ValueType { get; private set; }
public Type ValueType { get; private set; } = typeof(Element);

/// <summary>
/// Gets or sets the OverrideType of this Attributes.
Expand Down Expand Up @@ -84,7 +84,7 @@ public AttributeList.OverrideType? OverrideType
/// <summary>
/// Gets the <see cref="AttributeList"/> which this Attribute is a member of.
/// </summary>
public AttributeList Owner
public AttributeList? Owner
{
get { return _Owner; }
internal set
Expand All @@ -95,9 +95,9 @@ internal set
_Owner = value;
}
}
AttributeList _Owner;
AttributeList? _Owner;

Datamodel OwnerDatamodel { get { return Owner?.Owner; } }
Datamodel? OwnerDatamodel { get { return Owner?.Owner; } }

/// <summary>
/// Gets whether the value of this Attribute has yet to be decoded.
Expand Down Expand Up @@ -125,7 +125,7 @@ public void DeferredLoad()
}
catch (Exception err)
{
throw new CodecException($"Deferred loading of attribute \"{Name}\" on element {((Element)Owner).ID} using {OwnerDatamodel.Codec} codec threw an exception.", err);
throw new CodecException($"Deferred loading of attribute \"{Name}\" on element {((Element?)Owner)?.ID} using {OwnerDatamodel.Codec} codec threw an exception.", err);
}
Offset = 0;

Expand All @@ -138,7 +138,7 @@ public void DeferredLoad()
/// </summary>
/// <exception cref="CodecException">Thrown when deferred value loading fails.</exception>
/// <exception cref="DestubException">Thrown when Element destubbing fails.</exception>
public object Value
public object? Value
{
get
{
Expand Down Expand Up @@ -188,21 +188,24 @@ public object Value
if (arr_elem == null) continue;
else if (arr_elem.Owner == null)
arr_elem.Owner = OwnerDatamodel;
else if (arr_elem.Owner != OwnerDatamodel)
throw new ElementOwnershipException("One or more Elements in the assigned collection are from a different Datamodel. Use ImportElement() to copy them to this one before assigning.");

// todo: remove ownership from values
// this is being printed on a debuggerdisplay output for some reason
// else if (arr_elem.Owner != OwnerDatamodel)
// throw new ElementOwnershipException("One or more Elements in the assigned collection are from a different Datamodel. Use ImportElement() to copy them to this one before assigning.");
}
}

_Value = value;
Offset = 0;
}
}
object _Value;
object? _Value = null;

/// <summary>
/// Gets the Attribute's Value without attempting deferred loading or destubbing.
/// </summary>
public object RawValue { get { return _Value; } }
public object? RawValue { get { return _Value; } }

#endregion

Expand Down
Loading