From 15a2cf2b3b5be92982dc4d2926b88d8c9d852d14 Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Tue, 13 Jun 2023 14:28:22 -0500 Subject: [PATCH] wip --- learn_sql_model/api/websocket.py | 4 ++-- learn_sql_model/console.py | 2 +- learn_sql_model/game/game.py | 31 +++++++++---------------------- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/learn_sql_model/api/websocket.py b/learn_sql_model/api/websocket.py index cce11ed..aed8f6d 100644 --- a/learn_sql_model/api/websocket.py +++ b/learn_sql_model/api/websocket.py @@ -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: diff --git a/learn_sql_model/console.py b/learn_sql_model/console.py index a25f03e..d160979 100644 --- a/learn_sql_model/console.py +++ b/learn_sql_model/console.py @@ -1,4 +1,4 @@ from rich.console import Console console = Console() -console.quiet = False +console.quiet = True diff --git a/learn_sql_model/game/game.py b/learn_sql_model/game/game.py index 15c68a0..fcf58fe 100644 --- a/learn_sql_model/game/game.py +++ b/learn_sql_model/game/game.py @@ -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