Skip to content

Commit

Permalink
Merge pull request #3835 from wowsims/saved-data-updates
Browse files Browse the repository at this point in the history
separate presets + custom data, add conditions for rotations
  • Loading branch information
kayla-glick authored Oct 7, 2023
2 parents 8a11934 + 5918d3c commit dab1df6
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 36 deletions.
2 changes: 1 addition & 1 deletion ui/core/components/individual_sim_ui/gear_tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class GearTab extends SimTab {
}

private buildSavedGearsetPicker() {
const savedGearManager = new SavedDataManager<Player<any>, SavedGearSet>(this.rightPanel, this.simUI, this.simUI.player, {
const savedGearManager = new SavedDataManager<Player<any>, SavedGearSet>(this.rightPanel, this.simUI.player, {
header: { title: "Gear Sets" },
label: 'Gear Set',
storageKey: this.simUI.getSavedGearStorageKey(),
Expand Down
4 changes: 2 additions & 2 deletions ui/core/components/individual_sim_ui/rotation_tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export class RotationTab extends SimTab {
private buildSavedDataPickers() {
const aplIsLaunched = aplLaunchStatuses[this.simUI.player.spec] == LaunchStatus.Launched;

const savedRotationsManager = new SavedDataManager<Player<any>, SavedRotation>(this.rightPanel, this.simUI, this.simUI.player, {
const savedRotationsManager = new SavedDataManager<Player<any>, SavedRotation>(this.rightPanel, this.simUI.player, {
label: 'Rotation',
header: { title: 'Saved Rotations' },
storageKey: this.simUI.getSavedRotationStorageKey(),
Expand All @@ -228,7 +228,7 @@ export class RotationTab extends SimTab {
}
});
},
changeEmitters: [this.simUI.player.rotationChangeEmitter, this.simUI.player.cooldownsChangeEmitter],
changeEmitters: [this.simUI.player.rotationChangeEmitter, this.simUI.player.cooldownsChangeEmitter, this.simUI.player.talentsChangeEmitter],
equals: (a: SavedRotation, b: SavedRotation) => {
// Uncomment this to debug equivalence checks with preset rotations (e.g. the chip doesn't highlight)
//console.log(`Rot A: ${SavedRotation.toJsonString(a, {prettySpaces: 2})}\n\nRot B: ${SavedRotation.toJsonString(b, {prettySpaces: 2})}`);
Expand Down
4 changes: 2 additions & 2 deletions ui/core/components/individual_sim_ui/settings_tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ export class SettingsTab extends SimTab {
}

private buildSavedDataPickers() {
const savedEncounterManager = new SavedDataManager<Encounter, SavedEncounter>(this.rightPanel, this.simUI, this.simUI.sim.encounter, {
const savedEncounterManager = new SavedDataManager<Encounter, SavedEncounter>(this.rightPanel, this.simUI.sim.encounter, {
label: 'Encounter',
header: { title: 'Saved Encounters' },
storageKey: this.simUI.getSavedEncounterStorageKey(),
Expand All @@ -380,7 +380,7 @@ export class SettingsTab extends SimTab {
fromJson: (obj: any) => SavedEncounter.fromJson(obj),
});

const savedSettingsManager = new SavedDataManager<IndividualSimUI<any>, SavedSettings>(this.rightPanel, this.simUI, this.simUI, {
const savedSettingsManager = new SavedDataManager<IndividualSimUI<any>, SavedSettings>(this.rightPanel, this.simUI, {
label: 'Settings',
header: { title: 'Saved Settings' },
storageKey: this.simUI.getSavedSettingsStorageKey(),
Expand Down
2 changes: 1 addition & 1 deletion ui/core/components/individual_sim_ui/talents_tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class TalentsTab extends SimTab {
}

private buildSavedTalentsPicker() {
const savedTalentsManager = new SavedDataManager<Player<any>, SavedTalents>(this.rightPanel, this.simUI, this.simUI.player, {
const savedTalentsManager = new SavedDataManager<Player<any>, SavedTalents>(this.rightPanel, this.simUI.player, {
label: 'Talents',
header: { title: 'Saved Talents' },
storageKey: this.simUI.getSavedTalentsStorageKey(),
Expand Down
26 changes: 16 additions & 10 deletions ui/core/components/saved_data_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { ContentBlock, ContentBlockHeaderConfig } from './content_block';

import { Component } from '../components/component.js';
import { Tooltip } from 'bootstrap';
import { json } from 'stream/consumers';
import { SimUI } from '../sim_ui.js';

export type SavedDataManagerConfig<ModObject, T> = {
label: string;
Expand Down Expand Up @@ -37,20 +35,21 @@ type SavedData<ModObject, T> = {
};

export class SavedDataManager<ModObject, T> extends Component {
private readonly simUI: SimUI;
private readonly modObject: ModObject;
private readonly config: SavedDataManagerConfig<ModObject, T>;

private readonly userData: Array<SavedData<ModObject, T>>;
private readonly presets: Array<SavedData<ModObject, T>>;

private readonly savedDataDiv: HTMLElement;
private readonly savedDataDiv: HTMLElement
private readonly presetDataDiv: HTMLElement;
private readonly customDataDiv: HTMLElement;
private readonly saveInput?: HTMLInputElement;

private frozen: boolean;

constructor(parent: HTMLElement, simUI: SimUI, modObject: ModObject, config: SavedDataManagerConfig<ModObject, T>) {
constructor(parent: HTMLElement, modObject: ModObject, config: SavedDataManagerConfig<ModObject, T>) {
super(parent, 'saved-data-manager-root');
this.simUI = simUI;
this.modObject = modObject;
this.config = config;

Expand All @@ -60,8 +59,15 @@ export class SavedDataManager<ModObject, T> extends Component {

let contentBlock = new ContentBlock(this.rootElem, 'saved-data', { header: config.header });

contentBlock.bodyElement.innerHTML = `<div class="saved-data-container hide"></div>`;
contentBlock.bodyElement.innerHTML = `
<div class="saved-data-container hide">
<div class="saved-data-presets"></div>
<div class="saved-data-custom"></div>
</div>
`;
this.savedDataDiv = contentBlock.bodyElement.querySelector('.saved-data-container') as HTMLElement;
this.presetDataDiv = contentBlock.bodyElement.querySelector('.saved-data-presets') as HTMLElement;
this.customDataDiv = contentBlock.bodyElement.querySelector('.saved-data-custom') as HTMLElement;

if (!config.presetsOnly) {
contentBlock.bodyElement.appendChild(this.buildCreateContainer());
Expand All @@ -77,10 +83,10 @@ export class SavedDataManager<ModObject, T> extends Component {
const oldIdx = dataArr.findIndex(data => data.name == config.name);

if (oldIdx == -1) {
if (config.isPreset || this.presets.length == 0) {
this.savedDataDiv.appendChild(newData.elem);
if (config.isPreset) {
this.presetDataDiv.appendChild(newData.elem);
} else {
this.savedDataDiv.insertBefore(newData.elem, this.presets[0].elem);
this.customDataDiv.appendChild(newData.elem);
}
dataArr.push(newData);
} else {
Expand Down
2 changes: 1 addition & 1 deletion ui/core/talents/hunter_pet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class HunterPetTalentsPicker extends Component {
maxPoints: 16,
});

const savedTalentsManager = new SavedDataManager<Player<Spec.SpecHunter>, string>(pickerContainer, this.simUI, this.player, {
const savedTalentsManager = new SavedDataManager<Player<Spec.SpecHunter>, string>(pickerContainer, this.player, {
presetsOnly: true,
label: 'Pet Talents',
storageKey: '__NEVER_USED__',
Expand Down
22 changes: 11 additions & 11 deletions ui/deathknight/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,31 +261,31 @@ export const DefaultConsumes = Consumes.create({

export const BLOOD_ROTATION_PRESET_LEGACY_DEFAULT = {
name: 'Blood Legacy',
//enableWhen: (player: Player<Spec.SpecDeathknight>) => player.getTalentTree() == 0,
enableWhen: (player: Player<Spec.SpecDeathknight>) => player.getTalentTree() == 0,
rotation: SavedRotation.create({
specRotationOptionsJson: DeathKnightRotation.toJsonString(DefaultBloodRotation),
}),
}

export const FROST_ROTATION_PRESET_LEGACY_DEFAULT = {
name: 'Frost Legacy',
//enableWhen: (player: Player<Spec.SpecDeathknight>) => player.getTalentTree() == 1,
enableWhen: (player: Player<Spec.SpecDeathknight>) => player.getTalentTree() == 1,
rotation: SavedRotation.create({
specRotationOptionsJson: DeathKnightRotation.toJsonString(DefaultFrostRotation),
}),
}

export const UNHOLY_DW_ROTATION_PRESET_LEGACY_DEFAULT = {
name: 'Unholy DW Legacy',
//enableWhen: (player: Player<Spec.SpecDeathknight>) => player.getTalentTree() == 2,
enableWhen: (player: Player<Spec.SpecDeathknight>) => player.getTalentTree() == 2,
rotation: SavedRotation.create({
specRotationOptionsJson: DeathKnightRotation.toJsonString(DefaultUnholyRotation),
}),
}

export const BLOOD_PESTI_ROTATION_PRESET_DEFAULT = {
name: 'Blood Pesti APL',
//enableWhen: (player: Player<Spec.SpecDeathknight>) => player.getTalentTree() == 0,
enableWhen: (player: Player<Spec.SpecDeathknight>) => player.getTalentTree() == 0,
rotation: SavedRotation.create({
specRotationOptionsJson: DeathKnightRotation.toJsonString(DefaultBloodRotation),
rotation: APLRotation.fromJsonString(JSON.stringify(BloodPestiApl)),
Expand All @@ -294,7 +294,7 @@ export const BLOOD_PESTI_ROTATION_PRESET_DEFAULT = {

export const BLOOD_PESTI_DD_ROTATION_PRESET_DEFAULT = {
name: 'Blood Pesti DD APL',
//enableWhen: (player: Player<Spec.SpecDeathknight>) => player.getTalentTree() == 0,
enableWhen: (player: Player<Spec.SpecDeathknight>) => player.getTalentTree() == 0,
rotation: SavedRotation.create({
specRotationOptionsJson: DeathKnightRotation.toJsonString(DefaultBloodRotation),
rotation: APLRotation.fromJsonString(JSON.stringify(BloodPestiDDApl)),
Expand All @@ -303,7 +303,7 @@ export const BLOOD_PESTI_DD_ROTATION_PRESET_DEFAULT = {

export const BLOOD_PESTI_AOE_ROTATION_PRESET_DEFAULT = {
name: 'Blood Pesti AOE APL',
//enableWhen: (player: Player<Spec.SpecDeathknight>) => player.getTalentTree() == 0,
enableWhen: (player: Player<Spec.SpecDeathknight>) => player.getTalentTree() == 0,
rotation: SavedRotation.create({
specRotationOptionsJson: DeathKnightRotation.toJsonString(DefaultBloodRotation),
rotation: APLRotation.fromJsonString(JSON.stringify(BloodPestiAoeApl)),
Expand All @@ -312,7 +312,7 @@ export const BLOOD_PESTI_AOE_ROTATION_PRESET_DEFAULT = {

export const FROST_BL_PESTI_ROTATION_PRESET_DEFAULT = {
name: 'Frost BL Pesti APL',
//enableWhen: (player: Player<Spec.SpecDeathknight>) => player.getTalentTree() == 1,
enableWhen: (player: Player<Spec.SpecDeathknight>) => player.getTalentTree() == 1,
rotation: SavedRotation.create({
specRotationOptionsJson: DeathKnightRotation.toJsonString(DefaultFrostRotation),
rotation: APLRotation.fromJsonString(JSON.stringify(FrostBlPestiApl)),
Expand All @@ -321,7 +321,7 @@ export const FROST_BL_PESTI_ROTATION_PRESET_DEFAULT = {

export const FROST_UH_PESTI_ROTATION_PRESET_DEFAULT = {
name: 'Frost UH Pesti APL',
//enableWhen: (player: Player<Spec.SpecDeathknight>) => player.getTalentTree() == 1,
enableWhen: (player: Player<Spec.SpecDeathknight>) => player.getTalentTree() == 1,
rotation: SavedRotation.create({
specRotationOptionsJson: DeathKnightRotation.toJsonString(DefaultFrostRotation),
rotation: APLRotation.fromJsonString(JSON.stringify(FrostUhPestiApl)),
Expand All @@ -330,7 +330,7 @@ export const FROST_UH_PESTI_ROTATION_PRESET_DEFAULT = {

export const UNHOLY_DW_ROTATION_PRESET_DEFAULT = {
name: 'Unholy DW SS APL',
//enableWhen: (player: Player<Spec.SpecDeathknight>) => player.getTalentTree() == 2,
enableWhen: (player: Player<Spec.SpecDeathknight>) => player.getTalentTree() == 2,
rotation: SavedRotation.create({
specRotationOptionsJson: DeathKnightRotation.toJsonString(DefaultUnholyRotation),
rotation: APLRotation.fromJsonString(JSON.stringify(UhDwSsApl)),
Expand All @@ -339,7 +339,7 @@ export const UNHOLY_DW_ROTATION_PRESET_DEFAULT = {

export const UNHOLY_2H_ROTATION_PRESET_DEFAULT = {
name: 'Unholy 2H SS APL',
//enableWhen: (player: Player<Spec.SpecDeathknight>) => player.getTalentTree() == 2,
enableWhen: (player: Player<Spec.SpecDeathknight>) => player.getTalentTree() == 2,
rotation: SavedRotation.create({
specRotationOptionsJson: DeathKnightRotation.toJsonString(DefaultUnholyRotation),
rotation: APLRotation.fromJsonString(JSON.stringify(Uh2hSsApl)),
Expand All @@ -348,7 +348,7 @@ export const UNHOLY_2H_ROTATION_PRESET_DEFAULT = {

export const UNHOLY_DND_AOE_ROTATION_PRESET_DEFAULT = {
name: 'Unholy DND AOE APL',
//enableWhen: (player: Player<Spec.SpecDeathknight>) => player.getTalentTree() == 2,
enableWhen: (player: Player<Spec.SpecDeathknight>) => player.getTalentTree() == 2,
rotation: SavedRotation.create({
specRotationOptionsJson: DeathKnightRotation.toJsonString(DefaultUnholyRotation),
rotation: APLRotation.fromJsonString(JSON.stringify(UhDndAoeApl)),
Expand Down
7 changes: 6 additions & 1 deletion ui/hunter/presets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Consumes } from '../core/proto/common.js';
import { Consumes, Spec } from '../core/proto/common.js';
import { EquipmentSpec } from '../core/proto/common.js';
import { Flask } from '../core/proto/common.js';
import { Food } from '../core/proto/common.js';
Expand Down Expand Up @@ -107,6 +107,7 @@ export const ROTATION_PRESET_LEGACY_DEFAULT = {
}
export const ROTATION_PRESET_BM = {
name: 'BM',
enableWhen: (player: Player<Spec.SpecHunter>) => player.getTalentTree() == 0,
rotation: SavedRotation.create({
specRotationOptionsJson: HunterRotation.toJsonString(HunterRotation.create({
})),
Expand All @@ -116,6 +117,7 @@ export const ROTATION_PRESET_BM = {

export const ROTATION_PRESET_MM = {
name: 'MM',
enableWhen: (player: Player<Spec.SpecHunter>) => player.getTalentTree() == 1,
rotation: SavedRotation.create({
specRotationOptionsJson: HunterRotation.toJsonString(HunterRotation.create({
})),
Expand All @@ -125,6 +127,7 @@ export const ROTATION_PRESET_MM = {

export const ROTATION_PRESET_MM_ADVANCED = {
name: 'MM (Advanced)',
enableWhen: (player: Player<Spec.SpecHunter>) => player.getTalentTree() == 1,
rotation: SavedRotation.create({
specRotationOptionsJson: HunterRotation.toJsonString(HunterRotation.create({
})),
Expand All @@ -134,6 +137,7 @@ export const ROTATION_PRESET_MM_ADVANCED = {

export const ROTATION_PRESET_SV = {
name: 'SV',
enableWhen: (player: Player<Spec.SpecHunter>) => player.getTalentTree() == 2,
rotation: SavedRotation.create({
specRotationOptionsJson: HunterRotation.toJsonString(HunterRotation.create({
})),
Expand All @@ -143,6 +147,7 @@ export const ROTATION_PRESET_SV = {

export const ROTATION_PRESET_SV_ADVANCED = {
name: 'SV (Advanced)',
enableWhen: (player: Player<Spec.SpecHunter>) => player.getTalentTree() == 2,
rotation: SavedRotation.create({
specRotationOptionsJson: HunterRotation.toJsonString(HunterRotation.create({
})),
Expand Down
7 changes: 7 additions & 0 deletions ui/mage/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export const OtherDefaults = {

export const ARCANE_ROTATION_PRESET_DEFAULT = {
name: 'Arcane',
enableWhen: (player: Player<Spec.SpecMage>) => player.getTalentTree() == 0,
rotation: SavedRotation.create({
specRotationOptionsJson: MageRotation.toJsonString(DefaultArcaneRotation),
rotation: APLRotation.fromJsonString(JSON.stringify(ArcaneApl))
Expand All @@ -201,6 +202,7 @@ export const ARCANE_ROTATION_PRESET_DEFAULT = {

export const FIRE_ROTATION_PRESET_DEFAULT = {
name: 'Fire',
enableWhen: (player: Player<Spec.SpecMage>) => player.getTalentTree() == 1,
rotation: SavedRotation.create({
specRotationOptionsJson: MageRotation.toJsonString(DefaultFireRotation),
rotation: APLRotation.fromJsonString(JSON.stringify(FireApl)),
Expand All @@ -209,6 +211,7 @@ export const FIRE_ROTATION_PRESET_DEFAULT = {

export const FROSTFIRE_ROTATION_PRESET_DEFAULT = {
name: 'Frostfire',
enableWhen: (player: Player<Spec.SpecMage>) => player.getTalentTree() == 1,
rotation: SavedRotation.create({
specRotationOptionsJson: MageRotation.toJsonString(DefaultFFBRotation),
rotation: APLRotation.fromJsonString(JSON.stringify(FrostFireApl)),
Expand All @@ -217,6 +220,7 @@ export const FROSTFIRE_ROTATION_PRESET_DEFAULT = {

export const FROST_ROTATION_PRESET_DEFAULT = {
name: 'Frost',
enableWhen: (player: Player<Spec.SpecMage>) => player.getTalentTree() == 2,
rotation: SavedRotation.create({
specRotationOptionsJson: MageRotation.toJsonString(DefaultFrostRotation),
rotation: APLRotation.fromJsonString(JSON.stringify(FrostApl)),
Expand All @@ -225,6 +229,7 @@ export const FROST_ROTATION_PRESET_DEFAULT = {

export const ARCANE_ROTATION_PRESET_AOE = {
name: 'Arcane AOE',
enableWhen: (player: Player<Spec.SpecMage>) => player.getTalentTree() == 0,
rotation: SavedRotation.create({
specRotationOptionsJson: MageRotation.toJsonString(DefaultFrostRotation),
rotation: APLRotation.fromJsonString(JSON.stringify(ArcaneAoeApl)),
Expand All @@ -233,6 +238,7 @@ export const ARCANE_ROTATION_PRESET_AOE = {

export const FIRE_ROTATION_PRESET_AOE = {
name: 'Fire AOE',
enableWhen: (player: Player<Spec.SpecMage>) => player.getTalentTree() == 1,
rotation: SavedRotation.create({
specRotationOptionsJson: MageRotation.toJsonString(DefaultFrostRotation),
rotation: APLRotation.fromJsonString(JSON.stringify(FireAoeApl)),
Expand All @@ -241,6 +247,7 @@ export const FIRE_ROTATION_PRESET_AOE = {

export const FROST_ROTATION_PRESET_AOE = {
name: 'Frost AOE',
enableWhen: (player: Player<Spec.SpecMage>) => player.getTalentTree() == 2,
rotation: SavedRotation.create({
specRotationOptionsJson: MageRotation.toJsonString(DefaultFrostRotation),
rotation: APLRotation.fromJsonString(JSON.stringify(FrostAoeApl)),
Expand Down
3 changes: 1 addition & 2 deletions ui/raid/raid_tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ export class RaidTab extends SimTab {
this.simUI.raidPicker = new RaidPicker(this.leftPanel, this.simUI);
new RaidStats(this.leftPanel, this.simUI);

const savedRaidManager = new SavedDataManager<RaidSimUI, SavedRaid>(
this.rightPanel, this.simUI, this.simUI, {
const savedRaidManager = new SavedDataManager<RaidSimUI, SavedRaid>(this.rightPanel, this.simUI, {
label: 'Raid',
header: { title: 'Saved Raid Groups' },
storageKey: this.simUI.getSavedRaidStorageKey(),
Expand Down
2 changes: 1 addition & 1 deletion ui/raid/settings_tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class SettingsTab extends SimTab {
}

private buildSavedDataPickers() {
const savedEncounterManager = new SavedDataManager<Encounter, SavedEncounter>(this.rightPanel, this.simUI, this.simUI.sim.encounter, {
const savedEncounterManager = new SavedDataManager<Encounter, SavedEncounter>(this.rightPanel, this.simUI.sim.encounter, {
label: 'Encounter',
header: { title: 'Saved Encounters' },
storageKey: this.simUI.getSavedEncounterStorageKey(),
Expand Down
Loading

0 comments on commit dab1df6

Please sign in to comment.