mirror of
https://github.com/dcronqvist/DotTiled.git
synced 2025-05-08 18:26:03 +03:00
Added ValueString to IProperty
Able to get string of value without knowing the property type. It is generated for all values except EnumProperty, where it is set at construction. Ideally, all should be set at construction so it is 1:1 with the XML, but there are too many places to update, and generating the string is good enough. Also in this commit: OverrideObject stack overflow bug fixed. Unsure what the original recursive structure was for.
This commit is contained in:
parent
a7ad3b49a1
commit
8dba9e81a0
13 changed files with 47 additions and 10 deletions
|
@ -16,6 +16,9 @@ public class BoolProperty : IProperty<bool>
|
|||
/// </summary>
|
||||
public required bool Value { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string ValueString => Value.ToString();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IProperty Clone() => new BoolProperty
|
||||
{
|
||||
|
|
|
@ -25,6 +25,9 @@ public class ClassProperty : HasPropertiesBase, IProperty<IList<IProperty>>
|
|||
/// </summary>
|
||||
public required IList<IProperty> Value { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string ValueString => PropertyType;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IProperty Clone() => new ClassProperty
|
||||
{
|
||||
|
|
|
@ -16,6 +16,10 @@ public class ColorProperty : IProperty<Color>
|
|||
/// </summary>
|
||||
public required Color Value { get; set; }
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string ValueString => Value != null ? Value.ToString() : string.Empty;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IProperty Clone() => new ColorProperty
|
||||
{
|
||||
|
|
|
@ -25,12 +25,16 @@ public class EnumProperty : IProperty<ISet<string>>
|
|||
/// </summary>
|
||||
public required ISet<string> Value { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public required string ValueString { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IProperty Clone() => new EnumProperty
|
||||
{
|
||||
Name = Name,
|
||||
PropertyType = PropertyType,
|
||||
Value = Value.ToHashSet()
|
||||
Value = Value.ToHashSet(),
|
||||
ValueString = ValueString
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -16,6 +16,9 @@ public class FileProperty : IProperty<string>
|
|||
/// </summary>
|
||||
public required string Value { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string ValueString => Value;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IProperty Clone() => new FileProperty
|
||||
{
|
||||
|
|
|
@ -16,6 +16,9 @@ public class FloatProperty : IProperty<float>
|
|||
/// </summary>
|
||||
public required float Value { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string ValueString => Value.ToString();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IProperty Clone() => new FloatProperty
|
||||
{
|
||||
|
|
|
@ -10,6 +10,11 @@ public interface IProperty
|
|||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The value of the property as it is in the .tmx / .tmj
|
||||
/// </summary>
|
||||
public string ValueString { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The type of the property.
|
||||
/// </summary>
|
||||
|
|
|
@ -16,6 +16,9 @@ public class IntProperty : IProperty<int>
|
|||
/// </summary>
|
||||
public required int Value { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string ValueString => Value.ToString();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IProperty Clone() => new IntProperty
|
||||
{
|
||||
|
|
|
@ -16,6 +16,9 @@ public class ObjectProperty : IProperty<uint>
|
|||
/// </summary>
|
||||
public required uint Value { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string ValueString => Value.ToString();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IProperty Clone() => new ObjectProperty
|
||||
{
|
||||
|
|
|
@ -16,6 +16,9 @@ public class StringProperty : IProperty<string>
|
|||
/// </summary>
|
||||
public required string Value { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string ValueString => Value;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IProperty Clone() => new StringProperty
|
||||
{
|
||||
|
|
|
@ -135,16 +135,17 @@ public abstract partial class TmjReaderBase
|
|||
if (ced.ValueAsFlags)
|
||||
{
|
||||
var values = value.Split(',').Select(v => v.Trim()).ToHashSet();
|
||||
return new EnumProperty { Name = name, PropertyType = propertyType, Value = values };
|
||||
return new EnumProperty { Name = name, PropertyType = propertyType, Value = values, ValueString = value};
|
||||
}
|
||||
else
|
||||
{
|
||||
return new EnumProperty { Name = name, PropertyType = propertyType, Value = new HashSet<string> { value } };
|
||||
return new EnumProperty { Name = name, PropertyType = propertyType, Value = new HashSet<string> { value }, ValueString = value };
|
||||
}
|
||||
}
|
||||
else if (ced.StorageType == CustomEnumStorageType.Int)
|
||||
{
|
||||
var value = element.GetRequiredProperty<int>("value");
|
||||
var valueString = element.GetRequiredProperty<string>("value");
|
||||
if (ced.ValueAsFlags)
|
||||
{
|
||||
var allValues = ced.Values;
|
||||
|
@ -158,13 +159,13 @@ public abstract partial class TmjReaderBase
|
|||
_ = enumValues.Add(enumValue);
|
||||
}
|
||||
}
|
||||
return new EnumProperty { Name = name, PropertyType = propertyType, Value = enumValues };
|
||||
return new EnumProperty { Name = name, PropertyType = propertyType, Value = enumValues, ValueString = valueString };
|
||||
}
|
||||
else
|
||||
{
|
||||
var allValues = ced.Values;
|
||||
var enumValue = allValues[value];
|
||||
return new EnumProperty { Name = name, PropertyType = propertyType, Value = new HashSet<string> { enumValue } };
|
||||
return new EnumProperty { Name = name, PropertyType = propertyType, Value = new HashSet<string> { enumValue }, ValueString = valueString };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -159,7 +159,8 @@ public abstract partial class TmxReaderBase
|
|||
return obj;
|
||||
}
|
||||
|
||||
return OverrideObject((dynamic)obj, (dynamic)foundObject);
|
||||
//return OverrideObject((dynamic)obj, (dynamic)foundObject);
|
||||
return foundObject;
|
||||
}
|
||||
|
||||
internal EllipseObject ReadEllipseObject()
|
||||
|
|
|
@ -111,16 +111,17 @@ public abstract partial class TmxReaderBase
|
|||
if (ced.ValueAsFlags)
|
||||
{
|
||||
var values = value.Split(',').Select(v => v.Trim()).ToHashSet();
|
||||
return new EnumProperty { Name = name, PropertyType = propertyType, Value = values };
|
||||
return new EnumProperty { Name = name, PropertyType = propertyType, Value = values, ValueString = value };
|
||||
}
|
||||
else
|
||||
{
|
||||
return new EnumProperty { Name = name, PropertyType = propertyType, Value = new HashSet<string> { value } };
|
||||
return new EnumProperty { Name = name, PropertyType = propertyType, Value = new HashSet<string> { value }, ValueString = value };
|
||||
}
|
||||
}
|
||||
else if (ced.StorageType == CustomEnumStorageType.Int)
|
||||
{
|
||||
var value = _reader.GetRequiredAttributeParseable<int>("value");
|
||||
var valueString = _reader.GetRequiredAttribute("value");
|
||||
if (ced.ValueAsFlags)
|
||||
{
|
||||
var allValues = ced.Values;
|
||||
|
@ -134,13 +135,13 @@ public abstract partial class TmxReaderBase
|
|||
_ = enumValues.Add(enumValue);
|
||||
}
|
||||
}
|
||||
return new EnumProperty { Name = name, PropertyType = propertyType, Value = enumValues };
|
||||
return new EnumProperty { Name = name, PropertyType = propertyType, Value = enumValues, ValueString = valueString };
|
||||
}
|
||||
else
|
||||
{
|
||||
var allValues = ced.Values;
|
||||
var enumValue = allValues[value];
|
||||
return new EnumProperty { Name = name, PropertyType = propertyType, Value = new HashSet<string> { enumValue } };
|
||||
return new EnumProperty { Name = name, PropertyType = propertyType, Value = new HashSet<string> { enumValue }, ValueString = valueString };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue