Handle Configuration; promote Location, Setting

This commit is contained in:
Matt Nadareski
2020-09-02 22:38:00 -07:00
parent cefbc77dee
commit f9c072e78b
12 changed files with 741 additions and 93 deletions

View File

@@ -262,6 +262,9 @@ namespace SabreTools.Library.DatFiles
case ItemType.Instance: case ItemType.Instance:
datItem = datItemObj.ToObject<Instance>(); datItem = datItemObj.ToObject<Instance>();
break; break;
case ItemType.Location:
datItem = datItemObj.ToObject<Location>();
break;
case ItemType.Media: case ItemType.Media:
datItem = datItemObj.ToObject<Media>(); datItem = datItemObj.ToObject<Media>();
break; break;
@@ -280,6 +283,9 @@ namespace SabreTools.Library.DatFiles
case ItemType.Sample: case ItemType.Sample:
datItem = datItemObj.ToObject<Sample>(); datItem = datItemObj.ToObject<Sample>();
break; break;
case ItemType.Setting:
datItem = datItemObj.ToObject<Setting>();
break;
case ItemType.Slot: case ItemType.Slot:
datItem = datItemObj.ToObject<Slot>(); datItem = datItemObj.ToObject<Slot>();
break; break;

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using SabreTools.Library.DatItems; using SabreTools.Library.DatItems;
@@ -99,70 +100,6 @@ namespace SabreTools.Library.DatItems
#endregion #endregion
} }
/// <summary>
/// Represents one ListXML conflocation or diplocation
/// </summary>
[JsonObject("location")]
public class Location
{
#region Fields
/// <summary>
/// Location name
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Location ID
/// </summary>
[JsonProperty("number", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Number { get; set; }
/// <summary>
/// Determines if location is inverted or not
/// </summary>
[JsonProperty("inverted", DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool? Inverted { get; set; }
#endregion
}
/// <summary>
/// Represents one ListXML confsetting or dipvalue
/// </summary>
[JsonObject("setting")]
public class Setting
{
#region Fields
/// <summary>
/// Setting name
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Setting value
/// </summary>
[JsonProperty("value", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Value { get; set; }
/// <summary>
/// Determines if the setting is default or not
/// </summary>
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool? Default { get; set; }
/// <summary>
/// List of conditions on the setting
/// </summary>
[JsonProperty("conditions", DefaultValueHandling = DefaultValueHandling.Ignore)]
public List<Condition> Conditions { get; set; }
#endregion
}
/// <summary> /// <summary>
/// Represents one ListXML slotoption /// Represents one ListXML slotoption
/// </summary> /// </summary>

View File

@@ -4,9 +4,6 @@ using System.Linq;
using SabreTools.Library.Filtering; using SabreTools.Library.Filtering;
using Newtonsoft.Json; using Newtonsoft.Json;
/// <summary>
/// This holds all of the auxiliary types needed for proper parsing
/// </summary>
namespace SabreTools.Library.DatItems namespace SabreTools.Library.DatItems
{ {
/// <summary> /// <summary>

View File

@@ -84,9 +84,32 @@ 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* // Field.DatItem_Conditions does not apply here
// TODO: Handle DatItem_Location* if (Conditions != null)
// TODO: Handle DatItem_Setting* {
foreach (Condition condition in Conditions)
{
condition.SetFields(mappings);
}
}
// Field.DatItem_Locations does not apply here
if (Locations != null)
{
foreach (Location location in Locations)
{
location.SetFields(mappings);
}
}
// Field.DatItem_Settings does not apply here
if (Settings != null)
{
foreach (Setting setting in Settings)
{
setting.SetFields(mappings);
}
}
} }
#endregion #endregion
@@ -158,11 +181,38 @@ namespace SabreTools.Library.DatItems
Configuration newOther = other as Configuration; Configuration newOther = other as Configuration;
// If the Configuration information matches // If the Configuration 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)
// TODO: Handle DatItem_Condition* return match;
// TODO: Handle DatItem_Location*
// TODO: Handle DatItem_Setting* // 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 settings match
if (Settings != null)
{
foreach (Setting setting in Settings)
{
match &= newOther.Settings.Contains(setting);
}
}
return match;
} }
#endregion #endregion
@@ -225,9 +275,47 @@ 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 conditions
// TODO: Handle DatItem_Location* if (filter.DatItem_Conditions.MatchesNeutral(null, Conditions != null ? (bool?)(Conditions.Count > 0) : null) == false)
// TODO: Handle DatItem_Setting* return false;
// Filter on individual conditions
if (Conditions != null)
{
foreach (Condition condition in Conditions)
{
if (!condition.PassesFilter(filter))
return false;
}
}
// Filter on locations
if (filter.DatItem_Locations.MatchesNeutral(null, Locations != null ? (bool?)(Locations.Count > 0) : null) == false)
return false;
// Filter on individual locations
if (Locations != null)
{
foreach (Location location in Locations)
{
if (!location.PassesFilter(filter))
return false;
}
}
// Filter on settings
if (filter.DatItem_Settings.MatchesNeutral(null, Settings != null ? (bool?)(Settings.Count > 0) : null) == false)
return false;
// Filter on individual conditions
if (Settings != null)
{
foreach (Setting setting in Settings)
{
if (!setting.PassesFilter(filter))
return false;
}
}
return true; return true;
} }
@@ -254,15 +342,35 @@ namespace SabreTools.Library.DatItems
if (fields.Contains(Field.DatItem_Conditions)) if (fields.Contains(Field.DatItem_Conditions))
Conditions = null; Conditions = null;
if (Conditions != null)
{
foreach (Condition condition in Conditions)
{
condition.RemoveFields(fields);
}
}
if (fields.Contains(Field.DatItem_Locations)) if (fields.Contains(Field.DatItem_Locations))
Locations = null; Locations = null;
if (Locations != null)
{
foreach (Location location in Locations)
{
location.RemoveFields(fields);
}
}
if (fields.Contains(Field.DatItem_Settings)) if (fields.Contains(Field.DatItem_Settings))
Settings = null; Settings = null;
// TODO: Handle DatItem_Condition* if (Settings != null)
// TODO: Handle DatItem_Location* {
// TODO: Handle DatItem_Setting* foreach (Setting setting in Settings)
{
setting.RemoveFields(fields);
}
}
} }
/// <summary> /// <summary>
@@ -309,15 +417,17 @@ namespace SabreTools.Library.DatItems
if (fields.Contains(Field.DatItem_Conditions)) if (fields.Contains(Field.DatItem_Conditions))
Conditions = newItem.Conditions; Conditions = newItem.Conditions;
// Field replacement doesn't make sense for DatItem_Condition*
if (fields.Contains(Field.DatItem_Locations)) if (fields.Contains(Field.DatItem_Locations))
Locations = newItem.Locations; Locations = newItem.Locations;
// Field replacement doesn't make sense for DatItem_Location*
if (fields.Contains(Field.DatItem_Settings)) if (fields.Contains(Field.DatItem_Settings))
Settings = newItem.Settings; Settings = newItem.Settings;
// TODO: Handle DatItem_Condition* // Field replacement doesn't make sense for DatItem_Setting*
// TODO: Handle DatItem_Location*
// TODO: Handle DatItem_Setting*
} }
#endregion #endregion

