aboutsummaryrefslogtreecommitdiff
path: root/kennel
diff options
context:
space:
mode:
Diffstat (limited to 'kennel')
-rw-r--r--kennel/config.py3
-rw-r--r--kennel/engine/components/component.py2
-rw-r--r--kennel/engine/entities/entity.py3
-rw-r--r--kennel/engine/entities/laser.py5
-rw-r--r--kennel/engine/game.py8
-rw-r--r--kennel/engine/systems/network.py15
-rw-r--r--kennel/engine/systems/system.py3
-rw-r--r--kennel/engine/systems/world.py6
-rw-r--r--kennel/kennel.py21
-rw-r--r--kennel/kennelcats.py1
-rw-r--r--kennel/main.py34
-rw-r--r--kennel/middleware.py5
12 files changed, 60 insertions, 46 deletions
diff --git a/kennel/config.py b/kennel/config.py
index 4452044..a731c84 100644
--- a/kennel/config.py
+++ b/kennel/config.py
@@ -1,6 +1,7 @@
-from dotenv import load_dotenv
import os
+from dotenv import load_dotenv
+
load_dotenv()
diff --git a/kennel/engine/components/component.py b/kennel/engine/components/component.py
index da55138..9f56407 100644
--- a/kennel/engine/components/component.py
+++ b/kennel/engine/components/component.py
@@ -1,5 +1,5 @@
-from enum import Enum
from abc import abstractmethod
+from enum import Enum
class ComponentType(str, Enum):
diff --git a/kennel/engine/entities/entity.py b/kennel/engine/entities/entity.py
index 1d8c34d..d40ab19 100644
--- a/kennel/engine/entities/entity.py
+++ b/kennel/engine/entities/entity.py
@@ -1,7 +1,8 @@
from enum import Enum
-from kennel.engine.components.component import Component, ComponentType
from typing import List, Optional
+from kennel.engine.components.component import Component, ComponentType
+
class EntityType(str, Enum):
LASER = "LASER"
diff --git a/kennel/engine/entities/laser.py b/kennel/engine/entities/laser.py
index ead72a6..09c3c93 100644
--- a/kennel/engine/entities/laser.py
+++ b/kennel/engine/entities/laser.py
@@ -1,6 +1,7 @@
-from .entity import Entity, EntityType
-from kennel.engine.components.position import Position
from kennel.engine.components.controllable import Controllable
+from kennel.engine.components.position import Position
+
+from .entity import Entity, EntityType
class Laser(Entity):
diff --git a/kennel/engine/game.py b/kennel/engine/game.py
index f3134be..80e47bd 100644
--- a/kennel/engine/game.py
+++ b/kennel/engine/game.py
@@ -1,9 +1,9 @@
+import asyncio
+import time
+
+from kennel.app import logger
from kennel.engine.entities.entity import EntityManager
from kennel.engine.systems.system import SystemManager
-from kennel.app import logger
-from typing import List, Optional
-import time
-import asyncio
class Game:
diff --git a/kennel/engine/systems/network.py b/kennel/engine/systems/network.py
index 96ebc46..1c1d71c 100644
--- a/kennel/engine/systems/network.py
+++ b/kennel/engine/systems/network.py
@@ -1,9 +1,12 @@
+import asyncio
+from abc import abstractmethod
from enum import Enum
-from kennel.engine.entities.entity import Entity, EntityType, EntityManager
+from typing import List, Optional
+
+from kennel.app import logger
+from kennel.engine.entities.entity import Entity, EntityManager
+
from .system import System, SystemType
-from abc import abstractmethod
-from typing import Optional, List
-import asyncio
class EventType(str, Enum):
@@ -101,7 +104,9 @@ class Publishable:
class EventProcessor:
@abstractmethod
- def accept(self, entity_manager: EntityManager, event: Event | tuple[Event, str]) -> None:
+ def accept(
+ self, entity_manager: EntityManager, event: Event | tuple[Event, str]
+ ) -> None:
pass
diff --git a/kennel/engine/systems/system.py b/kennel/engine/systems/system.py
index 78bda58..e3ddb27 100644
--- a/kennel/engine/systems/system.py
+++ b/kennel/engine/systems/system.py
@@ -1,6 +1,7 @@
+from abc import abstractmethod
from enum import Enum
+
from kennel.engine.entities.entity import EntityManager
-from abc import abstractmethod
class SystemType(str, Enum):
diff --git a/kennel/engine/systems/world.py b/kennel/engine/systems/world.py
index 396e7cb..b74816f 100644
--- a/kennel/engine/systems/world.py
+++ b/kennel/engine/systems/world.py
@@ -1,7 +1,7 @@
-from kennel.engine.systems.system import System, SystemType
-from kennel.engine.entities.entity import EntityManager
-from kennel.engine.components.component import ComponentType
from kennel.app import logger
+from kennel.engine.components.component import ComponentType
+from kennel.engine.entities.entity import EntityManager
+from kennel.engine.systems.system import System, SystemType
class WorldSystem(System):
diff --git a/kennel/kennel.py b/kennel/kennel.py
index b1dc90a..1e23670 100644
--- a/kennel/kennel.py
+++ b/kennel/kennel.py
@@ -1,21 +1,22 @@
-from kennel.engine.game import Game
+import uuid
+from typing import List
+
+from kennel.config import config
from kennel.engine.components.component import ComponentType
-from kennel.engine.entities.entity import EntityManager, Entity
+from kennel.engine.entities.entity import Entity, EntityManager
from kennel.engine.entities.laser import Laser
-from kennel.engine.systems.system import SystemManager
+from kennel.engine.game import Game
from kennel.engine.systems.network import (
- NetworkSystem,
- EventProcessor,
+ EntityPositionUpdateEvent,
Event,
+ EventProcessor,
EventType,
- Entity,
- EntityPositionUpdateEvent,
+ NetworkSystem,
)
+from kennel.engine.systems.system import SystemManager
from kennel.engine.systems.world import WorldSystem
-from kennel.config import config
+
from .app import logger
-from typing import List
-import uuid
entity_manager = EntityManager()
system_manager = SystemManager()
diff --git a/kennel/kennelcats.py b/kennel/kennelcats.py
index 340b07e..970e44f 100644
--- a/kennel/kennelcats.py
+++ b/kennel/kennelcats.py
@@ -1,5 +1,6 @@
from datetime import datetime
from typing import List
+
import requests
diff --git a/kennel/main.py b/kennel/main.py
index fc0fd0e..c1106fe 100644
--- a/kennel/main.py
+++ b/kennel/main.py
@@ -1,37 +1,37 @@
+import asyncio
+import uuid
+from typing import Annotated, Optional
+
from fastapi import (
- FastAPI,
+ Cookie,
+ Depends,
Request,
Response,
WebSocket,
+ WebSocketDisconnect,
WebSocketException,
status,
- Cookie,
- Depends,
)
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles
-from kennel.engine.systems.system import SystemType
+
+from kennel.app import app, logger
+from kennel.config import config
from kennel.engine.systems.network import (
+ EntityBornEvent,
Event,
- Publishable,
EventType,
InitialStateEvent,
+ Publishable,
SetControllableEvent,
- EntityBornEvent,
)
-from typing import Annotated, Optional
+from kennel.engine.systems.system import SystemType
from kennel.kennel import (
+ create_session_controllable_entities,
+ entity_manager,
kennel,
system_manager,
- entity_manager,
- create_session_controllable_entities,
)
-from kennel.app import app, logger
-from kennel.kennelcats import KennelCatService
-from kennel.middleware import logger_middleware
-from kennel.config import config
-import asyncio
-import uuid
app.mount("/static", StaticFiles(directory="static/dist"), name="static")
@@ -118,7 +118,7 @@ async def websocket_endpoint(
network_system.add_client(session, WebSocketClient(websocket))
while True:
message = await websocket.receive_json()
- if type(message) is not list:
+ if not isinstance(message, list):
message = [message]
events = [Event.from_dict(event) for event in message]
if not all([event is not None for event in events]):
@@ -126,7 +126,7 @@ async def websocket_endpoint(
continue
for event in events:
network_system.client_event(session, event)
- except WebSocketDisconnect as e:
+ except WebSocketDisconnect:
logger.info(f"Websocket connection closed by client: {session}")
except Exception as e:
logger.error("Exception occurred", exc_info=e)
diff --git a/kennel/middleware.py b/kennel/middleware.py
index dddf63b..7bc932f 100644
--- a/kennel/middleware.py
+++ b/kennel/middleware.py
@@ -1,8 +1,11 @@
import uuid
+
import structlog
-from fastapi import Request, Response
+from fastapi import Request
+
from .app import app, logger
+
@app.middleware("http")
async def logger_middleware(request: Request, call_next):
structlog.contextvars.clear_contextvars()