forked from vXSovereignXv/CrewManifest
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Models.cs
70 lines (61 loc) · 1.75 KB
/
Models.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace CrewManifest
{
public class KerbalModel
{
public ProtoCrewMember Kerbal { get; set; }
public bool IsNew { get; set; }
public float Stupidity;
public float Courage;
public bool Badass;
public string Name;
public ProtoCrewMember.Gender Gender;
public ProtoCrewMember.KerbalType Type;
public KerbalModel(ProtoCrewMember kerbal, bool isNew)
{
this.Kerbal = kerbal;
Name = kerbal.name;
Stupidity = kerbal.stupidity;
Courage = kerbal.courage;
Badass = kerbal.isBadass;
Gender = kerbal.gender;
Type = kerbal.type;
IsNew = isNew;
}
public string SubmitChanges()
{
if (NameExists())
{
return "That name is in use!";
}
if (IsNew)
{
Kerbal = HighLogic.CurrentGame.CrewRoster.GetNewKerbal();
Kerbal.rosterStatus = ProtoCrewMember.RosterStatus.Available;
}
SyncKerbal();
return string.Empty;
}
public void SyncKerbal()
{
Kerbal.ChangeName(Name);
Kerbal.stupidity = Stupidity;
Kerbal.courage = Courage;
Kerbal.isBadass = Badass;
Kerbal.gender = Gender;
Kerbal.type = Type;
}
private bool NameExists()
{
if(IsNew || Kerbal.name != Name)
{
return HighLogic.CurrentGame.CrewRoster[Name] != null;
}
return false;
}
}
}