-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathModOptions.cs
76 lines (64 loc) · 2.52 KB
/
ModOptions.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
using System;
using System.IO;
using System.Xml.Serialization;
using ColossalFramework.Plugins;
namespace CS_Profitable_Offices
{
public class ModOptions
{
private const string OptionsFileName = "Profitable Office ModOptions.xml";
private static ModOptions _instance;
public static ModOptions Instance
{
get { return _instance != null ? _instance : (_instance = CreateFromFile()); }
}
public static int[] OfficeIncomeMultipliers = { 2, 3, 4, 5, 7, 10, 15, 20, 30, 50, 100 };
public static string[] OfficeIncomeMultipliersStr = { "x2", "x3", "x4", "x5", "x7", "x10", "x15", "x20", "x30", "x50", "x100" };
public int OfficeIncomeMultiplier;
public ModOptions()
{
OfficeIncomeMultiplier = 5;
}
public int GetOfficeIncomeMultiplierIndex()
{
var index = Array.IndexOf(OfficeIncomeMultipliers, OfficeIncomeMultiplier);
if (index == -1) return Array.IndexOf(OfficeIncomeMultipliers, 5); // Default to 5 if out of range
return index;
}
public void Save()
{
try
{
var ser = new XmlSerializer(typeof(ModOptions));
TextWriter writer = new StreamWriter(OptionsFileName);
ser.Serialize(writer, this);
writer.Close();
}
catch (Exception ex)
{
DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "Profitable Office Mod: " + ex.Message);
}
}
public static ModOptions CreateFromFile()
{
if (!File.Exists(OptionsFileName))
{
DebugOutputPanel.AddMessage(PluginManager.MessageType.Error, "Unable to load options file \"" + OptionsFileName + "\", file not found!");
return new ModOptions();
}
try
{
var ser = new XmlSerializer(typeof(ModOptions));
TextReader reader = new StreamReader(OptionsFileName);
var instance = (ModOptions)ser.Deserialize(reader);
reader.Close();
return instance;
}
catch (Exception ex)
{
DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "Profitable Office Mod (CreateFromFile): " + ex.Message);
return new ModOptions();
}
}
}
}