private async Task FetchChapter(ChapterId chapter) { if (!Global.Online) { GD.Print("Fetching info online not allowed"); return; } requestKey++; int thisRequest = requestKey; await ToSignal((Godot.Object) SWS.Call("get_high_scores", 10, $"chapter-{(int) chapter}"), "sw_scores_received"); if (thisRequest != requestKey) { GD.PrintErr("Fetched Multiple Chapters at the same time"); } ChapterScore chapterScore = new ChapterScore { Chapter = chapter, TimeStamp = DateTime.Now }; int rank = 1; foreach (Godot.Collections.Dictionary line in (Godot.Collections.Array)SWS.Get("scores")) { // GD.Print(line["player_name"].GetType(), " ", line["player_name"]); // GD.Print(line["score"].GetType(), " ", line["score"]); chapterScore.Scores.Add(new ScoreLine { Rank = rank, Name = (string)line["player_name"], Time = (int)-((float)line["score"]) }); rank++; } cachedScores[chapter] = chapterScore; EmitSignal(nameof(RefreshChapterScore), chapter); }
public async Task <ChapterScore> GetChapterScore(ChapterId chapter, float cacheTime = 15f) { if (!cachedScores.ContainsKey(chapter) || (DateTime.Now - cachedScores[chapter].TimeStamp).Seconds > cacheTime) { await FetchChapter(chapter); } return(cachedScores[chapter]); }
private static string Scene(ChapterId chapter, int level) { if (chapter >= ChapterId.TOTAL) { return($"res://Scenes/MainMenu.tscn"); } int chap = (int)(chapter); return($"res://Scenes/Levels/Chapter{chap}/Level{chap}-{level}.tscn"); }
public bool Equals(DbStats?other) { return(other != null && Id.Equals(other.Id) && ProfileId.Equals(other.ProfileId) && ChapterId.Equals(other.ChapterId) && Completed == other.Completed && Tips.SequenceEqual(other.Tips) && Submits.SequenceEqual(other.Submits) && Failures.SequenceEqual(other.Failures)); }
public static void LoadChapter(ChapterId chapter) { Chapter = chapter; Level = 1; Instance.GetTree().ChangeScene(CHAPTER_INTRO); }
internal ChapterContext(MangaContext root, ChapterId chapter, ProjectDirectoryListingProvider listing) { this.root = root; this.chapter = chapter; this.listing = listing; }
public async Task WipeChapter(ChapterId chapter) { await ToSignal((Godot.Object) SWS.Call("wipe_leaderboard", $"chapter-{(int) chapter}"), "sw_leaderboard_wiped"); }
public async Task AddScoreLine(ChapterId chapter, string player, int time) { await ToSignal((Godot.Object) SWS.Call("persist_score", player, -time, $"chapter-{(int) chapter}"), "sw_score_posted"); }
public ChapterScore GetCachedChapterScore(ChapterId chapter) { return(cachedScores.ContainsKey(chapter) ? cachedScores[chapter] : null); }
public static ChapterId Next(this ChapterId chapter) { return(chapter < ChapterId.TOTAL ? chapter + 1 : ChapterId.NONE); }
public bool Equals(Submit?other) { return(other != null && ChapterId.Equals(other.ChapterId) && PageIndex == other.PageIndex && Solution == other.Solution); }
protected override int GetHashCodeInternal() { return((ChapterId?.GetHashCode() ?? 0) * 19 + BlockId.GetHashCode() * 7 + LineId.GetHashCode()); }