Skip to content

Commit

Permalink
Remove some profound bullshit
Browse files Browse the repository at this point in the history
  • Loading branch information
Gatsik committed Jan 8, 2025
1 parent 36dc266 commit ff01216
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 75 deletions.
11 changes: 6 additions & 5 deletions src/api/models/Achievement.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from __future__ import annotations

from enum import Enum

from pydantic import Field

from src.api.models.AbstractEntity import AbstractEntity
from src.util import StringValuedEnum


class State(StringValuedEnum):
class State(Enum):
REVEALED = "REVEALED"
UNLOCKED = "UNLOCKED"


class ProgressType(StringValuedEnum):
class ProgressType(Enum):
STANDARD = "STANDARD"
INCREMENTAL = "INCREMENTAL"

Expand All @@ -34,8 +35,8 @@ class Achievement(AbstractEntity):

@property
def init_state(self) -> State:
return State.from_string(self.initial_state)
return State(self.initial_state)

@property
def progress_type(self) -> ProgressType:
return ProgressType.from_string(self.typ)
return ProgressType(self.typ)
8 changes: 3 additions & 5 deletions src/api/models/MapType.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ class MapType(Enum):

@staticmethod
def from_string(map_type: str) -> MapType:
for mtype in list(MapType):
if mtype.value == map_type:
return mtype
else:
return MapType.OTHER
if map_type in MapType:
return MapType(map_type)
return MapType.OTHER
5 changes: 2 additions & 3 deletions src/api/models/ModType.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class ModType(Enum):

@staticmethod
def from_string(string: str) -> ModType:
for modtype in list(ModType):
if modtype.value == string:
return modtype
if string in ModType:
return ModType(string)
return ModType.OTHER
2 changes: 1 addition & 1 deletion src/api/models/PlayerAchievement.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ class PlayerAchievement(AbstractEntity):

