From 4f695d907bb0f235238af90f74a8db0c2881f3d0 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Mon, 24 Feb 2025 08:48:33 +0100 Subject: [PATCH] Write out this shit for dotnet6 --- .../TerraTech/ObjectFieldMultiplier.cs | 59 ++++++++++++++----- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/Projects/TerraTech/TerraTech/ObjectFieldMultiplier.cs b/Projects/TerraTech/TerraTech/ObjectFieldMultiplier.cs index 49b9427..a67c5d0 100644 --- a/Projects/TerraTech/TerraTech/ObjectFieldMultiplier.cs +++ b/Projects/TerraTech/TerraTech/ObjectFieldMultiplier.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using BepInEx.Configuration; using HarmonyLib; @@ -9,24 +10,42 @@ namespace TerraTech { /// /// The type of the field value public class FieldConfiguration { - public string FieldName { get; } - public ConfigEntry DefaultMultiplier { get; } - public Func> ConditionalMultiplier { get; } + private string _fieldName; + private ConfigEntry _defaultMultiplier; + private Func> _conditionalMultiplier; + + public string FieldName { + get { return _fieldName; } + set { _fieldName = value; } + } + + public ConfigEntry DefaultMultiplier { + get { return _defaultMultiplier; } + set { _defaultMultiplier = value; } + } + + public Func> ConditionalMultiplier { + get { return _conditionalMultiplier; } + set { _conditionalMultiplier = value; } + } public FieldConfiguration(string fieldName, ConfigEntry defaultMultiplier) { - FieldName = fieldName; - DefaultMultiplier = defaultMultiplier; + _fieldName = fieldName; + _defaultMultiplier = defaultMultiplier; } public FieldConfiguration(string fieldName, ConfigEntry defaultMultiplier, Func> conditionalMultiplier) { - FieldName = fieldName; - DefaultMultiplier = defaultMultiplier; - ConditionalMultiplier = conditionalMultiplier; + _fieldName = fieldName; + _defaultMultiplier = defaultMultiplier; + _conditionalMultiplier = conditionalMultiplier; } public ConfigEntry 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 multiplier, Traverse parentTraverse) { _fieldName = fieldName; @@ -145,9 +166,12 @@ namespace TerraTech { } public void ApplyTo(IEnumerable fieldNames = null) { - var fieldsToApply = fieldNames != null - ? fieldNames.Where(name => _fields.ContainsKey(name)).Select(name => _fields[name]) - : _fields.Values; + IEnumerable> 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 fieldNames = null) { - var fieldsToRestore = - fieldNames != null ? fieldNames.Where(name => _fields.ContainsKey(name)).Select(name => _fields[name]) - : _fields.Values; + IEnumerable> 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();