mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Move front lines out of MapModel.
This commit is contained in:
@@ -1,9 +1,24 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from game.server.leaflet import LeafletPoint
|
||||
from game.theater import FrontLine
|
||||
from game.utils import nautical_miles
|
||||
|
||||
|
||||
class FrontLineJs(BaseModel):
|
||||
id: UUID
|
||||
extents: list[LeafletPoint]
|
||||
|
||||
@staticmethod
|
||||
def for_front_line(front_line: FrontLine) -> FrontLineJs:
|
||||
a = front_line.position.point_from_heading(
|
||||
front_line.attack_heading.right.degrees, nautical_miles(2).meters
|
||||
)
|
||||
b = front_line.position.point_from_heading(
|
||||
front_line.attack_heading.left.degrees, nautical_miles(2).meters
|
||||
)
|
||||
return FrontLineJs(id=front_line.id, extents=[a.latlng(), b.latlng()])
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from game import Game
|
||||
from game.utils import nautical_miles
|
||||
from .models import FrontLineJs
|
||||
from ..dependencies import GameContext
|
||||
|
||||
@@ -10,13 +11,11 @@ router: APIRouter = APIRouter(prefix="/front-lines")
|
||||
|
||||
@router.get("/")
|
||||
def list_front_lines(game: Game = Depends(GameContext.get)) -> list[FrontLineJs]:
|
||||
front_lines = []
|
||||
for front_line in game.theater.conflicts():
|
||||
a = front_line.position.point_from_heading(
|
||||
front_line.attack_heading.right.degrees, nautical_miles(2).meters
|
||||
)
|
||||
b = front_line.position.point_from_heading(
|
||||
front_line.attack_heading.left.degrees, nautical_miles(2).meters
|
||||
)
|
||||
front_lines.append(FrontLineJs(extents=[a.latlng(), b.latlng()]))
|
||||
return front_lines
|
||||
return [FrontLineJs.for_front_line(f) for f in game.theater.conflicts()]
|
||||
|
||||
|
||||
@router.get("/{front_line_id}")
|
||||
def get_front_line(
|
||||
front_line_id: UUID, game: Game = Depends(GameContext.get)
|
||||
) -> FrontLineJs:
|
||||
return FrontLineJs.for_front_line(game.db.front_lines.get(front_line_id))
|
||||
|
||||
Reference in New Issue
Block a user