Color navmesh zones based on threat.

This commit is contained in:
Dan Albert 2021-07-13 17:49:10 -07:00
parent 5f8be5fa91
commit a1910f49a8
2 changed files with 33 additions and 6 deletions

View File

@ -12,7 +12,7 @@ from shapely.geometry import LineString, Point as ShapelyPoint, Polygon, MultiPo
from game import Game from game import Game
from game.dcs.groundunittype import GroundUnitType from game.dcs.groundunittype import GroundUnitType
from game.navmesh import NavMesh from game.navmesh import NavMesh, NavMeshPoly
from game.profiling import logged_duration from game.profiling import logged_duration
from game.theater import ( from game.theater import (
ConflictTheater, ConflictTheater,
@ -646,11 +646,35 @@ class ThreatZoneContainerJs(QObject):
return self._red return self._red
class NavMeshPolyJs(QObject):
polyChanged = Signal()
threatenedChanged = Signal()
def __init__(self, poly: LeafletPoly, threatened: bool) -> None:
super().__init__()
self._poly = poly
self._threatened = threatened
@Property(list, notify=polyChanged)
def poly(self) -> LeafletPoly:
return self._poly
@Property(bool, notify=threatenedChanged)
def threatened(self) -> bool:
return self._threatened
@classmethod
def from_navmesh(cls, poly: NavMeshPoly, theater: ConflictTheater) -> NavMeshPolyJs:
return NavMeshPolyJs(
shapely_poly_to_leaflet_points(poly.poly, theater), poly.threatened
)
class NavMeshJs(QObject): class NavMeshJs(QObject):
blueChanged = Signal() blueChanged = Signal()
redChanged = Signal() redChanged = Signal()
def __init__(self, blue: list[LeafletPoly], red: list[LeafletPoly]) -> None: def __init__(self, blue: list[NavMeshPolyJs], red: list[NavMeshPolyJs]) -> None:
super().__init__() super().__init__()
self._blue = blue self._blue = blue
self._red = red self._red = red
@ -667,10 +691,10 @@ class NavMeshJs(QObject):
return self._red return self._red
@staticmethod @staticmethod
def to_polys(navmesh: NavMesh, theater: ConflictTheater) -> list[LeafletPoly]: def to_polys(navmesh: NavMesh, theater: ConflictTheater) -> list[NavMeshPolyJs]:
polys = [] polys = []
for poly in navmesh.polys: for poly in navmesh.polys:
polys.append(shapely_poly_to_leaflet_points(poly.poly, theater)) polys.append(NavMeshPolyJs.from_navmesh(poly, theater))
return polys return polys
@classmethod @classmethod

View File

@ -904,10 +904,13 @@ function drawThreatZones() {
function drawNavmesh(zones, layer) { function drawNavmesh(zones, layer) {
for (const zone of zones) { for (const zone of zones) {
L.polyline(zone, { L.polyline(zone.poly, {
color: "#000000", color: "#000000",
weight: 1, weight: 1,
fill: false, fillColor: zone.threatened ? "#ff0000" : "#00ff00",
fill: true,
fillOpacity: 0.1,
noClip: true,
interactive: false, interactive: false,
}).addTo(layer); }).addTo(layer);
} }