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

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

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

@ -122,11 +122,17 @@ export class EditorComponent implements OnInit {
} }
dropEndHandler(event: CdkDragDrop<WorldArea[]> | CdkDragDrop<PlanElement[]>) { 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) { 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(); this.scrollToEnd();
} else { } else {
moveItemInArray(this.plan.plan, event.previousIndex, this.plan.plan.length); moveItemInArray(this.plan.plan, event.previousIndex, end);
this.scrollToEnd(); this.scrollToEnd();
} }
} }
@ -175,15 +181,51 @@ export class EditorComponent implements OnInit {
this.scrollToEnd(); 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() { filterPlanElements() {
const value = (): any[] => { const value = (): any[] => {
if (this.planSearchString !== "" || this.planFilterAct.value != 0) { if (this.planSearchString !== "") {
this.disabledPlanDD = true; this.disabledPlanDD = true;
return this.planFuzzer.search(this.planSearchString).map(({ item }) => item).filter(item => { } 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; return this.areasMap?.get(item.area_key)?.act === this.planFilterAct.value || this.planFilterAct.value === 0;
}); });
}
} else { } else {
this.disabledPlanDD = false;
return this.plan.plan; return this.plan.plan;
} }
} }

Loading…
Cancel
Save