Skip to content

Commit

Permalink
fixed formating with ruff, including in unreleated files
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen-Griffin committed Jun 25, 2024
1 parent 1e48296 commit 89a2699
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 67 deletions.
7 changes: 2 additions & 5 deletions backend/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ def recruit_troop(self, troop_type: str, amount: str, currency: str = "gold"):

def get_market_orders(self, item: str, order_type: str) -> list[MarketOrder | None]:
route = Route("/market", "GET")
query_params = {
"item_type": item,
"order_type": order_type
}
query_params = {"item_type": item, "order_type": order_type}
response = self.request(route, query_params=query_params)
orders = response.json()["orders"]
orders = [MarketOrder.from_data(order) for order in orders.values()]
Expand Down Expand Up @@ -120,4 +117,4 @@ def attack_npc(self, troops: dict[UnitType, int]) -> NPCResult | None:
json = {"troops": troops}
print(json)
response = self.request(route, json=json)
return NPCResult.from_api(response.json())
return NPCResult.from_api(response.json())
4 changes: 3 additions & 1 deletion gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
from gui.frames.outposts import OutpostsFrame
from gui.frames.market import MarketFrame


def resource_path(asset_path: str) -> str:
try:
base_path = sys._MEIPASS2 # type: ignore
base_path = sys._MEIPASS2 # type: ignore
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, asset_path)


class App(tkinter.Tk):
def __init__(self):
tkinter.Tk.__init__(self)
Expand Down
2 changes: 2 additions & 0 deletions gui/components/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ def __init__(self, parent, text):
font=("Helvetica", 10, "bold"),
)


class FullWidthLabel(tkinter.Label):
def __init__(self, parent, text):
super().__init__(parent, text=text, width=50, height=2, font=("Helvetica", 20))


class FrameLabel(tkinter.Label):
def __init__(self, parent, text):
super().__init__(parent, text=text, width=42, height=2, font=("Helvetica", 20))
Expand Down
4 changes: 3 additions & 1 deletion gui/frames/api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
from ..components import labels, inputs, buttons
from backend.api import API


def resource_path(asset_path: str) -> str:
try:
base_path = sys._MEIPASS2 # type: ignore
base_path = sys._MEIPASS2 # type: ignore
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, asset_path)


class APIKeyFrame(tkinter.Frame):
def __init__(self, parent, sidebar=False):
self.sidebar = sidebar
Expand Down
11 changes: 5 additions & 6 deletions gui/frames/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,16 @@ def storehouse_upgrade(self) -> None:
self.upgrade_building("storehouse")

def show_feedback(self, feedback: str) -> None:
self.feedbackLabel = labels.InputLabel(
self, feedback
)
self.feedbackLabel = labels.InputLabel(self, feedback)
self.feedbackLabel.place(x=300, y=350)


def upgrade_building(self, building_type: str) -> None:
self.upgradeResponse = self.parent.backend.upgrade_building(building_type, '1')
self.upgradeResponse = self.parent.backend.upgrade_building(building_type, "1")

frame = ConstructionFrame(self.parent)
self.parent.change_frame(frame) # TODO instead of initialising a new frame, update the current frame
self.parent.change_frame(
frame
) # TODO instead of initialising a new frame, update the current frame
frame.show_feedback(self.upgradeResponse["detail"])

def render(self):
Expand Down
1 change: 1 addition & 0 deletions gui/frames/empty_frame.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import tkinter
from ..components import labels


class EmptyFrame(tkinter.Frame):
def __init__(self, parent):
super().__init__(parent, width=650, height=600)
Expand Down
19 changes: 12 additions & 7 deletions gui/frames/market.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import tkinter
from ..components import labels, dropdowns, inputs


class MarketFrame(tkinter.Frame):
def __init__(self, parent, bg="gray"):
super().__init__(parent, width=650, height=600, bg=bg)
Expand All @@ -14,11 +15,13 @@ def __init__(self, parent, bg="gray"):

self.buy_offers = tkinter.Listbox(self, bg=self.bg)
self.buy_offers_label = labels.InputLabel(self, "Buy Offers", bg="white")

self.sell_offers = tkinter.Listbox(self, bg=self.bg)
self.sell_offers_label = labels.InputLabel(self, "Sell Offers", bg="white")

self.refresh_button = tkinter.Button(self, bg="green", text="Refresh", command=self.update_offers)
self.refresh_button = tkinter.Button(
self, bg="green", text="Refresh", command=self.update_offers
)

self.amount = inputs.IntergerOnlyEntry(self, 0, 100)
self.amount_label = labels.InputLabel(self, "Amount", bg=self.bg)
Expand All @@ -29,7 +32,9 @@ def __init__(self, parent, bg="gray"):
self.instant_buy_button = tkinter.Button(self, bg="green", text="Buy Instantly")
self.instant_sell_button = tkinter.Button(self, bg="red", text="Sell Instantly")

self.accept_offer_button = tkinter.Button(self, bg="yellow", text="Accept Offer")
self.accept_offer_button = tkinter.Button(
self, bg="yellow", text="Accept Offer"
)

