From 2a5f25217e1c8000e504f2b55e49f8eab63bb6c7 Mon Sep 17 00:00:00 2001 From: Matej Dedina Date: Thu, 30 May 2024 14:05:25 +0200 Subject: [PATCH] Added comments for controllers and changed SettingsController. --- hiravrt/Controllers/MainController.cs | 9 +++ hiravrt/Controllers/Nav/SettingsController.cs | 76 +++++++++++++++---- hiravrt/Models/Game/GameModel.cs | 17 +---- hiravrt/Views/Pages/Nav/Settings.razor | 2 +- 4 files changed, 76 insertions(+), 28 deletions(-) diff --git a/hiravrt/Controllers/MainController.cs b/hiravrt/Controllers/MainController.cs index 9e6e07f..d9fb74b 100644 --- a/hiravrt/Controllers/MainController.cs +++ b/hiravrt/Controllers/MainController.cs @@ -4,8 +4,17 @@ namespace hiravrt.Controllers { public class MainController { + /// + /// Game controller that contains all available games for views. + /// public GameController GameC { get; } = new(); + /// + /// Home controller with mainly addresses used by views. + /// public HomeController HomeC { get; } = new(); + /// + /// Settings controller used to control settings specidied by user. + /// public SettingsController SettingsC { get; } = new(); public MainController() { diff --git a/hiravrt/Controllers/Nav/SettingsController.cs b/hiravrt/Controllers/Nav/SettingsController.cs index ca9861e..a5af5d9 100644 --- a/hiravrt/Controllers/Nav/SettingsController.cs +++ b/hiravrt/Controllers/Nav/SettingsController.cs @@ -6,10 +6,10 @@ namespace hiravrt.Controllers.Nav { /// Graph states in settings razor section. /// 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 { @@ -17,12 +17,39 @@ public class SettingsController { /// List of all game models that rely on settings' active syllables /// public List GameModels = []; - private readonly Dictionary keyGraphPair; + /// + /// Lookup dictionary that returns concrete GraphModel based on GraphState + /// + private readonly Dictionary StateGraphPair; + /// + /// Returns current set graph in sesttings. + /// public GraphState CurrentGraphState { get; set; } = GraphState.MONOGRAPH; - public List AvailableSyllables { get; set; } = []; + /// + /// List of all available/active syllables. + /// + private List AvailableSyllables = []; + /// + /// Default syllables used by every gamemodel. + /// + public static readonly List 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() { + StateGraphPair = new Dictionary() { { GraphState.MONOGRAPH, new MonographModel(this) }, { GraphState.DIGRAPH, new DigraphModel(this) }, { GraphState.DIACRITIC_MONOGRAPG, new DiacriticMonographModel(this) }, @@ -31,37 +58,60 @@ public SettingsController() { SetGuesses(); } + /// + /// Adds gamemodel to notify if list of available syllables has changed. + /// + /// Concrete gamemodel to notify. public void AddGame(GameModel model) { GameModels.Add(model); - model.RemainingSyllables = AvailableSyllables; + model.RemainingSyllables = new(AvailableSyllables); model.Reset(); } + /// + /// Gets current concrete graph model set. + /// + /// Current graph model. public GraphModel GetCurrentGraph() { - return keyGraphPair[CurrentGraphState]; + return StateGraphPair[CurrentGraphState]; } + /// + /// Sets next current graph based on syllable count (MONOGRAPH to DIGRAPH and vice versa) + /// public void NextGraph() { CurrentGraphState = (GraphState)(((int)CurrentGraphState ^ 0b01) & ~0b10); } + /// + /// Sets next current graph based on diacritic (NON-DIACRITIC MONO/DIGRAPH to DIACRITIC and vice versa) + /// public void NextDiacritic() { CurrentGraphState = (GraphState)((int)CurrentGraphState ^ 0b10); } + /// + /// Clears AvailableSyllables and adds new active guesses. + /// 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); } } } + /// + /// Resets AvailableSyllables and notifies all subscribed gamemodels that AvailableSyllables have changed by resetting them. + /// public void Notify() { SetGuesses(); - foreach (GameModel m in GameModels) m.Reset(); + foreach (GameModel m in GameModels) { + m.RemainingSyllables = new(AvailableSyllables); + m.Reset(); + } } } } diff --git a/hiravrt/Models/Game/GameModel.cs b/hiravrt/Models/Game/GameModel.cs index 8ca2a26..1acf8a2 100644 --- a/hiravrt/Models/Game/GameModel.cs +++ b/hiravrt/Models/Game/GameModel.cs @@ -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; @@ -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(); diff --git a/hiravrt/Views/Pages/Nav/Settings.razor b/hiravrt/Views/Pages/Nav/Settings.razor index e81297e..78b66da 100644 --- a/hiravrt/Views/Pages/Nav/Settings.razor +++ b/hiravrt/Views/Pages/Nav/Settings.razor @@ -45,7 +45,7 @@

HIRAGANA GRID

-

ACTIVE SYLLABLES: @mc.SettingsC.AvailableSyllables.Count

+

ACTIVE SYLLABLES: @mc.SettingsC.AvailableSyllablesCount

@switch (mc.SettingsC.CurrentGraphState) {