diff --git a/src/actions.js b/src/actions.js new file mode 100644 index 0000000..baf9115 --- /dev/null +++ b/src/actions.js @@ -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); + } +} diff --git a/src/index.js b/src/index.js index adbaa76..fe1692d 100644 --- a/src/index.js +++ b/src/index.js @@ -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"; @@ -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...");