From 4aa51edb737e01d750977cd104d3be4ad5bd1839 Mon Sep 17 00:00:00 2001 From: versedi Date: Fri, 12 Jun 2020 03:22:15 +0200 Subject: [PATCH] Trade chat macro WIP, path issue to resolve --- README.md | 1 - src/app/app.module.ts | 2 + src/app/modules/trade/component/index.ts | 1 + .../trade-settings.component.html | 45 ++++++++++++++ .../trade-settings.component.scss | 3 + .../trade-settings.component.spec.ts | 37 ++++++++++++ .../trade-settings.component.ts | 26 ++++++++ .../trade/service/trade-chat.service.ts | 46 ++++++++++++++ src/app/modules/trade/trade.module.ts | 60 +++++++++++++++++++ src/assets/i18n/english.json | 13 +++- src/assets/i18n/polish.json | 10 ++++ 11 files changed, 242 insertions(+), 2 deletions(-) create mode 100644 src/app/modules/trade/component/index.ts create mode 100644 src/app/modules/trade/component/trade-settings/trade-settings.component.html create mode 100644 src/app/modules/trade/component/trade-settings/trade-settings.component.scss create mode 100644 src/app/modules/trade/component/trade-settings/trade-settings.component.spec.ts create mode 100644 src/app/modules/trade/component/trade-settings/trade-settings.component.ts create mode 100644 src/app/modules/trade/service/trade-chat.service.ts create mode 100644 src/app/modules/trade/trade.module.ts diff --git a/README.md b/README.md index 730894ab..72b9ff41 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # PoE Overlay (Community Fork) PoE Overlay is a tool for Path of Exile. The ***core aspect*** is to blend in with the game. Built with Electron and Angular. -No Overwolf, no tracking, no shit. Everyone can commit and is free to fork and built uppon. - [Community Development](#community-development) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index d13c51ae..d0c35b0f 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -5,6 +5,7 @@ import { CommandModule } from '@modules/command/command.module'; import { EvaluateModule } from '@modules/evaluate/evaluate.module'; import { MapModule } from '@modules/map/map.module'; import { MiscModule } from '@modules/misc/misc.module'; +import { TradeModule } from '@modules/trade/trade.module'; import { TranslateLoader, TranslateModule } from '@ngx-translate/core'; import { AppTranslationsLoader } from './app-translations.loader'; import { AppComponent } from './app.component'; @@ -42,6 +43,7 @@ const routes: Routes = [ CommandModule, MapModule, MiscModule, + TradeModule, BookmarkModule ], bootstrap: [AppComponent] diff --git a/src/app/modules/trade/component/index.ts b/src/app/modules/trade/component/index.ts new file mode 100644 index 00000000..8533bf08 --- /dev/null +++ b/src/app/modules/trade/component/index.ts @@ -0,0 +1 @@ +export * from './trade-settings/trade-settings.component'; diff --git a/src/app/modules/trade/component/trade-settings/trade-settings.component.html b/src/app/modules/trade/component/trade-settings/trade-settings.component.html new file mode 100644 index 00000000..9be8915e --- /dev/null +++ b/src/app/modules/trade/component/trade-settings/trade-settings.component.html @@ -0,0 +1,45 @@ +
+
+ +
+
+ + {{'trade.chat-read-client-file' | translate}} + + + {{'trade.chat-client-file-path' | translate}} + + +
+
+
+
+
+ +
+
+ +
+
+ + +
+
+
+
+
+
+ + +
+
+ + {{'trade.chat-reply-message' | translate}} + + +
+
+
\ No newline at end of file diff --git a/src/app/modules/trade/component/trade-settings/trade-settings.component.scss b/src/app/modules/trade/component/trade-settings/trade-settings.component.scss new file mode 100644 index 00000000..7f8a925b --- /dev/null +++ b/src/app/modules/trade/component/trade-settings/trade-settings.component.scss @@ -0,0 +1,3 @@ +body { + +} \ No newline at end of file diff --git a/src/app/modules/trade/component/trade-settings/trade-settings.component.spec.ts b/src/app/modules/trade/component/trade-settings/trade-settings.component.spec.ts new file mode 100644 index 00000000..e3c92aa6 --- /dev/null +++ b/src/app/modules/trade/component/trade-settings/trade-settings.component.spec.ts @@ -0,0 +1,37 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { TranslateFakeLoader, TranslateLoader, TranslateModule } from '@ngx-translate/core'; +import { SharedModule } from '@shared/shared.module'; +import { TradeSettingsComponent } from './trade-settings.component'; + + +describe('MiscSettingsComponent', () => { + let component: TradeSettingsComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [ + SharedModule, + TranslateModule.forRoot({ + loader: { + provide: TranslateLoader, + useFactory: () => new TranslateFakeLoader() + } + }) + ], + declarations: [TradeSettingsComponent] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(TradeSettingsComponent); + component = fixture.componentInstance; + component.settings = {} as any; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/modules/trade/component/trade-settings/trade-settings.component.ts b/src/app/modules/trade/component/trade-settings/trade-settings.component.ts new file mode 100644 index 00000000..cdcfb62c --- /dev/null +++ b/src/app/modules/trade/component/trade-settings/trade-settings.component.ts @@ -0,0 +1,26 @@ +import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; +import { UserSettings, UserSettingsComponent } from 'src/app/layout/type'; +import { EnumValues } from '@app/class'; + +export interface TradeUserSettings extends UserSettings { + tradeChatReadClientFile: boolean; + tradeChatClientFilePath: string; + chatReplyMessage: string; + chatReplyMessageKeybinding: string; + chatInviteLastKeybinding: string; +} + +@Component({ + selector: 'app-trade-settings', + templateUrl: './trade-settings.component.html', + styleUrls: ['./trade-settings.component.scss'], + changeDetection: ChangeDetectionStrategy.OnPush +}) +export class TradeSettingsComponent implements UserSettingsComponent { + @Input() + public settings: TradeUserSettings; + + public load(): void { + // stub + } +} diff --git a/src/app/modules/trade/service/trade-chat.service.ts b/src/app/modules/trade/service/trade-chat.service.ts new file mode 100644 index 00000000..0fffc8dc --- /dev/null +++ b/src/app/modules/trade/service/trade-chat.service.ts @@ -0,0 +1,46 @@ +import { Injectable } from '@angular/core'; +import { BrowserService } from '@app/service'; +import { SnackBarService } from '@shared/module/material/service'; +import { ItemClipboardResultCode, ItemClipboardService } from '@shared/module/poe/service'; +import { ItemExternalService } from '@shared/module/poe/service/item/item-external.service'; +import { ItemSection, Language } from '@shared/module/poe/type'; +import { Observable, of, throwError } from 'rxjs'; +import { catchError, flatMap } from 'rxjs/operators'; + + +@Injectable({ + providedIn: 'root' +}) +export class TradeChatService { + + constructor( + private readonly itemClipboard: ItemClipboardService, + private readonly itemExternalService: ItemExternalService, + private readonly browser: BrowserService, + private readonly snackbar: SnackBarService) { + } + + public open(external: boolean): Observable { + return this.itemClipboard.copy({ + [ItemSection.Rartiy]: true + }).pipe( + flatMap(({ code, item }) => { + switch (code) { + case ItemClipboardResultCode.Success: + const url = this.itemExternalService.getDbUrl(item); + this.browser.open(url, external); + return of(null); + case ItemClipboardResultCode.Empty: + return this.snackbar.warning('clipboard.empty'); + case ItemClipboardResultCode.ParserError: + return this.snackbar.warning('clipboard.parser-error'); + default: + return throwError(`code: '${code}' out of range`); + } + }), + catchError(() => { + return this.snackbar.error('clipboard.parser-error'); + }) + ); + } +} diff --git a/src/app/modules/trade/trade.module.ts b/src/app/modules/trade/trade.module.ts new file mode 100644 index 00000000..c3cc14d5 --- /dev/null +++ b/src/app/modules/trade/trade.module.ts @@ -0,0 +1,60 @@ +import { NgModule } from '@angular/core'; +import { FEATURE_MODULES } from '@app/token'; +import { Feature, FeatureModule } from '@app/type'; +import { SharedModule } from '@shared/shared.module'; +import { UserSettingsFeature } from 'src/app/layout/type'; +import { TradeSettingsComponent, TradeUserSettings } from './component'; +import { TradeChatService } from './service/trade-chat.service'; + +@NgModule({ + providers: [{ provide: FEATURE_MODULES, useClass: TradeModule, multi: true }], + declarations: [TradeSettingsComponent], + imports: [SharedModule] +}) +export class TradeModule implements FeatureModule { + + constructor(private readonly chat: TradeChatService) { } + + public getSettings(): UserSettingsFeature { + const defaultSettings: TradeUserSettings = { + tradeChatClientFilePath: "C:\\Program Files (x86)\\Grinding Gear Games\\Path of Exile\\Logs\\Client.txt", + tradeChatReadClientFile: false, + chatInviteLastKeybinding: 'Alt + F1', + chatReplyMessageKeybinding: 'ALT + F2', + chatReplyMessage: 'Be right back, Im inside a map.', + }; + return { + name: 'trade.name', + component: TradeSettingsComponent, + defaultSettings + }; + } + + public getFeatures(settings: TradeUserSettings): Feature[] { + const features: Feature[] = [ + { + name: 'chat-read-client-file', + accelerator: settings.tradeChatReadClientFile ? '1' : '0', + }, + { + name: 'chat-client-file-path', + accelerator: settings.tradeChatClientFilePath, + }, + ]; + + return features; + } + + public run(feature: string, _: TradeUserSettings): void { + switch (feature) { + case 'chat-read-client-file': + this.chat.open(feature === 'chat-read-client-file').subscribe(); + break; + case 'chat-client-file-path': + this.chat.open(feature === 'chat-client-file-path').subscribe(); + break; + default: + break; + } + } +} diff --git a/src/assets/i18n/english.json b/src/assets/i18n/english.json index dffa3db4..186083bd 100644 --- a/src/assets/i18n/english.json +++ b/src/assets/i18n/english.json @@ -235,8 +235,19 @@ "league": "League", "open-settings": "Open Settings", "relaunch-app": "Relaunch App", + "read-client-file": "Read Client.txt file", "save": "Save", "ui-language": "UI Language", "zoom": "Zoom" + }, + "trade": { + "name": "Trade Chat", + "chat-reply-message": "Text that you want to reply with", + "chat-reply-message-keybinding": "Keybind you want to use the reply", + "chat-read-client-file": "Read Client.txt from your PoE directory (may affect performance on HDD drives)", + "chat-client-file-path": "Path to Client.txt in your PoE directory", + "chat-settings": "Chat related trading settings", + "chat-invite-last-keybinding": "Key to invite last messenger to party", + "chat-settings-keybinds": "Settings for trading related chat keybinds" } -} +} \ No newline at end of file diff --git a/src/assets/i18n/polish.json b/src/assets/i18n/polish.json index 6e2a8fe6..e17bd2fe 100644 --- a/src/assets/i18n/polish.json +++ b/src/assets/i18n/polish.json @@ -238,5 +238,15 @@ "save": "Zapisz", "ui-language": "Język programu", "zoom": "Powiększenie" + }, + "trade": { + "name": "Trade Chat", + "chat-reply-message": "Treść wiadomości, którą będziesz wysyłał", + "chat-reply-message-keybinding": "Klawisz, którym chcesz odpowiedzieć", + "chat-read-client-file": "Odczytuj plik Client.txt z folderu z grą PoE (może wpływać na wydajność w przypadku dysków HDD)", + "chat-client-file-path": "Scieżka do pliku Client.txt w Twoim folderze z grą", + "chat-settings": "Ustawienia dotyczące czatu marketowego", + "chat-invite-last-keybinding": "Klawisz, by zaprosić autora ostatniej wiadomości do party", + "chat-settings-keybinds": "Przypisania klawiszy w czacie marketowym" } }