Skip to content

Commit

Permalink
Merge pull request #2530 from wowsims/cleanups
Browse files Browse the repository at this point in the history
Fix ranged weapon filters
  • Loading branch information
jimmyt857 authored Jan 30, 2023
2 parents e060de4 + c5a43e5 commit 5c0f8ba
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ui/core/components/filters_menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class FiltersMenu extends Popup {
float: true,
positive: true,
changedEvent: (sim: Sim) => sim.filtersChangeEmitter,
getValue: (sim: Sim) => sim.getFilters().minMhWeaponSpeed,
getValue: (sim: Sim) => sim.getFilters().minRangedWeaponSpeed,
setValue: (eventID: EventID, sim: Sim, newValue: number) => {
const filters = sim.getFilters();
filters.minRangedWeaponSpeed = newValue;
Expand All @@ -200,7 +200,7 @@ export class FiltersMenu extends Popup {
float: true,
positive: true,
changedEvent: (sim: Sim) => sim.filtersChangeEmitter,
getValue: (sim: Sim) => sim.getFilters().maxMhWeaponSpeed,
getValue: (sim: Sim) => sim.getFilters().maxRangedWeaponSpeed,
setValue: (eventID: EventID, sim: Sim, newValue: number) => {
const filters = sim.getFilters();
filters.maxRangedWeaponSpeed = newValue;
Expand Down
6 changes: 5 additions & 1 deletion ui/core/components/number_picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export class NumberPicker<ModObject> extends Input<ModObject, number> {

if (this.positive) {
this.inputElem.onchange = e => {
this.inputElem.value = Math.abs(parseInt(this.inputElem.value)).toString()
if (this.float) {
this.inputElem.value = Math.abs(parseFloat(this.inputElem.value)).toString()
} else {
this.inputElem.value = Math.abs(parseInt(this.inputElem.value)).toString()
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions ui/core/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,10 @@ export class Player<SpecType extends Spec> {
return itemData.filter(itemElem => {
const item = getItemFunc(itemElem);

if (!filters.rangedWeaponTypes.includes(item.rangedWeaponType)) {
return false;
}

const minSpeed = filters.minRangedWeaponSpeed;
const maxSpeed = filters.maxRangedWeaponSpeed;
if (minSpeed > 0 && item.weaponSpeed < minSpeed) {
Expand Down
9 changes: 8 additions & 1 deletion ui/core/sim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Race } from './proto/common.js';
import { RaidTarget } from './proto/common.js';
import { Spec } from './proto/common.js';
import { Stat, PseudoStat } from './proto/common.js';
import { WeaponType } from './proto/common.js';
import { RangedWeaponType, WeaponType } from './proto/common.js';
import { Raid as RaidProto } from './proto/api.js';
import { ComputeStatsRequest, ComputeStatsResult } from './proto/api.js';
import { RaidSimRequest, RaidSimResult } from './proto/api.js';
Expand Down Expand Up @@ -441,6 +441,7 @@ export class Sim {

private static readonly ALL_ARMOR_TYPES = (getEnumValues(ArmorType) as Array<ArmorType>).filter(v => v != 0);
private static readonly ALL_WEAPON_TYPES = (getEnumValues(WeaponType) as Array<WeaponType>).filter(v => v != 0);
private static readonly ALL_RANGED_WEAPON_TYPES = (getEnumValues(RangedWeaponType) as Array<RangedWeaponType>).filter(v => v != 0);

toProto(): SimSettingsProto {
const filters = this.getFilters();
Expand All @@ -450,6 +451,9 @@ export class Sim {
if (filters.weaponTypes.length == Sim.ALL_WEAPON_TYPES.length) {
filters.weaponTypes = [];
}
if (filters.rangedWeaponTypes.length == Sim.ALL_RANGED_WEAPON_TYPES.length) {
filters.rangedWeaponTypes = [];
}

return SimSettingsProto.create({
iterations: this.getIterations(),
Expand Down Expand Up @@ -484,6 +488,9 @@ export class Sim {
if (filters.weaponTypes.length == 0) {
filters.weaponTypes = Sim.ALL_WEAPON_TYPES.slice();
}
if (filters.rangedWeaponTypes.length == 0) {
filters.rangedWeaponTypes = Sim.ALL_RANGED_WEAPON_TYPES.slice();
}
this.setFilters(eventID, filters);
});
}
Expand Down

0 comments on commit 5c0f8ba

Please sign in to comment.