Write out this shit for dotnet6
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
|
||||
@@ -9,24 +10,42 @@ namespace TerraTech {
|
||||
/// </summary>
|
||||
/// <typeparam name="TValue">The type of the field value</typeparam>
|
||||
public class FieldConfiguration<TValue> {
|
||||
public string FieldName { get; }
|
||||
public ConfigEntry<TValue> DefaultMultiplier { get; }
|
||||
public Func<object, ConfigEntry<TValue>> ConditionalMultiplier { get; }
|
||||
private string _fieldName;
|
||||
private ConfigEntry<TValue> _defaultMultiplier;
|
||||
private Func<object, ConfigEntry<TValue>> _conditionalMultiplier;
|
||||
|
||||
public string FieldName {
|
||||
get { return _fieldName; }
|
||||
set { _fieldName = value; }
|
||||
}
|
||||
|
||||
public ConfigEntry<TValue> DefaultMultiplier {
|
||||
get { return _defaultMultiplier; }
|
||||
set { _defaultMultiplier = value; }
|
||||
}
|
||||
|
||||
public Func<object, ConfigEntry<TValue>> ConditionalMultiplier {
|
||||
get { return _conditionalMultiplier; }
|
||||
set { _conditionalMultiplier = value; }
|
||||
}
|
||||
|
||||
public FieldConfiguration(string fieldName, ConfigEntry<TValue> defaultMultiplier) {
|
||||
FieldName = fieldName;
|
||||
DefaultMultiplier = defaultMultiplier;
|
||||
_fieldName = fieldName;
|
||||
_defaultMultiplier = defaultMultiplier;
|
||||
}
|
||||
|
||||
public FieldConfiguration(string fieldName, ConfigEntry<TValue> defaultMultiplier,
|
||||
Func<object, ConfigEntry<TValue>> conditionalMultiplier) {
|
||||
FieldName = fieldName;
|
||||
DefaultMultiplier = defaultMultiplier;
|
||||
ConditionalMultiplier = conditionalMultiplier;
|
||||
_fieldName = fieldName;
|
||||
_defaultMultiplier = defaultMultiplier;
|
||||
_conditionalMultiplier = conditionalMultiplier;
|
||||
}
|
||||
|
||||
public ConfigEntry<TValue> GetMultiplier(object instance) {
|
||||
return ConditionalMultiplier?.Invoke(instance) ?? DefaultMultiplier;
|
||||
if (_conditionalMultiplier == null) {
|
||||
return _defaultMultiplier;
|
||||
}
|
||||
return _conditionalMultiplier(instance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +55,9 @@ namespace TerraTech {
|
||||
private readonly Traverse _parentTraverse;
|
||||
private TValue _originalValue;
|
||||
|
||||
public string FieldName => _fieldName;
|
||||
public string FieldName {
|
||||
get { return _fieldName; }
|
||||
}
|
||||
|
||||
public MultipliedField(string fieldName, ConfigEntry<TValue> multiplier, Traverse parentTraverse) {
|
||||
_fieldName = fieldName;
|
||||
@@ -145,9 +166,12 @@ namespace TerraTech {
|
||||
}
|
||||
|
||||
public void ApplyTo(IEnumerable<string> fieldNames = null) {
|
||||
var fieldsToApply = fieldNames != null
|
||||
? fieldNames.Where(name => _fields.ContainsKey(name)).Select(name => _fields[name])
|
||||
: _fields.Values;
|
||||
IEnumerable<MultipliedField<float>> fieldsToApply;
|
||||
if (fieldNames != null) {
|
||||
fieldsToApply = fieldNames.Where(name => _fields.ContainsKey(name)).Select(name => _fields[name]);
|
||||
} else {
|
||||
fieldsToApply = _fields.Values;
|
||||
}
|
||||
|
||||
foreach (var field in fieldsToApply) {
|
||||
field.Apply();
|
||||
@@ -155,9 +179,12 @@ namespace TerraTech {
|
||||
}
|
||||
|
||||
public void RestoreTo(IEnumerable<string> fieldNames = null) {
|
||||
var fieldsToRestore =
|
||||
fieldNames != null ? fieldNames.Where(name => _fields.ContainsKey(name)).Select(name => _fields[name])
|
||||
: _fields.Values;
|
||||
IEnumerable<MultipliedField<float>> fieldsToRestore;
|
||||
if (fieldNames != null) {
|
||||
fieldsToRestore = fieldNames.Where(name => _fields.ContainsKey(name)).Select(name => _fields[name]);
|
||||
} else {
|
||||
fieldsToRestore = _fields.Values;
|
||||
}
|
||||
|
||||
foreach (var field in fieldsToRestore) {
|
||||
field.Restore();
|
||||
|
Reference in New Issue
Block a user