-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
135 lines (120 loc) · 4.44 KB
/
Copy pathProgram.cs
File metadata and controls
135 lines (120 loc) · 4.44 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
127
128
129
130
131
132
133
134
135
using VModLoader.DynamicNodes;
using VModLoader.Nodes;
namespace VModLoader
{
internal class Program
{
static readonly DecisionNode decisionTree = new
("Main Menu",
[
new DynamicDecisionNode("Run Installs", RunInstallGenerator.LoadFromInstallFile),
new DynamicDecisionNode("Manage VVVVVV installs", ManageAllInstallsGenerator.LoadFromInstallFile),
new ExitNode("Exit VML"),
]
);
static DecisionNode traverse = decisionTree;
static readonly List<DecisionNode> backHistory = [ ];
const int INDEX_OFFSET = 1;
internal const string BACK_CMD = "back";
/// <summary>
/// Writes the VML icon to the console.
/// </summary>
public static void WriteIcon()
{
Console.WriteLine(@" _____ _____ ________ _____ _____ ");
Console.WriteLine(@" \\\\ \ //// / //// | / | |||| | ");
Console.WriteLine(@" \\\\ \ //// / //// /| |/ /| | |||| | ");
Console.WriteLine(@" \\\\ \/// / //// /|| | /|| | |||| | ");
Console.WriteLine(@" \\\\ \/ / //// /||| /||| | |||| |___ ");
Console.WriteLine(@" \\\\____/ ////__/||||___/||||__| ||||______| ");
Console.WriteLine(@" ");
Console.WriteLine(@" x-->> VModLoader <<--x ");
Console.WriteLine(@" | By MonkeManII | ");
Console.WriteLine(@" >>----------x--------------------x-------------<< ");
Console.WriteLine(@" | A basic modloader for Terry Cavanagh's VVVVVV | ");
Console.WriteLine(@" >>---------------------------------------------<< ");
}
/// <summary>
/// Writes the current traversal info to the console.
/// </summary>
internal static void WriteTraverse()
{
Console.Clear();
WriteIcon();
traverse.ConsoleWrite(INDEX_OFFSET);
if (backHistory.Count > 0)
{
Console.WriteLine($"Run '{BACK_CMD}' to go back!");
}
}
/// <summary>
/// Runs the given user command.
/// </summary>
/// <param name="command">The user command.</param>
internal static void RunCommand(string command)
{
// Check for the back command.
if (command.ToLower() == BACK_CMD.ToLower())
{
if (backHistory.Count <= 0)
{
return;
}
traverse = backHistory[^1];
backHistory.RemoveAt(backHistory.Count - 1);
WriteTraverse();
return;
}
// Try to parse it as a node input.
if (!traverse.ParseInput(command, INDEX_OFFSET, out string? error, out int index))
{
Console.WriteLine(error);
return;
}
else
{
// Select it and traverse if applicable.
DecisionNode? newNode = traverse.GetChild(index);
if (newNode is not null)
{
if (!newNode.OnSelected())
{
return;
}
backHistory.Add(traverse);
traverse = newNode;
}
WriteTraverse();
}
}
static void Main(string[] args)
{
FileUtils.Initialize();
WriteTraverse();
while (true)
{
// Because this is blocking, while true works fine.
string? inp = Console.ReadLine();
if (!string.IsNullOrEmpty(inp))
{
RunCommand(inp);
}
}
}
/// <summary>
/// Closes this window.
/// </summary>
internal static void Close()
{
Environment.Exit(0);
}
/// <summary>
/// Traverses to the given node.
/// </summary>
/// <param name="node">The node to traverse to.</param>
internal static void TraverseTo(DecisionNode node)
{
traverse = node;
}
}
}