Skip to content

Commit

Permalink
Merge pull request #3873 from wowsims/apl
Browse files Browse the repository at this point in the history
Add PresetUtils file to reduce preset boilerplate
  • Loading branch information
jimmyt857 committed Oct 13, 2023
2 parents a3813f9 + fcfe278 commit 17f4d69
Show file tree
Hide file tree
Showing 31 changed files with 340 additions and 705 deletions.
13 changes: 3 additions & 10 deletions ui/balance_druid/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
UnitReference, Spec,
TristateEffect
} from '../core/proto/common.js';
import { SavedRotation, SavedTalents } from '../core/proto/ui.js';
import { SavedTalents } from '../core/proto/ui.js';

import {
BalanceDruid_Options as BalanceDruidOptions,
Expand All @@ -25,9 +25,9 @@ import {
DruidMinorGlyph,
} from '../core/proto/druid.js';

import * as PresetUtils from '../core/preset_utils.js';
import * as Tooltips from '../core/constants/tooltips.js';
import { Player } from "../core/player";
import { APLRotation } from '../core/proto/apl.js';

import BasicP3AplJson from './apls/basic_p3.apl.json';

Expand Down Expand Up @@ -273,11 +273,4 @@ export const P3_PRESET_ALLI = {
]}`),
};


export const ROTATION_PRESET_P3_APL = {
name: 'Basic P3 APL',
rotation: SavedRotation.create({
specRotationOptionsJson: BalanceDruidRotation.toJsonString(DefaultRotation),
rotation: APLRotation.fromJsonString(JSON.stringify(BasicP3AplJson)),
}),
};
export const ROTATION_PRESET_P3_APL = PresetUtils.makePresetAPLRotation('P3', BasicP3AplJson);
24 changes: 3 additions & 21 deletions ui/core/individual_sim_ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ import {
Stat,
} from './proto/common';

import { IndividualSimSettings, SavedRotation, SavedTalents } from './proto/ui';
import { IndividualSimSettings, SavedTalents } from './proto/ui';
import { StatWeightsResult } from './proto/api';

import { Gear } from './proto_utils/gear';
import { getMetaGemConditionDescription } from './proto_utils/gems';
import { professionNames } from './proto_utils/names';
import { Stats } from './proto_utils/stats';
Expand All @@ -52,6 +51,8 @@ import {
specToLocalStorageKey,
} from './proto_utils/utils';

import {PresetGear, PresetRotation} from './preset_utils';

import * as Exporters from './components/exporters';
import * as Importers from './components/importers';
import * as IconInputs from './components/icon_inputs';
Expand Down Expand Up @@ -142,25 +143,6 @@ export interface IndividualSimUIConfig<SpecType extends Spec> {
simpleRotation?: SimpleRotationGenerator<SpecType>,
}

export interface GearAndStats {
gear: Gear,
bonusStats?: Stats,
}

export interface PresetGear {
name: string;
gear: EquipmentSpec;
tooltip?: string;
enableWhen?: (obj: Player<any>) => boolean;
}

export interface PresetRotation {
name: string;
rotation: SavedRotation;
tooltip?: string;
enableWhen?: (obj: Player<any>) => boolean;
}

export interface Settings {
raidBuffs: RaidBuffs,
partyBuffs: PartyBuffs,
Expand Down
70 changes: 70 additions & 0 deletions ui/core/preset_utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import {
APLRotation,
APLRotation_Type as APLRotationType,
} from './proto/apl';
import {
EquipmentSpec,
Spec,
} from './proto/common';
import {
SavedRotation,
} from './proto/ui';

import { Player } from './player';
import {
SpecRotation,
specTypeFunctions,
} from './proto_utils/utils';

export interface PresetGear {
name: string;
gear: EquipmentSpec;
tooltip?: string;
enableWhen?: (obj: Player<any>) => boolean;
}

export interface PresetRotation {
name: string;
rotation: SavedRotation;
tooltip?: string;
enableWhen?: (obj: Player<any>) => boolean;
}

export interface PresetRotationOptions {
talentTree?: number,
}

export function makePresetAPLRotation(name: string, rotationJson: any, options?: PresetRotationOptions): PresetRotation {
const rotation = SavedRotation.create({
specRotationOptionsJson: '{}',
rotation: APLRotation.fromJsonString(JSON.stringify(rotationJson)),
});
return makePresetRotationHelper(name, rotation, options);
}

export function makePresetSimpleRotation<SpecType extends Spec>(name: string, spec: SpecType, simpleRotation: SpecRotation<SpecType>, options?: PresetRotationOptions): PresetRotation {
const rotation = SavedRotation.create({
rotation: {
type: APLRotationType.TypeSimple,
simple: {
specRotationJson: JSON.stringify(specTypeFunctions[spec].rotationToJson(simpleRotation)),
},
},
});
return makePresetRotationHelper(name, rotation, options);
}

export function makePresetLegacyRotation<SpecType extends Spec>(name: string, spec: SpecType, simpleRotation: SpecRotation<SpecType>, options?: PresetRotationOptions): PresetRotation {
const rotation = SavedRotation.create({
specRotationOptionsJson: JSON.stringify(specTypeFunctions[spec].rotationToJson(simpleRotation)),
});
return makePresetRotationHelper(name, rotation, options);
}

function makePresetRotationHelper(name: string, rotation: SavedRotation, options?: PresetRotationOptions): PresetRotation {
return {
name: name,
enableWhen: options?.talentTree == undefined ? undefined : (player: Player<any>) => player.getTalentTree() == options.talentTree,
rotation: rotation,
};
}
111 changes: 14 additions & 97 deletions ui/deathknight/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
UnitReference,
Spec
} from '../core/proto/common.js';
import { SavedRotation, SavedTalents } from '../core/proto/ui.js';
import { SavedTalents } from '../core/proto/ui.js';
import { Player } from '../core/player.js';

import {
Expand All @@ -29,8 +29,8 @@ import {
Deathknight_Rotation_BloodSpell,
} from '../core/proto/deathknight.js';

import * as PresetUtils from '../core/preset_utils.js';
import * as Tooltips from '../core/constants/tooltips.js';
import { APLRotation } from '../core/proto/apl.js';

import BloodPestiApl from './apls/blood_pesti.apl.json';
import BloodPestiDDApl from './apls/blood_pesti_dd.apl.json';
Expand Down Expand Up @@ -259,101 +259,18 @@ export const DefaultConsumes = Consumes.create({
fillerExplosive: Explosive.ExplosiveSaroniteBomb,
});

export const BLOOD_ROTATION_PRESET_LEGACY_DEFAULT = {
name: 'Blood Legacy',
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,
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,
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,
rotation: SavedRotation.create({
specRotationOptionsJson: DeathKnightRotation.toJsonString(DefaultBloodRotation),
rotation: APLRotation.fromJsonString(JSON.stringify(BloodPestiApl)),
}),
}

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

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

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

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

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

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

export const UNHOLY_DND_AOE_ROTATION_PRESET_DEFAULT = {
name: 'Unholy DND AOE APL',
enableWhen: (player: Player<Spec.SpecDeathknight>) => player.getTalentTree() == 2,
rotation: SavedRotation.create({
specRotationOptionsJson: DeathKnightRotation.toJsonString(DefaultUnholyRotation),
rotation: APLRotation.fromJsonString(JSON.stringify(UhDndAoeApl)),
}),
}
export const BLOOD_ROTATION_PRESET_LEGACY_DEFAULT = PresetUtils.makePresetLegacyRotation('Blood Legacy', Spec.SpecDeathknight, DefaultBloodRotation, { talentTree: 0 });
export const FROST_ROTATION_PRESET_LEGACY_DEFAULT = PresetUtils.makePresetLegacyRotation('Frost Legacy', Spec.SpecDeathknight, DefaultFrostRotation, { talentTree: 1 });
export const UNHOLY_DW_ROTATION_PRESET_LEGACY_DEFAULT = PresetUtils.makePresetLegacyRotation('Unholy DW Legacy', Spec.SpecDeathknight, DefaultUnholyRotation, { talentTree: 2 });

export const BLOOD_PESTI_ROTATION_PRESET_DEFAULT = PresetUtils.makePresetAPLRotation('Blood Pesti', BloodPestiApl, { talentTree: 0 });
export const BLOOD_PESTI_DD_ROTATION_PRESET_DEFAULT = PresetUtils.makePresetAPLRotation('Blood Pesti DD', BloodPestiDDApl, { talentTree: 0 });
export const BLOOD_PESTI_AOE_ROTATION_PRESET_DEFAULT = PresetUtils.makePresetAPLRotation('Blood Pesti AOE', BloodPestiAoeApl, { talentTree: 0 });
export const FROST_BL_PESTI_ROTATION_PRESET_DEFAULT = PresetUtils.makePresetAPLRotation('Frost BL Pesti', FrostBlPestiApl, { talentTree: 1 });
export const FROST_UH_PESTI_ROTATION_PRESET_DEFAULT = PresetUtils.makePresetAPLRotation('Frost UH Pesti', FrostUhPestiApl, { talentTree: 1 });
export const UNHOLY_DW_ROTATION_PRESET_DEFAULT = PresetUtils.makePresetAPLRotation('Unholy DW SS', UhDwSsApl, { talentTree: 2 });
export const UNHOLY_2H_ROTATION_PRESET_DEFAULT = PresetUtils.makePresetAPLRotation('Unholy 2H SS', Uh2hSsApl, { talentTree: 2 });
export const UNHOLY_DND_AOE_ROTATION_PRESET_DEFAULT = PresetUtils.makePresetAPLRotation('Unholy DND AOE', UhDndAoeApl, { talentTree: 2 });

export const P1_BLOOD_BIS_PRESET = {
name: 'P1 Blood',
Expand Down
23 changes: 5 additions & 18 deletions ui/elemental_shaman/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import { Flask } from '../core/proto/common.js';
import { Food } from '../core/proto/common.js';
import { Glyphs } from '../core/proto/common.js';
import { Potions } from '../core/proto/common.js';
import { SavedRotation, SavedTalents } from '../core/proto/ui.js';
import { SavedTalents } from '../core/proto/ui.js';
import { Spec } from '../core/proto/common.js';
import { Player } from '../core/player.js';
import { APLRotation } from '../core/proto/apl.js';

import { ElementalShaman_Rotation as ElementalShamanRotation, ElementalShaman_Options as ElementalShamanOptions, ShamanShield, ShamanMajorGlyph, ShamanMinorGlyph } from '../core/proto/shaman.js';
import { ElementalShaman_Rotation_RotationType as RotationType } from '../core/proto/shaman.js';
Expand All @@ -21,7 +20,7 @@ import {
ShamanTotems,
} from '../core/proto/shaman.js';


import * as PresetUtils from '../core/preset_utils.js';
import * as Tooltips from '../core/constants/tooltips.js';
import { Faction } from '../core/proto/common.js';

Expand Down Expand Up @@ -244,18 +243,6 @@ export const P4_PRESET = {
]}`),
};

