This repository was archived by the owner on Jul 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathToonState.cs
More file actions
111 lines (99 loc) · 2.04 KB
/
Copy pathToonState.cs
File metadata and controls
111 lines (99 loc) · 2.04 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
110
111
using System;
using System.Collections.Generic;
using System.Text;
using Glider.Common.Objects;
namespace Pather
{
public class ToonState
{
// Simple saved storage or key=>value pairs
Dictionary<string, string> dic = new Dictionary<string, string>();
string toonName = null;
bool changed = false;
public void Save()
{
lock (this)
{
if (!changed)
return;
if (toonName == null)
return;
string filename = "PPather\\ToonInfo\\" + toonName + ".txt";
try
{
System.IO.TextWriter s = System.IO.File.CreateText(filename);
foreach (string key in dic.Keys)
{
string val = dic[key];
s.WriteLine(key + "|" + val);
}
s.Close();
}
catch (Exception e)
{
PPather.WriteLine("!Error:Exception writing toon state data: " + e);
}
changed = false;
}
}
public void Load()
{
lock (this)
{
if (toonName == null)
return;
dic = new Dictionary<string, string>();
// Load from file
PPather.WriteLine("Loading toon data...");
try
{
string filename = "PPather\\ToonInfo\\" + toonName + ".txt";
System.IO.TextReader s = System.IO.File.OpenText(filename);
int nr = 0;
string line;
while ((line = s.ReadLine()) != null)
{
char[] splitter = { '|' };
string[] st = line.Split(splitter);
if (st.Length == 2)
{
string key = st[0];
string val = st[1];
Set(key, val);
nr++;
}
}
PPather.WriteLine("Loaded " + nr + " toon state data");
s.Close();
}
catch (Exception)
{
PPather.WriteLine("!Warning:Failed reading toon state data");
}
changed = false;
}
}
public void SetToonName(string name)
{
Save();
toonName = name;
Load();
}
public string Get(string key)
{
string val;
if (dic.TryGetValue(key, out val))
{
return val;
}
return null;
}
public void Set(string key, string name)
{
if (dic.ContainsKey(key))
dic.Remove(key);
dic.Add(key, name);
changed = true;
}
}
}