Skip to content

Commit

Permalink
Initial UI for computing/updating EP ratios.
Browse files Browse the repository at this point in the history
  • Loading branch information
merijn committed Apr 10, 2023
1 parent 6d08ecc commit 16591e7
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions ui/core/components/stat_weights_action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,31 @@ class EpWeightsMenu extends BaseModal {
</a>
</th>
</tr>
<tr>
<th>Ratio</th>
<td class="damage-metrics type-ratio type-weight">
</td>
<td class="damage-metrics type-ratio type-ep">
</td>
<td class="healing-metrics type-ratio type-weight">
</td>
<td class="healing-metrics type-ratio type-ep">
</td>
<td class="threat-metrics type-ratio type-weight">
</td>
<td class="threat-metrics type-ratio type-ep">
</td>
<td class="threat-metrics type-ratio type-weight">
</td>
<td class="threat-metrics type-ratio type-ep">
</td>
<td>
<button class="btn btn-primary compute-ep">
<i class="fas fa-calculator"></i>
Compute EP
</button>
</td>
</tr>
</thead>
<tbody></tbody>
</table>
Expand Down Expand Up @@ -248,6 +273,51 @@ class EpWeightsMenu extends BaseModal {
});

this.updateTable(this.simUI.prevEpIterations || 1, this.getPrevSimResult(), true);

const makeEpRatioCell = (cell: HTMLElement, idx: number) => {
new NumberPicker(cell, this.simUI.player, {
float: true,
changedEvent: (player: Player<any>) => player.epRatiosChangeEmitter,
getValue: (player: Player<any>) => this.simUI.player.getEpRatios()[idx],
setValue: (eventID: EventID, player: Player<any>, newValue: number) => {
const epRatios = player.getEpRatios();
epRatios[idx] = newValue;
player.setEpRatios(eventID, epRatios);
},
});
};
const epRatioCells = this.body.querySelectorAll('.type-ratio.type-ep') as NodeListOf<HTMLElement>;
epRatioCells.forEach(makeEpRatioCell);

const weightRatioCells = this.body.querySelectorAll('.type-ratio.type-weight') as NodeListOf<HTMLElement>;
weightRatioCells.forEach(makeEpRatioCell);

const updateButton = this.rootElem.getElementsByClassName('compute-ep')[0] as HTMLElement;
updateButton.setAttribute('data-bs-toggle', 'tooltip');
updateButton.setAttribute('data-bs-title', "Compute Weighted EP");
updateButton.setAttribute('data-bs-html', 'true');

Tooltip.getOrCreateInstance(updateButton);

updateButton.addEventListener('click', event => {
const results = this.getPrevSimResult();
const epRatios = this.simUI.player.getEpRatios();
if (this.statsType == 'ep') {
const scaledDpsEp = Stats.fromProto(results.dps!.epValues).scale(epRatios[0]);
const scaledHpsEp = Stats.fromProto(results.hps!.epValues).scale(epRatios[1]);
const scaledTpsEp = Stats.fromProto(results.tps!.epValues).scale(epRatios[2]);
const scaledDtpsEp = Stats.fromProto(results.dtps!.epValues).scale(epRatios[3]);
const newEp = scaledDpsEp.add(scaledHpsEp).add(scaledTpsEp).add(scaledDtpsEp);
this.simUI.player.setEpWeights(TypedEvent.nextEventID(), newEp);
} else {
const scaledDpsWeights = Stats.fromProto(results.dps!.epValues).scale(epRatios[0]);
const scaledHpsWeights = Stats.fromProto(results.hps!.epValues).scale(epRatios[1]);
const scaledTpsWeights = Stats.fromProto(results.tps!.epValues).scale(epRatios[2]);
const scaledDtpsWeights = Stats.fromProto(results.dtps!.epValues).scale(epRatios[3]);
const newWeights = scaledDpsWeights.add(scaledHpsWeights).add(scaledTpsWeights).add(scaledDtpsWeights);
this.simUI.player.setEpWeights(TypedEvent.nextEventID(), newWeights);
}
});
}

private setSimProgress(progress: ProgressMetrics) {
Expand Down

0 comments on commit 16591e7

Please sign in to comment.