export const ROTATION_PRESET_DEFAULT = {
name: 'Default',
rotation: SavedRotation.create({
specRotationOptionsJson: ElementalShamanRotation.toJsonString(DefaultRotation),
rotation: APLRotation.fromJsonString(JSON.stringify(DefaultApl)),
}),
};

export const ROTATION_PRESET_ADVANCED = {
name: 'Advanced APL',
rotation: SavedRotation.create({
specRotationOptionsJson: ElementalShamanRotation.toJsonString(DefaultRotation),
rotation: APLRotation.fromJsonString(JSON.stringify(AdvancedApl)),
}),
}
export const ROTATION_PRESET_LEGACY = PresetUtils.makePresetLegacyRotation('Legacy', Spec.SpecElementalShaman, DefaultRotation);
export const ROTATION_PRESET_DEFAULT = PresetUtils.makePresetAPLRotation('Default', DefaultApl);
export const ROTATION_PRESET_ADVANCED = PresetUtils.makePresetAPLRotation('Advanced', AdvancedApl);
1 change: 1 addition & 0 deletions ui/elemental_shaman/sim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export class ElementalShamanSimUI extends IndividualSimUI<Spec.SpecElementalSham
],
// Preset rotations that the user can quickly select.
rotations: [
Presets.ROTATION_PRESET_LEGACY,
Presets.ROTATION_PRESET_DEFAULT,
Presets.ROTATION_PRESET_ADVANCED,
],
Expand Down
33 changes: 5 additions & 28 deletions ui/enhancement_shaman/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import {
Spec,
Faction,
} from '../core/proto/common.js';
import { SavedRotation, SavedTalents } from '../core/proto/ui.js';
import { APLRotation } from '../core/proto/apl.js';
import { SavedTalents } from '../core/proto/ui.js';

