From 103675e5bb175614d828c45d1dfd17d189978afd Mon Sep 17 00:00:00 2001 From: Magnus Wolffelt Date: Sat, 14 Aug 2021 21:45:23 +0200 Subject: [PATCH] Make some paths cross-platform compatible (#1543) * Make some paths cross-platform compatible * Fix lint error for Path --- game/theater/conflicttheater.py | 14 +++++++------- game/theater/landmap.py | 3 ++- qt_ui/windows/newgame/QCampaignList.py | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/game/theater/conflicttheater.py b/game/theater/conflicttheater.py index 7f9fee11..dc2d3e53 100644 --- a/game/theater/conflicttheater.py +++ b/game/theater/conflicttheater.py @@ -292,7 +292,7 @@ class CaucasusTheater(ConflictTheater): ReferencePoint(caucasus.Batumi.position, Point(1307, 1205)), ) - landmap = load_landmap("resources\\caulandmap.p") + landmap = load_landmap(Path("resources/caulandmap.p")) daytime_map = { "dawn": (6, 9), "day": (9, 18), @@ -320,7 +320,7 @@ class PersianGulfTheater(ConflictTheater): ReferencePoint(persiangulf.Jiroft.position, Point(1692, 1343)), ReferencePoint(persiangulf.Liwa_AFB.position, Point(358, 3238)), ) - landmap = load_landmap("resources\\gulflandmap.p") + landmap = load_landmap(Path("resources/gulflandmap.p")) daytime_map = { "dawn": (6, 8), "day": (8, 16), @@ -348,7 +348,7 @@ class NevadaTheater(ConflictTheater): ReferencePoint(nevada.Mina_Airport_3Q0.position, Point(252, 295)), ReferencePoint(nevada.Laughlin_Airport.position, Point(844, 909)), ) - landmap = load_landmap("resources\\nevlandmap.p") + landmap = load_landmap(Path("resources/nevlandmap.p")) daytime_map = { "dawn": (4, 6), "day": (6, 17), @@ -376,7 +376,7 @@ class NormandyTheater(ConflictTheater): ReferencePoint(normandy.Needs_Oar_Point.position, Point(515, 329)), ReferencePoint(normandy.Evreux.position, Point(2029, 1709)), ) - landmap = load_landmap("resources\\normandylandmap.p") + landmap = load_landmap(Path("resources/normandylandmap.p")) daytime_map = { "dawn": (6, 8), "day": (10, 17), @@ -404,7 +404,7 @@ class TheChannelTheater(ConflictTheater): ReferencePoint(thechannel.Abbeville_Drucat.position, Point(2005, 2390)), ReferencePoint(thechannel.Detling.position, Point(706, 382)), ) - landmap = load_landmap("resources\\channellandmap.p") + landmap = load_landmap(Path("resources/channellandmap.p")) daytime_map = { "dawn": (6, 8), "day": (10, 17), @@ -432,7 +432,7 @@ class SyriaTheater(ConflictTheater): ReferencePoint(syria.Eyn_Shemer.position, Point(564, 1289)), ReferencePoint(syria.Tabqa.position, Point(1329, 491)), ) - landmap = load_landmap("resources\\syrialandmap.p") + landmap = load_landmap(Path("resources/syrialandmap.p")) daytime_map = { "dawn": (6, 8), "day": (8, 16), @@ -457,7 +457,7 @@ class MarianaIslandsTheater(ConflictTheater): terrain = marianaislands.MarianaIslands() overview_image = "marianaislands.gif" - landmap = load_landmap("resources\\marianaislandslandmap.p") + landmap = load_landmap(Path("resources/marianaislandslandmap.p")) daytime_map = { "dawn": (6, 8), "day": (8, 16), diff --git a/game/theater/landmap.py b/game/theater/landmap.py index 2cc3867c..8192b057 100644 --- a/game/theater/landmap.py +++ b/game/theater/landmap.py @@ -3,6 +3,7 @@ import pickle from functools import cached_property from typing import Optional, Tuple, Union import logging +from pathlib import Path from shapely import geometry from shapely.geometry import MultiPolygon, Polygon @@ -27,7 +28,7 @@ class Landmap: return self.inclusion_zones - self.exclusion_zones - self.sea_zones -def load_landmap(filename: str) -> Optional[Landmap]: +def load_landmap(filename: Path) -> Optional[Landmap]: try: with open(filename, "rb") as f: return pickle.load(f) diff --git a/qt_ui/windows/newgame/QCampaignList.py b/qt_ui/windows/newgame/QCampaignList.py index 1fae35bc..1832baa4 100644 --- a/qt_ui/windows/newgame/QCampaignList.py +++ b/qt_ui/windows/newgame/QCampaignList.py @@ -104,7 +104,7 @@ class Campaign: def load_campaigns() -> List[Campaign]: - campaign_dir = Path("resources\\campaigns") + campaign_dir = Path("resources/campaigns") campaigns = [] for path in campaign_dir.glob("*.json"): try: