Skip to content

Commit

Permalink
Merge pull request #24 from creazy231/feature/disableTakeout
Browse files Browse the repository at this point in the history
Feature: dsiable takeout recognition
  • Loading branch information
creazy231 authored Apr 11, 2024
2 parents 89b34bf + 8bd0809 commit 38dfd3b
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 30 deletions.
58 changes: 36 additions & 22 deletions components/PageConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@
</div>

<div class="space-y-4 rounded border border-white/10 p-4">
<div>
<h2 class="text-lg font-semibold">
Disable takeout recognition
</h2>
<p class="max-w-2xl text-white/40">
Disables the takeout recognition. So you have to manually click 'Next' after takeout.
</p>
</div>
<div class="grid grid-cols-[5rem_auto] items-center gap-4">
<AppToggle v-model="config.disableTakeout.enabled" />
</div>
</div>

<div v-if="!config.disableTakeout.enabled" class="space-y-4 rounded border border-white/10 p-4">
<div>
<h2 class="text-lg font-semibold">
Takeout Notification
Expand All @@ -132,7 +146,7 @@
</div>
</div>

<div class="space-y-4 rounded border border-white/10 p-4">
<div v-if="!config.disableTakeout.enabled" class="space-y-4 rounded border border-white/10 p-4">
<div>
<h2 class="text-lg font-semibold">
Automatic next player on takeout
Expand All @@ -153,6 +167,27 @@
</div>
</div>

<div v-if="!config.disableTakeout.enabled" class="space-y-4 rounded border border-white/10 p-4">
<div>
<h2 class="text-lg font-semibold">
Automatic next Leg
</h2>
<p class="max-w-2xl text-white/40">
Automatically starts the next leg x seconds <span class="font-semibold text-white/60">after takeout</span>.
</p>
</div>
<div class="grid grid-cols-[5rem_5rem_auto] items-center gap-4">
<AppToggle v-model="config.automaticNextLeg.enabled" />
<input
v-if="config.automaticNextLeg.enabled"
v-model="config.automaticNextLeg.sec"
type="text"
class="rounded-md border border-white/10 bg-transparent px-2 py-1 text-center outline-none"
>
<span v-if="config.automaticNextLeg.enabled">seconds</span>
</div>
</div>

<div class="space-y-4 rounded border border-white/10 p-4">
<div>
<h2 class="text-lg font-semibold">
Expand Down Expand Up @@ -331,27 +366,6 @@
</div>
</div>

<div class="space-y-4 rounded border border-white/10 p-4">
<div>
<h2 class="text-lg font-semibold">
Automatic next Leg
</h2>
<p class="max-w-2xl text-white/40">
Automatically starts the next leg x seconds <span class="font-semibold text-white/60">after takeout</span>.
</p>
</div>
<div class="grid grid-cols-[5rem_5rem_auto] items-center gap-4">
<AppToggle v-model="config.automaticNextLeg.enabled" />
<input
v-if="config.automaticNextLeg.enabled"
v-model="config.automaticNextLeg.sec"
type="text"
class="rounded-md border border-white/10 bg-transparent px-2 py-1 text-center outline-none"
>
<span v-if="config.automaticNextLeg.enabled">seconds</span>
</div>
</div>

<div class="space-y-4 rounded border border-white/10 p-4">
<div>
<h2 class="text-lg font-semibold">
Expand Down
28 changes: 28 additions & 0 deletions entrypoints/match.content/disableTakeout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { AutodartsToolsConfig, AutodartsToolsMatchStatus } from "@/utils/storage";
import { getNextBtn, getResetBtn, getStartBtn, getStopBtn } from "@/utils/getElements";

export async function disableTakeout() {
const { disableTakeout } = await AutodartsToolsConfig.getValue();
if (!disableTakeout.enabled) return;

try {
AutodartsToolsMatchStatus.watch(async (matchStatus) => {
if (matchStatus.isInUndoMode) {
getStartBtn()?.click();
}
if (matchStatus.throws.length === 3) {
getStopBtn()?.click();
};
});

const nextBtn = getNextBtn();
nextBtn?.addEventListener("click", () => {
getResetBtn()?.click();
setTimeout(() => {
getStartBtn()?.click();
}, 100);
});
} catch (e) {
console.error("Autodarts Tools: disable takeout recognition - Error: ", e);
}
}
26 changes: 18 additions & 8 deletions entrypoints/match.content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { setPlayerInfo } from "@/entrypoints/match.content/setPlayerInfo";
import { nextPlayerAfter3darts } from "@/entrypoints/match.content/nextPlayerAfter3darts";
import { handleUndoMode } from "@/entrypoints/match.content/handleUndoMode";
import { nextPlayerOnTakeOutStuck } from "@/entrypoints/match.content/nextPlayerOnTakeOutStuck";
import { disableTakeout } from "@/entrypoints/match.content/disableTakeout";

