Skip to content

Commit

Permalink
midsave
Browse files Browse the repository at this point in the history
  • Loading branch information
SpazElectro committed Sep 8, 2023
1 parent 4b29370 commit 5874e17
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions experiments/adminpanel/gui/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ def disassemble_packet(message):
else:
return None

connection = None
connection: wsc.ClientConnection
def websocket_loop(msgcallback, playercallback):
global connection
connection = wsc.connect("ws://localhost:1337")
print("Connected!")

while True:
data = connection.recv()
ctype, content = disassemble_packet(data)
ctype, content = disassemble_packet(data) # type: ignore

print(f"Packet type: {ctype}")
print(f"Packet content: {content}")
Expand Down
2 changes: 2 additions & 0 deletions experiments/adminpanel/gui/views/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from flet_route import Params, Basket

def IndexView(page: ft.Page, params: Params, basket: Basket):
# TODO: disable when not connected yet

return ft.View(
"/",
controls=[
Expand Down
17 changes: 11 additions & 6 deletions experiments/adminpanel/gui/views/players.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from general import websocket_send, assemble_packet
import json, base64

gpage = None
playersList = None
gpage: ft.Page
playersList: ft.ListView

class Player(ft.Row):
def __init__(self, name: str, char: str, fur: str, roasts: int, deaths: int, team: int):
def __init__(self, name: str, char: str, fur: bytes, roasts: int, deaths: int, team: int):
super().__init__()

self.name = name
Expand All @@ -19,18 +19,23 @@ def __init__(self, name: str, char: str, fur: str, roasts: int, deaths: int, tea
furC = fur[2]
furD = fur[3]

self.vertical_alignment = "start"
self.vertical_alignment = "start" # type: ignore
self.controls = [
ft.Row([
ft.Image(src=f"https://jj2multiplayer.online/fur/?a={furA}&b={furB}&c={furC}&d={furD}&char={char}&frame=3"),
ft.Text(name, selectable=True),
ft.Text(name),
ft.Text(value=f"{roasts} roasts", text_align=ft.TextAlign.RIGHT),
ft.Text(value=f"{deaths} deaths", text_align=ft.TextAlign.RIGHT),
# TODO: green and yellow
ft.Text(value=f"{'red' if team == 1 else 'blue'} team", text_align=ft.TextAlign.RIGHT),
], tight=True, spacing=5)
]

import hexdump
def on_player(content):
global playersList, gpage
players = json.loads(content)
playersList.controls = []

for data in players:
print(json.dumps(data, indent=2))
Expand All @@ -46,7 +51,7 @@ def PlayersView(page: ft.Page, params: Params, basket: Basket):
websocket_send(assemble_packet("request", "players"))

return ft.View("/players", [
ft.AppBar(leading=ft.Icon(ft.icons.PALETTE),
ft.AppBar(leading=ft.Icon(ft.icons.LIST_ROUNDED),
leading_width=40,
title=ft.Text("Player list"),
center_title=False,
Expand Down

0 comments on commit 5874e17

Please sign in to comment.