Skip to content

Commit

Permalink
added 'true latin form' support for keyboard game mode
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGAzed committed Jun 19, 2024
1 parent a234594 commit 5fb3371
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 29 deletions.
10 changes: 6 additions & 4 deletions hiravrt/Models/Game/KeyboardModel.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
using System.Linq;
using System.Globalization;
using System.Linq;
using System.Text;
using static System.Formats.Asn1.AsnWriter;

namespace hiravrt.Models.Game {
public class KeyboardModel(LookUp lookUp) : GameModel(1) {
private StringBuilder GuessLatin = new StringBuilder();
private readonly StringBuilder GuessLatin = new();
public string CorrectSyllableGrid = "";
public string CorrectSyllableGridAlternative = "";
private readonly CultureInfo Culture = new("en-US");

public override bool IsCorrect(string syllable) {
return CorrectSyllableGrid.CompareTo(GuessLatin.ToString() + syllable) == 0 ||
CorrectSyllableGridAlternative.CompareTo(GuessLatin.ToString() + syllable) == 0;
}

public bool IsValid(string syllable) {
return CorrectSyllableGrid.StartsWith(GuessLatin.ToString() + syllable) ||
CorrectSyllableGridAlternative.StartsWith(GuessLatin.ToString() + syllable);
return CorrectSyllableGrid.StartsWith(GuessLatin.ToString() + syllable, false, Culture) ||
CorrectSyllableGridAlternative.StartsWith(GuessLatin.ToString() + syllable, false, Culture);
}

public override void NextMove(string syllable) {
Expand Down
47 changes: 39 additions & 8 deletions hiravrt/Views/Pages/Game/Keyboard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
{ "YA", SyllableState.UNSET }, { "YU", SyllableState.UNSET }, { "YO", SyllableState.UNSET },

{ "K", SyllableState.UNSET }, { "S", SyllableState.UNSET }, { "T", SyllableState.UNSET }, { "N", SyllableState.UNSET }, { "H", SyllableState.UNSET },
{ "M", SyllableState.UNSET }, { "Y", SyllableState.UNSET }, { "R", SyllableState.UNSET }, { "W", SyllableState.UNSET },
{ "M", SyllableState.UNSET }, { "Y", SyllableState.UNSET }, { "R", SyllableState.UNSET }, { "W", SyllableState.UNSET }, { "C", SyllableState.UNSET },
{ "F", SyllableState.UNSET },

{ "G", SyllableState.UNSET }, { "Z", SyllableState.UNSET }, { "D", SyllableState.UNSET }, { "B", SyllableState.UNSET }, { "P", SyllableState.UNSET },
{ "J", SyllableState.UNSET },
};

private HashSet<string> digraphVowels = new() { "YA", "YU", "YO", };
Expand All @@ -43,6 +45,17 @@
private HashSet<string> diacriticConsonants = new() { "G", "Z", "D", "B", "P", "J", };
private HashSet<string> nonDiacriticConsonants = new() { "K", "S", "T", "N", "H", "M", "Y", "R", "W", "C", "F" };

private HashSet<string> SyllableSet = new();

private string HiraganaGridRegex = "([AIUEO])|([KSTNHMRWCFY])(YA|YU|YO|[AIUEO])";

Check warning on line 50 in hiravrt/Views/Pages/Game/Keyboard.razor

View workflow job for this annotation

GitHub Actions / build

The field 'Keyboard.HiraganaGridRegex' is assigned but its value is never used

Check warning on line 50 in hiravrt/Views/Pages/Game/Keyboard.razor

View workflow job for this annotation

GitHub Actions / build

The field 'Keyboard.HiraganaGridRegex' is assigned but its value is never used

public Keyboard() {
SyllableSet.UnionWith(digraphVowels);
SyllableSet.UnionWith(monographVowels);
SyllableSet.UnionWith(diacriticConsonants);
SyllableSet.UnionWith(nonDiacriticConsonants);
}

private void ResetProgressBar() {
int wrong = mc.GameC.EitherOrModel.WrongGuessesCount;
int correct = mc.GameC.EitherOrModel.CorrectGuessesCount;
Expand Down Expand Up @@ -249,10 +262,10 @@
}
</div>

<hr class="LINE">
<hr>

@if (isDiacritic) {
<div id="toplower">
<div class="lower" id='first-lower-row'>
<button class="toggle" @onclick="handleDiacriticToggle">D:</button>

<button class='@getButtonType("G")' @onclick='async () => await checkClick("G")'>G</button>
Expand All @@ -262,16 +275,25 @@
<button class='@getButtonType("B")' @onclick='async () => await checkClick("B")'>B</button>
</div>

<div id="bottomlower">
<div class="lower" id='second-lower-row'>
<button class="empty"></button>
<button class='@getButtonType("P")' @onclick='async () => await checkClick("P")'>P</button>
<button class="unset">M</button>
<button class="unset">Y</button>
<button class="unset">R</button>
<button class="unset">W</button>
</div>

<div class="lower" id='third-lower-row'>
<button class="empty"></button>
<button class="empty"></button>
<button class='unset'>C</button>
<button class='unset'>F</button>
<button class='@getButtonType("J")' @onclick='async () => await checkClick("J")'>J</button>
<button class="empty"></button>
</div>
} else {
<div id="toplower">
<div class="lower" id='first-lower-row'>
<button class="toggle" @onclick="handleDiacriticToggle">d:</button>

<button class='@getButtonType("K")' @onclick='async () => await checkClick("K")'>K</button>
Expand All @@ -281,9 +303,9 @@
<button class='@getButtonType("H")' @onclick='async () => await checkClick("H")'>H</button>
</div>

<div id="bottomlower">
<button class="empty"></button>
<div class="lower" id='second-lower-row'>
<button class="empty"></button>
<button class="unset">P</button>
<button class='@getButtonType("M")' @onclick='async () => await checkClick("M")'>M</button>

@if (isDigraph) {
Expand All @@ -295,7 +317,16 @@
<button class='@getButtonType("R")' @onclick='async () => await checkClick("R")'>R</button>
<button class='@getButtonType("W")' @onclick='async () => await checkClick("W")'>W</button>
}
</div>
</div>

<div class="lower" id='third-lower-row'>
<button class="empty"></button>
<button class="empty"></button>
<button class='@getButtonType("C")' @onclick='async () => await checkClick("C")'>C</button>
<button class='@getButtonType("F")' @onclick='async () => await checkClick("F")'>F</button>
<button class="unset">J</button>
<button class="empty"></button>
</div>
}
</section>
</article>
7 changes: 7 additions & 0 deletions hiravrt/wwwroot/css/defaults.css
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ form {
row-gap: 0.5em;
}

hr {
width: 100%;
height: 0%;
border-style: solid;
margin: unset;
}

@media screen and (max-width: 950px) {
article {
grid-template-columns: 15em 3.5em 15em;
Expand Down
25 changes: 8 additions & 17 deletions hiravrt/wwwroot/css/game/Keyboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
text-shadow: 0 0 4px #1b1b1b;
}

section#KEYBOARDSECTION, div#bottomlower, div#toplower, div#upperkeyboard {
section#KEYBOARDSECTION, div#upperkeyboard {
display: flex;
}

Expand All @@ -35,11 +35,8 @@ div#lowerkeyboard {
justify-content: center;
}

div#toplower {
justify-content: space-between;
}

div#bottomlower {
div.lower {
display: flex;
justify-content: center;
grid-template-columns: repeat(5, 1fr);
gap: 0.5em;
Expand Down Expand Up @@ -80,31 +77,25 @@ button.active, button.unset {

button.unset {
cursor: default;
opacity: 0.5;
opacity: 0.25;
filter: saturate(0);
}

button.empty {
opacity: 0;
cursor: default;
}

button.toggle {
border-color: #1B1B1B;
background: #FFF;
color: #1B1B1B;
border-color: #2B2B2B;
background: #2B2B2B;
color: #fff;
}

button.KEYBOARDBUTTON:active, button.active:active, button.toggle:active {
transform: scale(0.95);
}

hr.LINE {
width: 100%;
height: 0%;
border-style: solid;
margin: unset;
}

article.SUBPAGE {
height: 100%;
}
Expand Down

0 comments on commit 5fb3371

Please sign in to comment.