wip
This commit is contained in:
parent
6676011ec6
commit
15a2cf2b3b
3 changed files with 12 additions and 25 deletions
|
|
@ -2,7 +2,6 @@ from contextlib import contextmanager
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, WebSocket, WebSocketDisconnect
|
from fastapi import APIRouter, Depends, WebSocket, WebSocketDisconnect
|
||||||
from fastapi.responses import HTMLResponse
|
from fastapi.responses import HTMLResponse
|
||||||
from rich.console import Console
|
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.orm import scoped_session, sessionmaker
|
from sqlalchemy.orm import scoped_session, sessionmaker
|
||||||
from sqlmodel import Session
|
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.api.websocket_connection_manager import manager
|
||||||
from learn_sql_model.config import get_config, get_session
|
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
|
from learn_sql_model.models.hero import HeroUpdate, Heros
|
||||||
|
|
||||||
web_socket_router = APIRouter()
|
web_socket_router = APIRouter()
|
||||||
|
|
@ -110,7 +110,7 @@ async def websocket_endpoint_hero_echo(
|
||||||
heros = con.execute("SELECT * FROM hero").fetchall()
|
heros = con.execute("SELECT * FROM hero").fetchall()
|
||||||
heros = Heros.parse_obj({"heros": heros})
|
heros = Heros.parse_obj({"heros": heros})
|
||||||
hero.update(session=session)
|
hero.update(session=session)
|
||||||
Console().print(heros)
|
console.print(heros)
|
||||||
await websocket.send_text(heros.json())
|
await websocket.send_text(heros.json())
|
||||||
|
|
||||||
except WebSocketDisconnect:
|
except WebSocketDisconnect:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
|
|
||||||
console = Console()
|
console = Console()
|
||||||
console.quiet = False
|
console.quiet = True
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,12 @@
|
||||||
import atexit
|
import atexit
|
||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
from rich.console import Console
|
|
||||||
import typer
|
import typer
|
||||||
from typer import Typer
|
from typer import Typer
|
||||||
from websocket import create_connection
|
from websocket import create_connection
|
||||||
|
|
||||||
from learn_sql_model.config import get_config
|
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
|
from learn_sql_model.models.hero import Hero, HeroCreate, HeroDelete, HeroUpdate, Heros
|
||||||
|
|
||||||
speed = 10
|
speed = 10
|
||||||
|
|
@ -25,9 +25,6 @@ my_font = pygame.font.SysFont("Comic Sans MS", 30)
|
||||||
|
|
||||||
config = get_config()
|
config = get_config()
|
||||||
|
|
||||||
console = Console()
|
|
||||||
console.quiet = True
|
|
||||||
|
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
def __init__(self, name, secret_name):
|
def __init__(self, name, secret_name):
|
||||||
|
|
@ -61,19 +58,6 @@ class Client:
|
||||||
connect()
|
connect()
|
||||||
return self._ws
|
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):
|
def run(self):
|
||||||
while self.running:
|
while self.running:
|
||||||
console.print("running")
|
console.print("running")
|
||||||
|
|
@ -119,7 +103,10 @@ class Client:
|
||||||
others = Heros.parse_raw(raw_heros)
|
others = Heros.parse_raw(raw_heros)
|
||||||
|
|
||||||
for other in others.heros:
|
for other in others.heros:
|
||||||
pygame.draw.circle(self.screen, (255, 0, 0), (other.x, other.y), other.size)
|
if other.id != self.hero.id:
|
||||||
|
pygame.draw.circle(
|
||||||
|
self.screen, (255, 0, 0), (other.x, other.y), other.size
|
||||||
|
)
|
||||||
self.screen.blit(
|
self.screen.blit(
|
||||||
my_font.render(other.name, False, (255, 255, 255), 1),
|
my_font.render(other.name, False, (255, 255, 255), 1),
|
||||||
(other.x, other.y),
|
(other.x, other.y),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue