mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Handle Adjuster conditions
This commit is contained in:
@@ -63,7 +63,14 @@ namespace SabreTools.Library.DatItems
|
||||
if (mappings.Keys.Contains(Field.DatItem_Default))
|
||||
Default = mappings[Field.DatItem_Default].AsYesNo();
|
||||
|
||||
// TODO: Handle DatItem_Condition*
|
||||
// Field.DatItem_Conditions does not apply here
|
||||
if (Conditions != null)
|
||||
{
|
||||
foreach (Condition condition in Conditions)
|
||||
{
|
||||
condition.SetFields(mappings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -132,7 +139,20 @@ namespace SabreTools.Library.DatItems
|
||||
Adjuster newOther = other as Adjuster;
|
||||
|
||||
// If the Adjuster information matches
|
||||
return (Name == newOther.Name && Default == newOther.Default); // TODO: Handle DatItem_Condition*
|
||||
bool match = (Name == newOther.Name && Default == newOther.Default);
|
||||
if (!match)
|
||||
return match;
|
||||
|
||||
// If the conditions match
|
||||
if (Conditions != null)
|
||||
{
|
||||
foreach (Condition condition in Conditions)
|
||||
{
|
||||
match &= newOther.Conditions.Contains(condition);
|
||||
}
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -187,7 +207,19 @@ namespace SabreTools.Library.DatItems
|
||||
if (filter.DatItem_Default.MatchesNeutral(null, Default) == false)
|
||||
return false;
|
||||
|
||||
// TODO: Handle DatItem_Condition*
|
||||
// Filter on conditions
|
||||
if (filter.DatItem_Conditions.MatchesNeutral(null, Conditions != null ? (bool?)(Conditions.Count > 0) : null) == false)
|
||||
return false;
|
||||
|
||||
// Filter on individual conditions
|
||||
if (Conditions != null)
|
||||
{
|
||||
foreach (Condition condition in Conditions)
|
||||
{
|
||||
if (!condition.PassesFilter(filter))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -211,7 +243,13 @@ namespace SabreTools.Library.DatItems
|
||||
if (fields.Contains(Field.DatItem_Conditions))
|
||||
Conditions = null;
|
||||
|
||||
// TODO: Handle DatItem_Condition*
|
||||
if (Conditions != null)
|
||||
{
|
||||
foreach (Condition condition in Conditions)
|
||||
{
|
||||
condition.RemoveFields(fields);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -255,7 +293,7 @@ namespace SabreTools.Library.DatItems
|
||||
if (fields.Contains(Field.DatItem_Conditions))
|
||||
Conditions = newItem.Conditions;
|
||||
|
||||
// TODO: Handle DatItem_Condition*
|
||||
// Field replacement doesn't make sense for DatItem_Condition*
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -15,7 +15,6 @@ namespace SabreTools.Library.DatItems
|
||||
[JsonObject("condition")]
|
||||
public class Condition : DatItem
|
||||
{
|
||||
// TODO: Handle obscure field mappings due to this being used *under* other items as well
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
@@ -58,15 +57,23 @@ namespace SabreTools.Library.DatItems
|
||||
// Handle Condition-specific fields
|
||||
if (mappings.Keys.Contains(Field.DatItem_Tag))
|
||||
Tag = mappings[Field.DatItem_Tag];
|
||||
else if (mappings.Keys.Contains(Field.DatItem_Condition_Tag))
|
||||
Tag = mappings[Field.DatItem_Condition_Tag];
|
||||
|
||||
if (mappings.Keys.Contains(Field.DatItem_Mask))
|
||||
Mask = mappings[Field.DatItem_Mask];
|
||||
else if (mappings.Keys.Contains(Field.DatItem_Condition_Mask))
|
||||
Mask = mappings[Field.DatItem_Condition_Mask];
|
||||
|
||||
if (mappings.Keys.Contains(Field.DatItem_Relation))
|
||||
Relation = mappings[Field.DatItem_Relation];
|
||||
else if (mappings.Keys.Contains(Field.DatItem_Condition_Relation))
|
||||
Relation = mappings[Field.DatItem_Condition_Relation];
|
||||
|
||||
if (mappings.Keys.Contains(Field.DatItem_ConditionValue))
|
||||
ConditionValue = mappings[Field.DatItem_ConditionValue];
|
||||
else if (mappings.Keys.Contains(Field.DatItem_Condition_Value))
|
||||
ConditionValue = mappings[Field.DatItem_Condition_Value];
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -161,24 +168,40 @@ namespace SabreTools.Library.DatItems
|
||||
return false;
|
||||
if (filter.DatItem_Tag.MatchesNegativeSet(Tag) == true)
|
||||
return false;
|
||||
if (filter.DatItem_Condition_Tag.MatchesPositiveSet(Tag) == false)
|
||||
return false;
|
||||
if (filter.DatItem_Condition_Tag.MatchesNegativeSet(Tag) == true)
|
||||
return false;
|
||||
|
||||
// Filter on mask
|
||||
if (filter.DatItem_Mask.MatchesPositiveSet(Mask) == false)
|
||||
return false;
|
||||
if (filter.DatItem_Mask.MatchesNegativeSet(Mask) == true)
|
||||
return false;
|
||||
if (filter.DatItem_Condition_Mask.MatchesPositiveSet(Mask) == false)
|
||||
return false;
|
||||
if (filter.DatItem_Condition_Mask.MatchesNegativeSet(Mask) == true)
|
||||
return false;
|
||||
|
||||
// Filter on mask
|
||||
if (filter.DatItem_Relation.MatchesPositiveSet(Relation) == false)
|
||||
return false;
|
||||
if (filter.DatItem_Relation.MatchesNegativeSet(Relation) == true)
|
||||
return false;
|
||||
if (filter.DatItem_Condition_Relation.MatchesPositiveSet(Relation) == false)
|
||||
return false;
|
||||
if (filter.DatItem_Condition_Relation.MatchesNegativeSet(Relation) == true)
|
||||
return false;
|
||||
|
||||
// Filter on value
|
||||
if (filter.DatItem_ConditionValue.MatchesPositiveSet(ConditionValue) == false)
|
||||
return false;
|
||||
if (filter.DatItem_ConditionValue.MatchesNegativeSet(ConditionValue) == true)
|
||||
return false;
|
||||
if (filter.DatItem_Condition_Value.MatchesPositiveSet(ConditionValue) == false)
|
||||
return false;
|
||||
if (filter.DatItem_Condition_Value.MatchesNegativeSet(ConditionValue) == true)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -195,15 +218,23 @@ namespace SabreTools.Library.DatItems
|
||||
// Remove the fields
|
||||
if (fields.Contains(Field.DatItem_Tag))
|
||||
Tag = null;
|
||||
else if (fields.Contains(Field.DatItem_Condition_Tag))
|
||||
Tag = null;
|
||||
|
||||
if (fields.Contains(Field.DatItem_Mask))
|
||||
Mask = null;
|
||||
else if (fields.Contains(Field.DatItem_Condition_Mask))
|
||||
Mask = null;
|
||||
|
||||
if (fields.Contains(Field.DatItem_Relation))
|
||||
Relation = null;
|
||||
else if (fields.Contains(Field.DatItem_Condition_Relation))
|
||||
Relation = null;
|
||||
|
||||
if (fields.Contains(Field.DatItem_ConditionValue))
|
||||
ConditionValue = null;
|
||||
else if (fields.Contains(Field.DatItem_Condition_Value))
|
||||
ConditionValue = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -230,15 +261,23 @@ namespace SabreTools.Library.DatItems
|
||||
// Replace the fields
|
||||
if (fields.Contains(Field.DatItem_Tag))
|
||||
Tag = newItem.Tag;
|
||||
else if (fields.Contains(Field.DatItem_Condition_Tag))
|
||||
Tag = newItem.Tag;
|
||||
|
||||
if (fields.Contains(Field.DatItem_Mask))
|
||||
Mask = newItem.Mask;
|
||||
else if (fields.Contains(Field.DatItem_Condition_Mask))
|
||||
Mask = newItem.Mask;
|
||||
|
||||
if (fields.Contains(Field.DatItem_Relation))
|
||||
Relation = newItem.Relation;
|
||||
else if (fields.Contains(Field.DatItem_Condition_Relation))
|
||||
Relation = newItem.Relation;
|
||||
|
||||
if (fields.Contains(Field.DatItem_ConditionValue))
|
||||
ConditionValue = newItem.ConditionValue;
|
||||
else if (fields.Contains(Field.DatItem_Condition_Value))
|
||||
ConditionValue = newItem.ConditionValue;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user