let takeoutUI: any;
let streamingModeUI: any;
Expand All @@ -53,8 +54,10 @@ export default defineContentScript({
await waitForElement("#ad-ext-turn");
console.log("Autodarts Tools: Match Ready");

const takeoutDiv = document.querySelector("autodarts-tools-takeout");
if (!takeoutDiv) initTakeout(ctx).catch(console.error);
if (!config.disableTakeout.enabled) {
const takeoutDiv = document.querySelector("autodarts-tools-takeout");
if (!takeoutDiv) initTakeout(ctx).catch(console.error);
}

if (config.streamingMode.enabled) {
const div = document.querySelector("autodarts-tools-streaming-mode");
Expand Down Expand Up @@ -103,7 +106,7 @@ async function initMatch() {
const globalStatus = await AutodartsToolsGlobalStatus.getValue();

startThrowsObserver();
if (getBoardStatusEl() && (config.takeout.enabled || config.automaticNextLeg.enabled || config.nextPlayerOnTakeOutStuck.enabled)) startBoardStatusObserver();
if (!config.disableTakeout.enabled && getBoardStatusEl() && (config.takeout.enabled || config.automaticNextLeg.enabled || config.nextPlayerOnTakeOutStuck.enabled)) startBoardStatusObserver();

if (isX01() && config.liveViewRing.enabled) {
await liveViewRing();
Expand All @@ -117,11 +120,17 @@ async function initMatch() {
await hideMenu();
await playerMatchDataLarger();
await handleUndoMode();
await nextPlayerOnTakeOutStuck();
if (!config.disableTakeout.enabled) {
await nextPlayerOnTakeOutStuck();
}

if (isValidGameMode()) {
if (globalStatus.isFirstStart) {
await soundsStart();
await AutodartsToolsGlobalStatus.setValue({ ...globalStatus, isFirstStart: false });
}

if (isValidGameMode() && globalStatus.isFirstStart) {
await soundsStart();
await AutodartsToolsGlobalStatus.setValue({ ...globalStatus, isFirstStart: false });
await disableTakeout();
}

throwsChange().catch(console.error);
Expand Down Expand Up @@ -163,6 +172,8 @@ async function throwsChange() {
} else {
await removeWinnerAnimation();
}

await nextPlayerAfter3darts();
}

if (isBullOff() && matchStatus.hasWinner) {
Expand All @@ -175,7 +186,6 @@ async function throwsChange() {
}

await scoreSmaller();
await nextPlayerAfter3darts();
await sounds();

if (isCricket()) await setCricketClosedPoints(matchStatus.playerCount).catch(console.error);
Expand Down
2 changes: 2 additions & 0 deletions utils/getElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export function getMenuBar(): Element | null {

export const getBoardStatusEl = () => (getMenuBar()?.lastChild?.lastChild as Element)?.querySelector("a");

export const getStartBtn = () => [ ...getMenuBar()?.querySelectorAll("button") as NodeListOf<HTMLButtonElement> ].find(el => el.textContent === "Start");
export const getStopBtn = () => [ ...getMenuBar()?.querySelectorAll("button") as NodeListOf<HTMLButtonElement> ].find(el => el.textContent === "Stop");
export const getResetBtn = () => [ ...getMenuBar()?.querySelectorAll("button") as NodeListOf<HTMLButtonElement> ].find(el => el.textContent === "Reset");

export const getMenu = () => document.querySelector("#root > div > div") as HTMLElement | null;
Expand Down
6 changes: 6 additions & 0 deletions utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ export interface IConfig {
enabled: boolean;
sec: number;
};
disableTakeout: {
enabled: boolean;
};
teamLobby: {
enabled: boolean;
};
Expand Down Expand Up @@ -206,6 +209,9 @@ export const defaultConfig: IConfig = {
enabled: false,
sec: 10,
},
disableTakeout: {
enabled: false,
},
teamLobby: {
enabled: false,
},
Expand Down

0 comments on commit 38dfd3b

Please sign in to comment.