-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainPage.xaml.cs
More file actions
126 lines (86 loc) · 4.23 KB
/
MainPage.xaml.cs
File metadata and controls
126 lines (86 loc) · 4.23 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using MessengerRandomizerMappingGenerator.RandomizerGeneration;
using MessengerRandomizerMappingGenerator.RandomizerGeneration.Constants;
using MessengerRandomizerMappingGenerator.RandomizerGeneration.RO;
using System;
using System.Collections.Generic;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using System.Text.Json;
using System.Text;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace MessengerRandomizerMappingGenerator
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
private string text = "";
public MainPage()
{
this.InitializeComponent();
RadioButton radio = (RadioButton)FindName("BasicRadial");
radio.IsChecked = true;
}
private void HandleChecked(object sender, RoutedEventArgs e)
{
}
private void HandleUnchecked(object sender, RoutedEventArgs e)
{
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
this.text = "Generation starting up...\n";
CheckBox logicEngineCheckBox = (CheckBox)FindName("LogicalEngineCheckBox");
RadioButton basicRadial = (RadioButton)FindName("BasicRadial");
this.text += $"Using logic engine: '{logicEngineCheckBox.IsChecked}'\n";
this.text += $"Is a basic seed: '{basicRadial.IsChecked}'\n";
this.text += $"Is an advanced seed: '{!basicRadial.IsChecked}'\n";
this.text += "Got the seed info, beginning item mapping!\n\n\n";
//Generate seed
int seedNum = RandomizerGenerator.GenerateSeed();
SeedType seedType = (bool)logicEngineCheckBox.IsChecked ? SeedType.Logic : SeedType.No_Logic;
Dictionary<SettingType, SettingValue> settings = new Dictionary<SettingType, SettingValue>();
SettingValue difficulty = (bool)basicRadial.IsChecked ? SettingValue.Basic : SettingValue.Advanced;
settings.Add(SettingType.Difficulty, difficulty);
SeedRO seed = new SeedRO(seedNum,seedType,settings);
try
{
//generate mappings!
Dictionary<LocationRO, string> mappings = RandomizerGenerator.GenerateRandomizedMappings(seed);
this.text += "Mapping complete, listing mapping now:\n";
//Take the mapping I have and turn it into something nice and usable.
StringBuilder mappingText = new StringBuilder("mappings=");
foreach (LocationRO location in mappings.Keys)
{
this.text += $"Item '{mappings[location]}' at Location '{location.PrettyLocationName}'\n";
mappingText.Append(location.LocationName + "-" + mappings[location] + ",");
}
//Shave off trailing comma
mappingText.Length--;
mappingText.Append("|");
foreach (SettingType settingType in settings.Keys)
{
mappingText.Append(settingType + "=" + settings[settingType] + ",");
}
//Shave off trailing comma
mappingText.Length--;
mappingText.Append("|");
mappingText.Append("seedtype=" + seedType);
byte[] mappingBytes = Encoding.ASCII.GetBytes(mappingText.ToString());
string b64MappingText = Convert.ToBase64String(mappingBytes);
this.text += mappingText.ToString() + "\n";
this.text += $"Mapping bytes dump: '{mappingBytes}'\n";
this.text += $"Mapping after encoding: '{b64MappingText}'\n";
this.text += "\nGeneration complete! Enjoy the game!!!";
}
catch(Exception ex)
{
this.text = $"An error occurred during generation: {ex.Message}\nPlease try again.";
}
//Set text in box
TextBox text = (TextBox)FindName("Text");
text.Text = this.text;
}
}
}