-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathModConfiguration.cs
More file actions
109 lines (80 loc) · 3.11 KB
/
ModConfiguration.cs
File metadata and controls
109 lines (80 loc) · 3.11 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
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
using System;
using System.IO;
using System.Xml.Serialization;
using UnityEngine;
namespace PythonConsole
{
[XmlRoot("Configuration")]
public sealed class ModConfiguration
{
private const float RGB = 255f;
private const float Opaque = 1f;
#region General
[XmlElement("tcpPort")]
public int tcpPort { get; set; } = 0;
[XmlElement("customPrefabsObject")]
public bool CustomPrefabsObject { get; set; } = true;
[XmlElement("extendGamePanels")]
public bool ExtendGamePanels { get; set; } = true;
[XmlElement("logLevel")]
public int LogLevel { get; set; }
[XmlElement("selectionTool")]
public bool SelectionTool { get; set; } = true;
#endregion
#region Appearance
[XmlElement("fontName")]
public string FontName { get; set; } = "Courier New Bold";
[XmlElement("fontSize")]
public int FontSize { get; set; } = 14;
[XmlElement("backgroundColor")]
public Color BackgroundColor { get; set; } = new Color(100 / RGB, 100 / RGB, 110 / RGB, 235 / RGB);
[XmlElement("titlebarColor")]
public Color TitleBarColor { get; set; } = new Color(0 / RGB, 0 / RGB, 0 / RGB, Opaque);
[XmlElement("titlebarTextColor")]
public Color TitleBarTextColor { get; set; } = new Color(255 / RGB, 255 / RGB, 255 / RGB, Opaque);
#endregion
#region Window state
[XmlElement("mainWindowRect")]
public Rect MainWindowRect { get; set; } = new Rect(128, 128, 356, 300);
[XmlElement("consoleRect")]
public Rect ConsoleRect { get; set; } = new Rect(16f, 16f, 512f, 256f);
[XmlElement("sceneExplorerRect")]
public Rect SceneExplorerRect { get; set; } = new Rect(128, 440, 800, 500);
[XmlElement("watchesRect")]
public Rect WatchesRect { get; set; } = new Rect(504, 128, 800, 300);
#endregion
#region Script editor
[XmlElement("scriptEditorWorkspacePath")]
public string ScriptWorkspacePath { get; set; } = string.Empty;
#endregion
public static ModConfiguration Deserialize(string filename)
{
var serializer = new XmlSerializer(typeof(ModConfiguration));
try
{
using (var reader = new StreamReader(filename))
return (ModConfiguration)serializer.Deserialize(reader);
}
catch (Exception e)
{
Debug.LogError("Error happened when deserializing configuration");
Debug.LogException(e);
}
return null;
}
public void Serialize(string filename)
{
var serializer = new XmlSerializer(typeof(ModConfiguration));
try
{
using (var writer = new StreamWriter(filename))
serializer.Serialize(writer, this);
}
catch (Exception ex)
{
Debug.LogError("Failed to serialize configuration");
Debug.LogException(ex);
}
}
}
}