Fix everything with subitems

This commit is contained in:
Matt Nadareski
2020-09-03 15:02:59 -07:00
parent 57b3521582
commit 45fb1ebfe7
11 changed files with 488 additions and 138 deletions

View File

@@ -68,7 +68,7 @@ namespace SabreTools.Library.DatItems
{ {
foreach (Condition condition in Conditions) foreach (Condition condition in Conditions)
{ {
condition.SetFields(mappings); condition.SetFields(mappings, true);
} }
} }
} }
@@ -194,7 +194,7 @@ namespace SabreTools.Library.DatItems
{ {
foreach (Condition condition in Conditions) foreach (Condition condition in Conditions)
{ {
if (!condition.PassesFilter(filter)) if (!condition.PassesFilter(filter, true))
return false; return false;
} }
} }
@@ -222,7 +222,7 @@ namespace SabreTools.Library.DatItems
{ {
foreach (Condition condition in Conditions) foreach (Condition condition in Conditions)
{ {
condition.RemoveFields(fields); condition.RemoveFields(fields, true);
} }
} }
} }
@@ -265,7 +265,9 @@ namespace SabreTools.Library.DatItems
if (fields.Contains(Field.DatItem_Default)) if (fields.Contains(Field.DatItem_Default))
Default = newItem.Default; Default = newItem.Default;
// Field replacement doesn't make sense for DatItem_Condition* // DatItem_Condition_* doesn't make sense here
// since not every condition under the other item
// can replace every condition under this item
} }
#endregion #endregion

View File

@@ -102,9 +102,9 @@ namespace SabreTools.Library.DatItems
return false; return false;
// Filter on mask // Filter on mask
if (filter.DatItem_Mask.MatchesPositiveSet(Mask) == false) if (filter.DatItem_Analog_Mask.MatchesPositiveSet(Mask) == false)
return false; return false;
if (filter.DatItem_Mask.MatchesNegativeSet(Mask) == true) if (filter.DatItem_Analog_Mask.MatchesNegativeSet(Mask) == true)
return false; return false;
return true; return true;

View File

@@ -60,11 +60,11 @@ namespace SabreTools.Library.DatItems
if (mappings.Keys.Contains(Field.DatItem_Name)) if (mappings.Keys.Contains(Field.DatItem_Name))
Name = mappings[Field.DatItem_Name]; Name = mappings[Field.DatItem_Name];
if (mappings.Keys.Contains(Field.DatItem_Default))
Default = mappings[Field.DatItem_Default].AsYesNo();
if (mappings.Keys.Contains(Field.DatItem_Description)) if (mappings.Keys.Contains(Field.DatItem_Description))
Description = mappings[Field.DatItem_Description]; Description = mappings[Field.DatItem_Description];
if (mappings.Keys.Contains(Field.DatItem_Default))
Default = mappings[Field.DatItem_Default].AsYesNo();
} }
#endregion #endregion
@@ -115,7 +115,9 @@ namespace SabreTools.Library.DatItems
BiosSet newOther = other as BiosSet; BiosSet newOther = other as BiosSet;
// If the BiosSet information matches // If the BiosSet information matches
return (Name == newOther.Name && Description == newOther.Description && Default == newOther.Default); return (Name == newOther.Name
&& Description == newOther.Description
&& Default == newOther.Default);
} }
#endregion #endregion

View File

