Added continue learning support!!!
This commit is contained in:
parent
b5870a4279
commit
2264087322
3 changed files with 106 additions and 14 deletions
|
@ -26,12 +26,16 @@
|
|||
|
||||
<MudContainer Class="justify-center d-flex ma-0" Style="height: 100%;">
|
||||
<MudStack Class="d-flex">
|
||||
@*<MudStack Row=true Class="pt-2 d-flex justify-center">
|
||||
@if (!Answers.Any(x => x == null))
|
||||
{
|
||||
<MudButton Disabled="@(!(Answers.Any(x=>x.isSelected)))" OnClick="()=>RemoveCCharFromSelection()" Variant="Variant.Outlined">Avoid</MudButton>
|
||||
}
|
||||
</MudStack>*@
|
||||
@*True if debug, false for not debug. (TODO: Use an extensíonMethod: https://stackoverflow.com/questions/4696175/preprocessor-directives-in-razor)*@
|
||||
@if (true)
|
||||
{
|
||||
<MudStack Row=true Class="pt-2 d-flex justify-center">
|
||||
@if (!Answers.Any(x => x == null))
|
||||
{
|
||||
<MudButton Disabled="@(!(Answers.Any(x=>x.isSelected)))" OnClick="()=>RemoveCCharFromSelection()" Variant="Variant.Outlined">Avoid</MudButton>
|
||||
}
|
||||
</MudStack>
|
||||
}
|
||||
<MudContainer Class="pt-12">
|
||||
<MudPaper Class="pa-16 ma-2 rounded-xl mud-dark" Elevation="1">
|
||||
<MudContainer Style="width: 100px; height: 100px" Class="pa-8 ma-4 d-flex justify-center align-center">
|
||||
|
@ -118,6 +122,28 @@
|
|||
{
|
||||
Program.UpdateUiEvent += OnUiUpdate;
|
||||
|
||||
bool continueLast =
|
||||
await localStorage.ContainKeyAsync("ContinueLearning")
|
||||
&& await localStorage.ContainKeyAsync("ContinueData")
|
||||
&& await localStorage.GetItemAsync<bool>("ContinueLearning");
|
||||
|
||||
if (continueLast)
|
||||
{
|
||||
await LoadCharectersFromContinue();
|
||||
}
|
||||
else
|
||||
{
|
||||
await LoadCharectersFromChunk();
|
||||
}
|
||||
|
||||
Program.CCharsLeft = DontSkipTheseCChar.Count;
|
||||
Program.InvokeUiUpdate();
|
||||
|
||||
GenerateQuestion();
|
||||
}
|
||||
|
||||
async Task LoadCharectersFromChunk()
|
||||
{
|
||||
isSavedLocally = await localStorage.ContainKeyAsync("Normalized_chunk_001.json");
|
||||
|
||||
int selectedChunk = await localStorage.GetItemAsync<int>("SelectedChunk");
|
||||
|
@ -130,11 +156,15 @@
|
|||
Charecters = JsonConvert.DeserializeObject<CChar[]>(json);
|
||||
}
|
||||
|
||||
DontSkipTheseCChar = Charecters.Select(x=>new CCharStats(x)).ToList();
|
||||
Program.CCharsLeft = DontSkipTheseCChar.Count;
|
||||
Program.InvokeUiUpdate();
|
||||
DontSkipTheseCChar = Charecters.Select(x => new CCharStats(x)).ToList();
|
||||
}
|
||||
|
||||
GenerateQuestion();
|
||||
async Task LoadCharectersFromContinue()
|
||||
{
|
||||
string continueDataJson = await localStorage.GetItemAsStringAsync("ContinueData");
|
||||
CCharStats[] charectersLeft = JsonConvert.DeserializeObject<CCharStats[]>(continueDataJson);
|
||||
|
||||
DontSkipTheseCChar = charectersLeft.ToList();
|
||||
}
|
||||
|
||||
void OnUiUpdate() => StateHasChanged();
|
||||
|
@ -170,9 +200,11 @@
|
|||
|
||||
Answers[i].isCorrect = true;
|
||||
}
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
void FinishAndKickBackToLearn()
|
||||
async void FinishAndKickBackToLearn()
|
||||
{
|
||||
Snackbar.Add("Congrats, you have compleated this chunk!", Severity.Success, config =>
|
||||
{
|
||||
|
@ -182,6 +214,8 @@
|
|||
Program.UpdateUiEvent -= OnUiUpdate;
|
||||
Program.CCharsLeft = 0;
|
||||
|
||||
await localStorage.RemoveItemAsync("ContinueData");
|
||||
|
||||
navigator.NavigateTo("");
|
||||
}
|
||||
|
||||
|
@ -221,9 +255,20 @@
|
|||
}
|
||||
}
|
||||
|
||||
await SaveContinueData();
|
||||
|
||||
GenerateQuestion();
|
||||
}
|
||||
|
||||
async Task SaveContinueData()
|
||||
{
|
||||
CCharStats[] charectersLeft = DontSkipTheseCChar.ToArray();
|
||||
string continueDataJson = JsonConvert.SerializeObject(charectersLeft);
|
||||
|
||||
await localStorage.SetItemAsStringAsync("ContinueData", continueDataJson);
|
||||
await localStorage.SetItemAsync("ContinueCharectersLeft", charectersLeft.Length);
|
||||
}
|
||||
|
||||
public class Answer
|
||||
{
|
||||
public Answer()
|
||||
|
@ -260,6 +305,7 @@
|
|||
CCharStats correctCCharStats = DontSkipTheseCChar.First(x => x.cchar == correctChar);
|
||||
return correctCCharStats;
|
||||
}
|
||||
|
||||
public void increaseCCharStat(CCharStats stats, StatType statType)
|
||||
{
|
||||
int correctStatsIndex = DontSkipTheseCChar.IndexOf(stats);
|
||||
|
@ -275,7 +321,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
public void RemoveCCharFromSelection(bool ignoreSelection = false)
|
||||
public async void RemoveCCharFromSelection(bool ignoreSelection = false)
|
||||
{
|
||||
CCharStats correctCCharStats = GetCorrectCCharStats();
|
||||
|
||||
|
@ -294,6 +340,9 @@
|
|||
Console.WriteLine("Remaining CChars: " + DontSkipTheseCChar);
|
||||
Program.CCharsLeft = DontSkipTheseCChar.Count;
|
||||
Program.InvokeUiUpdate();
|
||||
|
||||
await SaveContinueData();
|
||||
|
||||
GenerateQuestion();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue