-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathProject.cs
184 lines (160 loc) · 5.85 KB
/
Project.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
181
182
183
184
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OpenXP
{
public class Project
{
public string Path;
public string Directory;
public List<string> ResourcePaths;
public bool Dirty = false;
public bool Extended = false; //does it make use of OpenXP extensions?
public GameIni Ini;
public ScriptHive Scripts;
public MapInfos Maps;
public Ruby Ruby;
public Database Database;
//call on loading to set up the project
//return a string message if there is a problem or null if everything is okay
public string Setup()
{
//Game.ini
Ini = new GameIni();
if(File.Exists(System.IO.Path.Combine(Directory, "Game.ini")))
{
Ini.Deserialize(File.ReadAllText(System.IO.Path.Combine(Directory, "Game.ini")));
} else
{
return "There was an error reading Game.ini";
}
//Load RTP(s)
FindRTPs();
//Ruby
Ruby = new Ruby();
//Scripts.rxdata
Scripts = new ScriptHive();
Ruby.PopulateScriptHive(Scripts);
//Database
Database = new Database();
Ruby.PopulateDatabase(Database);
//MapInfos.rxdata
Maps = new MapInfos();
Ruby.PopulateMapInfos(Maps);
Maps.FinishedLoading();
//setup starting position
MapHandler.startMapId = Database.System.start_map_id;
MapHandler.startMapX = Database.System.start_x;
MapHandler.startMapY = Database.System.start_y;
return null;
}
//call to save the project and clear the dirty flag
public void Save()
{
//if (Dirty) { //disabled, let's just always save
//save the .rxproj file
File.WriteAllText(Path, "RPGXP 1.05");
//save the Game.ini
File.WriteAllText(System.IO.Path.Combine(Directory, "Game.ini"), Ini.Serialize());
//save Scripts.rxdata
Ruby.WriteScriptHive(Scripts);
//Save starting position
Database.System.start_map_id = MapHandler.startMapId;
Database.System.start_x = MapHandler.startMapX;
Database.System.start_y = MapHandler.startMapY;
//save Database
Database.System.edit_map_id = Editor.GetSelectedMapId();
Ruby.WriteDatabase(Database);
//save MapInfos.rxdata
Ruby.WriteMapInfos(Maps);
Dirty = false; //set this last if everything saved okay
//}
}
//call this when you change something that needs to be saved
public void Touch()
{
Dirty = true;
}
//called by DialogScriptEditor at initialization to get a cancelable script hive
public ScriptHive CreateTemporaryScriptHive()
{
return Scripts.Clone();
}
public void Dispose()
{
if (Ruby != null) Ruby.Dispose();
}
private void FindRTPs()
{
ResourcePaths = new List<string>();
ResourcePaths.Add(Directory);
string rtpn;
string rtpnn = Ini.RTP1;
if (!String.IsNullOrWhiteSpace(rtpnn))
{
bool found = false;
rtpn = FindRTP(rtpnn);
if (!String.IsNullOrWhiteSpace(rtpn))
{
if (System.IO.Directory.Exists(rtpn))
{
Console.WriteLine("Found RTP: " + rtpnn + " at: " + rtpn);
ResourcePaths.Add(rtpn);
found = true;
}
}
if (!found) Console.WriteLine("Could not locate RTP: " + rtpnn);
}
rtpnn = Ini.RTP2;
if (!String.IsNullOrWhiteSpace(rtpnn))
{
bool found = false;
rtpn = FindRTP(rtpnn);
if (!String.IsNullOrWhiteSpace(rtpn))
{
if (System.IO.Directory.Exists(rtpn))
{
Console.WriteLine("Found RTP: " + rtpnn + " at: " + rtpn);
ResourcePaths.Add(rtpn);
found = true;
}
}
if (!found) Console.WriteLine("Could not locate RTP: " + rtpnn);
}
rtpnn = Ini.RTP3;
if (!String.IsNullOrWhiteSpace(rtpnn))
{
bool found = false;
rtpn = FindRTP(rtpnn);
if (!String.IsNullOrWhiteSpace(rtpn))
{
if (System.IO.Directory.Exists(rtpn))
{
Console.WriteLine("Found RTP: " + rtpnn + " at: " + rtpn);
ResourcePaths.Add(rtpn);
found = true;
}
}
if (!found) Console.WriteLine("Could not locate RTP: " + rtpnn);
}
}
private string FindRTP(string name)
{
string key = @"HKEY_LOCAL_MACHINE\Software\Enterbrain\RGSS\RTP";
string rtp = (string)Microsoft.Win32.Registry.GetValue(key, "Standard", "");
if (String.IsNullOrWhiteSpace(rtp))
{
key = @"HKEY_LOCAL_MACHINE\Software\Wow6432Node\Enterbrain\RGSS\RTP";
rtp = (string)Microsoft.Win32.Registry.GetValue(key, "Standard", "");
}
if (!String.IsNullOrWhiteSpace(rtp))
{
return rtp + @"\";
}
return null;
}
}
}