This commit is contained in:
Waylon Walker 2023-06-13 14:28:22 -05:00
parent 6676011ec6
commit 15a2cf2b3b
3 changed files with 12 additions and 25 deletions

View file

@ -2,7 +2,6 @@ from contextlib import contextmanager
from fastapi import APIRouter, Depends, WebSocket, WebSocketDisconnect
from fastapi.responses import HTMLResponse
from rich.console import Console
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlmodel import Session
@ -10,6 +9,7 @@ from websockets.exceptions import ConnectionClosed
from learn_sql_model.api.websocket_connection_manager import manager
from learn_sql_model.config import get_config, get_session
from learn_sql_model.console import console
from learn_sql_model.models.hero import HeroUpdate, Heros
web_socket_router = APIRouter()
@ -110,7 +110,7 @@ async def websocket_endpoint_hero_echo(
heros = con.execute("SELECT * FROM hero").fetchall()
heros = Heros.parse_obj({"heros": heros})
hero.update(session=session)
Console().print(heros)
console.print(heros)
await websocket.send_text(heros.json())
except WebSocketDisconnect:

View file

@ -1,4 +1,4 @@
from rich.console import Console
console = Console()
console.quiet = False
console.quiet = True

View file

@ -9,12 +9,12 @@
import atexit
import pygame
from rich.console import Console
import typer
from typer import Typer
from websocket import create_connection
from learn_sql_model.config import get_config
from learn_sql_model.console import console
from learn_sql_model.models.hero import Hero, HeroCreate, HeroDelete, HeroUpdate, Heros
speed = 10
@ -25,9 +25,6 @@ my_font = pygame.font.SysFont("Comic Sans MS", 30)
config = get_config()
console = Console()
console.quiet = True
class Client:
def __init__(self, name, secret_name):
@ -61,19 +58,6 @@ class Client:
connect()
return self._ws
@property
def ws_update(self):
def connect():
self._ws_update = create_connection(
f"ws://{config.api_client.host}:{config.api_client.port}/ws-hero-update"
)
if not hasattr(self, "_ws_update"):
connect()
if not self._ws_update.connected:
connect()
return self._ws_update
def run(self):
while self.running:
console.print("running")
@ -119,11 +103,14 @@ class Client:
others = Heros.parse_raw(raw_heros)
for other in others.heros:
pygame.draw.circle(self.screen, (255, 0, 0), (other.x, other.y), other.size)
self.screen.blit(
my_font.render(other.name, False, (255, 255, 255), 1),
(other.x, other.y),
)
if other.id != self.hero.id:
pygame.draw.circle(
self.screen, (255, 0, 0), (other.x, other.y), other.size
)
self.screen.blit(
my_font.render(other.name, False, (255, 255, 255), 1),
(other.x, other.y),
)
pygame.draw.circle(
self.screen, (0, 0, 255), (self.hero.x, self.hero.y), self.hero.size