Skip to content

Commit

Permalink
fix(refining): refining should update when hitting craft
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Mar 15, 2023
1 parent f9fdd9f commit d5e3e42
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Component, Input, OnChanges, OnInit } from '@angular/core';
import { Store } from '@ngxs/store';
import { ChangeDetectionStrategy, Component, Input, OnChanges, OnDestroy, OnInit } from '@angular/core';
import { Select, Store } from '@ngxs/store';
import { sortBy } from 'lodash';
import { Observable, Subscription } from 'rxjs';
import { IGameItem, IGameRecipe, IGameRefiningOptions, IGameRefiningRecipe, IGameWorkersRefining } from '../../../interfaces';
import { CharSelectState } from '../../../stores';
import { AssignRefiningWorker, UnassignRefiningWorker } from '../../../stores/workers/workers.actions';
import { canCraftRecipe } from '../../helpers';
import { ContentService } from '../../services/content.service';
Expand All @@ -11,13 +13,16 @@ import { ItemCreatorService } from '../../services/item-creator.service';
selector: 'app-refining-page-display',
templateUrl: './refining-page-display.component.html',
styleUrls: ['./refining-page-display.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class RefiningPageDisplayComponent implements OnInit, OnChanges {
export class RefiningPageDisplayComponent implements OnInit, OnChanges, OnDestroy {

@Select(CharSelectState.activeCharacterDiscoveries) discoveries$!: Observable<Record<string, boolean>>;
@Select(CharSelectState.activeCharacterResources) resources$!: Observable<Record<string, number>>;

@Input() tradeskill = '';
@Input() level = 0;
@Input() currentQueue: { queue: IGameRefiningRecipe[]; size: number } = { queue: [], size: 1 };
@Input() resources: Record<string, number> = {};
@Input() items: IGameItem[] = [];

@Input() refiningWorkers: {
Expand All @@ -33,14 +38,15 @@ export class RefiningPageDisplayComponent implements OnInit, OnChanges {
hideHasNoIngredients: false,
};

@Input() discoveries: Record<string, boolean> = {};
@Input() locationData: IGameRecipe[] = [];
@Input() startAction: any;
@Input() cancelAction: any;
@Input() changeOptionAction: any;

public type!: 'resources'|'items';
public amounts: Record<string, number> = {};
public resources: Record<string, number> = {};
public discoveries: Record<string, boolean> = {};

public resourceRecipes: IGameRecipe[] = [];
public itemRecipes: IGameRecipe[] = [];
Expand All @@ -52,6 +58,9 @@ export class RefiningPageDisplayComponent implements OnInit, OnChanges {

public summedResources: Record<string, number> = {};

private resourcesSub!: Subscription;
private discoveriesSub!: Subscription;

constructor(
private store: Store,
private contentService: ContentService,
Expand All @@ -62,22 +71,41 @@ export class RefiningPageDisplayComponent implements OnInit, OnChanges {
this.setVisibleRecipes();
this.setRefiningWorkerHash();
this.setTotalResources();

this.resourcesSub = this.resources$.subscribe((resources) => {
console.log({ resources });
this.resources = resources;

this.setVisibleRecipes();
this.setTotalResources();
});

this.discoveriesSub = this.discoveries$.subscribe((discoveries) => {
this.discoveries = discoveries;

this.setVisibleRecipes();
});
}

ngOnChanges(changes: any) {
if(changes.discoveries || changes.filterOptions || changes.resources) {
if(changes.discoveries || changes.filterOptions) {
this.setVisibleRecipes();
}

if(changes.refiningWorkers) {
this.setRefiningWorkerHash();
}

if(changes.resources || changes.items) {
if(changes.items) {
this.setTotalResources();
}
}

ngOnDestroy() {
this.resourcesSub?.unsubscribe();
this.discoveriesSub?.unsubscribe();
}

setTotalResources() {
this.summedResources = this.totalResourceHashForCrafting();
}
Expand Down
4 changes: 0 additions & 4 deletions src/app/pages/tradeskills/refining/alchemy/alchemy.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,19 @@

<ng-container *ngIf="{
level: level$ | async,
resources: resources$ | async,
currentQueue: currentQueue$ | async,
refiningWorkers: refiningWorkers$ | async,
options: options$ | async,
discoveries: discoveries$ | async,
items: items$ | async
} as pageData">

<app-refining-page-display
[tradeskill]="'alchemy'"
[level]="pageData.level || 0"
[resources]="pageData.resources || {}"
[items]="pageData.items || []"
[currentQueue]="pageData.currentQueue || { queue: [], size: 1 }"
[refiningWorkers]="pageData.refiningWorkers || { workerAllocations: [], canAssignWorker: false, hasWorkers: false }"
[filterOptions]="pageData.options || { hideDiscovered: false, hideNew: false, hideHasIngredients: false, hideHasNoIngredients: false }"
[discoveries]="pageData.discoveries || {}"
[locationData]="locationData"
[startAction]="startAction"
[cancelAction]="cancelAction"
Expand Down
10 changes: 4 additions & 6 deletions src/app/pages/tradeskills/refining/alchemy/alchemy.page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { Select } from '@ngxs/store';
import { Observable, first } from 'rxjs';
import { IGameItem, IGameRefiningOptions, IGameRefiningRecipe, IGameWorkersRefining } from '../../../../../interfaces';
import { IGameItem, IGameRecipe, IGameRefiningOptions, IGameRefiningRecipe, IGameWorkersRefining } from '../../../../../interfaces';
import { AlchemyState, CharSelectState, WorkersState } from '../../../../../stores';

import { CancelAlchemyJob, ChangeAlchemyFilterOption, StartAlchemyJob } from '../../../../../stores/alchemy/alchemy.actions';
Expand All @@ -15,9 +15,7 @@ import { ContentService } from '../../../../services/content.service';
})
export class AlchemyPage implements OnInit {

public get locationData() {
return this.contentService.getAlchemyRecipes();
}
public locationData: IGameRecipe[] = [];

public get startAction() {
return StartAlchemyJob;
Expand All @@ -37,8 +35,6 @@ export class AlchemyPage implements OnInit {
@Select(AlchemyState.currentQueue) currentQueue$!: Observable<{ queue: IGameRefiningRecipe[]; size: number }>;
@Select(AlchemyState.options) options$!: Observable<IGameRefiningOptions>;

@Select(CharSelectState.activeCharacterDiscoveries) discoveries$!: Observable<Record<string, boolean>>;
@Select(CharSelectState.activeCharacterResources) resources$!: Observable<Record<string, number>>;
@Select(CharSelectState.activeCharacterInventory) items$!: Observable<IGameItem[]>;
@Select(WorkersState.refiningWorkers) refiningWorkers$!: Observable<{
workerAllocations: IGameWorkersRefining[];
Expand All @@ -49,6 +45,8 @@ export class AlchemyPage implements OnInit {
constructor(private contentService: ContentService) { }

ngOnInit() {
this.locationData = this.contentService.getAlchemyRecipes();

this.level$.pipe(first()).subscribe(level => {
this.currentQueue$.pipe(first()).subscribe(currentQueue => {
const state = currentQueue.queue.length > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,19 @@

<ng-container *ngIf="{
level: level$ | async,
resources: resources$ | async,
currentQueue: currentQueue$ | async,
refiningWorkers: refiningWorkers$ | async,
options: options$ | async,
discoveries: discoveries$ | async,
items: items$ | async
} as pageData">

<app-refining-page-display
[tradeskill]="'alchemy'"
[level]="pageData.level || 0"
[resources]="pageData.resources || {}"
[items]="pageData.items || []"
[currentQueue]="pageData.currentQueue || { queue: [], size: 1 }"
[refiningWorkers]="pageData.refiningWorkers || { workerAllocations: [], canAssignWorker: false, hasWorkers: false }"
[filterOptions]="pageData.options || { hideDiscovered: false, hideNew: false, hideHasIngredients: false, hideHasNoIngredients: false }"
[discoveries]="pageData.discoveries || {}"
[locationData]="locationData"
[startAction]="startAction"
[cancelAction]="cancelAction"
Expand Down
10 changes: 4 additions & 6 deletions src/app/pages/tradeskills/refining/blacksmith/blacksmith.page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { Select } from '@ngxs/store';
import { Observable, first } from 'rxjs';
import { IGameItem, IGameRefiningOptions, IGameRefiningRecipe, IGameWorkersRefining } from '../../../../../interfaces';
import { IGameItem, IGameRecipe, IGameRefiningOptions, IGameRefiningRecipe, IGameWorkersRefining } from '../../../../../interfaces';
import { BlacksmithingState, CharSelectState, WorkersState } from '../../../../../stores';

import {
Expand All @@ -18,9 +18,7 @@ import { ContentService } from '../../../../services/content.service';
})
export class BlacksmithPage implements OnInit {

public get locationData() {
return this.contentService.getBlacksmithingRecipes();
}
public locationData: IGameRecipe[] = [];

public get startAction() {
return StartBlacksmithingJob;
Expand All @@ -38,8 +36,6 @@ export class BlacksmithPage implements OnInit {
@Select(BlacksmithingState.currentQueue) currentQueue$!: Observable<{ queue: IGameRefiningRecipe[]; size: number }>;
@Select(BlacksmithingState.options) options$!: Observable<IGameRefiningOptions>;

@Select(CharSelectState.activeCharacterDiscoveries) discoveries$!: Observable<Record<string, boolean>>;
@Select(CharSelectState.activeCharacterResources) resources$!: Observable<Record<string, number>>;
@Select(CharSelectState.activeCharacterInventory) items$!: Observable<IGameItem[]>;
@Select(WorkersState.refiningWorkers) refiningWorkers$!: Observable<{
workerAllocations: IGameWorkersRefining[];
Expand All @@ -50,6 +46,8 @@ export class BlacksmithPage implements OnInit {
constructor(private contentService: ContentService) { }

ngOnInit() {
this.locationData = this.contentService.getBlacksmithingRecipes();

this.level$.pipe(first()).subscribe(level => {
this.currentQueue$.pipe(first()).subscribe(currentQueue => {
const state = currentQueue.queue.length > 0
Expand Down
4 changes: 0 additions & 4 deletions src/app/pages/tradeskills/refining/cooking/cooking.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,19 @@

<ng-container *ngIf="{
level: level$ | async,
resources: resources$ | async,
currentQueue: currentQueue$ | async,
refiningWorkers: refiningWorkers$ | async,
options: options$ | async,
discoveries: discoveries$ | async,
items: items$ | async
} as pageData">

<app-refining-page-display
[tradeskill]="'alchemy'"
[level]="pageData.level || 0"
[resources]="pageData.resources || {}"
[items]="pageData.items || []"
[currentQueue]="pageData.currentQueue || { queue: [], size: 1 }"
[refiningWorkers]="pageData.refiningWorkers || { workerAllocations: [], canAssignWorker: false, hasWorkers: false }"
[filterOptions]="pageData.options || { hideDiscovered: false, hideNew: false, hideHasIngredients: false, hideHasNoIngredients: false }"
[discoveries]="pageData.discoveries || {}"
[locationData]="locationData"
[startAction]="startAction"
[cancelAction]="cancelAction"
Expand Down
10 changes: 4 additions & 6 deletions src/app/pages/tradeskills/refining/cooking/cooking.page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { Select } from '@ngxs/store';
import { Observable, first } from 'rxjs';
import { IGameItem, IGameRefiningOptions, IGameRefiningRecipe, IGameWorkersRefining } from '../../../../../interfaces';
import { IGameItem, IGameRecipe, IGameRefiningOptions, IGameRefiningRecipe, IGameWorkersRefining } from '../../../../../interfaces';
import { CharSelectState, CookingState, WorkersState } from '../../../../../stores';

import { CancelCookingJob, ChangeCookingFilterOption, StartCookingJob } from '../../../../../stores/cooking/cooking.actions';
Expand All @@ -15,9 +15,7 @@ import { ContentService } from '../../../../services/content.service';
})
export class CookingPage implements OnInit {

public get locationData() {
return this.contentService.getCookingRecipes();
}
public locationData: IGameRecipe[] = [];

public get startAction() {
return StartCookingJob;
Expand All @@ -35,8 +33,6 @@ export class CookingPage implements OnInit {
@Select(CookingState.currentQueue) currentQueue$!: Observable<{ queue: IGameRefiningRecipe[]; size: number }>;
@Select(CookingState.options) options$!: Observable<IGameRefiningOptions>;

@Select(CharSelectState.activeCharacterDiscoveries) discoveries$!: Observable<Record<string, boolean>>;
@Select(CharSelectState.activeCharacterResources) resources$!: Observable<Record<string, number>>;
@Select(CharSelectState.activeCharacterInventory) items$!: Observable<IGameItem[]>;
@Select(WorkersState.refiningWorkers) refiningWorkers$!: Observable<{
workerAllocations: IGameWorkersRefining[];
Expand All @@ -47,6 +43,8 @@ export class CookingPage implements OnInit {
constructor(private contentService: ContentService) { }

ngOnInit() {
this.locationData = this.contentService.getCookingRecipes();

this.level$.pipe(first()).subscribe(level => {
this.currentQueue$.pipe(first()).subscribe(currentQueue => {
const state = currentQueue.queue.length > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,19 @@

<ng-container *ngIf="{
level: level$ | async,
resources: resources$ | async,
currentQueue: currentQueue$ | async,
refiningWorkers: refiningWorkers$ | async,
options: options$ | async,
discoveries: discoveries$ | async,
items: items$ | async
} as pageData">

<app-refining-page-display
[tradeskill]="'alchemy'"
[level]="pageData.level || 0"
[resources]="pageData.resources || {}"
[items]="pageData.items || []"
[currentQueue]="pageData.currentQueue || { queue: [], size: 1 }"
[refiningWorkers]="pageData.refiningWorkers || { workerAllocations: [], canAssignWorker: false, hasWorkers: false }"
[filterOptions]="pageData.options || { hideDiscovered: false, hideNew: false, hideHasIngredients: false, hideHasNoIngredients: false }"
[discoveries]="pageData.discoveries || {}"
[locationData]="locationData"
[startAction]="startAction"
[cancelAction]="cancelAction"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { Select } from '@ngxs/store';
import { Observable, first } from 'rxjs';
import { IGameItem, IGameRefiningOptions, IGameRefiningRecipe, IGameWorkersRefining } from '../../../../../interfaces';
import { IGameItem, IGameRecipe, IGameRefiningOptions, IGameRefiningRecipe, IGameWorkersRefining } from '../../../../../interfaces';
import { CharSelectState, JewelcraftingState, WorkersState } from '../../../../../stores';

import {
Expand All @@ -18,9 +18,7 @@ import { ContentService } from '../../../../services/content.service';
})
export class JewelcraftingPage implements OnInit {

public get locationData() {
return this.contentService.getJewelcraftingRecipes();
}
public locationData: IGameRecipe[] = [];

public get startAction() {
return StartJewelcraftingJob;
Expand All @@ -38,8 +36,6 @@ export class JewelcraftingPage implements OnInit {
@Select(JewelcraftingState.currentQueue) currentQueue$!: Observable<{ queue: IGameRefiningRecipe[]; size: number }>;
@Select(JewelcraftingState.options) options$!: Observable<IGameRefiningOptions>;

@Select(CharSelectState.activeCharacterDiscoveries) discoveries$!: Observable<Record<string, boolean>>;
@Select(CharSelectState.activeCharacterResources) resources$!: Observable<Record<string, number>>;
@Select(CharSelectState.activeCharacterInventory) items$!: Observable<IGameItem[]>;
@Select(WorkersState.refiningWorkers) refiningWorkers$!: Observable<{
workerAllocations: IGameWorkersRefining[];
Expand All @@ -50,6 +46,8 @@ export class JewelcraftingPage implements OnInit {
constructor(private contentService: ContentService) { }

ngOnInit() {
this.locationData = this.contentService.getJewelcraftingRecipes();

this.level$.pipe(first()).subscribe(level => {
this.currentQueue$.pipe(first()).subscribe(currentQueue => {
const state = currentQueue.queue.length > 0
Expand Down
4 changes: 0 additions & 4 deletions src/app/pages/tradeskills/refining/weaving/weaving.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,19 @@

<ng-container *ngIf="{
level: level$ | async,
resources: resources$ | async,
currentQueue: currentQueue$ | async,
refiningWorkers: refiningWorkers$ | async,
options: options$ | async,
discoveries: discoveries$ | async,
items: items$ | async
} as pageData">

<app-refining-page-display
[tradeskill]="'alchemy'"
[level]="pageData.level || 0"
[resources]="pageData.resources || {}"
[items]="pageData.items || []"
[currentQueue]="pageData.currentQueue || { queue: [], size: 1 }"
[refiningWorkers]="pageData.refiningWorkers || { workerAllocations: [], canAssignWorker: false, hasWorkers: false }"
[filterOptions]="pageData.options || { hideDiscovered: false, hideNew: false, hideHasIngredients: false, hideHasNoIngredients: false }"
[discoveries]="pageData.discoveries || {}"
[locationData]="locationData"
[startAction]="startAction"
[cancelAction]="cancelAction"
Expand Down
Loading

0 comments on commit d5e3e42

Please sign in to comment.