Skip to content

Commit

Permalink
fix: use the correct algorithm to request item information (#936)
Browse files Browse the repository at this point in the history
* fix: use callbacks to fetch item information from the server

It turns out that you do need to use callbacks to fetch all item
information from the server.  Modify the update code to listen for
ITEM_DATA_LOAD_RESULT events to execute a callback to properly
update an equipped item.

Change the way that `Ovale_EquipmentChanged` is fired by always
including the slot name that has been changed.  The event now fires
whenever ITEM_DATA_LOAD_RESULT returns success and the slot that
had a pending data load has been changed.

This avoids needing the 3-second delay kludge to wait for server
data.

* fix: consistently use SlotName instead of InventorySlotName in API

Make all Ovale modules consistently use `ammoslot`, etc., instead
of `AMMOSLOT`, etc., to refer to the names of the equipment slots.
Make the conversion between the `SlotName` and `InventorySlotName`
types internal to the `Equipment` module.
  • Loading branch information
johnnylam88 committed Jul 23, 2021
1 parent 565f696 commit b2a5315
Show file tree
Hide file tree
Showing 4 changed files with 244 additions and 212 deletions.
6 changes: 2 additions & 4 deletions src/engine/best-action.ts
@@ -1,17 +1,15 @@
import { OvaleActionBarClass } from "./action-bar";
import { OvaleDataClass } from "./data";
import { OvaleEquipmentClass } from "../states/Equipment";
import { OvaleEquipmentClass, SlotName } from "../states/Equipment";
import aceEvent, { AceEvent } from "@wowts/ace_event-3.0";
import { pairs, tonumber, tostring } from "@wowts/lua";
import { upper } from "@wowts/string";
import {
GetActionCooldown,
GetActionTexture,
GetItemIcon,
GetItemCooldown,
GetItemSpell,
GetSpellTexture,
InventorySlotName,
IsActionInRange,
IsItemInRange,
IsUsableAction,
Expand Down Expand Up @@ -88,7 +86,7 @@ export class OvaleBestActionClass {
const result = node.result;
setResultType(result, "action");
if (!isNumber(itemId)) {
const slot = <InventorySlotName>upper(tostring(itemId));
const slot = tostring(itemId) as SlotName;
const itemIdFromSlot = this.ovaleEquipment.getEquippedItemId(slot);
if (!itemIdFromSlot) {
this.tracer.log("Unknown item '%s'.", itemId);
Expand Down
21 changes: 8 additions & 13 deletions src/states/AzeriteArmor.ts
Expand Up @@ -11,13 +11,12 @@ import {
} from "@wowts/lua";
import { sort, insert, concat } from "@wowts/table";
import {
InventorySlotName,
C_AzeriteEmpoweredItem,
GetSpellInfo,
AzeriteEmpoweredItemSelectionUpdatedEvent,
PlayerEnteringWorldEvent,
} from "@wowts/wow-mock";
import { InventorySlotNameMap, OvaleEquipmentClass } from "./Equipment";
import { OvaleEquipmentClass, SlotName } from "./Equipment";
import { AceModule } from "@wowts/tsaddon";
import { OvaleClass } from "../Ovale";
import { DebugTools } from "../engine/debug";
Expand All @@ -30,10 +29,11 @@ import {
} from "../engine/condition";
import { AstFunctionNode, NamedParametersOf } from "../engine/ast";

const azeriteSlots: InventorySlotNameMap = {
HEADSLOT: true,
SHOULDERSLOT: true,
CHESTSLOT: true,
type SlotNameMap = { [key in SlotName]?: boolean };
const azeriteSlots: SlotNameMap = {
headslot: true,
shoulderslot: true,
chestslot: true,
};

interface Trait {
Expand Down Expand Up @@ -116,13 +116,8 @@ export class OvaleAzeriteArmor {
this.module.UnregisterEvent("PLAYER_ENTERING_WORLD");
};

private handleOvaleEquipmentChanged = (
event: string,
slot?: InventorySlotName
) => {
if (slot == undefined) {
this.updateTraits();
} else if (azeriteSlots[slot]) {
private handleOvaleEquipmentChanged = (event: string, slot: SlotName) => {
if (azeriteSlots[slot]) {
this.updateTraits();
}
};
Expand Down

0 comments on commit b2a5315

Please sign in to comment.