@@ -47,30 +47,49 @@ namespace SabreTools.Library.DatItems
/// </summary> /// </summary>
/// <param name="mappings">Mappings dictionary</param> /// <param name="mappings">Mappings dictionary</param>
public override void SetFields(Dictionary<Field, string> mappings) public override void SetFields(Dictionary<Field, string> mappings)
{
SetFields(mappings, false);
}
/// <summary>
/// Set fields with given values
/// </summary>
/// <param name="mappings">Mappings dictionary</param>
/// <param name="sub">True if this is a subitem, false otherwise</param>
public void SetFields(Dictionary<Field, string> mappings, bool sub)
{ {
// Set base fields // Set base fields
base.SetFields(mappings); base.SetFields(mappings);
// Handle Condition-specific fields // Handle Condition-specific fields
if (sub)
{
if (mappings.Keys.Contains(Field.DatItem_Condition_Tag))
Tag = mappings[Field.DatItem_Condition_Tag];
if (mappings.Keys.Contains(Field.DatItem_Condition_Mask))
Mask = mappings[Field.DatItem_Condition_Mask];
if (mappings.Keys.Contains(Field.DatItem_Condition_Relation))
Relation = mappings[Field.DatItem_Condition_Relation];
if (mappings.Keys.Contains(Field.DatItem_Condition_Value))
Value = mappings[Field.DatItem_Condition_Value];
}
else
{
if (mappings.Keys.Contains(Field.DatItem_Tag)) if (mappings.Keys.Contains(Field.DatItem_Tag))
Tag = mappings[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)) if (mappings.Keys.Contains(Field.DatItem_Mask))
Mask = mappings[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)) if (mappings.Keys.Contains(Field.DatItem_Relation))
Relation = mappings[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_Value)) if (mappings.Keys.Contains(Field.DatItem_Value))
Value = mappings[Field.DatItem_Value]; Value = mappings[Field.DatItem_Value];
else if (mappings.Keys.Contains(Field.DatItem_Condition_Value)) }
Value = mappings[Field.DatItem_Condition_Value];
} }
#endregion #endregion
@@ -137,50 +156,74 @@ namespace SabreTools.Library.DatItems
/// <param name="filter">Filter to check against</param> /// <param name="filter">Filter to check against</param>
/// <returns>True if the item passed the filter, false otherwise</returns> /// <returns>True if the item passed the filter, false otherwise</returns>
public override bool PassesFilter(Filter filter) public override bool PassesFilter(Filter filter)
{
return PassesFilter(filter, false);
}
/// <summary>
/// Check to see if a DatItem passes the filter
/// </summary>
/// <param name="filter">Filter to check against</param>
/// <param name="sub">True if this is a subitem, false otherwise</param>
/// <returns>True if the item passed the filter, false otherwise</returns>
public bool PassesFilter(Filter filter, bool sub)
{ {
// Check common fields first // Check common fields first
if (!base.PassesFilter(filter)) if (!base.PassesFilter(filter))
return false; return false;
if (sub)
{
// Filter on tag
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_Condition_Mask.MatchesPositiveSet(Mask) == false)
return false;
if (filter.DatItem_Condition_Mask.MatchesNegativeSet(Mask) == true)
return false;
// Filter on relation
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_Condition_Value.MatchesPositiveSet(Value) == false)
return false;
if (filter.DatItem_Condition_Value.MatchesNegativeSet(Value) == true)
return false;
}
else
{
// Filter on tag // Filter on tag
if (filter.DatItem_Tag.MatchesPositiveSet(Tag) == false) if (filter.DatItem_Tag.MatchesPositiveSet(Tag) == false)
return false; return false;
if (filter.DatItem_Tag.MatchesNegativeSet(Tag) == true) if (filter.DatItem_Tag.MatchesNegativeSet(Tag) == true)
return false; 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 // Filter on mask
if (filter.DatItem_Mask.MatchesPositiveSet(Mask) == false) if (filter.DatItem_Mask.MatchesPositiveSet(Mask) == false)
return false; return false;
if (filter.DatItem_Mask.MatchesNegativeSet(Mask) == true) if (filter.DatItem_Mask.MatchesNegativeSet(Mask) == true)
return false; 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 // Filter on relation
if (filter.DatItem_Relation.MatchesPositiveSet(Relation) == false) if (filter.DatItem_Relation.MatchesPositiveSet(Relation) == false)
return false; return false;
if (filter.DatItem_Relation.MatchesNegativeSet(Relation) == true) if (filter.DatItem_Relation.MatchesNegativeSet(Relation) == true)
return false; 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 // Filter on value
if (filter.DatItem_Value.MatchesPositiveSet(Value) == false) if (filter.DatItem_Value.MatchesPositiveSet(Value) == false)
return false; return false;
if (filter.DatItem_Value.MatchesNegativeSet(Value) == true) if (filter.DatItem_Value.MatchesNegativeSet(Value) == true)
return false; return false;
if (filter.DatItem_Condition_Value.MatchesPositiveSet(Value) == false) }
return false;
if (filter.DatItem_Condition_Value.MatchesNegativeSet(Value) == true)
return false;
return true; return true;
} }
@@ -190,30 +233,49 @@ namespace SabreTools.Library.DatItems
/// </summary> /// </summary>
/// <param name="fields">List of Fields to remove</param> /// <param name="fields">List of Fields to remove</param>
public override void RemoveFields(List<Field> fields) public override void RemoveFields(List<Field> fields)
{
RemoveFields(fields, false);
}
/// <summary>
/// Remove fields from the DatItem
/// </summary>
/// <param name="fields">List of Fields to remove</param>
/// <param name="sub">True if this is a subitem, false otherwise</param>
public void RemoveFields(List<Field> fields, bool sub)
{ {
// Remove common fields first // Remove common fields first
base.RemoveFields(fields); base.RemoveFields(fields);
// Remove the fields // Remove the fields
if (fields.Contains(Field.DatItem_Tag)) if (sub)
{
if (fields.Contains(Field.DatItem_Condition_Tag))
Tag = null; Tag = null;
else if (fields.Contains(Field.DatItem_Condition_Tag))
if (fields.Contains(Field.DatItem_Condition_Mask))
Mask = null;
if (fields.Contains(Field.DatItem_Condition_Relation))
Relation = null;
if (fields.Contains(Field.DatItem_Condition_Value))
Value = null;
}
else
{
if (fields.Contains(Field.DatItem_Tag))
Tag = null; Tag = null;
if (fields.Contains(Field.DatItem_Mask)) if (fields.Contains(Field.DatItem_Mask))
Mask = null; Mask = null;
else if (fields.Contains(Field.DatItem_Condition_Mask))
Mask = null;
if (fields.Contains(Field.DatItem_Relation)) if (fields.Contains(Field.DatItem_Relation))
Relation = null; Relation = null;
else if (fields.Contains(Field.DatItem_Condition_Relation))
Relation = null;
if (fields.Contains(Field.DatItem_Value)) if (fields.Contains(Field.DatItem_Value))
Value = null; Value = null;
else if (fields.Contains(Field.DatItem_Condition_Value)) }
Value = null;
} }
#endregion #endregion
@@ -238,6 +300,7 @@ namespace SabreTools.Library.DatItems
Condition newItem = item as Condition; Condition newItem = item as Condition;
// Replace the fields // Replace the fields
// TODO: Would this ever make sense to have these `else` statements?
if (fields.Contains(Field.DatItem_Tag)) if (fields.Contains(Field.DatItem_Tag))
Tag = newItem.Tag; Tag = newItem.Tag;
else if (fields.Contains(Field.DatItem_Condition_Tag)) else if (fields.Contains(Field.DatItem_Condition_Tag))