self.create_offer_button = tkinter.Button(self, bg="green", text="Create Offer")

Expand All @@ -38,14 +43,14 @@ def __init__(self, parent, bg="gray"):
def render(self):
self.item_selector.place(x=100, y=50)
self.item_selector_label.place(x=100, y=20)

self.buy_offers.place(x=100, y=190)
self.buy_offers_label.place(x=100, y=160)
self.sell_offers.place(x=275, y=190)
self.sell_offers_label.place(x=275, y=160)

self.refresh_button.place(x=500, y=30)

self.amount.place(x=500, y=100)
self.amount_label.place(x=500, y=80)

Expand All @@ -63,7 +68,7 @@ def update_offers(self) -> None:
item = self.item_selector.get_selection().get()
buy_orders = self.parent.backend.get_market_orders(item, "buy")
sell_orders = self.parent.backend.get_market_orders(item, "sell")

self.buy_offers.delete(0, "end")
self.sell_offers.delete(0, "end")
for order in buy_orders:
Expand Down
68 changes: 44 additions & 24 deletions gui/frames/npc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from ..components import labels, buttons, inputs
from models import UnitType, NPCResult


class NPCResultFrame(tkinter.Frame):
def __init__(self, parent, result: NPCResult):
self.bg = "orange"
Expand Down Expand Up @@ -38,29 +39,48 @@ def __init__(self, parent):
big_bowmen = self.player.units[UnitType.BIG_BOWMEN]
heavy_men = self.player.units[UnitType.HEAVY_MEN]
king_guards = self.player.units[UnitType.KINGS_GUARDS]
self.npcLevelLabel = labels.InputLabel(self, f"Last NPC Level Defeated: {self.player.npc_level}")


self.troopSelectorLabel = labels.InputLabel(self, 'Select Troops:')
self.infantryLabel = labels.InputLabel(self, f'Infantry ({infantry}):')
self.cavalryLabel = labels.InputLabel(self, f'Cavalry ({cavalry}):')
self.artilleryLabel = labels.InputLabel(self, f'Artillery ({artillery}):')
self.assassinLabel = labels.InputLabel(self, f'Assassins ({assassins}):')
self.bowmenLabel = labels.InputLabel(self, f'Bowmen ({bowmen}):')
self.bigBowmenLabel = labels.InputLabel(self, f'Big Bowmen ({big_bowmen}):')
self.heavyMenLabel = labels.InputLabel(self, f'Heavy Men ({heavy_men}):')
self.kingGuardsLabel = labels.InputLabel(self, f'King Guards ({king_guards}):')

self.infantryQuantity = inputs.IntergerOnlyEntry(self, minNumber=1, maxNumber=infantry)
self.cavalryQuantity = inputs.IntergerOnlyEntry(self, minNumber=1, maxNumber=cavalry)
self.artilleryQuantity = inputs.IntergerOnlyEntry(self, minNumber=1, maxNumber=artillery)
self.assassinsQuantity = inputs.IntergerOnlyEntry(self, minNumber=1, maxNumber=assassins)
self.bowmenQuantity = inputs.IntergerOnlyEntry(self, minNumber=1, maxNumber=bowmen)
self.bigBowmenQuantity = inputs.IntergerOnlyEntry(self, minNumber=1, maxNumber=big_bowmen)
self.heavyMenQuantity = inputs.IntergerOnlyEntry(self, minNumber=1, maxNumber=heavy_men)
self.kingGuardsQuantity = inputs.IntergerOnlyEntry(self, minNumber=1, maxNumber=king_guards)

self.npcAttackButton = buttons.SubmitButton(self, text='Attack', height=2, width=6, command=self.attack_npc)
self.npcLevelLabel = labels.InputLabel(
self, f"Last NPC Level Defeated: {self.player.npc_level}"
)

self.troopSelectorLabel = labels.InputLabel(self, "Select Troops:")
self.infantryLabel = labels.InputLabel(self, f"Infantry ({infantry}):")
self.cavalryLabel = labels.InputLabel(self, f"Cavalry ({cavalry}):")
self.artilleryLabel = labels.InputLabel(self, f"Artillery ({artillery}):")
self.assassinLabel = labels.InputLabel(self, f"Assassins ({assassins}):")
self.bowmenLabel = labels.InputLabel(self, f"Bowmen ({bowmen}):")
self.bigBowmenLabel = labels.InputLabel(self, f"Big Bowmen ({big_bowmen}):")
self.heavyMenLabel = labels.InputLabel(self, f"Heavy Men ({heavy_men}):")
self.kingGuardsLabel = labels.InputLabel(self, f"King Guards ({king_guards}):")

