mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-06-11 05:54:07 +00:00
34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
|
using System;
|
||
|
using System.Reflection;
|
||
|
using ConformalDecals.Util;
|
||
|
|
||
|
namespace ConformalDecals.Tweakables {
|
||
|
[AttributeUsage(AttributeTargets.Field)]
|
||
|
public class TweakableToggle : TweakableData {
|
||
|
// The default value for the toggle
|
||
|
public bool defaultValue;
|
||
|
public string defaultValueKey;
|
||
|
|
||
|
public TweakableToggle(string name) : base(name) {
|
||
|
defaultValueKey = name + "Default";
|
||
|
}
|
||
|
|
||
|
public override void Load(ConfigNode node) {
|
||
|
base.Load(node);
|
||
|
|
||
|
// Set the default value on first load
|
||
|
if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight) {
|
||
|
ParseUtil.ParseBoolIndirect(ref defaultValue, node, defaultValueKey);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public override void Apply(BaseField baseField, PartModule module) {
|
||
|
base.Apply(baseField, module);
|
||
|
|
||
|
// Set the default value on first load
|
||
|
if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight) {
|
||
|
baseField.FieldInfo.SetValue(module, defaultValue);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|