View File

@@ -84,16 +84,14 @@ namespace SabreTools.Library.DatItems
if (mappings.Keys.Contains(Field.DatItem_Mask)) if (mappings.Keys.Contains(Field.DatItem_Mask))
Mask = mappings[Field.DatItem_Mask]; Mask = mappings[Field.DatItem_Mask];
// Field.DatItem_Conditions does not apply here
if (Conditions != null) if (Conditions != null)
{ {
foreach (Condition condition in Conditions) foreach (Condition condition in Conditions)
{ {
condition.SetFields(mappings); condition.SetFields(mappings, true);
} }
} }
// Field.DatItem_Locations does not apply here
if (Locations != null) if (Locations != null)
{ {
foreach (Location location in Locations) foreach (Location location in Locations)
@@ -102,7 +100,6 @@ namespace SabreTools.Library.DatItems
} }
} }
// Field.DatItem_Settings does not apply here
if (Settings != null) if (Settings != null)
{ {
foreach (Setting setting in Settings) foreach (Setting setting in Settings)
@@ -163,7 +160,9 @@ namespace SabreTools.Library.DatItems
Configuration newOther = other as Configuration; Configuration newOther = other as Configuration;
// If the Configuration information matches // If the Configuration information matches
bool match = (Name == newOther.Name && Tag == newOther.Tag && Mask == newOther.Mask); bool match = (Name == newOther.Name
&& Tag == newOther.Tag
&& Mask == newOther.Mask);
if (!match) if (!match)
return match; return match;
@@ -262,7 +261,7 @@ namespace SabreTools.Library.DatItems
{ {
foreach (Condition condition in Conditions) foreach (Condition condition in Conditions)
{ {
if (!condition.PassesFilter(filter)) if (!condition.PassesFilter(filter, true))
return false; return false;
} }
} }
@@ -313,7 +312,7 @@ namespace SabreTools.Library.DatItems
{ {
foreach (Condition condition in Conditions) foreach (Condition condition in Conditions)
{ {
condition.RemoveFields(fields); condition.RemoveFields(fields, true);
} }
} }
@@ -375,9 +374,17 @@ namespace SabreTools.Library.DatItems
if (fields.Contains(Field.DatItem_Mask)) if (fields.Contains(Field.DatItem_Mask))
Mask = newItem.Mask; Mask = newItem.Mask;
// Field replacement doesn't make sense for DatItem_Condition* // DatItem_Condition_* doesn't make sense here
// Field replacement doesn't make sense for DatItem_Location* // since not every condition under the other item
// Field replacement doesn't make sense for DatItem_Setting* // can replace every condition under this item
// DatItem_Location_* doesn't make sense here
// since not every location under the other item
// can replace every location under this item
// DatItem_Setting_* doesn't make sense here
// since not every setting under the other item
// can replace every setting under this item
} }
#endregion #endregion

