-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathIgnitorResource.cs
More file actions
62 lines (54 loc) · 1.64 KB
/
IgnitorResource.cs
File metadata and controls
62 lines (54 loc) · 1.64 KB
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
61
62
using System;
using UnityEngine;
namespace EngineIgnitor
{
[Serializable]
internal class KerbalInfo
{
public KerbalInfo()
{
VesselId = 0;
KerbalName = string.Empty;
Time = 0;
FoundIgnitors = 0;
}
public int VesselId { get; set; }
public string KerbalName { get; set; }
public int Time { get; set; }
public double FoundIgnitors { get; set; }
}
[Serializable]
public class IgnitorResource : IConfigNode
{
[SerializeField]
public string Name;
[SerializeField]
public float Amount;
public float CurrentAmount;
public void Load(ConfigNode node)
{
Name = node.GetValue("name");
if (node.HasValue("amount"))
{
Amount = Mathf.Max(0.0f, float.Parse(node.GetValue("amount")));
}
}
public void Save(ConfigNode node)
{
node.AddValue("name", Name);
node.AddValue("amount", Mathf.Max(0.0f, Amount));
}
public override string ToString()
{
return Name + "(" + Amount.ToString("F3") + ")";
}
public static IgnitorResource FromString(string str)
{
IgnitorResource ir = new IgnitorResource();
int indexL = str.LastIndexOf('('); int indexR = str.LastIndexOf(')');
ir.Name = str.Substring(0, indexL);
ir.Amount = float.Parse(str.Substring(indexL + 1, indexR - indexL - 1));
return ir;
}
}
}