You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
2.7 KiB
112 lines
2.7 KiB
import { invoke } from "@tauri-apps/api/tauri";
|
|
import { Subject, debounceTime, from } from "rxjs";
|
|
|
|
export interface PlanInterface {
|
|
plan: PlanElement[];
|
|
current: number;
|
|
stored_path?: string;
|
|
update_url?: string;
|
|
name?: string;
|
|
latest_server_etag?: string;
|
|
identifier?: string,
|
|
last_stored_time?: string;
|
|
}
|
|
|
|
export interface PlanMetadata {
|
|
stored_path?: string;
|
|
update_url?: string;
|
|
name: string;
|
|
latest_server_etag?: string;
|
|
identifier?: string;
|
|
last_stored_time?: string;
|
|
}
|
|
|
|
export class Plan {
|
|
plan: PlanElement[];
|
|
current: number;
|
|
update_url?: string;
|
|
name?: string;
|
|
latest_server_etag?: string;
|
|
identifier?: string;
|
|
last_stored_time?: string;
|
|
|
|
public path?: string;
|
|
private selfSaveSubject: Subject<void> = new Subject<void>();
|
|
|
|
|
|
constructor(plan?: PlanInterface) {
|
|
if(!plan) {
|
|
this.plan = [];
|
|
this.current = 0;
|
|
return;
|
|
};
|
|
|
|
this.plan = plan.plan;
|
|
this.current = plan.current;
|
|
if (plan.stored_path) {
|
|
this.path = plan.stored_path;
|
|
}
|
|
this.update_url = plan.update_url;
|
|
this.name = plan.name;
|
|
this.latest_server_etag = plan.latest_server_etag;
|
|
this.identifier = plan.identifier;
|
|
this.last_stored_time = plan.last_stored_time;
|
|
this.selfSaveSubject.pipe(debounceTime(500)).subscribe(() => this.directSelfSave());
|
|
}
|
|
|
|
setPath(path: string) {
|
|
this.path = path;
|
|
}
|
|
|
|
isNext(zoneId: string, current = this.current) {
|
|
return current + 1 < this.plan.length && zoneId === this.plan[current + 1].area_key;
|
|
}
|
|
|
|
next() {
|
|
if (this.current + 1 < this.plan!.length) {
|
|
this.current++;
|
|
this.requestSelfSave();
|
|
}
|
|
}
|
|
|
|
prev() {
|
|
if (this.current - 1 >= 0) {
|
|
this.current--;
|
|
this.requestSelfSave();
|
|
}
|
|
}
|
|
|
|
toInterface(): PlanInterface {
|
|
return {
|
|
plan: this.plan,
|
|
current: this.current,
|
|
stored_path: this.path,
|
|
update_url: this.update_url,
|
|
latest_server_etag: this.latest_server_etag,
|
|
identifier: this.identifier,
|
|
last_stored_time: this.last_stored_time,
|
|
};
|
|
}
|
|
|
|
public requestSelfSave() {
|
|
if (this.path) {
|
|
this.selfSaveSubject.next();
|
|
}
|
|
}
|
|
|
|
private directSelfSave() {
|
|
invoke('save_plan_at_path', { path: this.path, plan: this.toInterface() });
|
|
}
|
|
|
|
}
|
|
|
|
export interface PlanElement {
|
|
area_key: string;
|
|
notes?: string;
|
|
uuid?: string;
|
|
edited: boolean;
|
|
anchor_act?: number;
|
|
checkpoint?: boolean;
|
|
checkpoint_millis?: number;
|
|
checkpoint_your_millis?: number;
|
|
} |