forked from jrossignol/ContractConfigurator
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathHasAntennaFactory.cs
60 lines (51 loc) · 2.58 KB
/
HasAntennaFactory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using KSP;
using Contracts;
using Contracts.Parameters;
using ContractConfigurator.Parameters;
namespace ContractConfigurator.RemoteTech
{
/// <summary>
/// ParameterFactory wrapper for HasAntennaParameter ContractParameter.
/// </summary>
public class HasAntennaFactory : ParameterFactory
{
protected int minCount;
protected int maxCount;
protected bool activeVessel;
protected double minRange;
protected double maxRange;
protected HasAntennaParameter.AntennaType? antennaType;
public override bool Load(ConfigNode configNode)
{
bool hasTargetBody = configNode.HasValue("targetBody");
// Load base class
bool valid = base.Load(configNode);
// Base class attempts to load a default, remove it and re-load
if (!hasTargetBody)
{
configNode.RemoveValue("targetBody");
valid &= ConfigNodeUtil.ParseValue<CelestialBody>(configNode, "targetBody", x => _targetBody = x, this, (CelestialBody)null);
}
// Before loading, verify the RemoteTech version
valid &= Util.Version.VerifyRemoteTechVersion();
valid &= ConfigNodeUtil.ParseValue<int>(configNode, "minCount", x => minCount = x, this, 1, x => Validation.GE(x, 0));
valid &= ConfigNodeUtil.ParseValue<int>(configNode, "maxCount", x => maxCount = x, this, int.MaxValue, x => Validation.GE(x, 0));
valid &= ConfigNodeUtil.ParseValue<bool>(configNode, "activeVessel", x => activeVessel = x, this, false);
valid &= ConfigNodeUtil.ParseValue<double>(configNode, "minRange", x => minRange = x, this, 0.0, x => Validation.GE(x, 0.0));
valid &= ConfigNodeUtil.ParseValue<double>(configNode, "maxRange", x => maxRange = x, this, double.MaxValue, x => Validation.GE(x, 0.0));
valid &= ConfigNodeUtil.ParseValue<HasAntennaParameter.AntennaType?>(configNode, "antennaType", x => antennaType = x, this, (HasAntennaParameter.AntennaType?)null);
valid &= ConfigNodeUtil.MutuallyExclusive(configNode, new string[] { "activeVessel" }, new string[] { "targetBody" }, this);
return valid;
}
public override ContractParameter Generate(Contract contract)
{
HasAntennaParameter param = new HasAntennaParameter(minCount, maxCount, _targetBody, activeVessel, antennaType, minRange, maxRange, title);
return param;
}
}
}