mirror of
https://github.com/dcronqvist/DotTiled.git
synced 2025-05-08 22:06: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>
|
/// </summary>
|
||||||
public required bool Value { get; set; }
|
public required bool Value { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public string ValueString => Value.ToString();
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IProperty Clone() => new BoolProperty
|
public IProperty Clone() => new BoolProperty
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,6 +25,9 @@ public class ClassProperty : HasPropertiesBase, IProperty<IList<IProperty>>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public required IList<IProperty> Value { get; set; }
|
public required IList<IProperty> Value { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public string ValueString => PropertyType;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IProperty Clone() => new ClassProperty
|
public IProperty Clone() => new ClassProperty
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,6 +16,10 @@ public class ColorProperty : IProperty<Color>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public required Color Value { get; set; }
|
public required Color Value { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public string ValueString => Value != null ? Value.ToString() : string.Empty;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IProperty Clone() => new ColorProperty
|
public IProperty Clone() => new ColorProperty
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,12 +25,16 @@ public class EnumProperty : IProperty<ISet<string>>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public required ISet<string> Value { get; set; }
|
public required ISet<string> Value { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public required string ValueString { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IProperty Clone() => new EnumProperty
|
public IProperty Clone() => new EnumProperty
|
||||||
{
|
{
|
||||||
Name = Name,
|
Name = Name,
|
||||||
PropertyType = PropertyType,
|
PropertyType = PropertyType,
|
||||||
Value = Value.ToHashSet()
|
Value = Value.ToHashSet(),
|
||||||
|
ValueString = ValueString
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -16,6 +16,9 @@ public class FileProperty : IProperty<string>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public required string Value { get; set; }
|
public required string Value { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public string ValueString => Value;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IProperty Clone() => new FileProperty
|
public IProperty Clone() => new FileProperty
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,6 +16,9 @@ public class FloatProperty : IProperty<float>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public required float Value { get; set; }
|
public required float Value { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public string ValueString => Value.ToString();
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IProperty Clone() => new FloatProperty
|
public IProperty Clone() => new FloatProperty
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,6 +10,11 @@ public interface IProperty
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The value of the property as it is in the .tmx / .tmj
|
||||||
|
/// </summary>
|
||||||
|
public string ValueString { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The type of the property.
|
/// The type of the property.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -16,6 +16,9 @@ public class IntProperty : IProperty<int>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public required int Value { get; set; }
|
public required int Value { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public string ValueString => Value.ToString();
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IProperty Clone() => new IntProperty
|
public IProperty Clone() => new IntProperty
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,6 +16,9 @@ public class ObjectProperty : IProperty<uint>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public required uint Value { get; set; }
|
public required uint Value { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public string ValueString => Value.ToString();
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IProperty Clone() => new ObjectProperty
|
public IProperty Clone() => new ObjectProperty
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,6 +16,9 @@ public class StringProperty : IProperty<string>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public required string Value { get; set; }
|
public required string Value { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public string ValueString => Value;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IProperty Clone() => new StringProperty
|
public IProperty Clone() => new StringProperty
|
||||||
{
|
{
|
||||||
|
|
|
@ -135,16 +135,17 @@ public abstract partial class TmjReaderBase
|
||||||
if (ced.ValueAsFlags)
|
if (ced.ValueAsFlags)
|
||||||
{
|
{
|
||||||
var values = value.Split(',').Select(v => v.Trim()).ToHashSet();
|
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
|
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)
|
else if (ced.StorageType == CustomEnumStorageType.Int)
|
||||||
{
|
{
|
||||||
var value = element.GetRequiredProperty<int>("value");
|
var value = element.GetRequiredProperty<int>("value");
|
||||||
|
var valueString = element.GetRequiredProperty<string>("value");
|
||||||
if (ced.ValueAsFlags)
|
if (ced.ValueAsFlags)
|
||||||
{
|
{
|
||||||
var allValues = ced.Values;
|
var allValues = ced.Values;
|
||||||
|
@ -158,13 +159,13 @@ public abstract partial class TmjReaderBase
|
||||||
_ = enumValues.Add(enumValue);
|
_ = enumValues.Add(enumValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new EnumProperty { Name = name, PropertyType = propertyType, Value = enumValues };
|
return new EnumProperty { Name = name, PropertyType = propertyType, Value = enumValues, ValueString = valueString };
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var allValues = ced.Values;
|
var allValues = ced.Values;
|
||||||
var enumValue = allValues[value];
|
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 obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
return OverrideObject((dynamic)obj, (dynamic)foundObject);
|
//return OverrideObject((dynamic)obj, (dynamic)foundObject);
|
||||||
|
return foundObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal EllipseObject ReadEllipseObject()
|
internal EllipseObject ReadEllipseObject()
|
||||||
|
|
|
@ -111,16 +111,17 @@ public abstract partial class TmxReaderBase
|
||||||
if (ced.ValueAsFlags)
|
if (ced.ValueAsFlags)
|
||||||
{
|
{
|
||||||
var values = value.Split(',').Select(v => v.Trim()).ToHashSet();
|
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
|
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)
|
else if (ced.StorageType == CustomEnumStorageType.Int)
|
||||||
{
|
{
|
||||||
var value = _reader.GetRequiredAttributeParseable<int>("value");
|
var value = _reader.GetRequiredAttributeParseable<int>("value");
|
||||||
|
var valueString = _reader.GetRequiredAttribute("value");
|
||||||
if (ced.ValueAsFlags)
|
if (ced.ValueAsFlags)
|
||||||
{
|
{
|
||||||
var allValues = ced.Values;
|
var allValues = ced.Values;
|
||||||
|
@ -134,13 +135,13 @@ public abstract partial class TmxReaderBase
|
||||||
_ = enumValues.Add(enumValue);
|
_ = enumValues.Add(enumValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new EnumProperty { Name = name, PropertyType = propertyType, Value = enumValues };
|
return new EnumProperty { Name = name, PropertyType = propertyType, Value = enumValues, ValueString = valueString };
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var allValues = ced.Values;
|
var allValues = ced.Values;
|
||||||
var enumValue = allValues[value];
|
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