View File

@@ -85,8 +85,21 @@ namespace SabreTools.Library.DatItems
if (mappings.Keys.Contains(Field.DatItem_Interface)) if (mappings.Keys.Contains(Field.DatItem_Interface))
Interface = mappings[Field.DatItem_Interface]; Interface = mappings[Field.DatItem_Interface];
// TODO: Handle DatItem_Instance* if (Instances != null)
// TODO: Handle DatItem_Extension* {
foreach (Instance instance in Instances)
{
instance.SetFields(mappings);
}
}
if (Extensions != null)
{
foreach (Extension extension in Extensions)
{
extension.SetFields(mappings);
}
}
} }
#endregion #endregion
@@ -140,14 +153,33 @@ namespace SabreTools.Library.DatItems
Device newOther = other as Device; Device newOther = other as Device;
// If the Device information matches // If the Device information matches
return (DeviceType == newOther.DeviceType bool match = (DeviceType == newOther.DeviceType
&& Tag == newOther.Tag && Tag == newOther.Tag
&& FixedImage == newOther.FixedImage && FixedImage == newOther.FixedImage
&& Mandatory == newOther.Mandatory && Mandatory == newOther.Mandatory
&& Interface == newOther.Interface); && Interface == newOther.Interface);
if (!match)
return match;
// TODO: Handle DatItem_Instance* // If the instances match
// TODO: Handle DatItem_Extension* if (Instances != null)
{
foreach (Instance instance in Instances)
{
match &= newOther.Instances.Contains(instance);
}
}
// If the extensions match
if (Extensions != null)
{
foreach (Extension extension in Extensions)
{
match &= newOther.Extensions.Contains(extension);
}
}
return match;
} }
#endregion #endregion
@@ -195,8 +227,25 @@ namespace SabreTools.Library.DatItems
if (filter.DatItem_Interface.MatchesNegativeSet(Interface) == true) if (filter.DatItem_Interface.MatchesNegativeSet(Interface) == true)
return false; return false;
// TODO: Handle DatItem_Instance* // Filter on individual instances
// TODO: Handle DatItem_Extension* if (Instances != null)
{
foreach (Instance instance in Instances)
{
if (!instance.PassesFilter(filter))
return false;
}
}
// Filter on individual extensions
if (Extensions != null)
{
foreach (Extension extension in Extensions)
{
if (!extension.PassesFilter(filter))
return false;
}
}
return true; return true;
} }
@@ -226,8 +275,21 @@ namespace SabreTools.Library.DatItems
if (fields.Contains(Field.DatItem_Interface)) if (fields.Contains(Field.DatItem_Interface))
Interface = null; Interface = null;
// TODO: Handle DatItem_Instance* if (Instances != null)
// TODO: Handle DatItem_Extension* {
foreach (Instance instance in Instances)
{
instance.RemoveFields(fields);
}
}
if (Extensions != null)
{
foreach (Extension extension in Extensions)
{
extension.RemoveFields(fields);
}
}
} }
#endregion #endregion
@@ -267,8 +329,13 @@ namespace SabreTools.Library.DatItems
if (fields.Contains(Field.DatItem_Interface)) if (fields.Contains(Field.DatItem_Interface))
Interface = newItem.Interface; Interface = newItem.Interface;
// TODO: Handle DatItem_Instance* // DatItem_Instance_* doesn't make sense here
// TODO: Handle DatItem_Extension* // since not every instance under the other item
// can replace every instance under this item
// DatItem_Extension_* doesn't make sense here
// since not every extension under the other item
// can replace every extension under this item
} }
#endregion #endregion

