Skip to content

Commit

Permalink
feat(equipment): display stats in a more condensed view so % doesnt h…
Browse files Browse the repository at this point in the history
…ave its own stat line for everything
  • Loading branch information
seiyria committed Apr 19, 2023
1 parent 090a0ab commit 590685b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ export class StatNameDisplayComponent implements OnInit {
['health' as Stat]: 'Your total health',
['energy' as Stat]: 'Your total energy',

[Stat.PickaxePower]: 'Mining nodes will take less time (in seconds) to complete',
[Stat.AxePower]: 'Logging nodes will take less time (in seconds) to complete',
[Stat.FishingPower]: 'Fishing nodes will take less time (in seconds) to complete',
[Stat.ScythePower]: 'Harvesting nodes will take less time (in seconds) to complete',
[Stat.HuntingPower]: 'Hunting nodes will take less time (in seconds) to complete',
[Stat.PickaxePower]: 'Mining nodes will take less time (in seconds or by this percent) to complete',
[Stat.AxePower]: 'Logging nodes will take less time (in seconds or by this percent) to complete',
[Stat.FishingPower]: 'Fishing nodes will take less time (in seconds or by this percent) to complete',
[Stat.ScythePower]: 'Harvesting nodes will take less time (in seconds or by this percent) to complete',
[Stat.HuntingPower]: 'Hunting nodes will take less time (in seconds or by this percent) to complete',

[Stat.PickaxePowerPercent]: 'Mining nodes will take less time (by this percent) to complete',
[Stat.AxePowerPercent]: 'Logging nodes will take less time (by this percent) to complete',
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/character/equipment/equipment.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ <h2 [ngClass]="[getItemRarity(item)]">{{ item.name }}</h2>
You don't have any stats. How unfortunate!
</ion-item>

<ion-item *ngFor="let stat of totals | keyvalue" [class.hidden]="stat.value === 0">
<ion-item *ngFor="let stat of totals | keyvalue">
<ion-row class="stat-row">
<ion-col>
<app-stat-name-display [stat]="stat.key"></app-stat-name-display>
</ion-col>
<ion-col class="stat-value">
{{ stat.value | number }}
{{ stat.value }}
</ion-col>
</ion-row>
</ion-item>
Expand Down
42 changes: 40 additions & 2 deletions src/app/pages/character/equipment/equipment.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,47 @@ export class EquipmentPage implements OnInit {
this.store.dispatch(new UnequipItem(slot));
}

statTotals(character: IPlayerCharacter): Record<string, number> {
statTotals(character: IPlayerCharacter): Record<string, string> {
const stats = getStatTotals(this.store.snapshot(), character);
return { ...stats, healthBonus: 0, energyBonus: 0 };
const allStats: Record<string, number> = { ...stats, healthBonus: 0, energyBonus: 0 };

const resultHash: Record<string, string> = {};

// stats first pass
Object.keys(allStats).forEach(stat => {
if(allStats[stat] === 0) {
return;
}

resultHash[stat] = allStats[stat].toLocaleString();

if((stat.includes('Power') || stat.includes('Speed')) && !stat.includes('Percent')) {
resultHash[stat] = `-${resultHash[stat]}s`;
}

if(stat.includes('Percent')) {
resultHash[stat] = `${resultHash[stat]}%`;
}
});

// condense stats
Object.keys(resultHash).forEach(stat => {
if(!stat.includes('Percent')) {
return;
}

const baseStat = stat.split('Percent')[0];

if(resultHash[baseStat]) {
resultHash[baseStat] = `${resultHash[baseStat]} / -${resultHash[stat]}`;
delete resultHash[stat];
} else {
resultHash[baseStat] = `-${resultHash[stat]}`;
delete resultHash[stat];
}
});

return resultHash;
}

getItemRarity(item: IGameItem): string {
Expand Down

0 comments on commit 590685b

Please sign in to comment.