Added section anchor points and support for using these in the filter

cleanup
isark 2 years ago
parent 91d93711cc
commit d1d64b7960

File diff suppressed because one or more lines are too long

@ -24,6 +24,8 @@ pub struct PlanElement {
#[serde(default = "PlanElement::edited")]
edited: bool,
anchor_act: Option<u8>
}
impl PlanElement {
@ -76,6 +78,7 @@ pub fn convert_old(path: &str) -> Option<Plan> {
notes: plan_element.note,
uuid: PlanElement::generate_uuid(),
edited: PlanElement::edited(),
anchor_act: None,
})
.collect::<Vec<PlanElement>>(),
stored_path: None

@ -70,4 +70,5 @@ export interface PlanElement {
notes?: string;
uuid?: string;
edited: boolean;
anchor_act?: number;
}

@ -25,7 +25,6 @@
</div>
<div class="col-6">
<div class="row">
<mat-form-field>
<mat-label>Area filter</mat-label>

@ -22,7 +22,7 @@ import { EditNotesComponentDialog } from './notes/notes.component';
import { open } from '@tauri-apps/api/dialog';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatSelectModule} from '@angular/material/select';
import { MatSelectModule } from '@angular/material/select';
import { MatButtonModule } from '@angular/material/button';
import { MatSlideToggleModule } from '@angular/material/slide-toggle';
@ -122,11 +122,17 @@ export class EditorComponent implements OnInit {
}
dropEndHandler(event: CdkDragDrop<WorldArea[]> | CdkDragDrop<PlanElement[]>) {
let bounds = this.planElemFilterBounds();
let end = this.plan.plan.length;
if (bounds) {
end = bounds[1];
}
if (isWorldAreaEvent(event) && this.areas) {
this.plan.plan.splice(this.plan.plan.length, 0, this.planItemFromArea(event.previousContainer.data[event.previousIndex]));
this.plan.plan.splice(end, 0, this.planItemFromArea(event.previousContainer.data[event.previousIndex]));
this.scrollToEnd();
} else {
moveItemInArray(this.plan.plan, event.previousIndex, this.plan.plan.length);
moveItemInArray(this.plan.plan, event.previousIndex, end);
this.scrollToEnd();
}
}
@ -175,15 +181,51 @@ export class EditorComponent implements OnInit {
this.scrollToEnd();
}
planElemFilterBounds() {
if(this.planFilterAct.value !== 0) {
let bounds = this.plan.plan.filter(item => item.anchor_act === this.planFilterAct.value || this.planFilterAct.value + 1 === item.anchor_act).map((value) => this.planIndexOf(value));
console.log("bounds, ", bounds);
if (bounds.length == 2) {
return bounds;
}
if(bounds.length == 1 && this.planFilterAct.value == 10) {
console.log("Setting bound to last index");
bounds[1] = this.plan.plan.length;
return bounds;
}
}
return undefined;
}
filterPlanElements() {
const value = (): any[] => {
if (this.planSearchString !== "" || this.planFilterAct.value != 0) {
if (this.planSearchString !== "") {
this.disabledPlanDD = true;
return this.planFuzzer.search(this.planSearchString).map(({ item }) => item).filter(item => {
return this.areasMap?.get(item.area_key)?.act === this.planFilterAct.value || this.planFilterAct.value === 0;
});
} else {
this.disabledPlanDD = false;
}
if (this.planSearchString !== "" || this.planFilterAct.value != 0) {
let bounds = this.planElemFilterBounds();
const searched = this.planFuzzer.search(this.planSearchString).map(({ item }) => item);
if (bounds) {
const definedBounds: number[] = bounds;
return searched.filter(item => {
const index = this.planIndexOf(item);
return index >= definedBounds[0] && index < definedBounds[1];
});
} else {
return searched.filter(item => {
return this.areasMap?.get(item.area_key)?.act === this.planFilterAct.value || this.planFilterAct.value === 0;
});
}
} else {
return this.plan.plan;
}
}
@ -254,7 +296,7 @@ export class EditorComponent implements OnInit {
})
dialogRef.afterClosed().subscribe(note => {
if(note) {
if (note) {
if (item.notes !== note) {
item.edited = true;
}

Loading…
Cancel
Save