View File

@@ -101,9 +101,29 @@ namespace SabreTools.Library.DatItems
if (mappings.Keys.Contains(Field.DatItem_Mask)) if (mappings.Keys.Contains(Field.DatItem_Mask))
Mask = mappings[Field.DatItem_Mask]; Mask = mappings[Field.DatItem_Mask];
// TODO: Handle DatItem_Condition* if (Conditions != null)
// TODO: Handle DatItem_Location* {
// TODO: Handle DatItem_Value* foreach (Condition condition in Conditions)
{
condition.SetFields(mappings, true);
}
}
if (Locations != null)
{
foreach (Location location in Locations)
{
location.SetFields(mappings);
}
}
if (Values != null)
{
foreach (Setting value in Values)
{
value.SetFields(mappings);
}
}
#endregion #endregion
@@ -151,7 +171,6 @@ namespace SabreTools.Library.DatItems
{ {
return new DipSwitch() return new DipSwitch()
{ {
Name = this.Name,
ItemType = this.ItemType, ItemType = this.ItemType,
DupeType = this.DupeType, DupeType = this.DupeType,
@@ -159,6 +178,7 @@ namespace SabreTools.Library.DatItems
Source = this.Source.Clone() as Source, Source = this.Source.Clone() as Source,
Remove = this.Remove, Remove = this.Remove,
Name = this.Name,
Tag = this.Tag, Tag = this.Tag,
Mask = this.Mask, Mask = this.Mask,
Conditions = this.Conditions, Conditions = this.Conditions,
@@ -183,11 +203,42 @@ namespace SabreTools.Library.DatItems
DipSwitch newOther = other as DipSwitch; DipSwitch newOther = other as DipSwitch;
// If the DipSwitch information matches // If the DipSwitch information matches
return (Name == newOther.Name && Tag == newOther.Tag && Mask == newOther.Mask); bool match = (Name == newOther.Name
&& Tag == newOther.Tag
&& Mask == newOther.Mask);
if (!match)
return match;
// TODO: Handle DatItem_Condition* // TODO: Handle Part*
// TODO: Handle DatItem_Location*
// TODO: Handle DatItem_Value* // If the conditions match
if (Conditions != null)
{
foreach (Condition condition in Conditions)
{
match &= newOther.Conditions.Contains(condition);
}
}
// If the locations match
if (Locations != null)
{
foreach (Location location in Locations)
{
match &= newOther.Locations.Contains(location);
}
}
// If the values match
if (Values != null)
{
foreach (Setting value in Values)
{
match &= newOther.Values.Contains(value);
}
}
return match;
} }
#endregion #endregion
@@ -252,9 +303,35 @@ namespace SabreTools.Library.DatItems
if (filter.DatItem_Mask.MatchesNegativeSet(Mask) == true) if (filter.DatItem_Mask.MatchesNegativeSet(Mask) == true)
return false; return false;
// TODO: Handle DatItem_Condition* // Filter on individual conditions
// TODO: Handle DatItem_Location* if (Conditions != null)
// TODO: Handle DatItem_Value* {
foreach (Condition condition in Conditions)
{
if (!condition.PassesFilter(filter, true))
return false;
}
}
// Filter on individual locations
if (Locations != null)
{
foreach (Location location in Locations)
{
if (!location.PassesFilter(filter))
return false;
}
}
// Filter on individual conditions
if (Values != null)
{
foreach (Setting value in Values)
{
if (!value.PassesFilter(filter))
return false;
}
}
#endregion #endregion
@@ -301,9 +378,29 @@ namespace SabreTools.Library.DatItems
if (fields.Contains(Field.DatItem_Mask)) if (fields.Contains(Field.DatItem_Mask))
Mask = null; Mask = null;
// TODO: Handle DatItem_Condition* if (Conditions != null)
// TODO: Handle DatItem_Location* {
// TODO: Handle DatItem_Value* foreach (Condition condition in Conditions)
{
condition.RemoveFields(fields, true);
}
}
if (Locations != null)
{
foreach (Location location in Locations)
{
location.RemoveFields(fields);
}
}
if (Values != null)
{
foreach (Setting value in Values)
{
value.RemoveFields(fields);
}
}
#endregion #endregion
@@ -364,9 +461,17 @@ namespace SabreTools.Library.DatItems
if (fields.Contains(Field.DatItem_Mask)) if (fields.Contains(Field.DatItem_Mask))
Mask = newItem.Mask; Mask = newItem.Mask;
// TODO: Handle DatItem_Condition* // DatItem_Condition_* doesn't make sense here
// TODO: Handle DatItem_Location* // since not every condition under the other item
// TODO: Handle DatItem_Value* // can replace every condition under this item
// DatItem_Location_* doesn't make sense here
// since not every location under the other item
// can replace every location under this item
// DatItem_Setting_* doesn't make sense here
// since not every value under the other item
// can replace every value under this item
#endregion #endregion

