diff --git a/src-tauri/poe_data/src/world_area.rs b/src-tauri/poe_data/src/world_area.rs index 89443e5..a485e5e 100644 --- a/src-tauri/poe_data/src/world_area.rs +++ b/src-tauri/poe_data/src/world_area.rs @@ -48,25 +48,12 @@ pub type AreaName = String; #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)] pub struct WorldArea { - #[serde(rename = "Name")] pub name: String, - - #[serde(rename = "NamedId")] pub named_id: String, - - #[serde(rename = "Act")] pub act: i64, - - #[serde(rename = "_rid")] pub key_id: usize, - - #[serde(rename = "IsTown")] pub is_town: bool, - - #[serde(rename = "HasWaypoint")] pub has_waypoint: bool, - - #[serde(rename = "Connections_WorldAreasKeys")] pub connections_world_areas_keys: Vec, } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index f97538b..4ec0f5e 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -93,9 +93,9 @@ fn main() { app.manage(tx); app.manage(Mutex::new(Storage::default())); - app.get_window("Overlay") - .expect("Could not get main overlay window") - .open_devtools(); + // app.get_window("Overlay") + // .expect("Could not get main overlay window") + // .open_devtools(); Ok(()) }) diff --git a/src/app/app.component.html b/src/app/app.component.html index 9b63dd7..76660a0 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,4 +1,4 @@ -
+
Click me for color picker! @@ -6,3 +6,7 @@
+
+ +
+ diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 405978e..56f7d31 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,6 +1,6 @@ import { APP_INITIALIZER, NgModule } from "@angular/core"; -import { BrowserModule} from "@angular/platform-browser"; -import { BrowserAnimationsModule } from "@angular/platform-browser/animations"; +import { BrowserModule } from "@angular/platform-browser"; +import { BrowserAnimationsModule } from "@angular/platform-browser/animations"; import { AppComponent } from "./app.component"; import { FormsModule } from "@angular/forms"; @@ -9,6 +9,7 @@ import { PlanDisplayModule } from "./plan-display/plan-display.module"; import { ConfigService } from "./services/config.service"; import { ColorPickerComponent } from './color-picker/color-picker.component'; import { MatButtonModule } from "@angular/material/button"; +import { EditorComponent } from "./editor/editor.component"; export function initializeApp(configService: ConfigService) { return (): Promise => { @@ -18,21 +19,22 @@ export function initializeApp(configService: ConfigService) { @NgModule({ declarations: [ - AppComponent, - RecordKeyChord, ColorPickerComponent + AppComponent, + RecordKeyChord, ColorPickerComponent, ], imports: [ - BrowserModule, + BrowserModule, FormsModule, PlanDisplayModule, MatButtonModule, BrowserAnimationsModule, + EditorComponent, ], providers: [ { // Makes sure we can get the config initialized ASAP as we might need it in lots of places really early. provide: APP_INITIALIZER, - useFactory: initializeApp, + useFactory: initializeApp, deps: [ConfigService], multi: true } diff --git a/src/app/editor/editor.component.html b/src/app/editor/editor.component.html new file mode 100644 index 0000000..0f6b7d4 --- /dev/null +++ b/src/app/editor/editor.component.html @@ -0,0 +1,26 @@ +
+
+

available items

+ +
+
Name: {{item.name}}
in act {{item.act}}
+
+
+ +
+

Shopping basket

+
+
{{item.area_key}}
+
+
+
+ \ No newline at end of file diff --git a/src/app/editor/editor.component.scss b/src/app/editor/editor.component.scss new file mode 100644 index 0000000..575dd73 --- /dev/null +++ b/src/app/editor/editor.component.scss @@ -0,0 +1,68 @@ +:host { + height: 100%; +} + +.container { + width: 400px; + max-width: 100%; + margin: 0 25px 25px 0; + display: inline-block; + vertical-align: top; + flex-grow: 1 1 auto; + } + + .list { + border: solid 1px #ccc; + min-height: 60px; + background: white; + border-radius: 4px; + display: block; + padding-bottom: 50px; + overflow: auto; + max-height: 100%; + } + + .box { + padding: 20px 10px; + border-bottom: solid 1px #ccc; + color: rgba(0, 0, 0, 0.87); + display: flex; + flex-direction: row; + align-items: center; + justify-content: space-between; + box-sizing: border-box; + cursor: move; + background: white; + font-size: 14px; + } + + .cdk-drag-preview { + box-sizing: border-box; + border-radius: 4px; + box-shadow: 0 5px 5px -3px rgba(0, 0, 0, 0.2), + 0 8px 10px 1px rgba(0, 0, 0, 0.14), + 0 3px 14px 2px rgba(0, 0, 0, 0.12); + } + + .cdk-drag-placeholder { + opacity: 0; + } + + .cdk-drag-animating { + transition: transform 250ms cubic-bezier(0, 0, 0.2, 1); + } + + .box:last-child { + border: none; + } + + .list.cdk-drop-list-dragging .box:not(.cdk-drag-placeholder) { + transition: transform 250ms cubic-bezier(0, 0, 0.2, 1); + } + + +.editor-container { + display: flex; + flex-direction: row; + height: 100%; +} \ No newline at end of file diff --git a/src/app/editor/editor.component.spec.ts b/src/app/editor/editor.component.spec.ts new file mode 100644 index 0000000..430658f --- /dev/null +++ b/src/app/editor/editor.component.spec.ts @@ -0,0 +1,21 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { EditorComponent } from './editor.component'; + +describe('EditorComponent', () => { + let component: EditorComponent; + let fixture: ComponentFixture; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [EditorComponent] + }); + fixture = TestBed.createComponent(EditorComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/editor/editor.component.ts b/src/app/editor/editor.component.ts new file mode 100644 index 0000000..62c30f6 --- /dev/null +++ b/src/app/editor/editor.component.ts @@ -0,0 +1,65 @@ +import { Component, Input, OnInit } from '@angular/core'; + +import { + CdkDrag, + CdkDragDrop, + CdkDropList, + CdkDropListGroup, + moveItemInArray, + transferArrayItem, +} from '@angular/cdk/drag-drop'; + +import { CommonModule } from '@angular/common'; +import { WorldArea } from '../models/world-area'; +import { Plan, PlanElement } from '../models/plan'; +import { WorldAreaService } from '../services/world-area.service'; + +@Component({ + selector: 'plan-editor', + templateUrl: './editor.component.html', + styleUrls: ['./editor.component.scss'], + standalone: true, + imports: [ + CommonModule, + CdkDropListGroup, + CdkDropList, + CdkDrag + ], +}) +export class EditorComponent implements OnInit { + areas?: WorldArea[]; + planAreas: WorldArea[]; + plan: Plan; + + constructor(public worldAreaService: WorldAreaService) { + this.plan = { + plan: [], + current: 0, + } + + this.planAreas = []; + } + + ngOnInit(): void { + this.worldAreaService.getWorldAreas().subscribe(worldAreas => { + this.areas = [...worldAreas.values()]; + console.log(this.areas); + }); + } + + dropHandler(event: CdkDragDrop | CdkDragDrop) { + if (event.previousContainer === event.container) { + moveItemInArray(this.plan.plan, event.previousIndex, event.currentIndex); + } else + if (this.plan && this.areas) { + this.plan.plan.splice(event.currentIndex, 0, this.planItemFromArea(this.areas[event.previousIndex])); + } + } + + planItemFromArea(area: WorldArea): PlanElement { + return { + area_key: area.named_id, + notes: undefined, + }; + } +} diff --git a/src/app/models/plan.ts b/src/app/models/plan.ts index ea73641..78f7373 100644 --- a/src/app/models/plan.ts +++ b/src/app/models/plan.ts @@ -1,10 +1,11 @@ import { WorldArea } from "./world-area"; export interface Plan { - elements: PlanElement[]; + plan: PlanElement[]; + current: number; } -interface PlanElement { - area: WorldArea; - note: string; +export interface PlanElement { + area_key: string; + notes?: string; } \ No newline at end of file diff --git a/src/app/models/world-area.ts b/src/app/models/world-area.ts index e735f03..a23b65c 100644 --- a/src/app/models/world-area.ts +++ b/src/app/models/world-area.ts @@ -1,9 +1,9 @@ export interface WorldArea { name: string - namedId: string + named_id: string act: number - _rid: number - isTown: boolean - hasWaypoint: boolean - connections_WorldAreasKeys: number[] -} + key_id: number + is_town: boolean + has_waypoint: boolean + connections_world_areas_keys: number[] +} \ No newline at end of file diff --git a/src/app/services/world-area.service.ts b/src/app/services/world-area.service.ts index e890742..2c6358b 100644 --- a/src/app/services/world-area.service.ts +++ b/src/app/services/world-area.service.ts @@ -1,25 +1,42 @@ -import { Injectable } from '@angular/core'; +import { Injectable, NgZone } from '@angular/core'; import init, { Fuzzr } from 'fuzzr/pkg'; import { WorldArea } from '../models/world-area'; import { invoke } from '@tauri-apps/api'; -import { from } from 'rxjs'; +import { Observable, ReplaySubject, Subject, filter, from, map } from 'rxjs'; @Injectable({ providedIn: 'root' }) export class WorldAreaService { + private worldAreas?: Map; + private matcher?: Fuzzr; - world_areas?: Map; - matcher?: Fuzzr; + private worldAreasSubject = new ReplaySubject>(); + private matcherSubject = new ReplaySubject(); - constructor() { + constructor(private zone: NgZone) { from(invoke>('load_world_areas')).subscribe((data) => { - this.world_areas = new Map(Object.entries(data)); + this.worldAreas = new Map(Object.entries(data)); + console.log("pre next worldareas"); + this.zone.run(() => this.worldAreasSubject.next(this.worldAreas!)); + console.log("post next worldareas"); from(init("/fuzzr/pkg/fuzzr_bg.wasm")).subscribe(() => { - this.matcher = new Fuzzr(this.world_areas); + this.matcher = new Fuzzr(this.worldAreas); + this.zone.run(() => this.matcherSubject.next(this.matcher!)); }); }); + } + + getWorldAreas(): Observable> { + return this.worldAreasSubject.asObservable().pipe( + filter(worldAreas => !!worldAreas), + ); + } + getMatcher(): Observable { + return this.matcherSubject.asObservable().pipe( + filter(matcher => !!matcher), + ); } }