Skip to content

Commit

Permalink
Added equipped gem summary feature based on commmunity requests.
Browse files Browse the repository at this point in the history
 Changes to be committed:
	new file:   ui/core/components/gem_summary_action.ts
	modified:   ui/core/individual_sim_ui.ts
  • Loading branch information
NerdEgghead committed Nov 17, 2023
1 parent 4fb6b24 commit 831e4d9
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
61 changes: 61 additions & 0 deletions ui/core/components/gem_summary_action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { IndividualSimUI } from '../individual_sim_ui.js';
import { BaseModal } from './base_modal.js';
import { Player } from '../core/player.js';

export function addGemSummaryAction(simUI: IndividualSimUI<any>) {
simUI.addAction('Gem Summary', 'gem-summary-action', () => {
new GemSummaryMenu(simUI);
});
}

class GemSummaryMenu extends BaseModal {
private readonly simUI: IndividualSimUI<any>;
private readonly tableBody: HTMLElement;
private readonly player: Player<any>;

constructor(simUI: IndividualSimUI<any>) {
super(simUI.rootElem, 'gem-summary-menu', { scrollContents: true, size: 'md' });
this.simUI = simUI;
this.player = simUI.player;

this.header?.insertAdjacentHTML('afterbegin', '<h5 class="modal-title">Currently Socketed Gems</h5>');
this.body.innerHTML = `
<div class="gem-summary-table-container modal-scroll-table">
<table class="gem-summary-table" style="width: 100%">
<thead>
<tr>
<th>Gem Type</th>
<th style="text-align: right">
<span>Quantity</span>
</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
`;

this.tableBody = this.rootElem.querySelector('.gem-summary-table tbody') as HTMLElement;
this.updateTable();
}

private updateTable() {
this.tableBody.innerHTML = ``;
const fullGemList = this.player.getGear().getAllGems(this.player.isBlacksmithing());
const gemCounts = {};

for (const gem of fullGemList) {
gemCounts[gem.name] = gemCounts[gem.name] ? gemCounts[gem.name] + 1 : 1;
}

for (const gemName of Object.keys(gemCounts)) {
const row = document.createElement('tr');
row.innerHTML = `
<td>${gemName}</td>
<td style="text-align: right">${gemCounts[gemName].toFixed(0)}</td>
`;
this.tableBody.appendChild(row);
}
}

}
2 changes: 2 additions & 0 deletions ui/core/individual_sim_ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { EncounterPickerConfig } from './components/encounter_picker';
import { addRaidSimAction, RaidSimResultsManager } from './components/raid_sim_action';
import { SavedDataConfig } from './components/saved_data_manager';
import { addStatWeightsAction } from './components/stat_weights_action';
import { addGemSummaryAction } from './components/gem_summary_action';

import { BulkTab } from './components/individual_sim_ui/bulk_tab';
import { GearTab } from './components/individual_sim_ui/gear_tab';
Expand Down Expand Up @@ -340,6 +341,7 @@ export abstract class IndividualSimUI<SpecType extends Spec> extends SimUI {
private addSidebarComponents() {
this.raidSimResultsManager = addRaidSimAction(this);
addStatWeightsAction(this, this.individualConfig.epStats, this.individualConfig.epPseudoStats, this.individualConfig.epReferenceStat);
addGemSummaryAction(this);

const characterStats = new CharacterStats(
this.rootElem.getElementsByClassName('sim-sidebar-footer')[0] as HTMLElement,
Expand Down

0 comments on commit 831e4d9

Please sign in to comment.