Skip to content

Commit

Permalink
chore: remove experimental menu system (#535)
Browse files Browse the repository at this point in the history
* Remove experimental menu system

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
minisbett and pre-commit-ci[bot] authored Sep 28, 2023
1 parent c777a83 commit 8302818
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 153 deletions.
1 change: 0 additions & 1 deletion .github/docs/wiki/Project-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
| | ├── clan.py # representation of individual clans
| | ├── collection.py # collections of dynamic objects (for in-memory storage)
| | ├── match.py # individual multiplayer matches
| | ├── menu.py # (WIP) concept for interactive menus in chat channels
| | ├── models.py # structures of api request bodies
| | ├── player.py # representation of individual players
| | └── score.py # representation of individual scores
Expand Down
1 change: 0 additions & 1 deletion .github/docs/wiki/locale/de-DE/Project-structure-de-DE.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
| | ├── clan.py # Darstellung der einzelnen Clans
| | ├── collection.py # Sammlungen von dynamischen Objekten (zur Speicherung im Speicher)
| | ├── match.py # individuelle Multiplayer-Matches
| | ├── menu.py # (WIP) Konzept für interaktive Menüs in Chat-Kanälen
| | ├── models.py # Strukturen von Api-Anfragekörpern
| | ├── player.py # Darstellung der einzelnen Spieler
| | └── score.py # Darstellung einzelner Spielstände
Expand Down
1 change: 0 additions & 1 deletion .github/docs/wiki/locale/zh-CN/Project-structure-zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
| | ├── clan.py # 有关个人的地区(clans)
| | ├── collection.py # 动态类的集合 (存储在内存中)
| | ├── match.py # 多人比赛
| | ├── menu.py # (-正在制作中-) 聊天频道中的交互菜单
| | ├── models.py # api请求主体(bodies)的结构
| | ├── player.py # 关于个人的players
| | └── score.py # 有关个人的score
Expand Down
43 changes: 0 additions & 43 deletions app/api/domains/cho.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
from app.objects.match import MatchWinConditions
from app.objects.match import Slot
from app.objects.match import SlotStatus
from app.objects.menu import Menu
from app.objects.menu import MenuCommands
from app.objects.menu import MenuFunction
from app.objects.player import Action
from app.objects.player import ClientDetails
from app.objects.player import OsuStream
Expand Down Expand Up @@ -1370,53 +1367,13 @@ async def handle(self, player: Player) -> None:
log(f"{player} created a new multiplayer match.")


async def execute_menu_option(player: Player, key: int) -> None:
if key not in player.current_menu.options:
return

# this is one of their menu options, execute it.
cmd, data = player.current_menu.options[key]

if app.settings.DEBUG:
print(f"\x1b[0;95m{cmd!r}\x1b[0m {data}")

if cmd == MenuCommands.Reset:
# go back to the main menu
player.current_menu = player.previous_menus[0]
player.previous_menus.clear()
elif cmd == MenuCommands.Back:
# return one menu back
player.current_menu = player.previous_menus.pop()
player.send_current_menu()
elif cmd == MenuCommands.Advance:
# advance to a new menu
assert isinstance(data, Menu)
player.previous_menus.append(player.current_menu)
player.current_menu = data
player.send_current_menu()
elif cmd == MenuCommands.Execute:
# execute a function on the current menu
assert isinstance(data, MenuFunction)
await data.callback(player)


@register(ClientPackets.JOIN_MATCH)
class MatchJoin(BasePacket):
def __init__(self, reader: BanchoPacketReader) -> None:
self.match_id = reader.read_i32()
self.match_passwd = reader.read_string()

async def handle(self, player: Player) -> None:
is_menu_request = self.match_id >= 64 # max multi matches

if is_menu_request or self.match_id < 0:
if is_menu_request:
# NOTE: this function is unrelated to mp.
await execute_menu_option(player, self.match_id)

player.enqueue(app.packets.match_join_fail())
return

match = app.state.sessions.matches[self.match_id]
if not match:
log(f"{player} tried to join a non-existant mp lobby?")
Expand Down
8 changes: 0 additions & 8 deletions app/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,14 +1180,6 @@ async def wipemap(ctx: Context) -> str | None:
return "Scores wiped."


@command(Privileges.DEVELOPER, hidden=True)
async def menu(ctx: Context) -> str | None:
"""Temporary command to illustrate the menu option idea."""
ctx.player.send_current_menu()

return None


@command(Privileges.DEVELOPER, aliases=["re"])
async def reload(ctx: Context) -> str | None:
"""Reload a python module."""
Expand Down
1 change: 0 additions & 1 deletion app/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from . import clan
from . import collections
from . import match
from . import menu
from . import models
from . import player
from . import score
37 changes: 0 additions & 37 deletions app/objects/menu.py

This file was deleted.

61 changes: 0 additions & 61 deletions app/objects/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
from app.objects.match import MatchTeamTypes
from app.objects.match import Slot
from app.objects.match import SlotStatus
from app.objects.menu import Menu
from app.objects.menu import menu_keygen
from app.objects.menu import MenuCommands
from app.objects.menu import MenuFunction
from app.objects.score import Grade
from app.repositories import stats as stats_repo
from app.utils import escape_enum
Expand Down Expand Up @@ -113,33 +109,6 @@ class Status:
map_id: int = 0


# temporary menu-related stuff
async def bot_hello(player: Player) -> None:
player.send_bot(f"hello {player.name}!")


async def notif_hello(player: Player) -> None:
player.enqueue(app.packets.notification(f"hello {player.name}!"))


MENU2 = Menu(
"Second Menu",
{
menu_keygen(): (MenuCommands.Back, None),
menu_keygen(): (MenuCommands.Execute, MenuFunction("notif_hello", notif_hello)),
},
)

MAIN_MENU = Menu(
"Main Menu",
{
menu_keygen(): (MenuCommands.Execute, MenuFunction("bot_hello", bot_hello)),
menu_keygen(): (MenuCommands.Execute, MenuFunction("notif_hello", notif_hello)),
menu_keygen(): (MenuCommands.Advance, MENU2),
},
)


class LastNp(TypedDict):
bmap: Beatmap
mode_vn: int
Expand Down Expand Up @@ -312,10 +281,6 @@ def __init__(
# store the last beatmap /np'ed by the user.
self.last_np: LastNp | None = None

# TODO: document
self.current_menu = MAIN_MENU
self.previous_menus: list[Menu] = []

# subject to possible change in the future,
# although if anything, bot accounts will
# probably just use the /api/ routes?
Expand Down Expand Up @@ -1040,32 +1005,6 @@ async def stats_from_sql_full(self, db_conn: databases.core.Connection) -> None:
},
)

def send_menu_clear(self) -> None:
"""Clear the user's osu! chat with the bot
to make room for a new menu to be sent."""
# NOTE: the only issue with this is that it will
# wipe any messages the client can see from the bot
# (including any other channels). perhaps menus can
# be sent from a separate presence to prevent this?
self.enqueue(app.packets.user_silenced(app.state.sessions.bot.id))

def send_current_menu(self) -> None:
"""Forward a standardized form of the user's
current menu to them via the osu! chat."""
msg = [self.current_menu.name]

for key, (cmd, data) in self.current_menu.options.items():
val = data.name if data else "Back"
msg.append(f"[osump://{key}/ {val}]")

chat_height = 10
lines_used = len(msg)
if lines_used < chat_height:
msg += [chr(8192)] * (chat_height - lines_used)

self.send_menu_clear()
self.send_bot("\n".join(msg))

def update_latest_activity_soon(self) -> None:
"""Update the player's latest activity in the database."""
task = app.state.services.database.execute(
Expand Down

0 comments on commit 8302818

Please sign in to comment.