This repository has been archived by the owner on Apr 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
464 lines (420 loc) · 21.3 KB
/
MainWindow.xaml.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Threading;
// Looking for line 2?
// Code to be executed by - Line B Refactored Edition
//Its been moved, to see the easteregg go to settings and click on the the licence infomation
namespace NewDawn_Engine
{
static public class UserData // This stores the variables that are saved between reloads (Exlcudes savedata)
{
static public bool AutoUpdate = true;
public static string Path = AppDomain.CurrentDomain.BaseDirectory; //Gets the executing directory
public static char SlashType = Path.Last(); //Will get the type of slash (Prevents crashing on Unix Based system as / is used instead of \)
public static int GameWindowVisibility = 0;
public static string EngineRoom = ""; //Stores room that the engine should read from
public static string EngineChapter = ""; //Stores chapter that the engine should read from
public static string GameDir = "";
public static List<string> Links = new List<string>(); //Links are the names of folders (ID corresponds with Options)
public static List<string> Options = new List<string>(); //Options are shown to the user and when selected sends the user to the corresponding link
public static List<string?> TextVar = new List<string?>(); //Text array for engine variable
public static List<bool?> BoolVar = new List<bool?>(); //Boolean Variable for engine variable
public static bool Debug = true; //toggles debugblock
public static List<string?> Saves = new List<string?>(); //Stores the actual name of save folders
}
partial class MainWindow : Window //This interacts with the UI so bascially this stores buttons and other elements
{
public MainWindow() //This runs at start up and more or less is the closest thing to Main() in console newdawn
{
InitializeComponent(); //This initalises the window
EngineTab.IsEnabled = false;
string[] GameDirs = Directory.GetDirectories(UserData.Path + UserData.SlashType + "Data"); // This gets the full path to each directory in data
for (int i = 0; i <= GameDirs.Length - 1; i++)
{
GameSelectDropDown.Items.Add(System.IO.Path.GetFileName(GameDirs[i])); //Adds the name of the game folders to the dropdown
}
if (UserData.Debug == false) //Checks if the game should show the Debugblock (log)
{
DebugBlock.IsEnabled = false;
DebugBlock.Opacity = 0;
}
else
{
DebugBlock.IsEnabled = true;
DebugBlock.Opacity = 100;
}
SaveCombobox.IsEnabled = false;
Load.IsEnabled = false;
DeleteSave.IsEnabled = false;
}
private void EasterEggClick(object sender, RoutedEventArgs e) //Handles Eastergg button (Updated often)
{
MessageBox.Show("DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA\nDESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA\nDESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA\nDESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA\nDESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA\nDESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA\nDESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA\nDESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA DESTROYA");
}
private void AutoUpdateToggle(object sender, RoutedEventArgs e) //Ran when checkbox is clicked
{
if (AutoUpdateBox.IsChecked == true)
{
UserData.AutoUpdate = true;
MessageBox.Show("Auto-Update enabled");
}
else
{
UserData.AutoUpdate = false;
MessageBox.Show("Auto-Update disabled");
}
}
public void GameSelectDropDown_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string[] NFO = File.ReadAllLines(UserData.Path + "data" + UserData.SlashType + GameSelectDropDown.SelectedValue + UserData.SlashType + "i.nfo");
GameMenuInfoBox.Text = NFO[0] + " \nVersion: " + NFO[3] + "\n\n\nRelease Date: " + NFO[4] + "\n" + NFO[2];
DebugBlock.Text = DebugBlock.Text + "\nSelected game: " + GameSelectDropDown.SelectedValue;
SaveScan();
}
private void SaveScan()
{
SaveCombobox.Items.Clear(); //Clears combobox to prevent saves from being shown multiple times
DebugBlock.Text = DebugBlock.Text + "\nFailed to find save folder";
SaveCombobox.IsEnabled = false;
Load.IsEnabled = false;
DeleteSave.IsEnabled = false;
SaveInfo.Text = "No saves found";
UserData.Saves = new List<string?>();
if (Directory.Exists(UserData.Path + "\\Data\\" + GameSelectDropDown.SelectedValue + "\\Saves"))
{
DebugBlock.Text = DebugBlock.Text + "\nFound Saves folder at " + UserData.Path + "\\Data\\" + GameSelectDropDown.SelectedValue + "\\Saves";
string[] SaveDir = Directory.GetDirectories(UserData.Path + "\\Data\\" + GameSelectDropDown.SelectedValue + "\\Saves"); // This gets the full path to each directory in Saves
for (int i = 0; i <= SaveDir.Length - 1; i++)
{
SaveCombobox.Items.Add(DateTimeOffset.FromUnixTimeSeconds(Convert.ToInt32(Path.GetFileName(SaveDir[i])))); //Gets the name of the folder (Which is saved in Unix Second format) and converts it to a real time and then adds this to the dropdown
UserData.Saves.Add(Path.GetFileName(SaveDir[i]));
}
if (SaveDir.Count() - 1 >= 0)
{
DebugBlock.Text = DebugBlock.Text + "\nAmmount of saves - " + SaveCombobox.Items.Count;
SaveCombobox.IsEnabled = true;
Load.IsEnabled = true;
DeleteSave.IsEnabled = true;
SaveInfo.Text = "Select a save to load";
}
}
}
public void NewGameButton(object sender, RoutedEventArgs e) //Handles Eastergg button (Updated often)
{
if (GameSelectDropDown.SelectedIndex != -1) //Checks that combobox isnt blank
{
GameMenuInfoBox.Text = "Now Playing - (" + GameSelectDropDown.SelectedValue + ")\n\n Click the game tab to start playing!";
EngineConfigTab.IsEnabled = false; //Disables config once game has started
EngineTab.IsEnabled = true; //Enables Engine tab EngineTab
GameSelectDropDown.IsEnabled = false;
NewGame.IsEnabled = false;
Load.IsEnabled = false;
SaveCombobox.IsEnabled = false;
DeleteSave.IsEnabled = false;
UserData.EngineChapter = "1";
UserData.EngineRoom = "Start";
UserData.GameDir = UserData.Path + "data" + UserData.SlashType + GameSelectDropDown.SelectedValue + UserData.SlashType + "1" + UserData.SlashType + "Start" + UserData.SlashType;
for (int I = 0; I < 10000; I++) //Nulls 10K elements to prevent them from being read as false
{
UserData.BoolVar.Add(null);
UserData.TextVar.Add(null);
}
if (UserData.Debug == false) //Checks if the game should show the Debugblock (log)
{
DebugBlock.IsEnabled = false;
DebugBlock.Opacity = 0;
}
else
{
DebugBlock.IsEnabled = true;
DebugBlock.Opacity = 100;
}
EngineInitalise();
}
else
{
GameMenuInfoBox.Text = "\n\n\n\n Hey!\n You need to Select a game from the box above!"; //Werid spacing to make the text centered in 500x500
}
}
public void EngineInitalise()
{
if (File.Exists(UserData.GameDir + "ChapterChange.txt") == true) // Checks if a chapter Change exists
{
string[] Temp = File.ReadAllLines(UserData.GameDir + "ChapterChange.txt");
UserData.GameDir = UserData.Path + "data" + UserData.SlashType + GameSelectDropDown.SelectedValue + UserData.SlashType + Temp[0] + UserData.SlashType + "Start" + UserData.SlashType;
UserData.EngineChapter = Temp[0];
EngineInitalise();
}
UserData.Links.Clear(); //Clears all items in Links
UserData.Options.Clear();
EngineText.Text = File.ReadAllText(UserData.GameDir + "T.txt");
DebugBlock.Text = DebugBlock.Text + "\nInitalised room at " + UserData.GameDir;
UserData.Options.AddRange(File.ReadAllLines(UserData.GameDir + "O.txt")); //Adds each line in O.txt as a individual item in the list
UserData.Links.AddRange(File.ReadAllLines(UserData.GameDir + "L.txt")); //Adds each line in O.txt as a individual item in the list
option0.Content = UserData.Options[0]; //Since there will always be atleast 1 options 0 will always be used
DebugBlock.Text = DebugBlock.Text + "\nLoaded Options and Links";
EngineVariable();
}
public void EngineVariable()
{
DebugBlock.Text = DebugBlock.Text + "\nIs VarSet.text present - " + File.Exists(UserData.GameDir + "VarSet.txt") ;
DebugBlock.Text = DebugBlock.Text + "\nIs VarCheck.txt Present - " + File.Exists(UserData.GameDir + "VarCheck.txt");
string[] TempFile; //Used as a temporary file reader
if (File.Exists(UserData.GameDir + "VarSet.txt")) // This Sets Variables
{
TempFile = File.ReadAllLines(UserData.GameDir + "VarSet.txt"); // (0 - bool/text 1 - Place in array 2 - Value)
if (TempFile[0] == "bool")
{
if (TempFile[2] == "false")
{
UserData.BoolVar[Convert.ToInt32(TempFile[1])] = false;
DebugBlock.Text = DebugBlock.Text + "\nSet boolean variable " + TempFile[1] + " to " + TempFile[2];
}
else if (TempFile[2] == "true")
{
UserData.BoolVar[Convert.ToInt32(TempFile[1])] = true;
DebugBlock.Text = DebugBlock.Text + "\nSet boolean variable " + TempFile[1] + " to " + TempFile[2];
}
}
else if (TempFile[0] == "text")
{
UserData.TextVar[Convert.ToInt32(TempFile[1])] = TempFile[2];
DebugBlock.Text = DebugBlock.Text + "\nSet string variable " + TempFile[1] + " to " + TempFile[2];
}
}
if (File.Exists(UserData.GameDir + "VarCheck.txt"))// Checks Variables
{//0-text/bool 1-Position in array 2-expected result 3-Positive Result Option 4- Positive result link
TempFile = File.ReadAllLines(UserData.GameDir + "VarCheck.txt");
DebugBlock.Text = DebugBlock.Text + "\nFound a VarCheck File";
if (TempFile[0] == "bool")
{
DebugBlock.Text = DebugBlock.Text + "\nChecking a bool variable";
DebugBlock.Text = DebugBlock.Text + "\nChecking " + TempFile[2] + "==" + Convert.ToString(UserData.BoolVar[Convert.ToInt32(TempFile[1])]);
if (TempFile[2].ToUpper() == Convert.ToString(UserData.BoolVar[Convert.ToInt32(TempFile[1])]).ToUpper()) //Converts sp
{
DebugBlock.Text = DebugBlock.Text + "\nBool Variable matches requirement";
UserData.Options.Add(TempFile[3]);
UserData.Links.Add(TempFile[4]);
}
else
{
DebugBlock.Text = DebugBlock.Text + "\nBool Variable DOES NOT requirement";
}
DebugBlock.Text = DebugBlock.Text + System.Convert.ToString("\nChecking boolean variable " + TempFile[1] + " - Expected:" + TempFile[2] + " Reality:" + TempFile[2] == Convert.ToString(UserData.BoolVar[Convert.ToInt32(TempFile[1])]));
}
else if (TempFile[0] == "text")
{
if (TempFile[2].ToUpper() == Convert.ToString(UserData.TextVar[Convert.ToInt32(TempFile[1])]).ToUpper()) //Converts sp
{
UserData.Options.Add(TempFile[3]);
UserData.Links.Add(TempFile[4]);
}
DebugBlock.Text = DebugBlock.Text + System.Convert.ToString("\nChecking string variable " + TempFile[1] + " - Expected: " + TempFile[2] + " Reality:" + TempFile[2] == Convert.ToString(UserData.TextVar[Convert.ToInt32(TempFile[1])]));
}
else
{
Thread.Sleep(0);
DebugBlock.Text = DebugBlock.Text + "Failed to find a VarCheck File";
}
}
EngineButtonHandler();
}
public void EngineButtonHandler() // Just for readability I confined all the buttony stuff into a single function
{
if (UserData.Options.Count > 1)
{
option1.IsEnabled = true;
option1.Opacity = 100;
option1.Content = UserData.Options[1];
}
else
{
option1.IsEnabled = false;
option1.Opacity = 0;
}
if (UserData.Options.Count > 2)
{
option2.IsEnabled = true;
option2.Opacity = 100;
option2.Content = UserData.Options[2];
}
else
{
option2.IsEnabled = false;
option2.Opacity = 0;
}
if (UserData.Options.Count > 3)
{
option3.IsEnabled = true;
option3.Opacity = 100;
option3.Content = UserData.Options[3];
}
else
{
option3.IsEnabled = false;
option3.Opacity = 0;
}
if (UserData.Options.Count > 4)
{
option4.IsEnabled = true;
option4.Opacity = 100;
option4.Content = UserData.Options[4];
}
else
{
option4.IsEnabled = false;
option4.Opacity = 0;
}
if (UserData.Options.Count > 5)
{
option5.IsEnabled = true;
option5.Opacity = 100;
option5.Content = UserData.Options[5];
}
else
{
option5.IsEnabled = false;
option5.Opacity = 0;
}
if (UserData.Options.Count > 6)
{
option6.IsEnabled = true;
option6.Opacity = 100;
option6.Content = UserData.Options[6];
}
else
{
option6.IsEnabled = false;
option6.Opacity = 0;
}
if (UserData.Options.Count > 7)
{
option7.IsEnabled = true;
option7.Opacity = 100;
option7.Content = UserData.Options[7];
}
else
{
option7.IsEnabled = false;
option7.Opacity = 0;
}
if (UserData.Options.Count > 8)
{
option8.IsEnabled = true;
option8.Opacity = 100;
option8.Content = UserData.Options[8];
}
else
{
option8.IsEnabled = false;
option8.Opacity = 0;
}
if (UserData.Options.Count > 9)
{
option9.IsEnabled = true;
option9.Opacity = 100;
option9.Content = UserData.Options[9];
}
else
{
option9.IsEnabled = false;
option9.Opacity = 0;
}
}
void optionclick(object sender, RoutedEventArgs e)
{
Button button = sender as Button;
string ButtonNumber = Convert.ToString(button.Name.Replace("option", ""));
DebugBlock.Text = DebugBlock.Text + "\nParsed ButtonNumber to " + ButtonNumber + "\nSending player to " + UserData.Links[Convert.ToInt32(ButtonNumber)] + "\n\n\n\n";
UserData.EngineRoom = UserData.Links[Convert.ToInt32(ButtonNumber)];
UserData.GameDir = UserData.Path + "data" + UserData.SlashType + GameSelectDropDown.SelectedValue + UserData.SlashType + UserData.EngineChapter + UserData.SlashType + UserData.Links[Convert.ToInt32(ButtonNumber)] + UserData.SlashType; EngineInitalise();
EngineInitalise();
}
public void SaveGame(object sender, RoutedEventArgs e)
{
string SaveDir = UserData.Path + "data" + UserData.SlashType + GameSelectDropDown.SelectedValue + UserData.SlashType + "\\Saves\\" + Convert.ToString(DateTimeOffset.Now.ToUnixTimeSeconds());
List<string?> SaveTextVar = new List<string?>();
List<string?> SaveBoolVar = new List<string?>();
for (int i = 0; i <= UserData.BoolVar.Count - 1; i++)
{
if (UserData.TextVar[i] == null)
{
SaveTextVar.Add("null");
}
else
{
SaveTextVar.Add(UserData.TextVar[i]);
}
if (UserData.BoolVar[i] == null)
{
SaveBoolVar.Add("null");
}
else
{
SaveBoolVar.Add(Convert.ToString(UserData.BoolVar[i]));
}
}
string[] temp = { UserData.EngineChapter, UserData.EngineRoom };
Directory.CreateDirectory(SaveDir);
File.WriteAllLines(SaveDir + "\\TextVar", SaveTextVar);
File.WriteAllLines(SaveDir + "\\BoolVar", SaveBoolVar);
File.WriteAllLines(SaveDir + "\\UserData", temp);
}//Its like LoadGame() but in reverse
private void LoadGame(object sender, RoutedEventArgs e) //Its like SaveGame() but in reverse
{
string SaveDir = UserData.Path + "data" + UserData.SlashType + GameSelectDropDown.SelectedValue + UserData.SlashType + "\\Saves\\" + UserData.Saves[SaveCombobox.SelectedIndex];
UserData.TextVar = new List<string?>();
UserData.BoolVar = new List<bool?>();
string[] ReadTextVar = File.ReadAllLines(SaveDir + "\\TextVar");
string[] ReadBoolVar = File.ReadAllLines(SaveDir + "\\BoolVar");
string[] ReadRoomDat = File.ReadAllLines(SaveDir + "\\UserData");
SaveInfo.Text = "Loading...";
for (int i = 0; i <= ReadTextVar.Count() - 1; i++){
if (ReadTextVar[i] == "null")
{
UserData.TextVar.Add(null);
}
else
{
UserData.TextVar.Add(ReadTextVar[i]);
}
if (ReadBoolVar[i] == null)
{
UserData.BoolVar.Add(null);
}
else
{
if (ReadBoolVar[i] == "false")
{
UserData.BoolVar.Add(false);
}
else
{
UserData.BoolVar.Add(true);
}
}
}
DebugBlock.Text = DebugBlock.Text + "\n\nAdded " + UserData.BoolVar.Count + " to Boolean Variable\n\nAdded " + UserData.TextVar.Count + " to TextVariable";
UserData.GameDir = UserData.Path + "data" + UserData.SlashType + GameSelectDropDown.SelectedValue + UserData.SlashType + ReadRoomDat[0] + UserData.SlashType + ReadRoomDat[1] + UserData.SlashType;
GameMenuInfoBox.Text = "Now Playing - (" + GameSelectDropDown.SelectedValue + ")\n\n Click the game tab to start playing!";
EngineConfigTab.IsEnabled = false; //Disables config once game has started
EngineTab.IsEnabled = true; //Enables Engine tab EngineTab
GameSelectDropDown.IsEnabled = false;
NewGame.IsEnabled = false;
Load.IsEnabled = false;
SaveCombobox.IsEnabled = false;
DeleteSave.IsEnabled = false;
SaveInfo.Text = "Loaded!";
EngineInitalise();
}
private void DeleteSave_Click(object sender, RoutedEventArgs e)
{
Directory.Delete(UserData.Path + "data" + UserData.SlashType + GameSelectDropDown.SelectedValue + UserData.SlashType + "\\Saves\\" + UserData.Saves[SaveCombobox.SelectedIndex], true);
SaveScan();
}
}
}