self.infantryQuantity = inputs.IntergerOnlyEntry(
self, minNumber=1, maxNumber=infantry
)
self.cavalryQuantity = inputs.IntergerOnlyEntry(
self, minNumber=1, maxNumber=cavalry
)
self.artilleryQuantity = inputs.IntergerOnlyEntry(
self, minNumber=1, maxNumber=artillery
)
self.assassinsQuantity = inputs.IntergerOnlyEntry(
self, minNumber=1, maxNumber=assassins
)
self.bowmenQuantity = inputs.IntergerOnlyEntry(
self, minNumber=1, maxNumber=bowmen
)
self.bigBowmenQuantity = inputs.IntergerOnlyEntry(
self, minNumber=1, maxNumber=big_bowmen
)
self.heavyMenQuantity = inputs.IntergerOnlyEntry(
self, minNumber=1, maxNumber=heavy_men
)
self.kingGuardsQuantity = inputs.IntergerOnlyEntry(
self, minNumber=1, maxNumber=king_guards
)

self.npcAttackButton = buttons.SubmitButton(
self, text="Attack", height=2, width=6, command=self.attack_npc
)

def attack_npc(self):
infantry = self.infantryQuantity.get()
Expand Down Expand Up @@ -99,7 +119,7 @@ def render(self):
self.bigBowmenLabel.place(x=167, y=300)
self.heavyMenLabel.place(x=174, y=325)
self.kingGuardsLabel.place(x=170, y=350)

self.infantryQuantity.place(x=260, y=175)
self.cavalryQuantity.place(x=260, y=200)
self.artilleryQuantity.place(x=260, y=225)
Expand Down
3 changes: 2 additions & 1 deletion gui/frames/outposts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import tkinter
from ..components import labels, containers, buttons, popups


class OutpostsFrame(tkinter.Frame):
def __init__(self, parent):
super().__init__(parent, width=650, height=600, bg="pink")
Expand Down Expand Up @@ -35,7 +36,7 @@ def create_outpost_containers(self):
for i, outpost in enumerate(self.outpostsList):
x = 30 + (i % 3) * (container_width + container_padx)
y = 100 + (i // 3) * (container_height + 10)

container = containers.SubContainer(
self, width=container_width, height=container_height, bg="white"
)
Expand Down
2 changes: 1 addition & 1 deletion models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
from .units import UnitType
from .characteristics import Characteristics
from .order import MarketOrder
from .results import NPCResult
from .results import NPCResult
6 changes: 4 additions & 2 deletions models/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

__all__ = ("Player", "EventPlayer")

# For handling the edge-case where the date returned by the api is null, most likely to occur with last_npc_win

# For handling the edge-case where the date returned by the api is null, most likely to occur with last_npc_win
def _parse_date(date) -> datetime | None:
if date is None:
return None
Expand All @@ -16,6 +17,7 @@ def _parse_date(date) -> datetime | None:
except TypeError:
return None


class Player(NamedTuple):
id: int
registered_at: datetime
Expand All @@ -41,7 +43,7 @@ def from_data(data: dict):

return Player(
id=data["user_id"],
registered_at=_parse_date(data["registered_at"]), # type: ignore
registered_at=_parse_date(data["registered_at"]), # type: ignore
gold=data["gold"],
ruby=data["ruby"],
units={
Expand Down
3 changes: 2 additions & 1 deletion models/results.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .units import UnitType
from typing import NamedTuple


class NPCResult(NamedTuple):
won: bool
attacker_lost_troops: dict[UnitType, int]
Expand Down Expand Up @@ -43,4 +44,4 @@ def from_api(response: dict | None):
food_loot=response["food_loot"],
token_loot=response["token_loot"],
iron_frames=response["iron_frames"],
)
)
43 changes: 25 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,35 @@
import os.path

PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
os.environ["TCL_LIBRARY"] = os.path.join(PYTHON_INSTALL_DIR, "tcl", "tcl8.6")
os.environ["TK_LIBRARY"] = os.path.join(PYTHON_INSTALL_DIR, "tcl", "tk8.6")

include_files = [os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
"assets",
"backend",
"models"]
include_files = [
os.path.join(PYTHON_INSTALL_DIR, "DLLs", "tk86t.dll"),
os.path.join(PYTHON_INSTALL_DIR, "DLLs", "tcl86t.dll"),
"assets",
"backend",
"models",
]
# Dependencies are automatically detected, but it might need
# fine tuning.
build_options = {'packages': [], 'excludes': [], "include_files": include_files}
build_options = {"packages": [], "excludes": [], "include_files": include_files}


executables = [Executable('main.pyw',
target_name='Will of Steel.exe',
icon='assets/img/logo.ico',
copyright='Copyright (C) Will of Steel 2018',
base='gui')
executables = [
Executable(
"main.pyw",
target_name="Will of Steel.exe",
icon="assets/img/logo.ico",
copyright="Copyright (C) Will of Steel 2018",
base="gui",
)
]

setup(name='Will of Steel',
version = '0.1',
description = '',
options = {'build_exe': build_options},
executables = executables)
setup(
name="Will of Steel",
version="0.1",
description="",
options={"build_exe": build_options},
executables=executables,
)

0 comments on commit 89a2699

Please sign in to comment.