-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathListWriter.cs
94 lines (78 loc) · 2.07 KB
/
ListWriter.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
// bacteriamage.wordpress.com
using System.Collections.Generic;
using System.IO;
namespace BacteriaMage.N64.GameShark
{
/// <summary>
/// Write a list of games to a text file in the same format used by the official utility.
/// </summary>
class ListWriter
{
private TextWriter writer;
public static void ToFile(string path, ICollection<Game> games)
{
using (TextWriter writer = new StreamWriter(path))
{
new ListWriter(writer).WriteGames(games);
}
}
public ListWriter(TextWriter writer)
{
this.writer = writer;
}
public void WriteGames(ICollection<Game> games)
{
WriteSeparator();
WriteLine($";{games.Count} Games in list");
WriteSeparator();
WriteLine();
foreach (Game game in games)
{
WriteGame(game);
}
}
public void WriteGame(Game game)
{
WriteSeparator();
WriteLine(Quote(game.Name));
WriteLine();
foreach(Cheat cheat in game.Cheats)
{
WriteCheat(cheat);
}
WriteLine(".end");
}
public void WriteCheat(Cheat cheat)
{
if (cheat.Active)
{
WriteLine(Quote(cheat.Name));
}
else
{
WriteLine($"{Quote(cheat.Name)} .off");
}
foreach (Code code in cheat.Codes)
{
WriteLine(code.ToString());
}
WriteLine();
}
private void WriteSeparator()
{
WriteLine(";------------------------------------");
}
private void WriteLine(string line)
{
writer.WriteLine(line);
}
private void WriteLine()
{
writer.WriteLine();
}
private static string Quote(string s)
{
return '"' + s + '"';
}
}
}