// create mod option based on underlying type and attributes of cfgField public static ModOption create(Config.Field cfgField) { ModOption option = null; #if DEBUG // trying to use all creators to check for ambiguity foreach (var c in creators) { var optionTmp = c.create(cfgField); Debug.assert(option == null || optionTmp == null, $"Options.Factory: ambiguity for field '{cfgField.path}' (both {option?.GetType().Name} and {optionTmp?.GetType().Name})"); option ??= optionTmp; } #else foreach (var c in creators) { if ((option = c.create(cfgField)) != null) { break; } } #endif if (option != null) { modifiers.ForEach(m => m.process(option)); } return(option); }
public ModOption create(Config.Field cfgField) { // creating SliderOption if we have range for the field (from RangeAttribute or SliderAttribute) if (cfgField.type != typeof(float) && cfgField.type != typeof(int)) { return(null); } var rangeAttr = cfgField.getAttr <Config.Field.RangeAttribute>(); var sliderAttr = cfgField.getAttr <SliderAttribute>(); // slider range can't be wider than field range float min = Math.Max(rangeAttr?.min ?? float.MinValue, sliderAttr?.minValue ?? float.MinValue); float max = Math.Min(rangeAttr?.max ?? float.MaxValue, sliderAttr?.maxValue ?? float.MaxValue); if (min == float.MinValue || max == float.MaxValue) // we need to have both bounds for creating slider { return(null); } // in case of custom value type we add valueFormat in that component instead of SliderOption string valueFormat = sliderAttr?.customValueType == null? sliderAttr?.valueFormat: null; string label = cfgField.getAttr <FieldAttribute>()?.label; ModOption option = new SliderOption(cfgField, label, min, max, sliderAttr?.defaultValue, valueFormat); if (sliderAttr?.customValueType != null) { option.addHandler(new Components.SliderValue.Add(sliderAttr.customValueType, sliderAttr.valueFormat)); } return(option); }
public SliderOption(Config.Field cfgField, string label, float min, float max, float?defaultValue = null, string valueFormat = null) : base(cfgField, label) { this.min = min; this.max = max; this.defaultValue = defaultValue; this.valueFormat = valueFormat; }
public void setConfigField(Config.Field cfgField) { var range = cfgField.getAttr <Config.Field.RangeAttribute>(); Debug.assert(range != null); min = range.min; max = range.max; }
public ModOption create(Config.Field cfgField) { if (cfgField.type != typeof(KeyCode)) { return(null); } return(new KeyBindOption(cfgField, cfgField.getAttr <FieldAttribute>()?.label)); }
public ModOption create(Config.Field cfgField) { if (cfgField.type != typeof(int) || !cfgField.checkAttr <ButtonAttribute>()) // it's good enough for now { return(null); } return(new ButtonOption(cfgField, cfgField.getAttr <FieldAttribute>()?.label)); }
public ModOption create(Config.Field cfgField) { if (cfgField.type != typeof(bool)) { return(null); } return(new ToggleOption(cfgField, cfgField.getAttr <FieldAttribute>()?.label)); }
public ModOption(Config.Field _cfgField, string _label) { cfgField = _cfgField; id = cfgField.path; uniqueIDs.ensureUniqueID(ref id); label = _label ?? id.clampLength(40); registerLabel(id, ref label); }
static ChoiceOption create(Config.Field cfgField, string label, string[] choices, object[] values) { if (cfgField.checkAttr <ChoiceMasterAttribute>()) { return(new ChoiceMasterOption(cfgField, label, choices, values)); } else { return(new ChoiceOption(cfgField, label, choices, values)); } }
public void process(object config, FieldInfo field) { $"Options.FieldAttribute.process fieldName:'{field.Name}' fieldType:{field.FieldType} label: '{label}'".logDbg(); var cfgField = new Config.Field(config, field, rootConfig); if (Factory.create(cfgField) is ModOption option) { add(option); } else { $"FieldAttribute.process: error while creating option for field {field.Name}".logError(); } }
public ChoiceOption(Config.Field cfgField, string label, string[] choices, object[] values = null) : base(cfgField, label) { this.choices = choices; this.values = values; // adds choice labels to LanguageHandler, changing array in the process for (int i = 0; i < choices.Length; i++) { registerLabel($"{id}.{i}", ref choices[i]); } if (id.IndexOf('.') != -1) { ValidatorPatch.patch(); } }
// create mod option based on underlying type and attributes of cfgField public static ModOption create(Config.Field cfgField) { ModOption option = null; foreach (var c in creators) { if ((option = c.create(cfgField)) != null) { break; } } if (option != null) { modifiers.ForEach(m => m.process(option)); } return(option); }
public ModOption create(Config.Field cfgField) { if (cfgField.type.IsEnum && cfgField.type != typeof(UnityEngine.KeyCode)) // add choice option for enum { var names = Enum.GetNames(cfgField.type).Select(name => name.Replace('_', ' ')).ToArray(); var values = Enum.GetValues(cfgField.type).OfType <object>().ToArray(); return(create(cfgField, cfgField.getAttr <FieldAttribute>()?.label, names, values)); } if (cfgField.type == typeof(float) || cfgField.type == typeof(int)) // creating ChoiceOption if we also have choice attribute { if (cfgField.getAttr <ChoiceAttribute>() is ChoiceAttribute choice && choice.choices.Length > 0) { return(create(cfgField, cfgField.getAttr <FieldAttribute>()?.label, choice.choices, choice.values)); } } return(null); }
public ChoiceMasterOption(Config.Field cfgField, string label, string[] choices, object[] values = null) : base(cfgField, label, choices, values) { cfgField.getAttrs <ChoiceMasterAttribute>().forEach(attr => dependants[attr.choiceValue] = convert(attr.dependants)); }
public ButtonOption(Config.Field cfgField, string label) : base(cfgField, label) { }
internal static void addField(string fieldName, Config.Field field) { fieldNames.Add(fieldName); fields[fieldName] = field; }
public ToggleOption(Config.Field cfgField, string label) : base(cfgField, label) { }
public KeyBindOption(Config.Field cfgField, string label) : base(cfgField, label) { }