-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKIFExport.xaml.cs
62 lines (58 loc) · 2.09 KB
/
KIFExport.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
using Microsoft.Win32;
using System;
using System.IO;
using System.Windows;
namespace Shogi
{
/// <summary>
/// Interaction logic for KIFExport.xaml
/// </summary>
public partial class KIFExport : Window
{
private readonly ShogiGame game;
private readonly bool senteIsComputer;
private readonly bool goteIsComputer;
public KIFExport(ShogiGame game, bool senteIsComputer, bool goteIsComputer)
{
this.game = game;
this.senteIsComputer = senteIsComputer;
this.goteIsComputer = goteIsComputer;
InitializeComponent();
if (senteIsComputer)
{
senteNameBox.Text = "Computer";
senteNameBox.IsReadOnly = true;
senteNameBox.IsEnabled = false;
}
if (goteIsComputer)
{
goteNameBox.Text = "Computer";
goteNameBox.IsReadOnly = true;
goteNameBox.IsEnabled = false;
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
SaveFileDialog saveDialog = new()
{
AddExtension = true,
DefaultExt = ".kifu",
Filter = "Kifu File|*.kifu",
CheckPathExists = true
};
if (!saveDialog.ShowDialog() ?? true)
{
return;
}
string eventName = eventNameBox.Text.Trim();
string locationName = locationNameBox.Text.Trim();
DateOnly? date = dateBox.SelectedDate is null ? null : DateOnly.FromDateTime(dateBox.SelectedDate.Value);
string senteName = senteNameBox.Text.Trim();
string goteName = goteNameBox.Text.Trim();
File.WriteAllText(saveDialog.FileName, game.ToKIF(eventName != "" ? eventName : null,
locationName != "" ? locationName : null, date, senteName != "" ? senteName : "Player",
goteName != "" ? goteName : "Player", senteIsComputer, goteIsComputer));
Close();
}
}
}