@property
def current_state(self) -> State:
return State.from_string(self.state)
return State(self.state)
7 changes: 2 additions & 5 deletions src/contextmenu/playercontextmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,8 @@ def party_actions(
if online_player is None:
return

if online_player.id in self._client_window.games.party.memberIds:
if (
self._me.player.id
== self._client_window.games.party.owner_id
):
if online_player.id in self._client_window.games.party.member_ids:
if self._me.player.id == self._client_window.games.party.owner_id:
yield PlayerMenuItem.KICK_FROM_PARTY
elif online_player.currentGame is not None:
return
Expand Down
63 changes: 23 additions & 40 deletions src/games/_gameswidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
from typing import TYPE_CHECKING
from typing import Self

from PyQt6 import QtWidgets
from PyQt6.QtCore import Qt
Expand Down Expand Up @@ -34,43 +35,29 @@


class Party:
def __init__(self, owner_id=-1, owner=None):
def __init__(self, owner_id: int = -1, owner: PartyMember | None = None) -> None:
self.owner_id = owner_id
self.members = [owner] if owner else []

@property
def memberCount(self):
return len(self.memberList)
def member_count(self) -> int:
return len(self.members)

@property
def memberList(self):
return self.members

def addMember(self, member):
self.memberList.append(member)
def add_member(self, member: PartyMember) -> None:
self.members.append(member)

@property
def memberIds(self):
uids = []
if len(self.members) > 0:
for member in self.members:
uids.append(member.id_)
return uids

def __eq__(self, other):
if (
sorted(self.memberIds) == sorted(other.memberIds)
and self.owner_id == other.owner_id
):
return True
else:
return False
def member_ids(self) -> list[int]:
return [member.id_ for member in self.members]

def __eq__(self, other: Self) -> bool:
return set(self.member_ids) == set(other.member_ids) and self.owner_id == other.owner_id


class PartyMember:
def __init__(self, id_=-1, factions=None):
def __init__(self, id_: int = -1, factions: list[str] | None = None) -> None:
self.id_ = id_
self.factions = ["uef", "cybran", "aeon", "seraphim"]
self.factions = factions


class GamesWidget(FormClass, BaseClass):
Expand Down Expand Up @@ -199,7 +186,7 @@ def gameDoubleClicked(self, game):

if (
self.party is not None
and self.party.memberCount > 1
and self.party.member_count > 1
and not self.leave_party()
):
return
Expand Down Expand Up @@ -235,7 +222,7 @@ def hostGameClicked(self, item):

if (
self.party is not None
and self.party.memberCount > 1
and self.party.member_count > 1
and not self.leave_party()
):
return
Expand Down Expand Up @@ -263,9 +250,7 @@ def teamListItemClicked(self, item):
menu.popup(QCursor.pos())

def updateParty(self, message):
players_ids = []
for member in message["members"]:
players_ids.append(member["player"])
players_ids = [member["player"] for member in message["members"]]

old_owner = self.client.players[self.party.owner_id]
new_owner = self.client.players[message["owner"]]
Expand All @@ -283,17 +268,15 @@ def updateParty(self, message):
new_party.owner_id = new_owner.id
for member in message["members"]:
players_id = member["player"]
new_party.addMember(
PartyMember(id_=players_id, factions=member["factions"]),
)
new_party.add_member(PartyMember(id_=players_id, factions=member["factions"]))
else:
new_party.owner_id = self._me.id
new_party.addMember(PartyMember(id_=self._me.id))
new_party.add_member(PartyMember(id_=self._me.id))

if self.party != new_party:
self.stopSearch()
self.party = new_party
if self.party.memberCount > 1:
if self.party.member_count > 1:
self.client._chatMVC.connection.join(
"#{}{}".format(new_owner.login, PARTY_CHANNEL_SUFFIX),
)
Expand All @@ -308,15 +291,15 @@ def showPartyInfo(self):
def hidePartyInfo(self):
self.partyInfo.hide()

def updatePartyInfoFrame(self):
if self.party.memberCount > 1:
def updatePartyInfoFrame(self) -> None:
if self.party.member_count > 1:
self.showPartyInfo()
else:
self.hidePartyInfo()

def updateTeamList(self):
def updateTeamList(self) -> None:
self.teamList.clear()
for member_id in self.party.memberIds:
for member_id in self.party.member_ids:
if member_id != self._me.id:
item = QtWidgets.QListWidgetItem(
self.client.players[member_id].login,
Expand Down
4 changes: 2 additions & 2 deletions src/games/automatchframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def updateLabelMatchingIn(self):

def startSearchRanked(self):
if (
self.games.party.memberCount > self.teamSize
self.games.party.member_count > self.teamSize
or self.games.party.owner_id != self.client.me.id
):
return
Expand Down Expand Up @@ -196,7 +196,7 @@ def stopSearchRanked(self):

def handlePartyUpdate(self):
if (
self.games.party.memberCount > self.teamSize
self.games.party.member_count > self.teamSize
or self.games.party.owner_id != self.client.me.id
):
self.rankedPlay.setEnabled(False)
Expand Down
4 changes: 2 additions & 2 deletions src/replays/_replayswidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def liveTreeDoubleClicked(self, item):

if (
self.client.games.party
and self.client.games.party.memberCount > 1
and self.client.games.party.member_count > 1
):
if not self.client.games.leave_party():
return
Expand Down Expand Up @@ -918,7 +918,7 @@ def online_tree_clicked(self, item: ReplayItem | QTreeWidgetItem) -> None:
def onlineTreeDoubleClicked(self, item):
if (
self.client.games.party
and self.client.games.party.memberCount > 1
and self.client.games.party.member_count > 1
):
if not self.client.games.leave_party():
return
Expand Down
12 changes: 0 additions & 12 deletions src/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import shutil
import subprocess
import sys
from enum import Enum
from typing import Self

from PyQt6 import QtWidgets
from PyQt6.QtCore import QDateTime
Expand Down Expand Up @@ -529,13 +527,3 @@ def capitalize(string: str) -> str:
Capitalize the first letter only, leave the rest as it is
"""
return f"{string[0].upper()}{string[1:]}"


class StringValuedEnum(Enum):

@classmethod
def from_string(cls, string: str) -> Self:
for member in iter(cls):
if member.value == string:
return member
raise ValueError("Unsupported value")

0 comments on commit ff01216

Please sign in to comment.