From a8443964bca48270898a14fc15f1e6b2f5667400 Mon Sep 17 00:00:00 2001 From: isark Date: Mon, 18 Mar 2024 21:43:09 +0100 Subject: [PATCH] Scuffed display, scuffed uuid based checkpoint (for livesplit inspired functionality) --- src-tauri/src/time.rs | 1 + src/app/_services/run-stat.service.ts | 37 ++++--------------- src/app/_services/time-tracker.service.ts | 35 +++++++++++++++--- .../plan-display/plan-display.component.html | 6 +-- .../plan-display/plan-display.component.ts | 25 +++++++------ src/app/run-stats/run-stats.component.html | 2 +- src/app/run-stats/run-stats.component.ts | 6 ++- 7 files changed, 61 insertions(+), 51 deletions(-) diff --git a/src-tauri/src/time.rs b/src-tauri/src/time.rs index 86176c5..d722ee5 100644 --- a/src-tauri/src/time.rs +++ b/src-tauri/src/time.rs @@ -27,6 +27,7 @@ pub enum EntryType { PlanForceNext, PlanForcePrev, ZoneEnter, + CheckpointReached } #[derive(Serialize, Deserialize, Debug, Clone)] diff --git a/src/app/_services/run-stat.service.ts b/src/app/_services/run-stat.service.ts index 72e9892..a14d19d 100644 --- a/src/app/_services/run-stat.service.ts +++ b/src/app/_services/run-stat.service.ts @@ -54,7 +54,9 @@ export class RunStatService { /// practically which zone can't have a last exit time as last exit is not determinable for the last entry aggregateNAId?: string; - constructor() { } + constructor() { + + } calcAggregated(data: RunHistory): UnformattedAggregationData { const aggregation = new Map(); @@ -104,36 +106,11 @@ export class RunStatService { insertTimesAtCheckpoints(history: RunHistory, plan: Plan) { const data = this.calcDirect(history); - let fakeCurrent = 0; - console.log("history", history); - - data.forEach(entry => { - switch (entry.entryType) { - case EntryType.PlanForceNext: - fakeCurrent++; - break; - case EntryType.PlanForcePrev: - fakeCurrent--; - break; - case EntryType.ZoneEnter: - if (plan.isNext(entry.zoneId, fakeCurrent)) { - fakeCurrent++; - if (plan.plan[fakeCurrent].checkpoint) { - plan.plan[fakeCurrent].checkpoint_millis = entry.entryTime; - } - } - break; + const checkPointEntries = new Map(data.filter(entry => entry.entryType === EntryType.CheckpointReached).map(entry => [entry.zoneId, entry.entryTime])); + plan.plan.forEach(elem => { + if (checkPointEntries.has(elem.uuid!)) { + elem.checkpoint_millis = checkPointEntries.get(elem.uuid!); } }); - - if (fakeCurrent < plan.plan.length - 1) { - for (let current = fakeCurrent; current < plan.plan.length; current++) { - if (plan.plan[current].checkpoint) { - plan.plan[current].checkpoint_millis = -1; - } - } - } - - console.log("Inserted checkpoint times", plan); } } \ No newline at end of file diff --git a/src/app/_services/time-tracker.service.ts b/src/app/_services/time-tracker.service.ts index e3e94e4..65ac298 100644 --- a/src/app/_services/time-tracker.service.ts +++ b/src/app/_services/time-tracker.service.ts @@ -13,6 +13,7 @@ export enum EntryType { PlanForceNext = "PlanForceNext", PlanForcePrev = "PlanForcePrev", ZoneEnter = "ZoneEnter", + CheckpointReached = "CheckpointReached", } export interface TrackEntry { @@ -45,6 +46,8 @@ export class RunHistory { associatedName: string; last_updated: number; + plan?: Plan; + constructor(data: RunHistoryInterface) { this.uuid = data.uuid; this.currentElapsedMillis = data.current_elapsed_millis; @@ -115,6 +118,7 @@ export class TimeTrackerService { if (plan.last_stored_time) { this.loadHistory(plan.last_stored_time).subscribe(history => { + if (history) { this.currentRunHistory = history; } else { @@ -128,10 +132,12 @@ export class TimeTrackerService { plan.requestSelfSave(); } + this.currentRunHistory.plan = plan; this.askResume(plan); }); } else { this.currentRunHistory = this.createNew(plan.name); + this.currentRunHistory.plan = plan; } } @@ -154,7 +160,7 @@ export class TimeTrackerService { this.timerSubscription = timer(0, 1000).subscribe(() => { - this.zone.run(() => { + this.zone.run(() => { this.latest = new Date(); this.currentRunHistory!.currentElapsedMillis = this.elapsedTimeMillis; @@ -167,10 +173,19 @@ export class TimeTrackerService { } private underlyingSaveStopwatch() { - if(this.currentRunHistory && this.active && this.start && this.latest) { + if (this.currentRunHistory && this.active && this.start && this.latest) { + console.log("Underlying save!"); this.currentRunHistory!.currentElapsedMillis = this.elapsedTimeMillis; this.currentRunHistory!.last_updated = Date.now(); + this.saveHistory(this.currentRunHistory!).subscribe(() => { }); + this.loadCache(); + + + if(this.currentRunHistory.plan) { + this.currentRunHistory.plan.last_stored_time = this.currentRunHistory.uuid; + this.currentRunHistory.plan.requestSelfSave(); + } } } @@ -211,7 +226,17 @@ export class TimeTrackerService { } } + //Not perfect but good enough.. + public reportCheckpoint(checkpoint: string) { + this.currentRunHistory?.entries.push({ + type: EntryType.CheckpointReached, + zone: checkpoint, + current_elapsed_millis: this.elapsedTimeMillis + }) + } + public stop() { + console.log("Stopping stopwatch"); if (this.timerSubscription && !this.timerSubscription.closed) this.timerSubscription.unsubscribe(); if (this.debouncedSaveStopwatch && !this.debouncedSaveStopwatch.closed) this.debouncedSaveStopwatch.unsubscribe(); @@ -239,7 +264,7 @@ export class TimeTrackerService { return `${h}:${m}:${s}`; } - private loadCache() { + public loadCache() { from(invoke>('load_cache')).subscribe(data => { this.zone.run(() => { const cache = new Map(); @@ -251,9 +276,9 @@ export class TimeTrackerService { last_updated: value.last_updated, }); }); - + console.log("sending new cache!"); this.storedHistoriesSubject.next(cache); - }) + }); }); } diff --git a/src/app/plan-display/plan-display.component.html b/src/app/plan-display/plan-display.component.html index bfc0947..f8d415d 100644 --- a/src/app/plan-display/plan-display.component.html +++ b/src/app/plan-display/plan-display.component.html @@ -14,13 +14,13 @@
-
{{yourDiff(slide)}}
+
{{yourDiff(slide)}}
-
{{worldAreaMap!.get(slide.area_key)!.name}}
+
{{worldAreaMap!.get(slide.area_key)!.name}}
-
{{cpMillis(slide)}}
+
{{cpMillis(slide)}}
(W)
(T)
diff --git a/src/app/plan-display/plan-display.component.ts b/src/app/plan-display/plan-display.component.ts index ca07e15..3f371e6 100644 --- a/src/app/plan-display/plan-display.component.ts +++ b/src/app/plan-display/plan-display.component.ts @@ -9,7 +9,7 @@ import { PlanService, UrlError } from '../_services/plan.service'; import { Plan, PlanElement, PlanMetadata } from '../_models/plan'; import { WorldAreaService } from '../_services/world-area.service'; import { WorldArea } from '../_models/world-area'; -import { Subscription, from } from 'rxjs'; +import { Subscription, config, from } from 'rxjs'; import { open } from '@tauri-apps/api/dialog'; import { OverlayService, StateEvent } from '../_services/overlay.service'; import { appWindow } from '@tauri-apps/api/window'; @@ -19,12 +19,6 @@ import { MatDialog } from '@angular/material/dialog'; import { TimeTrackerService } from '../_services/time-tracker.service'; import { RunStatService } from '../_services/run-stat.service'; -enum Resume { - Discard, - Next, - Instant -} - @Component({ selector: 'plan-display', templateUrl: './plan-display.component.html', @@ -84,6 +78,7 @@ export class PlanDisplayComponent implements AfterViewInit, OnInit { this.currentPlan = plan; if (this.configService.config.enableStopwatch) { + console.log(configService.config.runCompareHistory); this.loadComparisonData(this.currentPlan); } this.timeTrackerService.onNewRun(plan); @@ -238,6 +233,7 @@ export class PlanDisplayComponent implements AfterViewInit, OnInit { this.prev(); if (this.configService.config.enableStopwatch) { this.timeTrackerService.onForcePrev(this.currentPlan!.plan[this.currentPlan!.current].area_key); + this.checkCheckpoint(); } }); @@ -245,6 +241,7 @@ export class PlanDisplayComponent implements AfterViewInit, OnInit { this.next(); if (this.configService.config.enableStopwatch) { this.timeTrackerService.onForceNext(this.currentPlan!.plan[this.currentPlan!.current].area_key); + this.checkCheckpoint(); } }); @@ -274,6 +271,7 @@ export class PlanDisplayComponent implements AfterViewInit, OnInit { const currentElem = this.currentPlan.plan[this.currentPlan.current]; if(currentElem.checkpoint && !currentElem.checkpoint_your_millis) { currentElem.checkpoint_your_millis = this.timeTrackerService.elapsedTimeMillis; + this.timeTrackerService.reportCheckpoint(currentElem.uuid!); } } @@ -281,17 +279,20 @@ export class PlanDisplayComponent implements AfterViewInit, OnInit { if (!element.checkpoint || !element.checkpoint_your_millis || !element.checkpoint_millis) return ""; const diff = element.checkpoint_your_millis - element.checkpoint_millis; - const neg = diff < 0; + const neg = diff <= 0; const abs = Math.abs(diff); - const cssClass = neg ? "negative-diff" : "positive-diff"; - return `${neg ? "-" : "+"}${this.timeTrackerService.hmsTimestamp(abs)}`; + if(diff == 0) { + return `${neg ? "-" : "+"}00:00:00`; + } else { + return `${neg ? "-" : "+"}${this.timeTrackerService.hmsTimestamp(abs)}`; + } } yourDiffClass(element: PlanElement): string { if (!element.checkpoint || !element.checkpoint_your_millis || !element.checkpoint_millis) return ""; const diff = element.checkpoint_your_millis - element.checkpoint_millis; - const neg = diff < 0; + const neg = diff <= 0; return neg ? "negative-diff" : "positive-diff"; } @@ -371,9 +372,11 @@ export class PlanDisplayComponent implements AfterViewInit, OnInit { if (event.deltaY < 0) { this.prev(); this.timeTrackerService.onForcePrev(this.currentPlan!.plan[this.currentPlan!.current].area_key); + this.checkCheckpoint(); } else { this.next(); this.timeTrackerService.onForceNext(this.currentPlan!.plan[this.currentPlan!.current].area_key); + this.checkCheckpoint(); } } diff --git a/src/app/run-stats/run-stats.component.html b/src/app/run-stats/run-stats.component.html index 2ead90a..c0a55e8 100644 --- a/src/app/run-stats/run-stats.component.html +++ b/src/app/run-stats/run-stats.component.html @@ -2,7 +2,7 @@
-
+
Plan: {{item.value.associatedName}} Run time: {{hms(item.value.currentElapsedMillis)}} diff --git a/src/app/run-stats/run-stats.component.ts b/src/app/run-stats/run-stats.component.ts index a7e5e6d..be611c6 100644 --- a/src/app/run-stats/run-stats.component.ts +++ b/src/app/run-stats/run-stats.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit } from '@angular/core'; -import { CommonModule } from '@angular/common'; +import { CommonModule, KeyValue } from '@angular/common'; import { EntryType, RunHistory, RunHistoryMetadata, TimeTrackerService } from '../_services/time-tracker.service'; import { MatTableModule } from '@angular/material/table'; import { MatSlideToggleModule } from '@angular/material/slide-toggle'; @@ -121,9 +121,13 @@ export class RunStatsComponent implements OnInit { } reset() { + this.timeTrackerService.loadCache(); this.aggregated = undefined; this.direct = undefined; + } + myOrder(a: KeyValue, b: KeyValue): number { + return b.value.last_updated - a.value.last_updated; } setComparison(id: string) {