Skip to content

Commit

Permalink
- added client.txt listener
Browse files Browse the repository at this point in the history
- added trade module backbone
  • Loading branch information
Kyusung4698 committed Jun 11, 2020
1 parent da948b2 commit a57a355
Show file tree
Hide file tree
Showing 31 changed files with 364 additions and 39 deletions.
16 changes: 15 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"GameInfo",
"GameControl",
"Clipboard",
"VideoCaptureSettings"
"VideoCaptureSettings",
"FileSystem"
],
"data": {
"start_window": "background",
Expand Down Expand Up @@ -136,6 +137,19 @@
"width": 1212,
"height": 699
}
},
"trade": {
"file": "dist/poe-overlay-overwolf/index.html",
"in_game_only": true,
"block_top_window_navigation": true,
"disable_restore_animation": true,
"disable_rightclick": true,
"transparent": true,
"resizable": true,
"size": {
"width": 1212,
"height": 699
}
}
},
"game_targeting": {
Expand Down
1 change: 1 addition & 0 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<app-replay-window *ngSwitchCase="'replay'"></app-replay-window>
<app-launcher-window *ngSwitchCase="'launcher'"></app-launcher-window>
<app-annotation-window *ngSwitchCase="'annotation'"></app-annotation-window>
<app-trade-window *ngSwitchCase="'trade'"></app-trade-window>
<div *ngSwitchDefault>Could not match window with name: {{window.name}}</div>
</ng-container>
</ng-container>
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { EvaluateModule } from '@modules/evaluate/evaluate.module';
import { InspectModule } from '@modules/inspect/inspect.module';
import { MarketModule } from '@modules/market/market.module';
import { ReplayModule } from '@modules/replay/replay.module';
import { TradeModule } from '@modules/trade/trade.module';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { AppErrorHandler } from './app-error-handler';
import { AppTranslationsLoader } from './app-translation-loader';
Expand All @@ -29,6 +30,7 @@ import { LayoutModule } from './layout/layout.module';
EvaluateModule,
MarketModule,
InspectModule,
TradeModule,
CommandsModule,
ReplayModule,
BookmarksModule
Expand Down
3 changes: 2 additions & 1 deletion src/app/core/config/window-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export enum WindowName {
Market = 'market',
Replay = 'replay',
Launcher = 'launcher',
Annotation = 'annotation'
Annotation = 'annotation',
Trade = 'trade'
}
4 changes: 4 additions & 0 deletions src/app/core/event/event-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export class EventEmitter<TEvent> {
private latest: TEvent;
private counter = 0;

constructor(first?: TEvent) {
this.latest = first;
}

public get(): TEvent {
return this.latest;
}
Expand Down
9 changes: 5 additions & 4 deletions src/app/core/feature/feature-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { FeatureSettings } from './feature-settings';
export interface FeatureModule<TSettings extends FeatureSettings> {
getConfig(): FeatureConfig<TSettings>;
getFeatures(): Feature[];
onKeyPressed(hotkey: Hotkey, settings: TSettings): void;
onSettingsChange(settings: TSettings): void;
onGameEvent(event: GameEvent | InfoUpdatesEvent, settings: TSettings): void;
onInfo(info: RunningGameInfo, settings: TSettings): void;
onKeyPressed?(hotkey: Hotkey, settings: TSettings): void;
onSettingsChange?(settings: TSettings): void;
onGameEvent?(event: GameEvent | InfoUpdatesEvent, settings: TSettings): void;
onInfo?(info: RunningGameInfo, settings: TSettings): void;
onLogLineAdd?(line: string): void;
}
1 change: 1 addition & 0 deletions src/app/core/odk/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './ow-file-listener';
export * from './ow-game-listener';
export * from './ow-games';
export * from './ow-games-events';
Expand Down
52 changes: 52 additions & 0 deletions src/app/core/odk/ow-file-listener.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

export interface OWFileListenerDelegate {
onLineAdd(line: string): void;
onLineRead?(line: string): void;
onError(error?: string): void;
}

interface OWFileListenerResult extends overwolf.Result {
content: string;
info: string;
}

export class OWFileListener {
constructor(
private readonly id: string,
private readonly delegate: OWFileListenerDelegate) { }

public start(path: string, skipToEnd = true): void {
overwolf.io.listenOnFile(this.id, path, { skipToEnd }, this.onListenOnFile);
}

public stop(): void {
overwolf.io.stopFileListener(this.id);
}

private onListenOnFile = (event: OWFileListenerResult): void => {
if (!event.success || event.error) {
return this.delegate.onError(event.error);
}

if (!event.info?.length) {
return;
}

let info: {
isNew: boolean
};
try {
info = JSON.parse(event.info);
} catch (error) {
return this.delegate.onError(error);
}

if (info.isNew) {
this.delegate.onLineAdd(event.content);
} else {
if (this.delegate.onLineRead) {
this.delegate.onLineRead(event.content);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { EventSubscription } from '@app/event';
import { FeatureModule, FeatureSettings, FEATURE_MODULES } from '@app/feature';
import { FeatureSettingsService } from '@app/feature/feature-settings.service';
import { NotificationService } from '@app/notification';
import { InfoUpdatesEvent, NewGameEvents, OnPressedEvent, OWGameClassId, OWGameListener, OWGamesEventsListener, OWHotkeysListener, OWWindow, OWWindowsListener, RunningGameInfo, WindowState, WindowStateChangedEvent } from '@app/odk';
import { InfoUpdatesEvent, NewGameEvents, OnPressedEvent, OWFileListener, OWGameClassId, OWGameListener, OWGamesEventsListener, OWHotkeysListener, OWWindow, OWWindowsListener, RunningGameInfo, WindowState, WindowStateChangedEvent } from '@app/odk';
import { concat, forkJoin } from 'rxjs';
import { flatMap } from 'rxjs/operators';
import { AnnotationWindowService, LauncherWindowService, NotificationWindowService, SettingsWindowService } from '../../service';
Expand All @@ -20,10 +20,12 @@ import { AnnotationWindowService, LauncherWindowService, NotificationWindowServi
export class BackgroundWindowComponent implements OnInit, OnDestroy {
private settingsChange: EventSubscription;
private shouldQuit = false;

private readonly game: OWGameListener;
private readonly events: OWGamesEventsListener;
private readonly hotkeys: OWHotkeysListener;
private readonly windows: OWWindowsListener;
private readonly log: OWFileListener;

constructor(
@Inject(FEATURE_MODULES)
Expand Down Expand Up @@ -52,6 +54,10 @@ export class BackgroundWindowComponent implements OnInit, OnDestroy {
this.windows = new OWWindowsListener({
onStateChange: this.onStateChange.bind(this)
});
this.log = new OWFileListener('log', {
onLineAdd: this.onLogLineAdd.bind(this),
onError: this.onLogError.bind(this),
});
}

public ngOnInit(): void {
Expand All @@ -61,7 +67,11 @@ export class BackgroundWindowComponent implements OnInit, OnDestroy {
this.asset.load().subscribe(() => {
this.settingsChange = this.settings.change().on(settings => {
this.ngZone.run(() => {
this.modules.forEach(module => module.onSettingsChange(settings));
this.modules.forEach(module => {
if (module.onSettingsChange) {
module.onSettingsChange(settings);
}
});
});
});
this.hotkeys.start();
Expand All @@ -84,13 +94,17 @@ export class BackgroundWindowComponent implements OnInit, OnDestroy {
break;
default:
for (const module of this.modules) {
if (!module.onKeyPressed) {
continue;
}
for (const feature of module.getFeatures()) {
if (feature.hotkey === event.name) {
this.settings.get().subscribe(settings => {
module.onKeyPressed(feature.hotkey, settings);
});
break;
if (feature.hotkey !== event.name) {
continue;
}
this.settings.get().subscribe(
settings => module.onKeyPressed(feature.hotkey, settings)
);
return;
}
}
}
Expand All @@ -104,14 +118,24 @@ export class BackgroundWindowComponent implements OnInit, OnDestroy {
this.shouldQuit = false;
this.launcherWindow.close();

const path = info.executionPath.split('/');
path.pop();
const log = `${path.join('/')}/logs/Client.txt`;
console.log(log);
this.log.start(log);

forkJoin([
this.annotationWindow.open(info.width, info.height),
this.notificationWindow.open(info.width, info.height)
]).pipe(
flatMap(() => this.events.start()),
).subscribe(result => {
this.settings.get().subscribe(settings => {
this.modules.forEach(module => module.onInfo(info, settings));
this.modules.forEach(module => {
if (module.onInfo) {
module.onInfo(info, settings);
}
});
});
if (!result) {
this.notification.show('event.start-error');
Expand All @@ -126,7 +150,11 @@ export class BackgroundWindowComponent implements OnInit, OnDestroy {

this.events.stop();
this.settings.get().subscribe(settings => {
this.modules.forEach(module => module.onInfo(info, settings));
this.modules.forEach(module => {
if (module.onInfo) {
module.onInfo(info, settings);
}
});

forkJoin([
this.settingsWindow.close(),
Expand All @@ -140,14 +168,26 @@ export class BackgroundWindowComponent implements OnInit, OnDestroy {

private onInfoUpdates(event: InfoUpdatesEvent): void {
this.settings.get().subscribe(settings => {
this.modules.forEach(module => module.onGameEvent(event, settings));
this.modules.forEach(module => {
if (module.onGameEvent) {
module.onGameEvent(event, settings);
}
});
});
}

private onNewEvents(event: NewGameEvents): void {
if (!event?.events?.length) {
return;
}

this.settings.get().subscribe(settings => {
this.modules.forEach(module => {
event?.events?.forEach(e => module.onGameEvent(e, settings));
event.events.forEach(e => {
if (module.onGameEvent) {
module.onGameEvent(e, settings);
}
});
});
});
}
Expand Down Expand Up @@ -197,4 +237,16 @@ export class BackgroundWindowComponent implements OnInit, OnDestroy {
break;
}
}

public onLogLineAdd(line: string): void {
this.modules.forEach(module => {
if (module.onLogLineAdd) {
module.onLogLineAdd(line);
}
});
}

public onLogError(error: string): void {
console.error('An unexpected error occured while listening to the Client.txt file.', error);
}
}
4 changes: 0 additions & 4 deletions src/app/modules/bookmarks/bookmarks.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,4 @@ export class BookmarksModule implements FeatureModule<BookmarksFeatureSettings>
throw new Error(`Hotkey: '${hotkey}' out of range.`);
}
}

public onSettingsChange(): void { }
public onGameEvent(): void { }
public onInfo(): void { }
}
4 changes: 0 additions & 4 deletions src/app/modules/commands/commands.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,4 @@ export class CommandsModule implements FeatureModule<CommandsFeatureSettings> {
throw new Error(`Hotkey: '${hotkey}' out of range.`);
}
}

public onSettingsChange(): void { }
public onGameEvent(): void { }
public onInfo(): void { }
}
4 changes: 0 additions & 4 deletions src/app/modules/evaluate/evaluate.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,4 @@ export class EvaluateModule implements FeatureModule<EvaluateFeatureSettings> {
throw new Error(`Hotkey: '${hotkey}' out of range.`);
}
}

public onSettingsChange(): void { }
public onGameEvent(): void { }
public onInfo(): void { }
}
4 changes: 0 additions & 4 deletions src/app/modules/inspect/inspect.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,4 @@ export class InspectModule implements FeatureModule<InspectFeatureSettings> {
throw new Error(`Hotkey: '${hotkey}' out of range.`);
}
}

public onSettingsChange(): void { }
public onGameEvent(): void { }
public onInfo(): void { }
}
4 changes: 0 additions & 4 deletions src/app/modules/market/market.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,4 @@ export class MarketModule implements FeatureModule<MarketFeatureSettings> {
throw new Error(`Hotkey: '${hotkey}' out of range.`);
}
}

public onSettingsChange(): void { }
public onGameEvent(): void { }
public onInfo(): void { }
}
2 changes: 0 additions & 2 deletions src/app/modules/replay/replay.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ export class ReplayModule implements FeatureModule<ReplayFeatureSettings> {
return features;
}

public onKeyPressed(): void { }

public onSettingsChange(settings: ReplayFeatureSettings): void {
const shouldCapture = settings.replayCaptureDeath || settings.replayCaptureKill;
if (shouldCapture !== this.shouldCapture) {
Expand Down
2 changes: 2 additions & 0 deletions src/app/modules/trade/component/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './trade-settings/trade-settings.component';

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>trade-settings works!</p>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { FeatureSettingsComponent } from '@app/feature';
import { TradeFeatureSettings } from '@modules/trade/trade-feature-settings';

@Component({
selector: 'app-trade-settings',
templateUrl: './trade-settings.component.html',
styleUrls: ['./trade-settings.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class TradeSettingsComponent extends FeatureSettingsComponent<TradeFeatureSettings> {
public load(): void { }
}
2 changes: 2 additions & 0 deletions src/app/modules/trade/service/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './trade-window.service';
export * from './trade.service';
Loading

0 comments on commit a57a355

Please sign in to comment.