View File

@@ -71,7 +71,13 @@ namespace SabreTools.Library.DatItems
if (mappings.Keys.Contains(Field.DatItem_Coins)) if (mappings.Keys.Contains(Field.DatItem_Coins))
Coins = mappings[Field.DatItem_Coins]; Coins = mappings[Field.DatItem_Coins];
// TODO: Handle DatItem_Control* if (Controls != null)
{
foreach (Control control in Controls)
{
control.SetFields(mappings);
}
}
} }
#endregion #endregion
@@ -123,12 +129,23 @@ namespace SabreTools.Library.DatItems
Input newOther = other as Input; Input newOther = other as Input;
// If the Input information matches // If the Input information matches
return (Service == newOther.Service bool match = (Service == newOther.Service
&& Tilt == newOther.Tilt && Tilt == newOther.Tilt
&& Players == newOther.Players && Players == newOther.Players
&& Coins == newOther.Coins); && Coins == newOther.Coins);
if (!match)
return match;
// TODO: Handle DatItem_Control* // If the controls match
if (Controls != null)
{
foreach (Control control in Controls)
{
match &= newOther.Controls.Contains(control);
}
}
return match;
} }
#endregion #endregion
@@ -166,7 +183,15 @@ namespace SabreTools.Library.DatItems
if (filter.DatItem_Coins.MatchesNegativeSet(Coins) == true) if (filter.DatItem_Coins.MatchesNegativeSet(Coins) == true)
return false; return false;
// TODO: Handle DatItem_Control* // Filter on individual controls
if (Controls != null)
{
foreach (Control control in Controls)
{
if (!control.PassesFilter(filter))
return false;
}
}
return true; return true;
} }
@@ -193,7 +218,13 @@ namespace SabreTools.Library.DatItems
if (fields.Contains(Field.DatItem_Coins)) if (fields.Contains(Field.DatItem_Coins))
Coins = null; Coins = null;
// TODO: Handle DatItem_Control* if (Controls != null)
{
foreach (Control control in Controls)
{
control.RemoveFields(fields);
}
}
} }
#endregion #endregion
@@ -230,7 +261,9 @@ namespace SabreTools.Library.DatItems
if (fields.Contains(Field.DatItem_Coins)) if (fields.Contains(Field.DatItem_Coins))
Coins = newItem.Coins; Coins = newItem.Coins;
// TODO: Handle DatItem_Control* // DatItem_Control_* doesn't make sense here
// since not every control under the other item
// can replace every control under this item
} }
#endregion #endregion