View File

@@ -509,6 +509,9 @@ namespace SabreTools.Library.DatItems
case ItemType.Instance: case ItemType.Instance:
return new Instance(); return new Instance();
case ItemType.Location:
return new Location();
case ItemType.Media: case ItemType.Media:
return new Media(); return new Media();
@@ -527,6 +530,9 @@ namespace SabreTools.Library.DatItems
case ItemType.Sample: case ItemType.Sample:
return new Sample(); return new Sample();
case ItemType.Setting:
return new Setting();
case ItemType.Slot: case ItemType.Slot:
return new Slot(); return new Slot();
@@ -559,6 +565,7 @@ namespace SabreTools.Library.DatItems
ItemType.Extension => new Extension(), ItemType.Extension => new Extension(),
ItemType.Feature => new Feature(), ItemType.Feature => new Feature(),
ItemType.Instance => new Instance(), ItemType.Instance => new Instance(),
ItemType.Location => new Location(),
ItemType.Media => new Media(), ItemType.Media => new Media(),
ItemType.Port => new Port(), ItemType.Port => new Port(),
ItemType.RamOption => new RamOption(), ItemType.RamOption => new RamOption(),

View File

@@ -4,9 +4,6 @@ using System.Linq;
using SabreTools.Library.Filtering; using SabreTools.Library.Filtering;
using Newtonsoft.Json; using Newtonsoft.Json;
/// <summary>
/// This holds all of the auxiliary types needed for proper parsing
/// </summary>
namespace SabreTools.Library.DatItems namespace SabreTools.Library.DatItems
{ {
/// <summary> /// <summary>

View File

@@ -4,9 +4,6 @@ using SabreTools.Library.Filtering;
using Newtonsoft.Json; using Newtonsoft.Json;
using SabreTools.Library.Tools; using SabreTools.Library.Tools;
/// <summary>
/// This holds all of the auxiliary types needed for proper parsing
/// </summary>
namespace SabreTools.Library.DatItems namespace SabreTools.Library.DatItems
{ {
/// <summary> /// <summary>

View File

@@ -492,10 +492,12 @@ namespace SabreTools.Library.DatItems
Feature, Feature,
Input, Input,
Instance, Instance,
Location,
Port, Port,
RamOption, RamOption,
Release, Release,
Sample, Sample,
Setting,
Slot, Slot,
SoftwareList, SoftwareList,
Sound, Sound,

View File

@@ -4,9 +4,6 @@ using SabreTools.Library.Filtering;
using Newtonsoft.Json; using Newtonsoft.Json;
using SabreTools.Library.Tools; using SabreTools.Library.Tools;
/// <summary>
/// This holds all of the auxiliary types needed for proper parsing
/// </summary>
namespace SabreTools.Library.DatItems namespace SabreTools.Library.DatItems
{ {
/// <summary> /// <summary>

View File

@@ -0,0 +1,265 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Library.Filtering;
using Newtonsoft.Json;
using SabreTools.Library.Tools;
namespace SabreTools.Library.DatItems
{
/// <summary>
/// Represents one conflocation or diplocation
/// </summary>
[JsonObject("location")]
public class Location : DatItem
{
#region Fields
/// <summary>
/// Location name
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Location ID
/// </summary>
[JsonProperty("number", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Number { get; set; }
/// <summary>
/// Determines if location is inverted or not
/// </summary>
[JsonProperty("inverted", DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool? Inverted { get; set; }
#endregion
#region Accessors
/// <summary>
/// Gets the name to use for a DatItem
/// </summary>
/// <returns>Name if available, null otherwise</returns>
public override string GetName()
{
return Name;
}
/// <summary>
/// Set fields with given values
/// </summary>
/// <param name="mappings">Mappings dictionary</param>
public override void SetFields(Dictionary<Field, string> mappings)
{
// Set base fields
base.SetFields(mappings);
// Handle Location-specific fields
if (mappings.Keys.Contains(Field.DatItem_Location_Name))
Name = mappings[Field.DatItem_Location_Name];
if (mappings.Keys.Contains(Field.DatItem_Location_Number))
Number = mappings[Field.DatItem_Location_Number];
if (mappings.Keys.Contains(Field.DatItem_Location_Inverted))
Inverted = mappings[Field.DatItem_Location_Inverted].AsYesNo();
}
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Location object
/// </summary>
public Location()
{
Name = string.Empty;
ItemType = ItemType.Location;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Location()
{
Name = this.Name,
ItemType = this.ItemType,
DupeType = this.DupeType,
AltName = this.AltName,
AltTitle = this.AltTitle,
Original = this.Original,
OpenMSXSubType = this.OpenMSXSubType,
OpenMSXType = this.OpenMSXType,
Remark = this.Remark,
Boot = this.Boot,
Part = this.Part,
Features = this.Features,
AreaName = this.AreaName,
AreaSize = this.AreaSize,
AreaWidth = this.AreaWidth,
AreaEndianness = this.AreaEndianness,
Value = this.Value,
LoadFlag = this.LoadFlag,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Number = this.Number,
Inverted = this.Inverted,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Location, return false
if (ItemType != other.ItemType)
return false;
// Otherwise, treat it as a Location
Location newOther = other as Location;
// If the Location information matches
return (Name == newOther.Name
&& Number == newOther.Number
&& Inverted == newOther.Inverted);
}
#endregion
#region Filtering
/// <summary>
/// Clean a DatItem according to the cleaner
/// </summary>
/// <param name="cleaner">Cleaner to implement</param>
public override void Clean(Cleaner cleaner)
{
// Clean common items first
base.Clean(cleaner);
// If we're stripping unicode characters, strip item name
if (cleaner?.RemoveUnicode == true)
Name = Sanitizer.RemoveUnicodeCharacters(Name);
// If we are in NTFS trim mode, trim the game name
if (cleaner?.Trim == true)
{
// Windows max name length is 260
int usableLength = 260 - Machine.Name.Length - (cleaner.Root?.Length ?? 0);
if (Name.Length > usableLength)
{
string ext = Path.GetExtension(Name);
Name = Name.Substring(0, usableLength - ext.Length);
Name += ext;
}
}
}
/// <summary>
/// Check to see if a DatItem passes the filter
/// </summary>
/// <param name="filter">Filter to check against</param>
/// <returns>True if the item passed the filter, false otherwise</returns>
public override bool PassesFilter(Filter filter)
{
// Check common fields first
if (!base.PassesFilter(filter))
return false;
// Filter on item name
if (filter.DatItem_Location_Name.MatchesPositiveSet(Name) == false)
return false;
if (filter.DatItem_Location_Name.MatchesNegativeSet(Name) == true)
return false;
// Filter on number
if (filter.DatItem_Location_Number.MatchesPositiveSet(Number) == false)
return false;
if (filter.DatItem_Location_Number.MatchesNegativeSet(Number) == true)
return false;
// Filter on inverted
if (filter.DatItem_Location_Inverted.MatchesNeutral(null, Inverted) == false)
return false;
return true;
}
/// <summary>
/// Remove fields from the DatItem
/// </summary>
/// <param name="fields">List of Fields to remove</param>
public override void RemoveFields(List<Field> fields)
{
// Remove common fields first
base.RemoveFields(fields);
// Remove the fields
if (fields.Contains(Field.DatItem_Location_Name))
Name = null;
if (fields.Contains(Field.DatItem_Location_Number))
Number = null;
if (fields.Contains(Field.DatItem_Location_Inverted))
Inverted = null;
}
/// <summary>
/// Set internal names to match One Rom Per Game (ORPG) logic
/// </summary>
public override void SetOneRomPerGame()
{
string[] splitname = Name.Split('.');
Machine.Name += $"/{string.Join(".", splitname.Take(splitname.Length > 1 ? splitname.Length - 1 : 1))}";
Name = Path.GetFileName(Name);
}
#endregion
#region Sorting and Merging
/// <summary>
/// Replace fields from another item
/// </summary>
/// <param name="item">DatItem to pull new information from</param>
/// <param name="fields">List of Fields representing what should be updated</param>
public override void ReplaceFields(DatItem item, List<Field> fields)
{
// Replace common fields first
base.ReplaceFields(item, fields);
// If we don't have a Location to replace from, ignore specific fields
if (item.ItemType != ItemType.Location)
return;
// Cast for easier access
Location newItem = item as Location;
// Replace the fields
if (fields.Contains(Field.DatItem_Location_Name))
Name = newItem.Name;
if (fields.Contains(Field.DatItem_Location_Number))
Number = newItem.Number;
if (fields.Contains(Field.DatItem_Location_Inverted))
Inverted = newItem.Inverted;
}
#endregion
}
}

View File

@@ -0,0 +1,321 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Library.Filtering;
using Newtonsoft.Json;
using SabreTools.Library.Tools;
namespace SabreTools.Library.DatItems
{
/// <summary>
/// Represents one ListXML confsetting or dipvalue
/// </summary>
[JsonObject("setting")]
public class Setting : DatItem
{
#region Fields
/// <summary>
/// Setting name
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Setting value
/// </summary>
[JsonProperty("value", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string SettingValue { get; set; }
/// <summary>
/// Determines if the setting is default or not
/// </summary>
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool? Default { get; set; }
/// <summary>
/// List of conditions on the setting
/// </summary>
[JsonProperty("conditions", DefaultValueHandling = DefaultValueHandling.Ignore)]
public List<Condition> Conditions { get; set; }
#endregion
#region Accessors
/// <summary>
/// Gets the name to use for a DatItem
/// </summary>
/// <returns>Name if available, null otherwise</returns>
public override string GetName()
{
return Name;
}
/// <summary>
/// Set fields with given values
/// </summary>
/// <param name="mappings">Mappings dictionary</param>
public override void SetFields(Dictionary<Field, string> mappings)
{
// Set base fields
base.SetFields(mappings);
// Handle Setting-specific fields
if (mappings.Keys.Contains(Field.DatItem_Setting_Name))
Name = mappings[Field.DatItem_Setting_Name];
if (mappings.Keys.Contains(Field.DatItem_Setting_Value))
SettingValue = mappings[Field.DatItem_Setting_Value];
if (mappings.Keys.Contains(Field.DatItem_Setting_Default))
Default = mappings[Field.DatItem_Setting_Default].AsYesNo();
// Field.DatItem_Conditions does not apply here
if (Conditions != null)
{
foreach (Condition condition in Conditions)
{
condition.SetFields(mappings);
}
}
}
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Setting object
/// </summary>
public Setting()
{
Name = string.Empty;
ItemType = ItemType.Setting;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Setting()
{
Name = this.Name,
ItemType = this.ItemType,
DupeType = this.DupeType,
AltName = this.AltName,
AltTitle = this.AltTitle,
Original = this.Original,
OpenMSXSubType = this.OpenMSXSubType,
OpenMSXType = this.OpenMSXType,
Remark = this.Remark,
Boot = this.Boot,
Part = this.Part,
Features = this.Features,
AreaName = this.AreaName,
AreaSize = this.AreaSize,
AreaWidth = this.AreaWidth,
AreaEndianness = this.AreaEndianness,
Value = this.Value,
LoadFlag = this.LoadFlag,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
SettingValue = this.SettingValue,
Default = this.Default,
Conditions = this.Conditions,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Setting, return false
if (ItemType != other.ItemType)
return false;
// Otherwise, treat it as a Setting
Setting newOther = other as Setting;
// If the Setting information matches
bool match = (Name == newOther.Name
&& SettingValue == newOther.SettingValue
&& 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
#region Filtering
/// <summary>
/// Clean a DatItem according to the cleaner
/// </summary>
/// <param name="cleaner">Cleaner to implement</param>
public override void Clean(Cleaner cleaner)
{
// Clean common items first
base.Clean(cleaner);
// If we're stripping unicode characters, strip item name
if (cleaner?.RemoveUnicode == true)
Name = Sanitizer.RemoveUnicodeCharacters(Name);
// If we are in NTFS trim mode, trim the game name
if (cleaner?.Trim == true)
{
// Windows max name length is 260
int usableLength = 260 - Machine.Name.Length - (cleaner.Root?.Length ?? 0);
if (Name.Length > usableLength)
{
string ext = Path.GetExtension(Name);
Name = Name.Substring(0, usableLength - ext.Length);
Name += ext;
}
}
}
/// <summary>
/// Check to see if a DatItem passes the filter
/// </summary>
/// <param name="filter">Filter to check against</param>
/// <returns>True if the item passed the filter, false otherwise</returns>
public override bool PassesFilter(Filter filter)
{
// Check common fields first
if (!base.PassesFilter(filter))
return false;
// Filter on item name
if (filter.DatItem_Setting_Name.MatchesPositiveSet(Name) == false)
return false;
if (filter.DatItem_Setting_Name.MatchesNegativeSet(Name) == true)
return false;
// Filter on value
if (filter.DatItem_Setting_Value.MatchesPositiveSet(SettingValue) == false)
return false;
if (filter.DatItem_Setting_Value.MatchesNegativeSet(SettingValue) == true)
return false;
// Filter on default
if (filter.DatItem_Setting_Default.MatchesNeutral(null, Default) == false)
return false;
// 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;
}
/// <summary>
/// Remove fields from the DatItem
/// </summary>
/// <param name="fields">List of Fields to remove</param>
public override void RemoveFields(List<Field> fields)
{
// Remove common fields first
base.RemoveFields(fields);
// Remove the fields
if (fields.Contains(Field.DatItem_Setting_Name))
Name = null;
if (fields.Contains(Field.DatItem_Setting_Value))
SettingValue = null;
if (fields.Contains(Field.DatItem_Setting_Default))
Default = null;
if (fields.Contains(Field.DatItem_Conditions))
Conditions = null;
if (Conditions != null)
{
foreach (Condition condition in Conditions)
{
condition.RemoveFields(fields);
}
}
}
/// <summary>
/// Set internal names to match One Rom Per Game (ORPG) logic
/// </summary>
public override void SetOneRomPerGame()
{
string[] splitname = Name.Split('.');
Machine.Name += $"/{string.Join(".", splitname.Take(splitname.Length > 1 ? splitname.Length - 1 : 1))}";
Name = Path.GetFileName(Name);
}
#endregion
#region Sorting and Merging
/// <summary>
/// Replace fields from another item
/// </summary>
/// <param name="item">DatItem to pull new information from</param>
/// <param name="fields">List of Fields representing what should be updated</param>
public override void ReplaceFields(DatItem item, List<Field> fields)
{
// Replace common fields first
base.ReplaceFields(item, fields);
// If we don't have a Setting to replace from, ignore specific fields
if (item.ItemType != ItemType.Setting)
return;
// Cast for easier access
Setting newItem = item as Setting;
// Replace the fields
if (fields.Contains(Field.DatItem_Setting_Name))
Name = newItem.Name;
if (fields.Contains(Field.DatItem_Setting_Value))
SettingValue = newItem.SettingValue;
if (fields.Contains(Field.DatItem_Setting_Default))
Default = newItem.Default;
// Field replacement doesn't make sense for DatItem_Condition*
}
#endregion
}
}

View File

@@ -1675,6 +1675,8 @@ namespace SabreTools.Library.Tools
return ItemType.Input; return ItemType.Input;
case "instance": case "instance":
return ItemType.Instance; return ItemType.Instance;
case "location":
return ItemType.Location;
case "media": case "media":
return ItemType.Media; return ItemType.Media;
case "port": case "port":
@@ -1687,6 +1689,8 @@ namespace SabreTools.Library.Tools
return ItemType.Rom; return ItemType.Rom;
case "sample": case "sample":
return ItemType.Sample; return ItemType.Sample;
case "setting":
return ItemType.Setting;
case "slot": case "slot":
return ItemType.Slot; return ItemType.Slot;
case "softwarelist": case "softwarelist":
@@ -1717,12 +1721,14 @@ namespace SabreTools.Library.Tools
"feature" => ItemType.Feature, "feature" => ItemType.Feature,
"input" => ItemType.Input, "input" => ItemType.Input,
"instance" => ItemType.Instance, "instance" => ItemType.Instance,
"location" => ItemType.Location,
"media" => ItemType.Media, "media" => ItemType.Media,
"port" => ItemType.Port, "port" => ItemType.Port,
"ramoption" => ItemType.RamOption, "ramoption" => ItemType.RamOption,
"release" => ItemType.Release, "release" => ItemType.Release,
"rom" => ItemType.Rom, "rom" => ItemType.Rom,
"sample" => ItemType.Sample, "sample" => ItemType.Sample,
"setting" => ItemType.Setting,
"slot" => ItemType.Slot, "slot" => ItemType.Slot,
"softwarelist" => ItemType.SoftwareList, "softwarelist" => ItemType.SoftwareList,
"sound" => ItemType.Sound, "sound" => ItemType.Sound,
@@ -2304,6 +2310,8 @@ namespace SabreTools.Library.Tools
return "input"; return "input";
case ItemType.Instance: case ItemType.Instance:
return "instance"; return "instance";
case ItemType.Location:
return "location";
case ItemType.Media: case ItemType.Media:
return "media"; return "media";
case ItemType.Port: case ItemType.Port:
@@ -2316,6 +2324,8 @@ namespace SabreTools.Library.Tools
return "rom"; return "rom";
case ItemType.Sample: case ItemType.Sample:
return "sample"; return "sample";
case ItemType.Setting:
return "setting";
case ItemType.Slot: case ItemType.Slot:
return "slot"; return "slot";
case ItemType.SoftwareList: case ItemType.SoftwareList:
@@ -2346,12 +2356,14 @@ namespace SabreTools.Library.Tools
ItemType.Feature => "feature", ItemType.Feature => "feature",
ItemType.Input => "input", ItemType.Input => "input",
ItemType.Instance => "instance", ItemType.Instance => "instance",
ItemType.Location => "location",
ItemType.Media => "media", ItemType.Media => "media",
ItemType.Port => "port", ItemType.Port => "port",
ItemType.RamOption => "ramoption", ItemType.RamOption => "ramoption",
ItemType.Release => "release", ItemType.Release => "release",
ItemType.Rom => "rom", ItemType.Rom => "rom",
ItemType.Sample => "sample", ItemType.Sample => "sample",
ItemType.Setting => "setting",
ItemType.Slot => "slot", ItemType.Slot => "slot",
ItemType.SoftwareList => "softwarelist", ItemType.SoftwareList => "softwarelist",
ItemType.Sound => "sound", ItemType.Sound => "sound",