mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Add migrator
Attempts to fix incompatibilities in save files across builds. The idea is to try and handle the incompatibility as graceful as possible, and adding more "incompatibility fixes" in the future.
This commit is contained in:
parent
13cb4d321a
commit
5aed3fbb87
@ -1,2 +1,3 @@
|
|||||||
from .game import Game
|
from .game import Game
|
||||||
from .version import VERSION
|
from .version import VERSION
|
||||||
|
from .migrator import Migrator
|
||||||
|
|||||||
44
game/migrator.py
Normal file
44
game/migrator.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
from game.ato.packagewaypoints import PackageWaypoints
|
||||||
|
from game.data.doctrine import MODERN_DOCTRINE, COLDWAR_DOCTRINE, WWII_DOCTRINE
|
||||||
|
from game.utils import knots, feet, nautical_miles
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from game import Game
|
||||||
|
|
||||||
|
|
||||||
|
class Migrator:
|
||||||
|
def __init__(self, game: Game):
|
||||||
|
self.game = game
|
||||||
|
self._migrate_game()
|
||||||
|
|
||||||
|
def _migrate_game(self) -> None:
|
||||||
|
self._update_doctrine()
|
||||||
|
self._update_packagewaypoints()
|
||||||
|
|
||||||
|
def _update_doctrine(self) -> None:
|
||||||
|
doctrines = [
|
||||||
|
MODERN_DOCTRINE,
|
||||||
|
COLDWAR_DOCTRINE,
|
||||||
|
WWII_DOCTRINE,
|
||||||
|
]
|
||||||
|
for c in self.game.coalitions:
|
||||||
|
if c.faction.doctrine.__dict__ in [d.__dict__ for d in doctrines]:
|
||||||
|
continue
|
||||||
|
found = False
|
||||||
|
for d in doctrines:
|
||||||
|
if c.faction.doctrine.rendezvous_altitude == d.rendezvous_altitude:
|
||||||
|
c.faction.doctrine = d
|
||||||
|
found = True
|
||||||
|
break
|
||||||
|
if not found:
|
||||||
|
c.faction.doctrine = MODERN_DOCTRINE
|
||||||
|
|
||||||
|
def _update_packagewaypoints(self) -> None:
|
||||||
|
for c in self.game.coalitions:
|
||||||
|
for p in c.ato.packages:
|
||||||
|
if not hasattr(p.waypoints, "initial"):
|
||||||
|
p.waypoints = PackageWaypoints.create(p, c)
|
||||||
@ -19,7 +19,7 @@ from PySide2.QtWidgets import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
import qt_ui.uiconstants as CONST
|
import qt_ui.uiconstants as CONST
|
||||||
from game import Game, VERSION, persistency
|
from game import Game, VERSION, persistency, Migrator
|
||||||
from game.debriefing import Debriefing
|
from game.debriefing import Debriefing
|
||||||
from game.game import TurnState
|
from game.game import TurnState
|
||||||
from game.layout import LAYOUTS
|
from game.layout import LAYOUTS
|
||||||
@ -108,6 +108,7 @@ class QLiberationWindow(QMainWindow):
|
|||||||
try:
|
try:
|
||||||
logging.info("Loading last saved game : " + str(last_save_file))
|
logging.info("Loading last saved game : " + str(last_save_file))
|
||||||
game = persistency.load_game(last_save_file)
|
game = persistency.load_game(last_save_file)
|
||||||
|
Migrator(game)
|
||||||
self.onGameGenerated(game)
|
self.onGameGenerated(game)
|
||||||
self.updateWindowTitle(last_save_file if game else None)
|
self.updateWindowTitle(last_save_file if game else None)
|
||||||
except:
|
except:
|
||||||
@ -317,6 +318,7 @@ class QLiberationWindow(QMainWindow):
|
|||||||
)
|
)
|
||||||
if file is not None and file[0] != "":
|
if file is not None and file[0] != "":
|
||||||
game = persistency.load_game(file[0])
|
game = persistency.load_game(file[0])
|
||||||
|
Migrator(game)
|
||||||
GameUpdateSignal.get_instance().game_loaded.emit(game)
|
GameUpdateSignal.get_instance().game_loaded.emit(game)
|
||||||
|
|
||||||
self.updateWindowTitle(file[0])
|
self.updateWindowTitle(file[0])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user