Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically load the correct deck #232

Merged
merged 9 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clashroyalebuildabot/bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def __init__(self, actions, auto_start=True):
)
keyboard_thread.start()

if config["load_deck"]:
self.emulator.load_deck(cards)

@staticmethod
def _log_and_wait(prefix, delay):
suffix = ""
Expand Down
3 changes: 3 additions & 0 deletions clashroyalebuildabot/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ bot:
# "WARNING" for warning messages, "ERROR" for error messages, and "CRITICAL" for critical issues.
log_level: "DEBUG"

# Create a deck code when the game starts
load_deck: True

adb:
# The IP address of your device or emulator.
# Use 127.0.0.1 for a local emulator. If you're connecting to a physical device,
Expand Down
3 changes: 2 additions & 1 deletion clashroyalebuildabot/detectors/detector.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from copy import deepcopy
import os
import time

Expand All @@ -20,7 +21,7 @@ def __init__(self, cards):
f"You must specify all {self.DECK_SIZE} of your cards"
)

self.cards = cards
self.cards = deepcopy(cards)

self.card_detector = CardDetector(self.cards)
self.number_detector = NumberDetector()
Expand Down
2 changes: 0 additions & 2 deletions clashroyalebuildabot/detectors/unit_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ def _get_tile_xy(bbox):
def _get_possible_ally_names(self):
possible_ally_names = set()
for card in self.cards:
if card.units is None:
continue
for unit in card.units:
possible_ally_names.add(unit.name)
return possible_ally_names
Expand Down
26 changes: 26 additions & 0 deletions clashroyalebuildabot/emulator/emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,29 @@ def take_screenshot(self):
screenshot, self.frame = self.frame, None

return screenshot

def load_deck(self, cards):
id_str = ";".join([str(card.id_) for card in cards])
slot_str = ";".join("0" for _ in range(len(cards)))
url = "&".join(
[
f"https://link.clashroyale.com/en/?clashroyale://copyDeck?deck={id_str}",
f"slots={slot_str}",
"tt=159000000",
"l=Royals",
"id=JR2RU0L90",
]
)

self._run_command(
[
"shell",
"am",
"start",
"-n",
"com.android.chrome/com.google.android.apps.chrome.Main",
"-d",
f"'{url}'",
]
)
input("Press a key when you've finished copying the deck ")
Loading