Add attribute for starting items
This commit is contained in:
@@ -57,6 +57,18 @@
|
||||
public string Setting { get; }
|
||||
}
|
||||
|
||||
internal class AddStartingItemsAttribute : RandomizerSpecificAttribute {
|
||||
public AddStartingItemsAttribute(params string[] items) : base(null) {
|
||||
this.Items = items;
|
||||
}
|
||||
|
||||
public AddStartingItemsAttribute(RandomizerInstance[] randomizers, params string[] items) : base(randomizers) {
|
||||
this.Items = items;
|
||||
}
|
||||
|
||||
public string[] Items { get; }
|
||||
}
|
||||
|
||||
internal class RequiredSettingAttribute : RandomizerSpecificAttribute {
|
||||
public RequiredSettingAttribute(params object[] values) : base(null) {
|
||||
this.Values = values;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
public class CommonSettingsProcessor {
|
||||
public IEnumerable<string> GetSettings(RandomizerInstance randomizer, SeedSettings settings) {
|
||||
var props = typeof(SeedSettings).GetProperties(BindingFlags.Instance | BindingFlags.Public);
|
||||
var starting = new List<string>();
|
||||
foreach (var prop in props) {
|
||||
var value = prop.GetValue(settings) ?? throw new SettingsLookupException("settings.{0} not found", prop.Name);
|
||||
var valueFieldName = value.ToString() ?? throw new SettingsLookupException("settings.{0}.ToString() returned null", prop.Name);
|
||||
@@ -28,6 +29,17 @@
|
||||
foreach (var att in fi.GetCustomAttributes<AdditionalSettingAttribute>().Where(att => att.HasRandomizer(randomizer))) {
|
||||
yield return att.Setting;
|
||||
}
|
||||
|
||||
foreach (var att in fi.GetCustomAttributes<AddStartingItemsAttribute>().Where(att => att.HasRandomizer(randomizer))) {
|
||||
foreach (var item in att.Items) {
|
||||
starting.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (starting.Count > 0) {
|
||||
yield return "--usestartinventory=true";
|
||||
yield return string.Format("--startinventory={0}", string.Join(",", starting));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user