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