Fixed issue with logged elapsed times
[VesselSimulator.git] / KerbalEngineer / Flight / Readouts / ReadoutLibrary.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
// 
//     Kerbal Engineer Redux
// 
//     Copyright (C) 2014 CYBUTEK
// 
//     This program is free software: you can redistribute it and/or modify
//     it under the terms of the GNU General Public License as published by
//     the Free Software Foundation, either version 3 of the License, or
//     (at your option) any later version.
// 
//     This program is distributed in the hope that it will be useful,
//     but WITHOUT ANY WARRANTY; without even the implied warranty of
//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//     GNU General Public License for more details.
// 
//     You should have received a copy of the GNU General Public License
//     along with this program.  If not, see <http://www.gnu.org/licenses/>.
// 
 
#region Using Directives
 
using System;
using System.Collections.Generic;
using System.Linq;
 
using KerbalEngineer.Flight.Readouts.Miscellaneous;
using KerbalEngineer.Flight.Readouts.Orbital;
using KerbalEngineer.Flight.Readouts.Rendezvous;
using KerbalEngineer.Flight.Readouts.Surface;
using KerbalEngineer.Flight.Readouts.Vessel;
using KerbalEngineer.Settings;
 
using AltitudeSeaLevel = KerbalEngineer.Flight.Readouts.Surface.AltitudeSeaLevel;
using ApoapsisHeight = KerbalEngineer.Flight.Readouts.Orbital.ApoapsisHeight;
using OrbitalPeriod = KerbalEngineer.Flight.Readouts.Orbital.OrbitalPeriod;
using PeriapsisHeight = KerbalEngineer.Flight.Readouts.Orbital.PeriapsisHeight;
using SemiMajorAxis = KerbalEngineer.Flight.Readouts.Orbital.SemiMajorAxis;
using SemiMinorAxis = KerbalEngineer.Flight.Readouts.Orbital.SemiMinorAxis;
using TimeToApoapsis = KerbalEngineer.Flight.Readouts.Orbital.TimeToApoapsis;
using TimeToPeriapsis = KerbalEngineer.Flight.Readouts.Orbital.TimeToPeriapsis;
 
#endregion
 
namespace KerbalEngineer.Flight.Readouts
{
    public static class ReadoutLibrary
    {
        #region Fields
 
        private static List<ReadoutModule> readouts = new List<ReadoutModule>();
 
        #endregion
 
        #region Constructors
 
