Skip to content

Commit

Permalink
chore: add naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidoine committed Jan 21, 2021
1 parent 4c10626 commit af6216a
Show file tree
Hide file tree
Showing 117 changed files with 8,140 additions and 8,208 deletions.
23 changes: 23 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,29 @@ module.exports = {

// Stylistics
"quote-props": ["error", "as-needed"],
"@typescript-eslint/naming-convention": [
"error",
{ selector: "typeLike", format: ["PascalCase"] },
{
selector: "typeProperty",
format: ["UPPER_CASE", "camelCase", "snake_case"],
},
{
selector: "objectLiteralProperty",
format: ["UPPER_CASE", "camelCase", "snake_case"],
},
{ selector: "method", format: ["camelCase"] },
{
selector: "property",
format: ["camelCase"],
},
{ selector: "parameterProperty", format: ["camelCase"] },
{
selector: "variableLike",
format: ["camelCase"],
leadingUnderscore: "allow",
},
],

// TODO enable these
"@typescript-eslint/no-unused-vars": "off",
Expand Down
40 changes: 19 additions & 21 deletions src/Ovale.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import { L } from "./ui/Localization";
import { l } from "./ui/Localization";
import { NewAddon, AceModule } from "@wowts/tsaddon";
import aceEvent from "@wowts/ace_event-3.0";
import { ipairs, wipe, LuaArray, LuaObj, _G } from "@wowts/lua";
import { UnitClass, UnitGUID, ClassId } from "@wowts/wow-mock";
import { huge } from "@wowts/math";
import { Library } from "@wowts/tslib";
import { ClearOneTimeMessages } from "./tools/tools";
import { clearOneTimeMessages } from "./tools/tools";

const MAX_REFRESH_INTERVALS = 500;
const self_refreshIntervals: LuaArray<number> = {};
let self_refreshIndex = 1;
const maxRefreshIntervals = 500;
const refreshIntervals: LuaArray<number> = {};
let refreshIndex = 1;

export type Constructor<T> = new (...args: any[]) => T;

const name = "Ovale";

const OvaleBase = NewAddon(name, aceEvent);
export const MSG_PREFIX = name;
const ovaleBase = NewAddon(name, aceEvent);
export const messagePrefix = name;

export class OvaleClass extends OvaleBase {
export class OvaleClass extends ovaleBase {
playerClass: ClassId = "WARRIOR";
playerGUID = "";
refreshNeeded: LuaObj<boolean> = {};

constructor() {
super();
_G["BINDING_HEADER_OVALE"] = "Ovale";
const toggleCheckBox = L["check_box_tooltip"];
const toggleCheckBox = l["check_box_tooltip"];
_G["BINDING_NAME_OVALE_CHECKBOX0"] = `${toggleCheckBox}(1)`;
_G["BINDING_NAME_OVALE_CHECKBOX1"] = `${toggleCheckBox}(2)`;
_G["BINDING_NAME_OVALE_CHECKBOX2"] = `${toggleCheckBox}(3)`;
Expand All @@ -41,13 +41,13 @@ export class OvaleClass extends OvaleBase {
// this.UnregisterMessage("Ovale_OptionChanged");
// this.frame.Hide();
// }
OnInitialize() {
handleInitialize() {
this.playerGUID = UnitGUID("player") || "error";
const [, classId] = UnitClass("player");
this.playerClass = classId || "WARRIOR";
wipe(self_refreshIntervals);
self_refreshIndex = 1;
ClearOneTimeMessages();
wipe(refreshIntervals);
refreshIndex = 1;
clearOneTimeMessages();
}

needRefresh() {
Expand All @@ -56,18 +56,16 @@ export class OvaleClass extends OvaleBase {
}
}

AddRefreshInterval(milliseconds: number) {
addRefreshInterval(milliseconds: number) {
if (milliseconds < huge) {
self_refreshIntervals[self_refreshIndex] = milliseconds;
self_refreshIndex =
(self_refreshIndex < MAX_REFRESH_INTERVALS &&
self_refreshIndex + 1) ||
1;
refreshIntervals[refreshIndex] = milliseconds;
refreshIndex =
(refreshIndex < maxRefreshIntervals && refreshIndex + 1) || 1;
}
}
GetRefreshIntervalStatistics() {
getRefreshIntervalStatistics() {
let [sumRefresh, minRefresh, maxRefresh, count] = [0, huge, 0, 0];
for (const [, v] of ipairs(self_refreshIntervals)) {
for (const [, v] of ipairs(refreshIntervals)) {
if (v > 0) {
if (minRefresh > v) {
minRefresh = v;
Expand Down
110 changes: 56 additions & 54 deletions src/engine/action-bar.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { L } from "../ui/Localization";
import { OvaleDebugClass, Tracer } from "./debug";
import { l } from "../ui/Localization";
import { DebugTools, Tracer } from "./debug";
import { OvaleProfilerClass, Profiler } from "./profiler";
import { OvaleSpellBookClass } from "../states/SpellBook";
import aceEvent, { AceEvent } from "@wowts/ace_event-3.0";
Expand Down Expand Up @@ -31,7 +31,7 @@ import { AceModule } from "@wowts/tsaddon";
import { OvaleClass } from "../Ovale";
import { OptionUiAll } from "../ui/acegui-helpers";

const ActionBars: LuaArray<string> = {
const actionBars: LuaArray<string> = {
1: "ActionButton",
2: "MultiBarRightButton",
3: "MultiBarLeftButton",
Expand All @@ -42,16 +42,16 @@ const ActionBars: LuaArray<string> = {
export class OvaleActionBarClass {
private debugOptions: LuaObj<OptionUiAll> = {
actionbar: {
name: L["action_bar"],
name: l["action_bar"],
type: "group",
args: {
spellbook: {
name: L["action_bar"],
name: l["action_bar"],
type: "input",
multiline: 25,
width: "full",
get: () => {
return this.DebugActions();
return this.debugActions();
},
},
},
Expand All @@ -68,15 +68,15 @@ export class OvaleActionBarClass {
private profiler: Profiler;

constructor(
ovaleDebug: OvaleDebugClass,
ovaleDebug: DebugTools,
ovale: OvaleClass,
ovaleProfiler: OvaleProfilerClass,
private ovaleSpellBook: OvaleSpellBookClass
) {
this.module = ovale.createModule(
"OvaleActionBar",
this.OnInitialize,
this.OnDisable,
this.handleInitialize,
this.handleDisable,
aceEvent,
aceTimer
);
Expand All @@ -87,32 +87,35 @@ export class OvaleActionBarClass {
}
}

private OnInitialize = () => {
private handleInitialize = () => {
this.module.RegisterEvent(
"ACTIONBAR_SLOT_CHANGED",
this.ACTIONBAR_SLOT_CHANGED
this.handleActionBarSlotChanged
);
this.module.RegisterEvent(
"PLAYER_ENTERING_WORLD",
this.UpdateActionSlots
this.handleActionSlotUpdate
);
this.module.RegisterEvent("UPDATE_BINDINGS", this.UPDATE_BINDINGS);
this.module.RegisterEvent("UPDATE_BINDINGS", this.handleUpdateBindings);
this.module.RegisterEvent(
"UPDATE_BONUS_ACTIONBAR",
this.UpdateActionSlots
this.handleActionSlotUpdate
);
this.module.RegisterEvent(
"SPELLS_CHANGED",
this.handleActionSlotUpdate
);
this.module.RegisterEvent("SPELLS_CHANGED", this.UpdateActionSlots);
this.module.RegisterMessage(
"Ovale_StanceChanged",
this.UpdateActionSlots
this.handleActionSlotUpdate
);
this.module.RegisterMessage(
"Ovale_TalentsChanged",
this.UpdateActionSlots
this.handleActionSlotUpdate
);
};

GetKeyBinding(slot: number) {
private getKeyBinding(slot: number) {
let name;
if (_G["Bartender4"]) {
name = `CLICK BT4Button${slot}:LeftButton`;
Expand Down Expand Up @@ -146,15 +149,15 @@ export class OvaleActionBarClass {
return key;
}

ParseHyperlink(hyperlink: string) {
private parseHyperlink(hyperlink: string) {
const [color, linkType, linkData, text] = match(
hyperlink,
"|?c?f?f?(%x*)|?H?([^:]*):?(%d+)|?h?%[?([^%[%]]*)%]?|?h?|?r?"
);
return [color, linkType, linkData, text];
}

private OnDisable = () => {
private handleDisable = () => {
this.module.UnregisterEvent("ACTIONBAR_SLOT_CHANGED");
this.module.UnregisterEvent("PLAYER_ENTERING_WORLD");
this.module.UnregisterEvent("UPDATE_BINDINGS");
Expand All @@ -164,39 +167,39 @@ export class OvaleActionBarClass {
this.module.UnregisterMessage("Ovale_TalentsChanged");
};

private ACTIONBAR_SLOT_CHANGED = (event: string, slot: number) => {
private handleActionBarSlotChanged = (event: string, slot: number) => {
slot = tonumber(slot);
if (slot == 0) {
this.UpdateActionSlots(event);
this.handleActionSlotUpdate(event);
} else if (ElvUI) {
const elvUIButtons = ElvUI.buttonRegistry;
for (const [btn] of pairs(elvUIButtons)) {
const s = btn.GetAttribute("action");
if (s == slot) {
this.UpdateActionSlot(slot);
this.updateActionSlot(slot);
}
}
} else if (slot) {
const bonus = tonumber(GetBonusBarIndex()) * 12;
const bonusStart = (bonus > 0 && bonus - 11) || 1;
const isBonus = slot >= bonusStart && slot < bonusStart + 12;
if (isBonus || (slot > 12 && slot < 73)) {
this.UpdateActionSlot(slot);
this.updateActionSlot(slot);
}
}
};

private UPDATE_BINDINGS = (event: string) => {
this.debug.Debug("%s: Updating key bindings.", event);
this.UpdateKeyBindings();
private handleUpdateBindings = (event: string) => {
this.debug.debug("%s: Updating key bindings.", event);
this.updateKeyBindings();
};
private TimerUpdateActionSlots = () => {
this.UpdateActionSlots("TimerUpdateActionSlots");
private handleTimerUpdateActionSlots = () => {
this.handleActionSlotUpdate("TimerUpdateActionSlots");
};

private UpdateActionSlots = (event: string) => {
this.profiler.StartProfiling("OvaleActionBar_UpdateActionSlots");
this.debug.Debug("%s: Updating all action slot mappings.", event);
private handleActionSlotUpdate = (event: string) => {
this.profiler.startProfiling("OvaleActionBar_UpdateActionSlots");
this.debug.debug("%s: Updating all action slot mappings.", event);
wipe(this.action);
wipe(this.item);
wipe(this.macro);
Expand All @@ -205,28 +208,28 @@ export class OvaleActionBarClass {
const elvUIButtons = ElvUI.buttonRegistry;
for (const [btn] of pairs(elvUIButtons)) {
const s = btn.GetAttribute("action");
this.UpdateActionSlot(s);
this.updateActionSlot(s);
}
} else {
let start = 1;
const bonus = tonumber(GetBonusBarIndex()) * 12;
if (bonus > 0) {
start = 13;
for (let slot = bonus - 11; slot <= bonus; slot += 1) {
this.UpdateActionSlot(slot);
this.updateActionSlot(slot);
}
}
for (let slot = start; slot <= 72; slot += 1) {
this.UpdateActionSlot(slot);
this.updateActionSlot(slot);
}
}
if (event != "TimerUpdateActionSlots") {
this.module.ScheduleTimer(this.TimerUpdateActionSlots, 1);
this.module.ScheduleTimer(this.handleTimerUpdateActionSlots, 1);
}
this.profiler.StopProfiling("OvaleActionBar_UpdateActionSlots");
this.profiler.stopProfiling("OvaleActionBar_UpdateActionSlots");
};
private UpdateActionSlot(slot: number) {
this.profiler.StartProfiling("OvaleActionBar_UpdateActionSlot");
private updateActionSlot(slot: number) {
this.profiler.startProfiling("OvaleActionBar_UpdateActionSlot");
const action = this.action[slot];
if (this.spell[<number>action] == slot) {
delete this.spell[<number>action];
Expand Down Expand Up @@ -276,7 +279,7 @@ export class OvaleActionBarClass {
} else {
const [, hyperlink] = GetMacroItem(id);
if (hyperlink) {
const [, , linkData] = this.ParseHyperlink(
const [, , linkData] = this.parseHyperlink(
hyperlink
);
const itemIdText = gsub(linkData, ":.*", "");
Expand All @@ -299,23 +302,23 @@ export class OvaleActionBarClass {
}
}
if (this.action[slot]) {
this.debug.Debug(
this.debug.debug(
"Mapping button %s to %s.",
slot,
this.action[slot]
);
} else {
this.debug.Debug("Clearing mapping for button %s.", slot);
this.debug.debug("Clearing mapping for button %s.", slot);
}
this.keybind[slot] = this.GetKeyBinding(slot);
this.profiler.StopProfiling("OvaleActionBar_UpdateActionSlot");
this.keybind[slot] = this.getKeyBinding(slot);
this.profiler.stopProfiling("OvaleActionBar_UpdateActionSlot");
}
UpdateKeyBindings() {
this.profiler.StartProfiling("OvaleActionBar_UpdateKeyBindings");
private updateKeyBindings() {
this.profiler.startProfiling("OvaleActionBar_UpdateKeyBindings");
for (let slot = 1; slot <= 120; slot += 1) {
this.keybind[slot] = this.GetKeyBinding(slot);
this.keybind[slot] = this.getKeyBinding(slot);
}
this.profiler.StopProfiling("OvaleActionBar_UpdateKeyBindings");
this.profiler.stopProfiling("OvaleActionBar_UpdateKeyBindings");
}
getSpellActionSlot(spellId: number) {
return this.spell[spellId];
Expand All @@ -339,24 +342,23 @@ export class OvaleActionBarClass {
} else {
const slotIndex = slot - 1;
const actionBar = (slotIndex - (slotIndex % 12)) / 12;
name = `${ActionBars[actionBar]}${(slotIndex % 12) + 1}`;
name = `${actionBars[actionBar]}${(slotIndex % 12) + 1}`;
}
}
return _G[name];
}

output: LuaArray<string> = {};
OutputTableValues(output: string, tbl: any) {}
private output: LuaArray<string> = {};

DebugActions() {
private debugActions() {
wipe(this.output);
const array: LuaArray<string> = {};

for (const [k, v] of pairs(this.spell)) {
insert(
array,
`${tostring(this.GetKeyBinding(v))}: ${tostring(k)} ${tostring(
this.ovaleSpellBook.GetSpellName(k)
`${tostring(this.getKeyBinding(v))}: ${tostring(k)} ${tostring(
this.ovaleSpellBook.getSpellName(k)
)}`
);
}
Expand Down
Loading

0 comments on commit af6216a

Please sign in to comment.