Lots of tweaks, bugfixes and improvements! Also supports storing and loading current position in a plan you've imported before. Can scroll on the plan window to quickly move forward/backward
parent
534dde670e
commit
5bcaa47008
@ -0,0 +1,71 @@
|
|||||||
|
import { invoke } from "@tauri-apps/api/tauri";
|
||||||
|
import { Subject, debounceTime, from } from "rxjs";
|
||||||
|
|
||||||
|
export interface PlanInterface {
|
||||||
|
plan: PlanElement[];
|
||||||
|
current: number;
|
||||||
|
stored_path?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Plan {
|
||||||
|
plan: PlanElement[];
|
||||||
|
current: number;
|
||||||
|
private path?: string;
|
||||||
|
private saveSubject: Subject<void> = new Subject<void>();
|
||||||
|
|
||||||
|
constructor(plan: PlanInterface) {
|
||||||
|
this.plan = plan.plan;
|
||||||
|
this.current = plan.current;
|
||||||
|
if(plan.stored_path) {
|
||||||
|
this.path = plan.stored_path;
|
||||||
|
}
|
||||||
|
this.saveSubject.pipe(debounceTime(500)).subscribe(() => this.underlyingSave());
|
||||||
|
}
|
||||||
|
|
||||||
|
setPath(path: string) {
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
next() {
|
||||||
|
if (this.current + 1 < this.plan!.length) {
|
||||||
|
this.current++;
|
||||||
|
this.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
prev() {
|
||||||
|
if (this.current - 1 >= 0) {
|
||||||
|
this.current--;
|
||||||
|
this.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setPrevious(prev: string) {
|
||||||
|
from(invoke<string>('path_for_previous', { prev })).subscribe(path => {
|
||||||
|
if (path) {
|
||||||
|
this.setPath(path);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private save() {
|
||||||
|
if (this.path) {
|
||||||
|
this.saveSubject.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private underlyingSave() {
|
||||||
|
console.log("Underlying save");
|
||||||
|
invoke('save_plan', {
|
||||||
|
plan: {
|
||||||
|
plan: this.plan,
|
||||||
|
current: this.current
|
||||||
|
}, path: this.path
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PlanElement {
|
||||||
|
area_key: string;
|
||||||
|
notes?: string;
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
import { Injectable, NgZone } from '@angular/core';
|
import { Injectable, NgZone } from '@angular/core';
|
||||||
import { WorldArea } from '../models/world-area';
|
import { WorldArea } from '../_models/world-area';
|
||||||
import { invoke } from '@tauri-apps/api';
|
import { invoke } from '@tauri-apps/api';
|
||||||
import { Observable, ReplaySubject, Subject, filter, from, map } from 'rxjs';
|
import { Observable, ReplaySubject, Subject, filter, from, map } from 'rxjs';
|
||||||
import naturalCompare from 'natural-compare';
|
import naturalCompare from 'natural-compare';
|
@ -1,11 +0,0 @@
|
|||||||
import { WorldArea } from "./world-area";
|
|
||||||
|
|
||||||
export interface Plan {
|
|
||||||
plan: PlanElement[];
|
|
||||||
current: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PlanElement {
|
|
||||||
area_key: string;
|
|
||||||
notes?: string;
|
|
||||||
}
|
|
Loading…
Reference in new issue