This repository was archived by the owner on Oct 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathSettings.cs
More file actions
62 lines (54 loc) · 2.09 KB
/
Settings.cs
File metadata and controls
62 lines (54 loc) · 2.09 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 System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace EditorTime
{
public class Settings
{
public float outsourceCost = 1000;
public int outsourceTime = 10;
public float timeRatio = 1;
public Rect timeWindow = new Rect((Screen.width / 2) + 300, -30, 125, 1);
//solution to possible future problems:
//public bool isInitialized = false;
string configFilePath = string.Empty;
public Settings()
{
configFilePath = KSPUtil.ApplicationRootPath + "/GameData/EditorTime/PluginData/config.txt";
}
public void Initialize()
{
ConfigNode config = null;
if (System.IO.File.Exists(configFilePath))
{
config = ConfigNode.Load(configFilePath);
}
float x = (Screen.width / 2) + 300, y = -30;
if (config != null)
{
//no fallback is needed as all values have already been initialized elsewhere.
float.TryParse(config.GetValue(nameof(outsourceCost)), out outsourceCost);
int.TryParse(config.GetValue(nameof(outsourceTime)), out outsourceTime);
float.TryParse(config.GetValue(nameof(timeRatio)), out timeRatio);
float.TryParse(config.GetValue("WindowX"), out x);
float.TryParse(config.GetValue("WindowY"), out y);
}
timeWindow.x = x;
timeWindow.y = y;
}
public void Save()
{
System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(configFilePath));
//Save the settings
ConfigNode config = new ConfigNode();
config.AddValue(nameof(outsourceCost), outsourceCost);
config.AddValue(nameof(outsourceTime), outsourceTime);
config.AddValue(nameof(timeRatio), timeRatio);
config.AddValue("WindowX", timeWindow.x);
config.AddValue("WindowY", timeWindow.y);
config.Save(configFilePath);
}
}
}