import { EnhancementShaman_Rotation as EnhancementShamanRotation, EnhancementShaman_Options as EnhancementShamanOptions, ShamanShield } from '../core/proto/shaman.js';
import {
Expand All @@ -31,6 +30,7 @@ import {
EnhancementShaman_Rotation_CustomRotationSpell as CustomRotationSpell
} from '../core/proto/shaman.js';

import * as PresetUtils from '../core/preset_utils.js';
import * as Tooltips from '../core/constants/tooltips.js';
import { Player } from 'ui/core/player.js';

Expand Down Expand Up @@ -105,32 +105,9 @@ export const DefaultRotation = EnhancementShamanRotation.create({
}),
});

export const ROTATION_FT_DEFAULT = {
name: 'Default FT',
rotation: SavedRotation.create({
specRotationOptionsJson: EnhancementShamanRotation.toJsonString(EnhancementShamanRotation.create({
})),
rotation: APLRotation.fromJsonString(JSON.stringify(DefaultFt)),
}),
};

export const ROTATION_WF_DEFAULT = {
name: 'Default WF',
rotation: SavedRotation.create({
specRotationOptionsJson: EnhancementShamanRotation.toJsonString(EnhancementShamanRotation.create({
})),
rotation: APLRotation.fromJsonString(JSON.stringify(DefaultWf)),
}),
};

export const ROTATION_PHASE_3 = {
name: 'Phase 3',
rotation: SavedRotation.create({
specRotationOptionsJson: EnhancementShamanRotation.toJsonString(EnhancementShamanRotation.create({
})),
rotation: APLRotation.fromJsonString(JSON.stringify(Phase3Apl)),
}),
};
export const ROTATION_FT_DEFAULT = PresetUtils.makePresetAPLRotation('Default FT', DefaultFt);
export const ROTATION_WF_DEFAULT = PresetUtils.makePresetAPLRotation('Default WF', DefaultWf);
export const ROTATION_PHASE_3 = PresetUtils.makePresetAPLRotation('Phase 3', Phase3Apl);

export const DefaultOptions = EnhancementShamanOptions.create({
shield: ShamanShield.LightningShield,
Expand Down
Loading

0 comments on commit 17f4d69

Please sign in to comment.