View File

@@ -43,7 +43,13 @@ namespace SabreTools.Library.DatItems
if (mappings.Keys.Contains(Field.DatItem_Tag)) if (mappings.Keys.Contains(Field.DatItem_Tag))
Tag = mappings[Field.DatItem_Tag]; Tag = mappings[Field.DatItem_Tag];
// TODO: Handle DatItem_Analog* if (Analogs != null)
{
foreach (Analog analog in Analogs)
{
analog.SetFields(mappings);
}
}
} }
#endregion #endregion
@@ -92,7 +98,20 @@ namespace SabreTools.Library.DatItems
Port newOther = other as Port; Port newOther = other as Port;
// If the Port information matches // If the Port information matches
return (Tag == newOther.Tag); // TODO: Handle DatItem_Analog* bool match = (Tag == newOther.Tag);
if (!match)
return match;
// If the analogs match
if (Analogs != null)
{
foreach (Analog analog in Analogs)
{
match &= newOther.Analogs.Contains(analog);
}
}
return match;
} }
#endregion #endregion
@@ -116,7 +135,15 @@ namespace SabreTools.Library.DatItems
if (filter.DatItem_Tag.MatchesNegativeSet(Tag) == true) if (filter.DatItem_Tag.MatchesNegativeSet(Tag) == true)
return false; return false;
// TODO: Handle DatItem_Analog* // Filter on individual analogs
if (Analogs != null)
{
foreach (Analog analog in Analogs)
{
if (!analog.PassesFilter(filter))
return false;
}
}
return true; return true;
} }
@@ -134,7 +161,13 @@ namespace SabreTools.Library.DatItems
if (fields.Contains(Field.DatItem_Tag)) if (fields.Contains(Field.DatItem_Tag))
Tag = null; Tag = null;
// TODO: Handle DatItem_Analog* if (Analogs != null)
{
foreach (Analog analog in Analogs)
{
analog.RemoveFields(fields);
}
}
} }
#endregion #endregion
@@ -162,7 +195,9 @@ namespace SabreTools.Library.DatItems
if (fields.Contains(Field.DatItem_Name)) if (fields.Contains(Field.DatItem_Name))
Tag = newItem.Tag; Tag = newItem.Tag;
// TODO: Handle DatItem_Analog* // DatItem_Analog_* doesn't make sense here
// since not every analog under the other item
// can replace every analog under this item
} }
#endregion #endregion

View File

