Skip to content

Commit

Permalink
fix(team-race): wrong template size
Browse files Browse the repository at this point in the history
  • Loading branch information
NateScarlet committed May 23, 2021
1 parent eee0467 commit 3529872
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 44 deletions.
Empty file added auto_derby/__init__.py
Empty file.
2 changes: 0 additions & 2 deletions auto_derby/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from auto_derby import templates
import ctypes
from os import name
import time
import webbrowser

Expand All @@ -24,7 +23,6 @@ def main():
"team_race": jobs.team_race,
"daily_race_money": lambda : jobs.daily_race(templates.MOONLIGHT_PRIZE),
"daily_race_sp": lambda : jobs.daily_race(templates.JUPITER_CUP),
"create_pos_mask": jobs.create_pos_mask,
}
parser = argparse.ArgumentParser()
parser.add_argument("job")
Expand Down
1 change: 0 additions & 1 deletion auto_derby/jobs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from .nurturing import nurturing
from .team_race import team_race
from .daily_race import daily_race
from .create_pos_mask import create_pos_mask
38 changes: 0 additions & 38 deletions auto_derby/jobs/create_pos_mask.py

This file was deleted.

3 changes: 2 additions & 1 deletion auto_derby/jobs/team_race.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def team_race():
templates.GREEN_NEXT_BUTTON,
templates.TEAM_RACE_CHOOSE_COMPETITOR,
templates.RACE_START_BUTTON,
templates.TEAM_RACE_SEE_RESULT_BUTTON,
templates.TEAM_RACE_RESULT_BUTTON,
templates.RACE_AGAIN_BUTTON,
templates.TEAM_RACE_WIN,
templates.TEAM_RACE_LOSE,
templates.TEAM_RACE_NEXT_BUTTON,
Expand Down
3 changes: 2 additions & 1 deletion auto_derby/templates/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Code Generated from [__init__.py.gotmpl], DO NOT EDIT.

CANCEL_BUTTON = "cancel_button.png"
CIRCLE_ITEM_REQUEST = "circle_item_request.png"
CONNECTING = "connecting.png"
DAILY_RACE = "daily_race.png"
DAILY_RACE_HARD = "daily_race_hard.png"
Expand All @@ -25,5 +26,5 @@
TEAM_RACE_GUARANTEED_WIN_REWARD = "team_race_guaranteed_win_reward.png"
TEAM_RACE_LOSE = "team_race_lose.png"
TEAM_RACE_NEXT_BUTTON = "team_race_next_button.png"
TEAM_RACE_SEE_RESULT_BUTTON = "team_race_see_result_button.png"
TEAM_RACE_RESULT_BUTTON = "team_race_result_button.png"
TEAM_RACE_WIN = "team_race_win.png"
2 changes: 1 addition & 1 deletion auto_derby/templates/__init__.py.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{{- end }}
{{ "" }}
{{- range .Files }}
{{- if . | hassuffix ".pos.png" }}
{{- if . | hasSuffix ".pos.png" }}
{{- else }}
{{ template "stem" . | snakecase | upper }} = "{{.}}"
{{- end }}
Expand Down
Binary file modified auto_derby/templates/race_again_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified auto_derby/templates/race_start_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified auto_derby/templates/rp_not_enough.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified auto_derby/templates/team_race_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added auto_derby/templates/team_race_button.pos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified auto_derby/templates/team_race_choose_competitor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified auto_derby/templates/team_race_lose.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added auto_derby/templates/team_race_result_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed auto_derby/templates/team_race_see_result_button.png
Binary file not shown.
Binary file modified auto_derby/templates/team_race_win.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 71 additions & 0 deletions scripts/capture_template_position.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# -*- coding=UTF-8 -*-
# pyright: strict

if True:
import sys
import os
sys.path.insert(0, os.path.join(__file__, "../.."), )


from typing import Text
import cv2
from auto_derby import window, template, templates
import pathlib
import PIL.Image
import numpy as np
import argparse

_TEMPLATES_PATH = pathlib.Path(templates.__file__).parent


def _all_templates():
for i in _TEMPLATES_PATH.glob("*.png"):
if i.is_dir():
continue
if str(i).endswith(".pos.png"):
continue
yield i


def _latest_file():
return str((sorted(_all_templates(), key=lambda x: x.stat().st_mtime, reverse=True))[0].name)


def create_pos_mask(name: Text):

game_img = template.screenshot(window.get_game())
match_img = template.load(name)
match = template.match(game_img, name)
last_match = template.DEBUG_DATA["last_match"]
if last_match is None:
raise ValueError("missing debug data")

out_img = np.zeros((game_img.height, game_img.width), dtype=float)

if match:
_, pos = match
x, y = pos
cv2.rectangle(out_img, pos, (x+match_img.width,
y+match_img.height), (255,), -1)

img = PIL.Image.fromarray(out_img).convert("1")
dest = str(_TEMPLATES_PATH / template.add_middle_ext(name, "pos"))
img.save(dest)
cv2.imshow("out", out_img)
cv2.waitKey()


def main():

parser = argparse.ArgumentParser()

parser.add_argument("--name", "-n", dest="name")
args = parser.parse_args()
name = args.name
if not name:
name = _latest_file()
create_pos_mask(name)


if __name__ == '__main__':
main()

0 comments on commit 3529872

Please sign in to comment.