Skip to content

Commit 4a339a5

Browse files
authored
Merge pull request #52 from poslogithub/dev
Dev
2 parents 4e5d824 + 9e26a9b commit 4a339a5

11 files changed

Lines changed: 671 additions & 511 deletions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using Newtonsoft.Json;
5+
using Newtonsoft.Json.Linq;
6+
7+
namespace MayhemFamiliar
8+
{
9+
10+
}

MayhemFamiliar/DialogueGenerator.cs

Lines changed: 379 additions & 388 deletions
Large diffs are not rendered by default.
Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@
1111
using System.Text.RegularExpressions;
1212
using System.Threading;
1313
using System.Threading.Tasks;
14-
using System.Xml.Linq;
15-
using static MayhemFamiliar.Config;
16-
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
1714

1815
namespace MayhemFamiliar
1916
{
20-
internal class Speaker
17+
internal class DialogueSpeaker
2118
{
2219
private Dictionary<string, ISynthesizer> _synthesizers = new Dictionary<string, ISynthesizer>();
23-
public Speaker(ISynthesizer synthesizerYou, ISynthesizer synthesizerOpponent)
20+
public DialogueSpeaker(ISynthesizer synthesizerYou, ISynthesizer synthesizerOpponent)
2421
{
2522
_synthesizers[PlayerWho.You] = synthesizerYou;
2623
_synthesizers[PlayerWho.Opponent] = synthesizerOpponent;
@@ -32,9 +29,9 @@ public async Task Start(CancellationToken cancellationToken)
3229
Logger.Instance.Log($"{this.GetType().Name}: 開始");
3330
while (!cancellationToken.IsCancellationRequested)
3431
{
35-
if (DialogueQueue.Queue.TryDequeue(out string dialogue))
32+
if (DialogueQueue.Queue.TryDequeue(out Dialogue dialogue))
3633
{
37-
InitProcessDialog(dialogue);
34+
ProcessDialogue(dialogue);
3835
}
3936
else
4037
{
@@ -53,28 +50,19 @@ public async Task Start(CancellationToken cancellationToken)
5350
Logger.Instance.Log($"{this.GetType().Name}: エラー発生: {ex.Message}");
5451
}
5552
}
56-
private void InitProcessDialog(string dialogue)
53+
private void ProcessDialogue(Dialogue dialogue)
5754
{
58-
string playerWho = PlayerWho.Unknown;
59-
if (dialogue.StartsWith(PlayerWho.You))
60-
{
61-
playerWho = PlayerWho.You;
62-
}
63-
else if (dialogue.StartsWith(PlayerWho.Opponent))
64-
{
65-
playerWho = PlayerWho.Opponent;
66-
}
55+
string playerWho = dialogue.PlayerWho;
6756

6857
if (playerWho != PlayerWho.Unknown)
6958
{
70-
dialogue = Regex.Replace(dialogue, $"^{playerWho} ", "");
7159
if (Program._config.SpeakerSettings.SpeakModes[playerWho] != Config.Speaker.SpeakModeOff)
7260
{
73-
_synthesizers[playerWho].ProcessDialogue(dialogue);
61+
_synthesizers[playerWho].ProcessDialogue(dialogue.Content);
7462
}
7563
if (Program._config.YukaConneNEOSettings.Enabled)
7664
{
77-
Task.Run(() => SendTextToYukaConneNEOAsync(dialogue));
65+
Task.Run(() => SendTextToYukaConneNEOAsync(dialogue.Content));
7866
}
7967
}
8068
else

MayhemFamiliar/JsonParser.cs

Lines changed: 145 additions & 79 deletions
Large diffs are not rendered by default.

MayhemFamiliar/LogWatcher.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using MayhemFamiliar.QueueManager;
2+
using Newtonsoft.Json.Linq;
23
using System;
34
using System.Diagnostics;
45
using System.IO;
@@ -64,22 +65,22 @@ public async void Start(CancellationToken _ctsLogWatcher, Boolean readFullLog =
6465
// ドラフト
6566
if (line.StartsWith(DraftPackStartsWith))
6667
{
67-
jsonBuilder = Regex.Replace(line, DraftPackStartPattern, "");
68-
JsonQueue.Queue.Enqueue(jsonBuilder);
68+
jsonBuilder = Regex.Replace(line, DraftPackStartPattern, ""); // ログの先頭部分(JSONでない箇所)を削除
69+
Enqueue(jsonBuilder);
6970
continue;
7071
}
7172
else if (line.StartsWith(DraftPickStartsWith))
7273
{
73-
jsonBuilder = Regex.Replace(line, DraftPickStartPattern, "");
74-
JsonQueue.Queue.Enqueue(jsonBuilder);
74+
jsonBuilder = Regex.Replace(line, DraftPickStartPattern, ""); // ログの先頭部分(JSONでない箇所)を削除
75+
Enqueue(jsonBuilder);
7576
continue;
7677
}
7778

7879
// ゲームプレイ
7980
if (line.StartsWith("{") && line.EndsWith("}"))
8081
{
8182
// 単一行JSON
82-
JsonQueue.Queue.Enqueue(line);
83+
Enqueue(line);
8384
continue;
8485
}
8586
else if (line.StartsWith("{"))
@@ -95,7 +96,7 @@ public async void Start(CancellationToken _ctsLogWatcher, Boolean readFullLog =
9596
if (line == "}")
9697
{
9798
// 複数行JSONの終了
98-
JsonQueue.Queue.Enqueue(jsonBuilder);
99+
Enqueue(jsonBuilder);
99100
jsonBuilder = "";
100101
}
101102
continue;
@@ -109,6 +110,21 @@ public async void Start(CancellationToken _ctsLogWatcher, Boolean readFullLog =
109110
Logger.Instance.Log($"{this.GetType().Name}: {ex.Message}");
110111
}
111112
}
113+
private Boolean Enqueue(string jsonString)
114+
{
115+
try
116+
{
117+
JObject json = JObject.Parse(jsonString);
118+
JsonQueue.Queue.Enqueue(json);
119+
return true;
120+
}
121+
catch (Exception ex)
122+
{
123+
Logger.Instance.Log($"{this.GetType().Name}: JSONのパースに失敗: {jsonString}");
124+
Logger.Instance.Log($"{this.GetType().Name}: {ex.Message}");
125+
return false;
126+
}
127+
}
112128
}
113129

114130
public static class ConsoleHelper

MayhemFamiliar/MainForm.Designer.cs

Lines changed: 64 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MayhemFamiliar/MainForm.cs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.IO;
45
using System.Linq;
56
using System.Text;
@@ -11,6 +12,14 @@ namespace MayhemFamiliar
1112
{
1213
public partial class MainForm : Form
1314
{
15+
private class Url
16+
{
17+
public const string CustomYourAction = "https://poslogithub.github.io/MayhemFamiliarCustom/your-action.html";
18+
public const string CustomOpponentsAction = "https://poslogithub.github.io/MayhemFamiliarCustom/opponent-action.html";
19+
public const string CustomOpponentsThirdAction = "https://poslogithub.github.io/MayhemFamiliarCustom/opponent-third-action.html";
20+
public const string CustomLimited = "https://poslogithub.github.io/MayhemFamiliarCustom/limited.html";
21+
}
22+
1423
// UI用
1524
private Dictionary<string, ComboBox> _comboBoxSynthesizers = new Dictionary<string, ComboBox>();
1625
private Dictionary<string, Button> _buttonTestSpeaks = new Dictionary<string, Button>();
@@ -26,7 +35,7 @@ public partial class MainForm : Form
2635
private LogWatcher _logWatcer;
2736
private JsonParser _jsonParser;
2837
private DialogueGenerator _dialogueGenerator;
29-
private Speaker _speaker;
38+
private DialogueSpeaker _speaker;
3039
private CancellationTokenSource _ctsLogWatcher, _ctsJsonParser, _ctsDialogueGenerator, _ctsSpeaker;
3140
private Boolean _readFullLog = false;
3241

@@ -404,7 +413,7 @@ private async void Form_Shown(object sender, EventArgs e)
404413
break;
405414
}
406415
}
407-
_speaker = new Speaker(synthesizers[PlayerWho.You], synthesizers[PlayerWho.Opponent]);
416+
_speaker = new DialogueSpeaker(synthesizers[PlayerWho.You], synthesizers[PlayerWho.Opponent]);
408417

409418
_ctsSpeaker = new CancellationTokenSource();
410419
Task.Run(() => _speaker.Start(_ctsSpeaker.Token));
@@ -574,6 +583,27 @@ private string GetLargestCardDatabaseFilePath(string cardDatabaseDirectoryPath)
574583
}
575584
return cardDatabaseFile;
576585
}
586+
587+
private void linkLabelCustomYourAction_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
588+
{
589+
Process.Start(Url.CustomYourAction);
590+
}
591+
592+
private void linkLabelCustomOpponentsAction_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
593+
{
594+
Process.Start(Url.CustomOpponentsAction);
595+
}
596+
597+
private void linkLabelCustomOpponentsThirdAction_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
598+
{
599+
Process.Start(Url.CustomOpponentsThirdAction);
600+
}
601+
602+
private void linkLabelCustomLimited_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
603+
{
604+
Process.Start(Url.CustomLimited);
605+
}
606+
577607
private string GetCardDatabaseFilePath()
578608
{
579609
string cardDatabaseDirectoryPath = Program._config.MtgArenaSettings?.CardDatabaseDirectoryPath ?? DefaultValue.CardDatabaseDirectory;

MayhemFamiliar/MayhemFamiliar.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
</ItemGroup>
102102
<ItemGroup>
103103
<Compile Include="CardData.cs" />
104+
<Compile Include="CustomDialogueTexts.cs" />
104105
<Compile Include="YukaConneNEO.cs" />
105106
<Compile Include="UpdateChecker.cs" />
106107
<Compile Include="Config.cs" />
@@ -119,9 +120,10 @@
119120
<Compile Include="Program.cs" />
120121
<Compile Include="Properties\AssemblyInfo.cs" />
121122
<Compile Include="Queue.cs" />
122-
<Compile Include="Speaker.cs" />
123+
<Compile Include="DialogueSpeaker.cs" />
123124
<EmbeddedResource Include="MainForm.resx">
124125
<DependentUpon>MainForm.cs</DependentUpon>
126+
<SubType>Designer</SubType>
125127
</EmbeddedResource>
126128
<EmbeddedResource Include="Properties\Resources.resx">
127129
<Generator>ResXFileCodeGenerator</Generator>

MayhemFamiliar/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ namespace MayhemFamiliar
88
{
99
internal static class Program
1010
{
11+
public static Config _config;
12+
1113
/// <summary>
1214
/// アプリケーションのメイン エントリ ポイントです。
1315
/// </summary>
14-
public static Config _config;
15-
1616
[STAThread]
1717
static void Main(string[] args)
1818
{

0 commit comments

Comments
 (0)