        /// <summary>
        ///     Sets up and populates the readout library with the stock readouts.
        /// </summary>
        static ReadoutLibrary()
        {
            try
            {
                ReadoutCategory.SetCategory("Orbital", "Readout for orbital manovoeures.");
                ReadoutCategory.SetCategory("Surface", "Surface and atmospheric readouts.");
                ReadoutCategory.SetCategory("Vessel", "Vessel performance statistics.");
                ReadoutCategory.SetCategory("Rendezvous", "Readouts for rendezvous manovoeures.");
                ReadoutCategory.SetCategory("Miscellaneous", "Miscellaneous readouts.");
 
                // Orbital
                readouts.Add(new ApoapsisHeight());
                readouts.Add(new PeriapsisHeight());
                readouts.Add(new TimeToApoapsis());
                readouts.Add(new TimeToPeriapsis());
                readouts.Add(new Inclination());
                readouts.Add(new TimeToEquatorialAscendingNode());
                readouts.Add(new TimeToEquatorialDescendingNode());
                readouts.Add(new AngleToEquatorialAscendingNode());
                readouts.Add(new AngleToEquatorialDescendingNode());
                readouts.Add(new Eccentricity());
                readouts.Add(new OrbitalSpeed());
                readouts.Add(new OrbitalPeriod());
                readouts.Add(new CurrentSoi());
                readouts.Add(new LongitudeOfAscendingNode());
                readouts.Add(new LongitudeOfPeriapsis());
                readouts.Add(new ArgumentOfPeriapsis());
                readouts.Add(new TrueAnomaly());
                readouts.Add(new MeanAnomaly());
                readouts.Add(new EccentricAnomaly());
                readouts.Add(new SemiMajorAxis());
                readouts.Add(new SemiMinorAxis());
                readouts.Add(new AngleToPrograde());
                readouts.Add(new AngleToRetrograde());
 
                // Surface
                readouts.Add(new AltitudeSeaLevel());
                readouts.Add(new AltitudeTerrain());
                readouts.Add(new VerticalSpeed());
                readouts.Add(new VerticalAcceleration());
                readouts.Add(new HorizontalSpeed());
                readouts.Add(new HorizontalAcceleration());
                readouts.Add(new Latitude());
                readouts.Add(new Longitude());
                readouts.Add(new GeeForce());
                readouts.Add(new TerminalVelocity());
                readouts.Add(new AtmosphericEfficiency());
                readouts.Add(new Biome());
                readouts.Add(new Situation());
                readouts.Add(new Slope());
                readouts.Add(new ImpactTime());
                readouts.Add(new ImpactLongitude());
                readouts.Add(new ImpactLatitude());
                readouts.Add(new ImpactAltitude());
                readouts.Add(new ImpactBiome());
 
                // Vessel
                readouts.Add(new DeltaVStaged());
                readouts.Add(new DeltaVCurrent());
                readouts.Add(new DeltaVTotal());
                readouts.Add(new DeltaVCurrentTotal());
                readouts.Add(new SpecificImpulse());
                readouts.Add(new Mass());
                readouts.Add(new Thrust());
                readouts.Add(new ThrustToWeight());
                readouts.Add(new SurfaceThrustToWeight());
                readouts.Add(new Acceleration());
                readouts.Add(new SuicideBurnAltitude());
                readouts.Add(new SuicideBurnDistance());
                readouts.Add(new SuicideBurnDeltaV());
                readouts.Add(new IntakeAirUsage());
                readouts.Add(new IntakeAirDemand());
                readouts.Add(new IntakeAirSupply());
                readouts.Add(new IntakeAirDemandSupply());
 
                // Rendezvous
                readouts.Add(new TargetSelector());
                readouts.Add(new PhaseAngle());
                readouts.Add(new InterceptAngle());
                readouts.Add(new RelativeVelocity());
                readouts.Add(new RelativeSpeed());
                readouts.Add(new RelativeInclination());
                readouts.Add(new TimeToRelativeAscendingNode());
                readouts.Add(new TimeToRelativeDescendingNode());
                readouts.Add(new AngleToRelativeAscendingNode());
                readouts.Add(new AngleToRelativeDescendingNode());
                readouts.Add(new Rendezvous.AltitudeSeaLevel());
                readouts.Add(new Rendezvous.ApoapsisHeight());
                readouts.Add(new Rendezvous.PeriapsisHeight());
                readouts.Add(new Rendezvous.TimeToApoapsis());
                readouts.Add(new Rendezvous.TimeToPeriapsis());
                readouts.Add(new Distance());
                readouts.Add(new Rendezvous.OrbitalPeriod());
                readouts.Add(new Rendezvous.SemiMajorAxis());
                readouts.Add(new Rendezvous.SemiMinorAxis());
 
                // Misc
                readouts.Add(new Separator());
                readouts.Add(new GuiSizeAdjustor());
                readouts.Add(new SimulationDelay());
                readouts.Add(new TimeReference());
 
                LoadHelpStrings();
            }
            catch (Exception ex)
            {
                Logger.Exception(ex);
            }
        }
 
        #endregion
 
        #region Properties
 
        /// <summary>
        ///     Gets and sets the available readout modules.
        /// </summary>
        public static List<ReadoutModule> Readouts
        {
            get { return readouts; }
            set { readouts = value; }
        }
 
        #endregion
 
        #region Methods: public
 
        /// <summary>
        ///     Gets a list of readout modules which are associated with the specified category.
        /// </summary>
        public static List<ReadoutModule> GetCategory(ReadoutCategory category)
        {
            return readouts.Where(r => r.Category == category).ToList();
        }
 
        /// <summary>
        ///     Gets a readout module with the specified name or class name. (Returns null if not found.)
        /// </summary>
        public static ReadoutModule GetReadout(string name)
        {
            return readouts.FirstOrDefault(r => r.Name == name || r.GetType().Name == name || r.Category + "." + r.GetType().Name == name);
        }
 
        /// <summary>
        ///     Resets all the readout modules.
        /// </summary>
        public static void Reset()
        {
            foreach (var readout in readouts)
            {
                readout.Reset();
            }
        }
 
        #endregion
 
        #region Methods: private
 
        /// <summary>
        ///     Loads the help strings from file.
        /// </summary>
        private static void LoadHelpStrings()
        {
            try
            {
                var handler = SettingHandler.Load("HelpStrings.xml");
                foreach (var readout in readouts)
                {
                    readout.HelpString = handler.GetSet(readout.Category + "." + readout.GetType().Name, readout.HelpString);
                }
                handler.Save("HelpStrings.xml");
            }
            catch (Exception ex)
            {
                Logger.Exception(ex);
            }
        }
 
        #endregion
    }
}