Skip to content

Commit

Permalink
Added comments for controllers and changed SettingsController.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGAzed committed May 30, 2024
1 parent 53745a1 commit 2a5f252
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 28 deletions.
9 changes: 9 additions & 0 deletions hiravrt/Controllers/MainController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@
namespace hiravrt.Controllers
{
public class MainController {
/// <summary>
/// Game controller that contains all available games for views.
/// </summary>
public GameController GameC { get; } = new();
/// <summary>
/// Home controller with mainly addresses used by views.
/// </summary>
public HomeController HomeC { get; } = new();
/// <summary>
/// Settings controller used to control settings specidied by user.
/// </summary>
public SettingsController SettingsC { get; } = new();

public MainController() {
Expand Down
76 changes: 63 additions & 13 deletions hiravrt/Controllers/Nav/SettingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,50 @@ namespace hiravrt.Controllers.Nav {
/// Graph states in settings razor section.
/// </summary>
public enum GraphState : int {
MONOGRAPH = 0b00,
DIGRAPH = 0b01,
DIACRITIC_MONOGRAPG = 0b10,
DIACRITIC_DIGRAPH = 0b11,
MONOGRAPH = 0b00, // MONOGRAPHIC SYLLABLES ENUM
DIGRAPH = 0b01, // DIGRAPHIC SYLLABLES ENUM
DIACRITIC_MONOGRAPG = 0b10, // MONOGRAPHIC SYLLABLES WITH DIACRITICS ENUM
DIACRITIC_DIGRAPH = 0b11, // DIGRAPHIC SYLLABLES WITH DIACRITICS ENUM
}

public class SettingsController {
/// <summary>
/// List of all game models that rely on settings' active syllables
/// </summary>
public List<GameModel> GameModels = [];
private readonly Dictionary<GraphState, GraphModel> keyGraphPair;
/// <summary>
/// Lookup dictionary that returns concrete GraphModel based on GraphState
/// </summary>
private readonly Dictionary<GraphState, GraphModel> StateGraphPair;
/// <summary>
/// Returns current set graph in sesttings.
/// </summary>
public GraphState CurrentGraphState { get; set; } = GraphState.MONOGRAPH;
public List<string> AvailableSyllables { get; set; } = [];
/// <summary>
/// List of all available/active syllables.
/// </summary>
private List<string> AvailableSyllables = [];
/// <summary>
/// Default syllables used by every gamemodel.
/// </summary>
public static readonly List<string> DefaultSyllables = [
"\u3042", "\u3044", "\u3046", "\u3048", "\u304a",
"\u304b", "\u304d", "\u304f", "\u3051", "\u3053",
"\u3055", "\u3057", "\u3059", "\u305b", "\u305d",
"\u305f", "\u3061", "\u3064", "\u3066", "\u3068",
"\u306a", "\u306b", "\u306c", "\u306d", "\u306e",
"\u306f", "\u3072", "\u3075", "\u3078", "\u307b",
"\u307e", "\u307f", "\u3080", "\u3081", "\u3082",
"\u3084", "\u3086", "\u3088",
"\u3089", "\u308a", "\u308b", "\u308c", "\u308d",
"\u308f", "\u3092",
"\u3093",
];

public int AvailableSyllablesCount { get { return AvailableSyllables.Count; } }

public SettingsController() {
keyGraphPair = new Dictionary<GraphState, GraphModel>() {
StateGraphPair = new Dictionary<GraphState, GraphModel>() {
{ GraphState.MONOGRAPH, new MonographModel(this) },
{ GraphState.DIGRAPH, new DigraphModel(this) },
{ GraphState.DIACRITIC_MONOGRAPG, new DiacriticMonographModel(this) },
Expand All @@ -31,37 +58,60 @@ public SettingsController() {
SetGuesses();
}

/// <summary>
/// Adds gamemodel to notify if list of available syllables has changed.
/// </summary>
/// <param name="model">Concrete gamemodel to notify.</param>
public void AddGame(GameModel model) {
GameModels.Add(model);
model.RemainingSyllables = AvailableSyllables;
model.RemainingSyllables = new(AvailableSyllables);
model.Reset();
}

/// <summary>
/// Gets current concrete graph model set.
/// </summary>
/// <returns>Current graph model.</returns>
public GraphModel GetCurrentGraph() {
return keyGraphPair[CurrentGraphState];
return StateGraphPair[CurrentGraphState];
}

/// <summary>
/// Sets next current graph based on syllable count (MONOGRAPH to DIGRAPH and vice versa)
/// </summary>
public void NextGraph() {
CurrentGraphState = (GraphState)(((int)CurrentGraphState ^ 0b01) & ~0b10);
}

/// <summary>
/// Sets next current graph based on diacritic (NON-DIACRITIC MONO/DIGRAPH to DIACRITIC and vice versa)
/// </summary>
public void NextDiacritic() {
CurrentGraphState = (GraphState)((int)CurrentGraphState ^ 0b10);
}

/// <summary>
/// Clears AvailableSyllables and adds new active guesses.
/// </summary>
private void SetGuesses() {
AvailableSyllables.Clear();

foreach (GraphModel m in keyGraphPair.Values) {
foreach (string g in m.Guesses) {
AvailableSyllables.Add(g);
foreach (GraphModel model in StateGraphPair.Values) {
foreach (string kana in model.Guesses) {
AvailableSyllables.Add(kana);
}
}
}

/// <summary>
/// Resets AvailableSyllables and notifies all subscribed gamemodels that AvailableSyllables have changed by resetting them.
/// </summary>
public void Notify() {
SetGuesses();
foreach (GameModel m in GameModels) m.Reset();
foreach (GameModel m in GameModels) {
m.RemainingSyllables = new(AvailableSyllables);
m.Reset();
}
}
}
}
17 changes: 3 additions & 14 deletions hiravrt/Models/Game/GameModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using hiravrt.Models.Nav.Graphs;
using hiravrt.Controllers.Nav;
using hiravrt.Models.Nav.Graphs;
using Microsoft.AspNetCore.Mvc;
using System.Text;
using System.Text.Json.Nodes;
Expand Down Expand Up @@ -28,19 +29,7 @@ public abstract class GameModel {
public int CorrectGuessesCount = default;

public GameModel(int MinimumGuessesCount) {
this.RemainingSyllables = [
"\u3042", "\u3044", "\u3046", "\u3048", "\u304a",
"\u304b", "\u304d", "\u304f", "\u3051", "\u3053",
"\u3055", "\u3057", "\u3059", "\u305b", "\u305d",
"\u305f", "\u3061", "\u3064", "\u3066", "\u3068",
"\u306a", "\u306b", "\u306c", "\u306d", "\u306e",
"\u306f", "\u3072", "\u3075", "\u3078", "\u307b",
"\u307e", "\u307f", "\u3080", "\u3081", "\u3082",
"\u3084", "\u3086", "\u3088",
"\u3089", "\u308a", "\u308b", "\u308c", "\u308d",
"\u308f", "\u3092",
"\u3093",
];
this.RemainingSyllables = SettingsController.DefaultSyllables;
this.MinimumGuessesCount = MinimumGuessesCount;

InitialMove();
Expand Down
2 changes: 1 addition & 1 deletion hiravrt/Views/Pages/Nav/Settings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<article class="article-page" id="settings-sub-article">
<hgroup>
<h2>HIRAGANA GRID</h2>
<h3>ACTIVE SYLLABLES: @mc.SettingsC.AvailableSyllables.Count</h3>
<h3>ACTIVE SYLLABLES: @mc.SettingsC.AvailableSyllablesCount</h3>
</hgroup>

@switch (mc.SettingsC.CurrentGraphState) {
Expand Down

0 comments on commit 2a5f252

Please sign in to comment.