-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathProtoAchievement.cs
101 lines (79 loc) · 2.92 KB
/
ProtoAchievement.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
namespace SpaceAge
{
public enum AchievementType
{
Undefined = 0,
Max,
Total,
First
};
public enum ValueType
{
None = 0,
Cost,
Mass,
PartsCount,
CrewCount,
TotalAssignedCrew,
Funds,
Science
};
public enum HomeConditionType
{
Default = 0,
Only,
Exclude
};
public class ProtoAchievement
{
string title = null;
public string Name { get; set; }
public string Title
{
get => title ?? $"{Name}{(IsBodySpecific ? " @ " : "")}";
set => title = value;
}
public AchievementType Type { get; set; } = AchievementType.Undefined;
public bool HasValue => Type == AchievementType.Max || Type == AchievementType.Total;
public bool HasTime => Type == AchievementType.First || Type == AchievementType.Max;
public ValueType ValueType { get; set; } = ValueType.None;
public IEnumerable<string> OnEvents { get; set; } = new List<string>();
public bool IsBodySpecific { get; set; }
public HomeConditionType Home { get; set; } = HomeConditionType.Default;
public bool CrewedOnly { get; set; }
public bool Unique { get; set; }
public string StockSynonym { get; set; } = null;
public string ScoreName { get; set; }
public double Score { get; set; }
public bool Valid => Type != AchievementType.Undefined || string.IsNullOrEmpty(Name);
public ProtoAchievement(string name) => Name = name;
public ProtoAchievement(ConfigNode node) => Load(node);
public void Load(ConfigNode node)
{
try
{
Name = node.GetString("name");
Core.Log($"Loading protoachievement {Name ?? "N/A"}...");
Title = node.GetString("title");
Type = (AchievementType)Enum.Parse(typeof(AchievementType), node.GetValue("type"), true);
if (node.HasValue("valueType"))
ValueType = (ValueType)Enum.Parse(typeof(ValueType), node.GetValue("valueType"), true);
OnEvents = node.GetValuesList("onEvent");
IsBodySpecific = node.GetBool("bodySpecific");
if (node.HasValue("home"))
Home = (HomeConditionType)Enum.Parse(typeof(HomeConditionType), node.GetValue("home"), true);
CrewedOnly = node.GetBool("crewedOnly");
Unique = node.GetBool("unique");
StockSynonym = node.GetString("stockSynonym");
ScoreName = node.GetString("scoreName");
Score = node.GetDouble("score");
}
catch (Exception)
{
Core.Log($"Error parsing a ProtoAchievement node: {node}", LogLevel.Error);
}
}
}
}