From 627c5aaf5f6da5b7feb6707356a9ca8364e80799 Mon Sep 17 00:00:00 2001 From: jarves Date: Wed, 4 Oct 2023 19:37:54 -0500 Subject: [PATCH 1/3] ui: swap names 'records' to map type Signed-off-by: jarves --- .../detailed_results/resource_metrics.ts | 2 +- .../components/detailed_results/timeline.tsx | 6 +- ui/core/components/encounter_picker.ts | 2 +- ui/core/components/exporters.ts | 6 +- ui/core/components/filters_menu.ts | 10 +- ui/core/components/gear_picker.tsx | 6 +- ui/core/components/importers.ts | 2 +- .../individual_sim_ui/settings_tab.ts | 6 +- ui/core/individual_sim_ui.ts | 2 +- ui/core/proto_utils/logs_parser.ts | 4 +- ui/core/proto_utils/names.ts | 356 +++++++++--------- ui/core/proto_utils/stats.ts | 2 +- ui/raid/import_export.ts | 12 +- 13 files changed, 203 insertions(+), 213 deletions(-) diff --git a/ui/core/components/detailed_results/resource_metrics.ts b/ui/core/components/detailed_results/resource_metrics.ts index bb93c703af..21401b260e 100644 --- a/ui/core/components/detailed_results/resource_metrics.ts +++ b/ui/core/components/detailed_results/resource_metrics.ts @@ -14,7 +14,7 @@ export class ResourceMetricsTable extends ResultComponent { orderedResourceTypes.forEach(resourceType => { const containerElem = document.createElement('div'); containerElem.classList.add('resource-metrics-table-container', 'hide'); - containerElem.innerHTML = `${resourceNames[resourceType]}`; + containerElem.innerHTML = `${resourceNames.get(resourceType)}`; this.rootElem.appendChild(containerElem); const childConfig = config; diff --git a/ui/core/components/detailed_results/timeline.tsx b/ui/core/components/detailed_results/timeline.tsx index 5a177bcc62..96ada58a4d 100644 --- a/ui/core/components/detailed_results/timeline.tsx +++ b/ui/core/components/detailed_results/timeline.tsx @@ -702,7 +702,7 @@ export class Timeline extends ResultComponent { - {resourceNames[resourceType]} + {resourceNames.get(resourceType)} ); @@ -717,7 +717,7 @@ export class Timeline extends ResultComponent { ) resourceLogs.forEach((resourceLogGroup, i) => { - const cNames = resourceNames[resourceType].toLowerCase().replaceAll(' ', '-'); + const cNames = resourceNames.get(resourceType)!.toLowerCase().replaceAll(' ', '-'); const resourceElem = (
`${val.toFixed(1)}`; return ( -
+
{log.timestamp.toFixed(2)}s
diff --git a/ui/core/components/encounter_picker.ts b/ui/core/components/encounter_picker.ts index 4c7d29cd1c..fec0b4633e 100644 --- a/ui/core/components/encounter_picker.ts +++ b/ui/core/components/encounter_picker.ts @@ -356,7 +356,7 @@ class TargetPicker extends Input { return new NumberPicker(section2, null, { inline: true, extraCssClasses: statData.extraCssClasses, - label: statNames[stat], + label: statNames.get(stat), labelTooltip: statData.tooltip, changedEvent: () => encounter.targetsChangeEmitter, getValue: () => this.getTarget().stats[stat], diff --git a/ui/core/components/exporters.ts b/ui/core/components/exporters.ts index e676125193..b236855532 100644 --- a/ui/core/components/exporters.ts +++ b/ui/core/components/exporters.ts @@ -127,8 +127,8 @@ export class IndividualWowheadGearPlannerExporter extends getData(): string { const player = this.simUI.player; - const classStr = classNames[player.getClass()].replaceAll(' ', '-').toLowerCase(); - const raceStr = raceNames[player.getRace()].replaceAll(' ', '-').toLowerCase(); + const classStr = classNames.get(player.getClass())!.replaceAll(' ', '-').toLowerCase(); + const raceStr = raceNames.get(player.getRace())!.replaceAll(' ', '-').toLowerCase(); let url = `https://www.wowhead.com/wotlk/gear-planner/${classStr}/${raceStr}/`; // See comments on the importer for how the binary formatting is structured. @@ -347,7 +347,7 @@ export class IndividualPawnEPExporter extends Exporter { } }); - return `( Pawn: v1: "${specNames[player.spec]} WoWSims Weights": Class=${classNames[player.getClass()]},` + + return `( Pawn: v1: "${specNames[player.spec]} WoWSims Weights": Class=${classNames.get(player.getClass())},` + Object.keys(namesToWeights) .map(statName => `${statName}=${namesToWeights[statName].toFixed(3)}`).join(',') + ' )'; diff --git a/ui/core/components/filters_menu.ts b/ui/core/components/filters_menu.ts index 6e673f351e..ccf5a830a4 100644 --- a/ui/core/components/filters_menu.ts +++ b/ui/core/components/filters_menu.ts @@ -68,7 +68,7 @@ export class FiltersMenu extends BaseModal { const sources = Sim.ALL_SOURCES.filter(s => s != SourceFilterOption.SourceUnknown); sources.forEach(source => { new BooleanPicker(section, player.sim, { - label: sourceNames[source], + label: sourceNames.get(source), inline: true, changedEvent: (sim: Sim) => sim.filtersChangeEmitter, getValue: (sim: Sim) => sim.getFilters().sources.includes(source), @@ -89,7 +89,7 @@ export class FiltersMenu extends BaseModal { const raids = Sim.ALL_RAIDS.filter(s => s != RaidFilterOption.RaidUnknown); raids.forEach(raid => { new BooleanPicker(section, player.sim, { - label: raidNames[raid], + label: raidNames.get(raid), inline: true, changedEvent: (sim: Sim) => sim.filtersChangeEmitter, getValue: (sim: Sim) => sim.getFilters().raids.includes(raid), @@ -116,7 +116,7 @@ export class FiltersMenu extends BaseModal { armorTypes.forEach(armorType => { new BooleanPicker(section, player.sim, { - label: armorTypeNames[armorType], + label: armorTypeNames.get(armorType), inline: true, changedEvent: (sim: Sim) => sim.filtersChangeEmitter, getValue: (sim: Sim) => sim.getFilters().armorTypes.includes(armorType), @@ -139,7 +139,7 @@ export class FiltersMenu extends BaseModal { weaponTypes.forEach(weaponType => { new BooleanPicker(weaponTypeSection, player.sim, { - label: weaponTypeNames[weaponType], + label: weaponTypeNames.get(weaponType), inline: true, changedEvent: (sim: Sim) => sim.filtersChangeEmitter, getValue: (sim: Sim) => sim.getFilters().weaponTypes.includes(weaponType), @@ -221,7 +221,7 @@ export class FiltersMenu extends BaseModal { rangedWeaponTypes.forEach(rangedWeaponType => { new BooleanPicker(rangedWeaponTypeSection, player.sim, { - label: rangedWeaponTypeNames[rangedWeaponType], + label: rangedWeaponTypeNames.get(rangedWeaponType), inline: true, changedEvent: (sim: Sim) => sim.filtersChangeEmitter, getValue: (sim: Sim) => sim.getFilters().rangedWeaponTypes.includes(rangedWeaponType), diff --git a/ui/core/components/gear_picker.tsx b/ui/core/components/gear_picker.tsx index 8cb7a6a46a..97687b2fe1 100644 --- a/ui/core/components/gear_picker.tsx +++ b/ui/core/components/gear_picker.tsx @@ -277,7 +277,7 @@ export class ItemPicker extends Component { set item(newItem: EquippedItem | null) { // Clear everything first this.itemElem.clear(); - this.itemElem.nameElem.textContent = slotNames[this.slot]; + this.itemElem.nameElem.textContent = slotNames.get(this.slot) ?? ''; setItemQualityCssClass(this.itemElem.nameElem, null); if (newItem != null) { @@ -1273,7 +1273,7 @@ export class ItemList { const source = item.sources[0]; if (source.source.oneofKind == 'crafted') { const src = source.source.crafted; - return makeAnchor( ActionId.makeSpellUrl(src.spellId), professionNames[src.profession]); + return makeAnchor( ActionId.makeSpellUrl(src.spellId), professionNames.get(src.profession) ?? 'Unknown'); } else if (source.source.oneofKind == 'drop') { const src = source.source.drop; const zone = sim.db.getZone(src.zoneId); @@ -1282,7 +1282,7 @@ export class ItemList { throw new Error('No zone found for item: ' + item); } - let rtnEl = makeAnchor( ActionId.makeZoneUrl(zone.id), `${zone.name} (${difficultyNames[src.difficulty]})`); + let rtnEl = makeAnchor( ActionId.makeZoneUrl(zone.id), `${zone.name} (${difficultyNames.get(src.difficulty) ?? 'Unknown'})`); const category = src.category ? ` - ${src.category}` : ''; if (npc) { diff --git a/ui/core/components/importers.ts b/ui/core/components/importers.ts index a593a959c9..97966fdf76 100644 --- a/ui/core/components/importers.ts +++ b/ui/core/components/importers.ts @@ -76,7 +76,7 @@ export abstract class Importer extends BaseModal { protected async finishIndividualImport(simUI: IndividualSimUI, charClass: Class, race: Race, equipmentSpec: EquipmentSpec, talentsStr: string, glyphs: Glyphs | null, professions: Array): Promise { const playerClass = simUI.player.getClass(); if (charClass != playerClass) { - throw new Error(`Wrong Class! Expected ${classNames[playerClass]} but found ${classNames[charClass]}!`); + throw new Error(`Wrong Class! Expected ${classNames.get(playerClass)} but found ${classNames.get(charClass)}!`); } await Database.loadLeftoversIfNecessary(equipmentSpec); diff --git a/ui/core/components/individual_sim_ui/settings_tab.ts b/ui/core/components/individual_sim_ui/settings_tab.ts index 8f75fe8414..8e020eb143 100644 --- a/ui/core/components/individual_sim_ui/settings_tab.ts +++ b/ui/core/components/individual_sim_ui/settings_tab.ts @@ -158,7 +158,7 @@ export class SettingsTab extends SimTab { label: 'Race', values: races.map(race => { return { - name: raceNames[race], + name: raceNames.get(race)!, value: race, }; }), @@ -179,7 +179,7 @@ export class SettingsTab extends SimTab { label: 'Profession 1', values: professions.map(p => { return { - name: professionNames[p], + name: professionNames.get(p)!, value: p, }; }), @@ -192,7 +192,7 @@ export class SettingsTab extends SimTab { label: 'Profession 2', values: professions.map(p => { return { - name: professionNames[p], + name: professionNames.get(p)!, value: p, }; }), diff --git a/ui/core/individual_sim_ui.ts b/ui/core/individual_sim_ui.ts index e9f558b3cb..300daa124d 100644 --- a/ui/core/individual_sim_ui.ts +++ b/ui/core/individual_sim_ui.ts @@ -229,7 +229,7 @@ export abstract class IndividualSimUI extends SimUI { return ''; } - return failedProfReqs.map(fpr => `${fpr.name} requires ${professionNames[fpr.requiredProfession]}, but it is not selected.`); + return failedProfReqs.map(fpr => `${fpr.name} requires ${professionNames.get(fpr.requiredProfession)!}, but it is not selected.`); }, }); this.addWarning({ diff --git a/ui/core/proto_utils/logs_parser.ts b/ui/core/proto_utils/logs_parser.ts index bde673aaa5..87ae32418b 100644 --- a/ui/core/proto_utils/logs_parser.ts +++ b/ui/core/proto_utils/logs_parser.ts @@ -597,7 +597,7 @@ export class ResourceChangedLog extends SimLog { const isHealth = this.resourceType == ResourceType.ResourceTypeHealth; const verb = isHealth ? (this.isSpend ? 'Lost' : 'Recovered') : (this.isSpend ? 'Spent' : 'Gained'); - return `${this.toStringPrefix()} ${verb} ${signedDiff.toFixed(1)} ${resourceNames[this.resourceType]} from ${this.actionId!.name}. (${this.valueBefore.toFixed(1)} --> ${this.valueAfter.toFixed(1)})`; + return `${this.toStringPrefix()} ${verb} ${signedDiff.toFixed(1)} ${resourceNames.get(this.resourceType)} from ${this.actionId!.name}. (${this.valueBefore.toFixed(1)} --> ${this.valueAfter.toFixed(1)})`; } resultString(): string { @@ -638,7 +638,7 @@ export class ResourceChangedLogGroup extends SimLog { } toString(): string { - return `${this.toStringPrefix()} ${resourceNames[this.resourceType]}: ${this.valueBefore.toFixed(1)} --> ${this.valueAfter.toFixed(1)}`; + return `${this.toStringPrefix()} ${resourceNames.get(this.resourceType)}: ${this.valueBefore.toFixed(1)} --> ${this.valueAfter.toFixed(1)}`; } static fromLogs(logs: Array): Record> { diff --git a/ui/core/proto_utils/names.ts b/ui/core/proto_utils/names.ts index 6284d110af..3f9ab62691 100644 --- a/ui/core/proto_utils/names.ts +++ b/ui/core/proto_utils/names.ts @@ -16,116 +16,110 @@ import { } from '../proto/ui.js'; import { ResourceType } from '../proto/api.js'; -export const armorTypeNames: Record = { - [ArmorType.ArmorTypeUnknown]: 'Unknown', - [ArmorType.ArmorTypeCloth]: 'Cloth', - [ArmorType.ArmorTypeLeather]: 'Leather', - [ArmorType.ArmorTypeMail]: 'Mail', - [ArmorType.ArmorTypePlate]: 'Plate', -}; +export const armorTypeNames: Map = new Map([ + [ArmorType.ArmorTypeUnknown, 'Unknown'], + [ArmorType.ArmorTypeCloth, 'Cloth'], + [ArmorType.ArmorTypeLeather, 'Leather'], + [ArmorType.ArmorTypeMail, 'Mail'], + [ArmorType.ArmorTypePlate, 'Plate'], +]); -export const weaponTypeNames: Record = { - [WeaponType.WeaponTypeUnknown]: 'Unknown', - [WeaponType.WeaponTypeAxe]: 'Axe', - [WeaponType.WeaponTypeDagger]: 'Dagger', - [WeaponType.WeaponTypeFist]: 'Fist', - [WeaponType.WeaponTypeMace]: 'Mace', - [WeaponType.WeaponTypeOffHand]: 'Misc', - [WeaponType.WeaponTypePolearm]: 'Polearm', - [WeaponType.WeaponTypeShield]: 'Shield', - [WeaponType.WeaponTypeStaff]: 'Staff', - [WeaponType.WeaponTypeSword]: 'Sword', -}; +export const weaponTypeNames: Map = new Map([ + [WeaponType.WeaponTypeUnknown, 'Unknown'], + [WeaponType.WeaponTypeAxe, 'Axe'], + [WeaponType.WeaponTypeDagger, 'Dagger'], + [WeaponType.WeaponTypeFist, 'Fist'], + [WeaponType.WeaponTypeMace, 'Mace'], + [WeaponType.WeaponTypeOffHand, 'Misc'], + [WeaponType.WeaponTypePolearm, 'Polearm'], + [WeaponType.WeaponTypeShield, 'Shield'], + [WeaponType.WeaponTypeStaff, 'Staff'], + [WeaponType.WeaponTypeSword, 'Sword'], +]); -export const rangedWeaponTypeNames: Record = { - [RangedWeaponType.RangedWeaponTypeUnknown]: 'Unknown', - [RangedWeaponType.RangedWeaponTypeBow]: 'Bow', - [RangedWeaponType.RangedWeaponTypeCrossbow]: 'Crossbow', - [RangedWeaponType.RangedWeaponTypeGun]: 'Gun', - [RangedWeaponType.RangedWeaponTypeIdol]: 'Idol', - [RangedWeaponType.RangedWeaponTypeLibram]: 'Libram', - [RangedWeaponType.RangedWeaponTypeSigil]: 'Sigil', - [RangedWeaponType.RangedWeaponTypeThrown]: 'Thrown', - [RangedWeaponType.RangedWeaponTypeTotem]: 'Totem', - [RangedWeaponType.RangedWeaponTypeWand]: 'Wand', -}; +export const rangedWeaponTypeNames: Map = new Map([ + [RangedWeaponType.RangedWeaponTypeUnknown, 'Unknown'], + [RangedWeaponType.RangedWeaponTypeBow, 'Bow'], + [RangedWeaponType.RangedWeaponTypeCrossbow, 'Crossbow'], + [RangedWeaponType.RangedWeaponTypeGun, 'Gun'], + [RangedWeaponType.RangedWeaponTypeIdol, 'Idol'], + [RangedWeaponType.RangedWeaponTypeLibram, 'Libram'], + [RangedWeaponType.RangedWeaponTypeSigil, 'Sigil'], + [RangedWeaponType.RangedWeaponTypeThrown, 'Thrown'], + [RangedWeaponType.RangedWeaponTypeTotem, 'Totem'], + [RangedWeaponType.RangedWeaponTypeWand, 'Wand'], +]); -export const raceNames: Record = { - [Race.RaceUnknown]: 'None', - [Race.RaceBloodElf]: 'Blood Elf', - [Race.RaceDraenei]: 'Draenei', - [Race.RaceDwarf]: 'Dwarf', - [Race.RaceGnome]: 'Gnome', - [Race.RaceHuman]: 'Human', - [Race.RaceNightElf]: 'Night Elf', - [Race.RaceOrc]: 'Orc', - [Race.RaceTauren]: 'Tauren', - [Race.RaceTroll]: 'Troll', - [Race.RaceUndead]: 'Undead', -}; +export const raceNames: Map = new Map([ + [Race.RaceUnknown, 'None'], + [Race.RaceBloodElf, 'Blood Elf'], + [Race.RaceDraenei, 'Draenei'], + [Race.RaceDwarf, 'Dwarf'], + [Race.RaceGnome, 'Gnome'], + [Race.RaceHuman, 'Human'], + [Race.RaceNightElf, 'Night Elf'], + [Race.RaceOrc, 'Orc'], + [Race.RaceTauren, 'Tauren'], + [Race.RaceTroll, 'Troll'], + [Race.RaceUndead, 'Undead'], +]); export function nameToRace(name: string): Race { const normalized = name.toLowerCase().replaceAll(' ', ''); - for (const key in raceNames) { - const race = parseInt(key) as Race; - if (raceNames[race].toLowerCase().replaceAll(' ', '') == normalized) { - return race; + for (const [key, value] of raceNames) { + if (value.toLowerCase().replaceAll(' ', '') == normalized) { + return key; } } - return Race.RaceUnknown; } -export const classNames: Record = { - [Class.ClassUnknown]: 'None', - [Class.ClassDruid]: 'Druid', - [Class.ClassHunter]: 'Hunter', - [Class.ClassMage]: 'Mage', - [Class.ClassPaladin]: 'Paladin', - [Class.ClassPriest]: 'Priest', - [Class.ClassRogue]: 'Rogue', - [Class.ClassShaman]: 'Shaman', - [Class.ClassWarlock]: 'Warlock', - [Class.ClassWarrior]: 'Warrior', - [Class.ClassDeathknight]: 'Death Knight', -} +export const classNames: Map = new Map([ + [Class.ClassUnknown, 'None'], + [Class.ClassDruid, 'Druid'], + [Class.ClassHunter, 'Hunter'], + [Class.ClassMage, 'Mage'], + [Class.ClassPaladin, 'Paladin'], + [Class.ClassPriest, 'Priest'], + [Class.ClassRogue, 'Rogue'], + [Class.ClassShaman, 'Shaman'], + [Class.ClassWarlock, 'Warlock'], + [Class.ClassWarrior, 'Warrior'], + [Class.ClassDeathknight, 'Death Knight'], +]); export function nameToClass(name: string): Class { const lower = name.toLowerCase(); - for (const key in classNames) { - const charClass = parseInt(key) as Class; - if (classNames[charClass].toLowerCase().replace(/\s+/g, '') == lower) { - return charClass; + for (const [key, value] of classNames) { + if (value.toLowerCase().replace(/\s+/g, '') == lower) { + return key; } } - return Class.ClassUnknown; } -export const professionNames: Record = { - [Profession.ProfessionUnknown]: 'None', - [Profession.Alchemy]: 'Alchemy', - [Profession.Blacksmithing]: 'Blacksmithing', - [Profession.Enchanting]: 'Enchanting', - [Profession.Engineering]: 'Engineering', - [Profession.Herbalism]: 'Herbalism', - [Profession.Inscription]: 'Inscription', - [Profession.Jewelcrafting]: 'Jewelcrafting', - [Profession.Leatherworking]: 'Leatherworking', - [Profession.Mining]: 'Mining', - [Profession.Skinning]: 'Skinning', - [Profession.Tailoring]: 'Tailoring', -}; +export const professionNames: Map = new Map([ + [Profession.ProfessionUnknown, 'None'], + [Profession.Alchemy, 'Alchemy'], + [Profession.Blacksmithing, 'Blacksmithing'], + [Profession.Enchanting, 'Enchanting'], + [Profession.Engineering, 'Engineering'], + [Profession.Herbalism, 'Herbalism'], + [Profession.Inscription, 'Inscription'], + [Profession.Jewelcrafting, 'Jewelcrafting'], + [Profession.Leatherworking, 'Leatherworking'], + [Profession.Mining, 'Mining'], + [Profession.Skinning, 'Skinning'], + [Profession.Tailoring, 'Tailoring'], +]); export function nameToProfession(name: string): Profession { const lower = name.toLowerCase(); - for (const key in professionNames) { - const prof = parseInt(key) as Profession; - if (professionNames[prof].toLowerCase() == lower) { - return prof; + for (const [key, value] of professionNames) { + if (value.toLowerCase() == lower) { + return key } } - return Profession.ProfessionUnknown; } @@ -221,14 +215,14 @@ export const pseudoStatOrder: Array = [ PseudoStat.PseudoStatRangedDps, PseudoStat.PseudoStatBlockValueMultiplier, ]; -export const pseudoStatNames: Record = { - [PseudoStat.PseudoStatMainHandDps]: 'Main Hand DPS', - [PseudoStat.PseudoStatOffHandDps]: 'Off Hand DPS', - [PseudoStat.PseudoStatRangedDps]: 'Ranged DPS', - [PseudoStat.PseudoStatBlockValueMultiplier]: 'Block Value Multiplier', - [PseudoStat.PseudoStatDodge]: 'Dodge Chance', - [PseudoStat.PseudoStatParry]: 'Parry Chance', -}; +export const pseudoStatNames: Map = new Map([ + [PseudoStat.PseudoStatMainHandDps, 'Main Hand DPS'], + [PseudoStat.PseudoStatOffHandDps, 'Off Hand DPS'], + [PseudoStat.PseudoStatRangedDps, 'Ranged DPS'], + [PseudoStat.PseudoStatBlockValueMultiplier, 'Block Value Multiplier'], + [PseudoStat.PseudoStatDodge, 'Dodge Chance'], + [PseudoStat.PseudoStatParry, 'Parry Chance'], +]); export function getClassStatName(stat: Stat, playerClass: Class): string { const statName = statNames[stat]; @@ -239,101 +233,101 @@ export function getClassStatName(stat: Stat, playerClass: Class): string { } } -export const slotNames: Record = { - [ItemSlot.ItemSlotHead]: 'Head', - [ItemSlot.ItemSlotNeck]: 'Neck', - [ItemSlot.ItemSlotShoulder]: 'Shoulders', - [ItemSlot.ItemSlotBack]: 'Back', - [ItemSlot.ItemSlotChest]: 'Chest', - [ItemSlot.ItemSlotWrist]: 'Wrist', - [ItemSlot.ItemSlotHands]: 'Hands', - [ItemSlot.ItemSlotWaist]: 'Waist', - [ItemSlot.ItemSlotLegs]: 'Legs', - [ItemSlot.ItemSlotFeet]: 'Feet', - [ItemSlot.ItemSlotFinger1]: 'Finger 1', - [ItemSlot.ItemSlotFinger2]: 'Finger 2', - [ItemSlot.ItemSlotTrinket1]: 'Trinket 1', - [ItemSlot.ItemSlotTrinket2]: 'Trinket 2', - [ItemSlot.ItemSlotMainHand]: 'Main Hand', - [ItemSlot.ItemSlotOffHand]: 'Off Hand', - [ItemSlot.ItemSlotRanged]: 'Ranged', -}; +export const slotNames: Map = new Map([ + [ItemSlot.ItemSlotHead, 'Head'], + [ItemSlot.ItemSlotNeck, 'Neck'], + [ItemSlot.ItemSlotShoulder, 'Shoulders'], + [ItemSlot.ItemSlotBack, 'Back'], + [ItemSlot.ItemSlotChest, 'Chest'], + [ItemSlot.ItemSlotWrist, 'Wrist'], + [ItemSlot.ItemSlotHands, 'Hands'], + [ItemSlot.ItemSlotWaist, 'Waist'], + [ItemSlot.ItemSlotLegs, 'Legs'], + [ItemSlot.ItemSlotFeet, 'Feet'], + [ItemSlot.ItemSlotFinger1, 'Finger 1'], + [ItemSlot.ItemSlotFinger2, 'Finger 2'], + [ItemSlot.ItemSlotTrinket1, 'Trinket 1'], + [ItemSlot.ItemSlotTrinket2, 'Trinket 2'], + [ItemSlot.ItemSlotMainHand, 'Main Hand'], + [ItemSlot.ItemSlotOffHand, 'Off Hand'], + [ItemSlot.ItemSlotRanged, 'Ranged'], +]); -export const resourceNames: Record = { - [ResourceType.ResourceTypeNone]: 'None', - [ResourceType.ResourceTypeHealth]: 'Health', - [ResourceType.ResourceTypeMana]: 'Mana', - [ResourceType.ResourceTypeEnergy]: 'Energy', - [ResourceType.ResourceTypeRage]: 'Rage', - [ResourceType.ResourceTypeComboPoints]: 'Combo Points', - [ResourceType.ResourceTypeFocus]: 'Focus', - [ResourceType.ResourceTypeRunicPower]: 'Runic Power', - [ResourceType.ResourceTypeBloodRune]: 'Blood Rune', - [ResourceType.ResourceTypeFrostRune]: 'Frost Rune', - [ResourceType.ResourceTypeUnholyRune]: 'Unholy Rune', - [ResourceType.ResourceTypeDeathRune]: 'Death Rune', -}; +export const resourceNames: Map = new Map([ + [ResourceType.ResourceTypeNone, 'None'], + [ResourceType.ResourceTypeHealth, 'Health'], + [ResourceType.ResourceTypeMana, 'Mana'], + [ResourceType.ResourceTypeEnergy, 'Energy'], + [ResourceType.ResourceTypeRage, 'Rage'], + [ResourceType.ResourceTypeComboPoints, 'Combo Points'], + [ResourceType.ResourceTypeFocus, 'Focus'], + [ResourceType.ResourceTypeRunicPower, 'Runic Power'], + [ResourceType.ResourceTypeBloodRune, 'Blood Rune'], + [ResourceType.ResourceTypeFrostRune, 'Frost Rune'], + [ResourceType.ResourceTypeUnholyRune, 'Unholy Rune'], + [ResourceType.ResourceTypeDeathRune, 'Death Rune'], +]); -export const resourceColors: Record = { - [ResourceType.ResourceTypeNone]: '#ffffff', - [ResourceType.ResourceTypeHealth]: '#22ba00', - [ResourceType.ResourceTypeMana]: '#2e93fa', - [ResourceType.ResourceTypeEnergy]: '#ffd700', - [ResourceType.ResourceTypeRage]: '#ff0000', - [ResourceType.ResourceTypeComboPoints]: '#ffa07a', - [ResourceType.ResourceTypeFocus]: '#cd853f', - [ResourceType.ResourceTypeRunicPower]: '#5b99ee', - [ResourceType.ResourceTypeBloodRune]: '#ff0000', - [ResourceType.ResourceTypeFrostRune]: '#0000ff', - [ResourceType.ResourceTypeUnholyRune]: '#00ff00', - [ResourceType.ResourceTypeDeathRune]: '#8b008b', -}; +export const resourceColors: Map = new Map([ + [ResourceType.ResourceTypeNone, '#ffffff'], + [ResourceType.ResourceTypeHealth, '#22ba00'], + [ResourceType.ResourceTypeMana, '#2e93fa'], + [ResourceType.ResourceTypeEnergy, '#ffd700'], + [ResourceType.ResourceTypeRage, '#ff0000'], + [ResourceType.ResourceTypeComboPoints, '#ffa07a'], + [ResourceType.ResourceTypeFocus, '#cd853f'], + [ResourceType.ResourceTypeRunicPower, '#5b99ee'], + [ResourceType.ResourceTypeBloodRune, '#ff0000'], + [ResourceType.ResourceTypeFrostRune, '#0000ff'], + [ResourceType.ResourceTypeUnholyRune, '#00ff00'], + [ResourceType.ResourceTypeDeathRune, '#8b008b'], +]); export function stringToResourceType(str: string): ResourceType { - for (const [key, val] of Object.entries(resourceNames)) { + for (const [key, val] of resourceNames) { if (val.toLowerCase() == str.toLowerCase()) { - return Number(key) as ResourceType; + return key; } } return ResourceType.ResourceTypeNone; } -export const sourceNames: Record = { - [SourceFilterOption.SourceUnknown]: 'Unknown', - [SourceFilterOption.SourceCrafting]: 'Crafting', - [SourceFilterOption.SourceQuest]: 'Quest', - [SourceFilterOption.SourceDungeon]: 'Dungeon', - [SourceFilterOption.SourceDungeonH]: 'Dungeon (H)', - [SourceFilterOption.SourceDungeonTRA]: 'Dungeon (TRA)', - [SourceFilterOption.SourceDungeonTRB]: 'Dungeon (TRB)', - [SourceFilterOption.SourceRaid10]: 'Raid (10N)', - [SourceFilterOption.SourceRaid10H]: 'Raid (10H)', - [SourceFilterOption.SourceRaid25]: 'Raid (25N)', - [SourceFilterOption.SourceRaid25H]: 'Raid (25H)', -}; -export const raidNames: Record = { - [RaidFilterOption.RaidUnknown]: 'Unknown', - [RaidFilterOption.RaidVanilla]: 'Vanilla', - [RaidFilterOption.RaidTbc]: 'TBC', - [RaidFilterOption.RaidNaxxramas]: 'Naxxramas', - [RaidFilterOption.RaidEyeOfEternity]: 'Eye of Eternity', - [RaidFilterOption.RaidObsidianSanctum]: 'Obsidian Sanctum', - [RaidFilterOption.RaidVaultOfArchavon]: 'Vault of Archavon', - [RaidFilterOption.RaidUlduar]: 'Ulduar', - [RaidFilterOption.RaidTrialOfTheCrusader]: 'Trial of the Crusader', - [RaidFilterOption.RaidOnyxiasLair]: 'Onyxia\'s Lair', - [RaidFilterOption.RaidIcecrownCitadel]: 'Icecrown Citadel', - [RaidFilterOption.RaidRubySanctum]: 'Ruby Sanctum', -}; +export const sourceNames: Map = new Map([ + [SourceFilterOption.SourceUnknown, 'Unknown'], + [SourceFilterOption.SourceCrafting, 'Crafting'], + [SourceFilterOption.SourceQuest, 'Quest'], + [SourceFilterOption.SourceDungeon, 'Dungeon'], + [SourceFilterOption.SourceDungeonH, 'Dungeon (H)'], + [SourceFilterOption.SourceDungeonTRA, 'Dungeon (TRA)'], + [SourceFilterOption.SourceDungeonTRB, 'Dungeon (TRB)'], + [SourceFilterOption.SourceRaid10, 'Raid (10N)'], + [SourceFilterOption.SourceRaid10H, 'Raid (10H)'], + [SourceFilterOption.SourceRaid25, 'Raid (25N)'], + [SourceFilterOption.SourceRaid25H, 'Raid (25H)'], +]); +export const raidNames: Map = new Map([ + [RaidFilterOption.RaidUnknown, 'Unknown'], + [RaidFilterOption.RaidVanilla, 'Vanilla'], + [RaidFilterOption.RaidTbc, 'TBC'], + [RaidFilterOption.RaidNaxxramas, 'Naxxramas'], + [RaidFilterOption.RaidEyeOfEternity, 'Eye of Eternity'], + [RaidFilterOption.RaidObsidianSanctum, 'Obsidian Sanctum'], + [RaidFilterOption.RaidVaultOfArchavon, 'Vault of Archavon'], + [RaidFilterOption.RaidUlduar, 'Ulduar'], + [RaidFilterOption.RaidTrialOfTheCrusader, 'Trial of the Crusader'], + [RaidFilterOption.RaidOnyxiasLair, 'Onyxia\'s Lair'], + [RaidFilterOption.RaidIcecrownCitadel, 'Icecrown Citadel'], + [RaidFilterOption.RaidRubySanctum, 'Ruby Sanctum'], +]); -export const difficultyNames: Record = { - [DungeonDifficulty.DifficultyUnknown]: 'Unknown', - [DungeonDifficulty.DifficultyNormal]: 'N', - [DungeonDifficulty.DifficultyHeroic]: 'H', - [DungeonDifficulty.DifficultyTitanRuneAlpha]: 'TRA', - [DungeonDifficulty.DifficultyTitanRuneBeta]: 'TRB', - [DungeonDifficulty.DifficultyRaid10]: '10N', - [DungeonDifficulty.DifficultyRaid10H]: '10H', - [DungeonDifficulty.DifficultyRaid25]: '25N', - [DungeonDifficulty.DifficultyRaid25H]: '25H', -}; +export const difficultyNames: Map = new Map([ + [DungeonDifficulty.DifficultyUnknown, 'Unknown'], + [DungeonDifficulty.DifficultyNormal, 'N'], + [DungeonDifficulty.DifficultyHeroic, 'H'], + [DungeonDifficulty.DifficultyTitanRuneAlpha, 'TRA'], + [DungeonDifficulty.DifficultyTitanRuneBeta, 'TRB'], + [DungeonDifficulty.DifficultyRaid10, '10N'], + [DungeonDifficulty.DifficultyRaid10H, '10H'], + [DungeonDifficulty.DifficultyRaid25, '25N'], + [DungeonDifficulty.DifficultyRaid25H, '25H'], +]); diff --git a/ui/core/proto_utils/stats.ts b/ui/core/proto_utils/stats.ts index 0fd6415fe2..adb4ff3492 100644 --- a/ui/core/proto_utils/stats.ts +++ b/ui/core/proto_utils/stats.ts @@ -42,7 +42,7 @@ export class UnitStat { if (this.isStat()) { return getClassStatName(this.stat!, clazz); } else { - return pseudoStatNames[this.pseudoStat!]; + return pseudoStatNames.get(this.pseudoStat!)!; } } diff --git a/ui/raid/import_export.ts b/ui/raid/import_export.ts index b7685ac252..dcd1234b49 100644 --- a/ui/raid/import_export.ts +++ b/ui/raid/import_export.ts @@ -1,6 +1,5 @@ import { Exporter } from '../core/components/exporters'; import { Importer } from '../core/components/importers'; -import { MAX_PARTY_SIZE } from '../core/party'; import { RaidSimSettings } from '../core/proto/ui'; import { EventID, TypedEvent } from '../core/typed_event'; import { Party as PartyProto, Player as PlayerProto, Raid as RaidProto } from '../core/proto/api'; @@ -10,7 +9,6 @@ import { EquipmentSpec, Faction, ItemSpec, - MobType, Profession, Race, UnitReference, @@ -18,7 +16,7 @@ import { Target as TargetProto, UnitReference_Type, } from '../core/proto/common'; -import { nameToClass, professionNames, raceNames } from '../core/proto_utils/names'; +import { professionNames, raceNames } from '../core/proto_utils/names'; import { DruidSpecs, DeathknightSpecs, @@ -29,8 +27,6 @@ import { getTalentTreePoints, makeDefaultBlessings, raceToFaction, - specTypeFunctions, - withSpecProto, isTankSpec, playerToSpec, } from '../core/proto_utils/utils'; @@ -312,7 +308,7 @@ export class RaidWCLImporter extends Importer { .forEach(aura => { const sourcePlayer = wclPlayers.find(player => player.id == aura.source); if (sourcePlayer && sourcePlayer.player.getRace() != Race.RaceDraenei) { - console.log(`Inferring player ${sourcePlayer.name} has race ${raceNames[Race.RaceDraenei]} from Heroic Presence aura event`); + console.log(`Inferring player ${sourcePlayer.name} has race ${raceNames.get(Race.RaceDraenei)} from Heroic Presence aura event`); sourcePlayer.player.setRace(eventID, Race.RaceDraenei); faction = Faction.Alliance; } @@ -325,7 +321,7 @@ export class RaidWCLImporter extends Importer { spellEvents.forEach(event => { const sourcePlayer = wclPlayers.find(player => player.id == event.sourceID); if (sourcePlayer) { - console.log(`Inferring player ${sourcePlayer.name} has race ${raceNames[spell.race]} from ${spell.name} event`); + console.log(`Inferring player ${sourcePlayer.name} has race ${raceNames.get(spell.race)} from ${spell.name} event`); sourcePlayer.player.setRace(eventID, spell.race); faction = raceToFaction[spell.race]; } @@ -346,7 +342,7 @@ export class RaidWCLImporter extends Importer { spellEvents.forEach(event => { const sourcePlayer = wclPlayers.find(player => player.id == event.sourceID); if (sourcePlayer && !sourcePlayer.inferredProfessions.includes(spell.profession)) { - console.log(`Inferring player ${sourcePlayer.name} has profession ${professionNames[spell.profession]} from ${spell.name} event`); + console.log(`Inferring player ${sourcePlayer.name} has profession ${professionNames.get(spell.profession)} from ${spell.name} event`); sourcePlayer.inferredProfessions.push(spell.profession); } }); From 88223c92a0a29ab5aefc08a06bfe65d11579afae Mon Sep 17 00:00:00 2001 From: jarves Date: Wed, 4 Oct 2023 19:38:15 -0500 Subject: [PATCH 2/3] ui: fix wowhead importer for dk Signed-off-by: jarves --- ui/core/components/importers.ts | 4 +- ui/core/proto_utils/names.ts | 88 +++++++++++++++++---------------- 2 files changed, 47 insertions(+), 45 deletions(-) diff --git a/ui/core/components/importers.ts b/ui/core/components/importers.ts index 97966fdf76..99db061439 100644 --- a/ui/core/components/importers.ts +++ b/ui/core/components/importers.ts @@ -231,12 +231,12 @@ export class IndividualWowheadGearPlannerImporter extends } // Parse all the settings. - const charClass = nameToClass(match[1].replaceAll('-', ' ')); + const charClass = nameToClass(match[1].replaceAll('-', '')); if (charClass == Class.ClassUnknown) { throw new Error('Could not parse Class: ' + match[1]); } - const race = nameToRace(match[2].replaceAll('-', ' ')); + const race = nameToRace(match[2].replaceAll('-', '')); if (race == Race.RaceUnknown) { throw new Error('Could not parse Race: ' + match[2]); } diff --git a/ui/core/proto_utils/names.ts b/ui/core/proto_utils/names.ts index 3f9ab62691..1c1889da5e 100644 --- a/ui/core/proto_utils/names.ts +++ b/ui/core/proto_utils/names.ts @@ -166,48 +166,48 @@ export const statOrder: Array = [ Stat.StatDeathRune, ]; -export const statNames: Record = { - [Stat.StatStrength]: 'Strength', - [Stat.StatAgility]: 'Agility', - [Stat.StatStamina]: 'Stamina', - [Stat.StatIntellect]: 'Intellect', - [Stat.StatSpirit]: 'Spirit', - [Stat.StatSpellPower]: 'Spell Dmg', - [Stat.StatMP5]: 'MP5', - [Stat.StatSpellHit]: 'Spell Hit', - [Stat.StatSpellCrit]: 'Spell Crit', - [Stat.StatSpellHaste]: 'Spell Haste', - [Stat.StatSpellPenetration]: 'Spell Pen', - [Stat.StatAttackPower]: 'Attack Power', - [Stat.StatMeleeHit]: 'Melee Hit', - [Stat.StatMeleeCrit]: 'Melee Crit', - [Stat.StatMeleeHaste]: 'Melee Haste', - [Stat.StatArmorPenetration]: 'Armor Pen', - [Stat.StatExpertise]: 'Expertise', - [Stat.StatMana]: 'Mana', - [Stat.StatEnergy]: 'Energy', - [Stat.StatRage]: 'Rage', - [Stat.StatArmor]: 'Armor', - [Stat.StatRangedAttackPower]: 'Ranged AP', - [Stat.StatDefense]: 'Defense', - [Stat.StatBlock]: 'Block', - [Stat.StatBlockValue]: 'Block Value', - [Stat.StatDodge]: 'Dodge', - [Stat.StatParry]: 'Parry', - [Stat.StatResilience]: 'Resilience', - [Stat.StatHealth]: 'Health', - [Stat.StatArcaneResistance]: 'Arcane Resistance', - [Stat.StatFireResistance]: 'Fire Resistance', - [Stat.StatFrostResistance]: 'Frost Resistance', - [Stat.StatNatureResistance]: 'Nature Resistance', - [Stat.StatShadowResistance]: 'Shadow Resistance', - [Stat.StatBonusArmor]: 'Bonus Armor', - [Stat.StatRunicPower]: 'Runic Power', - [Stat.StatBloodRune]: 'Blood Rune', - [Stat.StatFrostRune]: 'Frost Rune', - [Stat.StatUnholyRune]: 'Unholy Rune', - [Stat.StatDeathRune]: 'Death Rune', -}; +export const statNames: Map = new Map([ + [Stat.StatStrength, 'Strength'], + [Stat.StatAgility, 'Agility'], + [Stat.StatStamina, 'Stamina'], + [Stat.StatIntellect, 'Intellect'], + [Stat.StatSpirit, 'Spirit'], + [Stat.StatSpellPower, 'Spell Dmg'], + [Stat.StatMP5, 'MP5'], + [Stat.StatSpellHit, 'Spell Hit'], + [Stat.StatSpellCrit, 'Spell Crit'], + [Stat.StatSpellHaste, 'Spell Haste'], + [Stat.StatSpellPenetration, 'Spell Pen'], + [Stat.StatAttackPower, 'Attack Power'], + [Stat.StatMeleeHit, 'Melee Hit'], + [Stat.StatMeleeCrit, 'Melee Crit'], + [Stat.StatMeleeHaste, 'Melee Haste'], + [Stat.StatArmorPenetration, 'Armor Pen'], + [Stat.StatExpertise, 'Expertise'], + [Stat.StatMana, 'Mana'], + [Stat.StatEnergy, 'Energy'], + [Stat.StatRage, 'Rage'], + [Stat.StatArmor, 'Armor'], + [Stat.StatRangedAttackPower, 'Ranged AP'], + [Stat.StatDefense, 'Defense'], + [Stat.StatBlock, 'Block'], + [Stat.StatBlockValue, 'Block Value'], + [Stat.StatDodge, 'Dodge'], + [Stat.StatParry, 'Parry'], + [Stat.StatResilience, 'Resilience'], + [Stat.StatHealth, 'Health'], + [Stat.StatArcaneResistance, 'Arcane Resistance'], + [Stat.StatFireResistance, 'Fire Resistance'], + [Stat.StatFrostResistance, 'Frost Resistance'], + [Stat.StatNatureResistance, 'Nature Resistance'], + [Stat.StatShadowResistance, 'Shadow Resistance'], + [Stat.StatBonusArmor, 'Bonus Armor'], + [Stat.StatRunicPower, 'Runic Power'], + [Stat.StatBloodRune, 'Blood Rune'], + [Stat.StatFrostRune, 'Frost Rune'], + [Stat.StatUnholyRune, 'Unholy Rune'], + [Stat.StatDeathRune, 'Death Rune'], +]); export const pseudoStatOrder: Array = [ PseudoStat.PseudoStatMainHandDps, @@ -225,7 +225,9 @@ export const pseudoStatNames: Map = new Map([ ]); export function getClassStatName(stat: Stat, playerClass: Class): string { - const statName = statNames[stat]; + const statName = statNames.get(stat); + if (!statName) + return 'UnknownStat'; if (playerClass == Class.ClassHunter) { return statName.replace('Melee', 'Ranged'); } else { From 2ab4f96635ef778730d968a27c6d04a979fb7c7b Mon Sep 17 00:00:00 2001 From: jarves Date: Wed, 4 Oct 2023 20:00:15 -0500 Subject: [PATCH 3/3] ui: disable spellcheck on import/export textarea Signed-off-by: jarves --- ui/core/components/exporters.ts | 2 +- ui/core/components/importers.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/core/components/exporters.ts b/ui/core/components/exporters.ts index b236855532..59c03a3b55 100644 --- a/ui/core/components/exporters.ts +++ b/ui/core/components/exporters.ts @@ -23,7 +23,7 @@ export abstract class Exporter extends BaseModal { super(parent, 'exporter', { title: title, footer: true }); this.body.innerHTML = ` - + `; this.footer!.innerHTML = `