Skip to content

Commit

Permalink
feat: CommandBar API
Browse files Browse the repository at this point in the history
  • Loading branch information
controlado committed Sep 19, 2024
1 parent 9cd3f9f commit aa9ca72
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const pluginGroup = "Balaclava: Auto Champion Select";

class SwitchAction {
constructor(id, name, legend, tags, group, callback, toasts) {
this.id = id;
this.name = name;
this.legend = legend;
this.tags = tags;
this.group = group;
this.perform = this.perform.bind(this);
this.callback = callback;
this.toasts = toasts;
}

perform() {
try {
const currentStatus = this.callback();
Toast.success(currentStatus ? this.toasts.on : this.toasts.off);
} catch (error) {
Toast.error(this.toasts.error);
console.error(error);
}
}
}

export class AutoPickSwitchAction extends SwitchAction {
constructor(callback) {
super(
"controladoPickSwitch",
"Auto Pick [ON/OFF]",
"Turn the auto pick ON/OFF",
[pluginGroup, "pick", "switch"],
pluginGroup,
callback,
{
on: "Auto Pick is ON",
off: "Auto Pick is OFF",
error: "Failed to toggle Auto Pick. Check console."
}
)
}
}

export class AutoBanSwitchAction extends SwitchAction {
constructor(callback) {
super(
"controladoBanSwitch",
"Auto Ban [ON/OFF]",
"Turn the auto ban ON/OFF",
[pluginGroup, "ban", "switch"],
pluginGroup,
callback,
{
on: "Auto Ban is ON",
off: "Auto Ban is OFF",
error: "Failed to toggle Auto Ban. Check console."
}
);
}
}

export function addActions(actions) {
for (let action of actions) {
CommandBar.addAction(action);
}
}
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { request, sleep, linkEndpoint } from "https://cdn.skypack.dev/balaclava-utils@latest";
import { ChampionSelect, Dropdown, Checkbox, SocialSection } from "./models.js";
import { AutoPickSwitchAction, AutoBanSwitchAction, addActions } from "./actions.js";
import { version } from "../package.json";
import "./assets/style.css";

Expand Down Expand Up @@ -82,6 +83,11 @@ window.addEventListener("load", async () => {
secondAllChampionsDropdown.setup()
]);

addActions([
new AutoPickSwitchAction(() => pickCheckbox.toggle()),
new AutoBanSwitchAction(() => banCheckbox.toggle())
]);

linkEndpoint("/lol-inventory/v1/wallet", parsedEvent => {
if (parsedEvent.eventType === "Update") {
console.debug("auto-champion-select(wallet): Refreshing dropdowns...");
Expand Down

0 comments on commit aa9ca72

Please sign in to comment.