-
Notifications
You must be signed in to change notification settings - Fork 8
/
CameraWriteSettings.cs
180 lines (155 loc) · 5.05 KB
/
CameraWriteSettings.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
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
namespace Spark
{
class CameraWriteSettings
{
#region Settings
public string activeAnimation { get; set; } = "";
public Dictionary<string, CameraTransform> waypoints { get; } = new Dictionary<string, CameraTransform>();
public float rotSpeed { get; set; } = 30;
public float orbitRadius { get; set; } = 2;
public float followSmoothing { get; set; } = 1f;
public float lagCompDiscFollow { get; set; } = 0f;
public float spaceMouseMoveSpeed { get; set; } = .5f;
public float spaceMouseRotateSpeed { get; set; } = .2f;
public float spaceMouseMoveExponential { get; set; } = 1.5f;
public float spaceMouseRotateExponential { get; set; } = 1.5f;
public float joystickMoveSpeed { get; set; } = .5f;
public float joystickRotateSpeed { get; set; } = .1f;
public float joystickMoveExponential { get; set; } = 1.2f;
public float joystickRotateExponential { get; set; } = 1.2f;
public float xPlanePosMultiplier { get; set; } = .1f;
public bool enableHotKeys { get; set; } = false;
#endregion
public static CameraWriteSettings instance;
public static Dictionary<string, AnimationKeyframes> animations;
public void Save()
{
try
{
string settingsFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "IgniteVR", "Spark");
string filename = Path.Combine(settingsFolder, "camerawrite_settings.json");
string animationsFolder = Path.Combine(settingsFolder, "Animations");
Task.Run(() =>
{
try
{
if (!File.Exists(Path.GetDirectoryName(filename)))
{
Directory.CreateDirectory(Path.GetDirectoryName(filename));
}
string json = JsonConvert.SerializeObject(this, Formatting.Indented);
File.WriteAllText(filename, json);
// animation files
if (!Directory.Exists(animationsFolder))
{
Console.WriteLine("Animations folder doesn't exist, creating.");
Directory.CreateDirectory(animationsFolder);
}
foreach (var anim in animations)
{
if (anim.Value != null)
{
string animJson = JsonConvert.SerializeObject(anim.Value, Formatting.Indented);
File.WriteAllText(Path.Combine(animationsFolder, anim.Key + ".json"), animJson);
}
}
}
catch (Exception e)
{
Console.WriteLine($"Error writing to settings file\n{e}");
}
});
}
catch (Exception e)
{
Console.WriteLine($"Error writing to settings file (outside)\n{e}");
}
}
public static void Load()
{
string settingsFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "IgniteVR", "Spark");
string filename = Path.Combine(settingsFolder, "camerawrite_settings.json");
string animationsFolder = Path.Combine(settingsFolder, "Animations");
try
{
// general settings file
if (File.Exists(filename))
{
string json = File.ReadAllText(filename);
instance = JsonConvert.DeserializeObject<CameraWriteSettings>(json);
}
else
{
Console.WriteLine($"Settings file doesn't exist, creating.");
instance = new CameraWriteSettings();
}
}
catch (Exception e)
{
Console.WriteLine($"Error reading settings file\n{e}");
instance = new CameraWriteSettings();
}
try
{
// animation files
if (!Directory.Exists(animationsFolder))
{
Console.WriteLine("Animations folder doesn't exist, creating.");
Directory.CreateDirectory(animationsFolder);
}
animations = new Dictionary<string, AnimationKeyframes>();
string[] files = Directory.GetFiles(animationsFolder);
foreach (string file in files)
{
string json = File.ReadAllText(file);
AnimationKeyframes anim = JsonConvert.DeserializeObject<AnimationKeyframes>(json);
if (anim != null)
{
animations[Path.GetFileNameWithoutExtension(file)] = anim;
}
}
}
catch (Exception e)
{
Console.WriteLine($"Error reading animation files\n{e}");
}
}
public void SaveAnimation(string animName)
{
if (!animations.ContainsKey(animName)) return;
if (animations[animName] == null) return;
try
{
string settingsFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "IgniteVR", "Spark");
string animationsFolder = Path.Combine(settingsFolder, "Animations");
Task.Run(() =>
{
try
{
// animation files
if (!Directory.Exists(animationsFolder))
{
Console.WriteLine("Animations folder doesn't exist, creating.");
Directory.CreateDirectory(animationsFolder);
}
string animJson = JsonConvert.SerializeObject(animations[animName], Formatting.Indented);
File.WriteAllText(Path.Combine(animationsFolder, animName + ".json"), animJson);
}
catch (Exception e)
{
Console.WriteLine($"Error writing to settings file\n{e}");
}
});
}
catch (Exception e)
{
Console.WriteLine($"Error writing to settings file (outside)\n{e}");
}
}
}
}