|
|
|
@ -9,12 +9,20 @@ 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, from, timer } from 'rxjs';
|
|
|
|
|
import { open } from '@tauri-apps/api/dialog';
|
|
|
|
|
import { OverlayService, StateEvent } from '../_services/overlay.service';
|
|
|
|
|
import { appWindow } from '@tauri-apps/api/window';
|
|
|
|
|
import { EventsService } from '../_services/events.service';
|
|
|
|
|
import { Event } from '@tauri-apps/api/event';
|
|
|
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
|
|
|
import { ResumeDialog } from './resume-dialog.component';
|
|
|
|
|
|
|
|
|
|
enum Resume {
|
|
|
|
|
Discard,
|
|
|
|
|
Next,
|
|
|
|
|
Instant
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'plan-display',
|
|
|
|
@ -45,9 +53,15 @@ export class PlanDisplayComponent implements AfterViewInit, OnInit {
|
|
|
|
|
previousPlans: PlanMetadata[] = [];
|
|
|
|
|
checkingPlanUpdate: boolean = false;
|
|
|
|
|
|
|
|
|
|
start?: Date;
|
|
|
|
|
latest?: Date;
|
|
|
|
|
timerSubscription?: Subscription;
|
|
|
|
|
debouncedSaveStopwatch?: Subscription;
|
|
|
|
|
|
|
|
|
|
recentUpdateAttempts: Map<string, Date | UrlError> = new Map<string, Date | UrlError>();
|
|
|
|
|
resumeOnNext: boolean = false;
|
|
|
|
|
|
|
|
|
|
constructor(private events: EventsService, public configService: ConfigService, private cdr: ChangeDetectorRef, private shortcut: ShortcutService, public planService: PlanService, public worldAreaService: WorldAreaService, public overlayService: OverlayService, private zone: NgZone) {
|
|
|
|
|
constructor(private events: EventsService, public configService: ConfigService, private cdr: ChangeDetectorRef, private shortcut: ShortcutService, public planService: PlanService, public worldAreaService: WorldAreaService, public overlayService: OverlayService, private zone: NgZone, public dialog: MatDialog) {
|
|
|
|
|
window.addEventListener("resize", () => {
|
|
|
|
|
this.zone.run(() => {
|
|
|
|
|
this.windowInitHandler()
|
|
|
|
@ -60,15 +74,26 @@ export class PlanDisplayComponent implements AfterViewInit, OnInit {
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
this.planService.getCurrentPlan().subscribe(plan => {
|
|
|
|
|
if (this.timerSubscription && !this.timerSubscription.closed) this.timerSubscription.unsubscribe();
|
|
|
|
|
if (this.debouncedSaveStopwatch && !this.debouncedSaveStopwatch.closed) this.debouncedSaveStopwatch.unsubscribe();
|
|
|
|
|
|
|
|
|
|
this.currentPlan = plan;
|
|
|
|
|
|
|
|
|
|
this.start = undefined;
|
|
|
|
|
//Close settings anytime we get a new current plan.
|
|
|
|
|
this.settingsOpen = false;
|
|
|
|
|
|
|
|
|
|
if (this.currentPlan.last_stored_time) {
|
|
|
|
|
this.askResume();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setTimeout(() => this.setIndex(plan.current), 0);
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
this.registerOnZoneEnter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get disablePlans(): boolean {
|
|
|
|
|
return this.checkingPlanUpdate;
|
|
|
|
|
}
|
|
|
|
@ -82,11 +107,43 @@ export class PlanDisplayComponent implements AfterViewInit, OnInit {
|
|
|
|
|
if (entered.payload === this.currentPlan.plan[current + 1].area_key) {
|
|
|
|
|
this.zone.run(() => this.next());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log("config enableStopwatch", this.configService.config.enableStopwatch)
|
|
|
|
|
if (this.configService.config.enableStopwatch) {
|
|
|
|
|
console.log("this.start", this.start);
|
|
|
|
|
if (entered.payload === this.currentPlan!.plan[0].area_key && !this.start || this.resumeOnNext) {
|
|
|
|
|
this.resumeOnNext = false;
|
|
|
|
|
this.startStopwatch();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///Assumes currentPlan is set...
|
|
|
|
|
private startStopwatch() {
|
|
|
|
|
console.log("Starting stopwatch");
|
|
|
|
|
if (this.currentPlan?.last_stored_time) {
|
|
|
|
|
this.start = new Date(Date.now() - this.currentPlan.last_stored_time);
|
|
|
|
|
} else {
|
|
|
|
|
this.start = new Date();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.timerSubscription && !this.timerSubscription.closed) this.timerSubscription.unsubscribe();
|
|
|
|
|
if (this.debouncedSaveStopwatch && !this.debouncedSaveStopwatch.closed) this.debouncedSaveStopwatch.unsubscribe();
|
|
|
|
|
|
|
|
|
|
this.timerSubscription = timer(0, 1000).subscribe(() => {
|
|
|
|
|
this.zone.run(() => { this.latest = new Date(); });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.debouncedSaveStopwatch = timer(0, 10000).subscribe(() => {
|
|
|
|
|
this.currentPlan!.last_stored_time = this.elapsedTimeMillis();
|
|
|
|
|
console.log("last stored time at save attempt", this.currentPlan!.last_stored_time);
|
|
|
|
|
this.currentPlan!.requestSelfSave();
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
windowInitHandler() {
|
|
|
|
|
if (window.innerWidth > 0) {
|
|
|
|
|
this.ngAfterViewInit();
|
|
|
|
@ -364,6 +421,48 @@ export class PlanDisplayComponent implements AfterViewInit, OnInit {
|
|
|
|
|
if (this.hasUpdate(plan) && this.isErr(plan)) return "Error updating";
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentTime() {
|
|
|
|
|
if (!this.latest || !this.start) return "";
|
|
|
|
|
|
|
|
|
|
const diff = this.latest.valueOf() - this.start.valueOf();
|
|
|
|
|
const h = String(Math.floor(diff / 3600000)).padStart(2, '0');
|
|
|
|
|
const m = String(Math.floor((diff % 3600000) / 60000)).padStart(2, '0');
|
|
|
|
|
const s = String(Math.floor((diff % 60000) / 1000)).padStart(2, '0');
|
|
|
|
|
|
|
|
|
|
return `${h}:${m}:${s}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
elapsedTimeMillis() {
|
|
|
|
|
return this.latest!.valueOf() - this.start!.valueOf();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shouldDisplayTimer(): boolean {
|
|
|
|
|
if (!this.configService.config.enableStopwatch) return false;
|
|
|
|
|
if (!this.start || !this.latest) return false;
|
|
|
|
|
|
|
|
|
|
return this.overlayService.visible && !this.overlayService.interactable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
askResume() {
|
|
|
|
|
console.log("Asking resume");
|
|
|
|
|
const dialogRef = this.dialog.open(ResumeDialog, {disableClose: true});
|
|
|
|
|
|
|
|
|
|
dialogRef.afterClosed().subscribe(resume => {
|
|
|
|
|
switch(resume) {
|
|
|
|
|
case Resume.Instant:
|
|
|
|
|
this.startStopwatch();
|
|
|
|
|
break;
|
|
|
|
|
case Resume.Next:
|
|
|
|
|
this.resumeOnNext = true;
|
|
|
|
|
break;
|
|
|
|
|
case Resume.Discard:
|
|
|
|
|
this.currentPlan!.last_stored_time = undefined;
|
|
|
|
|
this.currentPlan!.requestSelfSave();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function commonUUIDToNewCurrent(oldPlan: Plan, updatedPlan: Plan): number {
|
|
|
|
|