Skip to content

Commit

Permalink
Various QOL fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Pbatch committed Jul 6, 2024
1 parent f6d2dd1 commit c14647c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
2 changes: 1 addition & 1 deletion clashroyalebuildabot/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ bot:
# The logging level for the bot.
# Use "DEBUG" for detailed debugging information, "INFO" for general information,
# "WARNING" for warning messages, "ERROR" for error messages, and "CRITICAL" for critical issues.
log_level: "DEBUG"
log_level: "INFO"

adb:
# The IP address of your device or emulator.
Expand Down
37 changes: 15 additions & 22 deletions clashroyalebuildabot/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,19 @@ def __init__(self):
os.makedirs(SCREENSHOTS_DIR, exist_ok=True)
os.makedirs(LABELS_DIR, exist_ok=True)
self.font = ImageFont.load_default()
self.unit_names = [unit[0] for unit in list(NAME2UNIT.values())]
self.unit_names = [unit["name"] for unit in list(NAME2UNIT.values())]

@staticmethod
def _write_label(image, state, basename):
labels = []
unit_names_and_positions = [
[unit_name, v["positions"]]
for unit_name, v in list(state.allies.items())
+ list(state.enemies.items())
]
for unit_name, positions in unit_names_and_positions:
for position in positions:
bbox = position.bbox
xc = (bbox[0] + bbox[2]) / (2 * image.width)
yc = (bbox[1] + bbox[3]) / (2 * image.height)
w = (bbox[2] - bbox[0]) / image.width
h = (bbox[3] - bbox[1]) / image.height
label = f"{unit_name} {xc} {yc} {w} {h}"
labels.append(label)
for det in state.allies + state.enemies:
bbox = det.position.bbox
xc = (bbox[0] + bbox[2]) / (2 * image.width)
yc = (bbox[1] + bbox[3]) / (2 * image.height)
w = (bbox[2] - bbox[0]) / image.width
h = (bbox[3] - bbox[1]) / image.height
label = f"{det.unit.name} {xc} {yc} {w} {h}"
labels.append(label)

with open(
os.path.join(LABELS_DIR, f"{basename}.txt"), "w", encoding="utf-8"
Expand All @@ -69,16 +63,15 @@ def _draw_text(self, d, bbox, text, rgba=(0, 0, 0, 255)):
d.rectangle(tuple(bbox), outline=rgba)
d.text(tuple(text_bbox[:2]), text=text, fill="white")

def _draw_unit_bboxes(self, d, units, prefix):
for unit_name, v in units.items():
colour_idx = self.unit_names.index(unit_name) % len(
def _draw_unit_bboxes(self, d, dets, prefix):
for det in dets:
colour_idx = self.unit_names.index(det.unit.name) % len(
self._COLOUR_AND_RGBA
)
rgba = self._COLOUR_AND_RGBA[colour_idx][1]
for position in v["positions"]:
self._draw_text(
d, position.bbox, f"{prefix}_{unit_name}", rgba
)
self._draw_text(
d, det.position.bbox, f"{prefix}_{det.unit.name}", rgba
)

def _write_image(self, image, state, basename):
d = ImageDraw.Draw(image, "RGBA")
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def main():
MinipekkaAction,
MusketeerAction,
}
bot = Bot(actions=actions, debug=False)
bot = Bot(actions=actions, debug=True)
bot.run()


Expand Down

0 comments on commit c14647c

Please sign in to comment.