@@ -72,12 +72,11 @@ namespace SabreTools.Library.DatItems
if (mappings.Keys.Contains(Field.DatItem_Setting_Default)) if (mappings.Keys.Contains(Field.DatItem_Setting_Default))
Default = mappings[Field.DatItem_Setting_Default].AsYesNo(); Default = mappings[Field.DatItem_Setting_Default].AsYesNo();
// Field.DatItem_Conditions does not apply here
if (Conditions != null) if (Conditions != null)
{ {
foreach (Condition condition in Conditions) foreach (Condition condition in Conditions)
{ {
condition.SetFields(mappings); condition.SetFields(mappings, true);
} }
} }
} }
@@ -212,7 +211,7 @@ namespace SabreTools.Library.DatItems
{ {
foreach (Condition condition in Conditions) foreach (Condition condition in Conditions)
{ {
if (!condition.PassesFilter(filter)) if (!condition.PassesFilter(filter, true))
return false; return false;
} }
} }
@@ -243,7 +242,7 @@ namespace SabreTools.Library.DatItems
{ {
foreach (Condition condition in Conditions) foreach (Condition condition in Conditions)
{ {
condition.RemoveFields(fields); condition.RemoveFields(fields, true);
} }
} }
} }
@@ -289,7 +288,9 @@ namespace SabreTools.Library.DatItems
if (fields.Contains(Field.DatItem_Setting_Default)) if (fields.Contains(Field.DatItem_Setting_Default))
Default = newItem.Default; Default = newItem.Default;
// Field replacement doesn't make sense for DatItem_Condition* // DatItem_Condition_* doesn't make sense here
// since not every condition under the other item
// can replace every condition under this item
} }
#endregion #endregion

View File

@@ -54,7 +54,13 @@ namespace SabreTools.Library.DatItems
if (mappings.Keys.Contains(Field.DatItem_Name)) if (mappings.Keys.Contains(Field.DatItem_Name))
Name = mappings[Field.DatItem_Name]; Name = mappings[Field.DatItem_Name];
// TODO: Handle DatItem_SlotOption* if (SlotOptions != null)
{
foreach (SlotOption slotOption in SlotOptions)
{
slotOption.SetFields(mappings);
}
}
} }
#endregion #endregion
@@ -104,7 +110,20 @@ namespace SabreTools.Library.DatItems
Slot newOther = other as Slot; Slot newOther = other as Slot;
// If the Slot information matches // If the Slot information matches
return (Name == newOther.Name); // TODO: Handle DatItem_SlotOption* bool match = (Name == newOther.Name);
if (!match)
return match;
// If the slot options match
if (SlotOptions != null)
{
foreach (SlotOption slotOption in SlotOptions)
{
match &= newOther.SlotOptions.Contains(slotOption);
}
}
return match;
} }
#endregion #endregion
@@ -155,7 +174,15 @@ namespace SabreTools.Library.DatItems
if (filter.DatItem_Name.MatchesNegativeSet(Name) == true) if (filter.DatItem_Name.MatchesNegativeSet(Name) == true)
return false; return false;
// TODO: Handle DatItem_SlotOption* // Filter on individual slot options
if (SlotOptions != null)
{
foreach (SlotOption slotOption in SlotOptions)
{
if (!slotOption.PassesFilter(filter))
return false;
}
}
return true; return true;
} }
@@ -173,7 +200,13 @@ namespace SabreTools.Library.DatItems
if (fields.Contains(Field.DatItem_Name)) if (fields.Contains(Field.DatItem_Name))
Name = null; Name = null;
// TODO: Handle DatItem_SlotOption* if (SlotOptions != null)
{
foreach (SlotOption slotOption in SlotOptions)
{
slotOption.RemoveFields(fields);
}
}
} }
/// <summary> /// <summary>
@@ -211,7 +244,9 @@ namespace SabreTools.Library.DatItems
if (fields.Contains(Field.DatItem_Name)) if (fields.Contains(Field.DatItem_Name))
Name = newItem.Name; Name = newItem.Name;
// TODO: Handle DatItem_SlotOption* // DatItem_SlotOption_* doesn't make sense here
// since not every slot option under the other item
// can replace every slot option under this item
} }
#endregion #endregion