Added moddable campaigns through json files.

This commit is contained in:
Khopa
2020-10-07 00:09:11 +02:00
parent 9101dae38a
commit 71f77dd8fb
10 changed files with 185 additions and 1031 deletions

View File

@@ -85,10 +85,10 @@ def load_icons():
ICONS["Hangar"] = QPixmap("./resources/ui/misc/hangar.png")
ICONS["Terrain_Caucasus"] = QPixmap("./resources/ui/terrain_caucasus.gif")
ICONS["Terrain_Persian_Gulf"] = QPixmap("./resources/ui/terrain_pg.gif")
ICONS["Terrain_PersianGulf"] = QPixmap("./resources/ui/terrain_pg.gif")
ICONS["Terrain_Nevada"] = QPixmap("./resources/ui/terrain_nevada.gif")
ICONS["Terrain_Normandy"] = QPixmap("./resources/ui/terrain_normandy.gif")
ICONS["Terrain_Channel"] = QPixmap("./resources/ui/terrain_channel.gif")
ICONS["Terrain_TheChannel"] = QPixmap("./resources/ui/terrain_channel.gif")
ICONS["Terrain_Syria"] = QPixmap("./resources/ui/terrain_syria.gif")
ICONS["Dawn"] = QPixmap("./resources/ui/daytime/dawn.png")

View File

@@ -1,41 +1,38 @@
import json
import logging
import os
from PySide2 import QtGui
from PySide2.QtCore import QSize, QItemSelectionModel
from PySide2.QtGui import QStandardItemModel, QStandardItem
from PySide2.QtWidgets import QListView, QAbstractItemView
from theater import caucasus, nevada, persiangulf, normandy, thechannel, syria
from theater import caucasus, nevada, persiangulf, normandy, thechannel, syria, ConflictTheater
import qt_ui.uiconstants as CONST
CAMPAIGNS = [
("Caucasus - Western Georgia", caucasus.WesternGeorgia, "Terrain_Caucasus"),
("Caucasus - Russia Small", caucasus.RussiaSmall, "Terrain_Caucasus"),
("Caucasus - North Caucasus", caucasus.NorthCaucasus, "Terrain_Caucasus"),
("Caucasus - Full Map", caucasus.CaucasusTheater, "Terrain_Caucasus"),
("Nevada - North Nevada", nevada.NevadaTheater, "Terrain_Nevada"),
("Persian Gulf - Invasion of Iran", persiangulf.IranianCampaign, "Terrain_Persian_Gulf"),
("Persian Gulf - Invasion of Iran [Lite]", persiangulf.IranInvasionLite, "Terrain_Persian_Gulf"),
("Persian Gulf - Emirates", persiangulf.Emirates, "Terrain_Persian_Gulf"),
("Persian Gulf - Desert War", persiangulf.DesertWar, "Terrain_Persian_Gulf"),
("Persian Gulf - Full Map", persiangulf.PersianGulfTheater, "Terrain_Persian_Gulf"),
("Syria - Golan heights battle", syria.GolanHeights, "Terrain_Syria"),
("Syria - Invasion from Turkey", syria.TurkishInvasion, "Terrain_Syria"),
("Syria - Syrian Civil War", syria.SyrianCivilWar, "Terrain_Syria"),
("Syria - Inherent Resolve", syria.InherentResolve, "Terrain_Syria"),
("Syria - Full Map", syria.SyriaFullMap, "Terrain_Syria"),
("Normandy - Normandy", normandy.NormandyTheater, "Terrain_Normandy"),
("Normandy - Normandy Small", normandy.NormandySmall, "Terrain_Normandy"),
("The Channel - Battle of Britain", thechannel.BattleOfBritain, "Terrain_Channel"),
("The Channel - Dunkirk", thechannel.Dunkirk, "Terrain_Channel"),
]
CAMPAIGN_DIR = ".\\resources\\campaigns"
CAMPAIGNS = []
# Load the campaigns files from the directory
campaign_files = os.listdir(CAMPAIGN_DIR)
for f in campaign_files:
try:
ff = os.path.join(CAMPAIGN_DIR, f)
with open(ff, "r") as campaign_data:
data = json.load(campaign_data)
choice = (data["name"], ff, "Terrain_" + data["theater"].replace(" ", ""))
logging.info("Loaded campaign : " + data["name"])
CAMPAIGNS.append(choice)
ConflictTheater.from_file(choice[1])
logging.info("Loaded campaign :" + ff)
except Exception as e:
logging.info("Unable to load campaign :" + f)
class QCampaignItem(QStandardItem):
def __init__(self, text, theater, icon):
def __init__(self, text, filename, icon):
super(QCampaignItem, self).__init__()
self.theater = theater
self.filename = filename
self.setIcon(QtGui.QIcon(CONST.ICONS[icon]))
self.setEditable(False)
self.setText(text)

View File

@@ -44,7 +44,8 @@ class NewGameWizard(QtWidgets.QWizard):
selectedCampaign = self.field("selectedCampaign")
if selectedCampaign is None:
selectedCampaign = CAMPAIGNS[0]
conflictTheater = selectedCampaign[1]()
conflictTheater = ConflictTheater.from_file(selectedCampaign[1])
timePeriod = db.TIME_PERIODS[list(db.TIME_PERIODS.keys())[self.field("timePeriod")]]
midGame = self.field("midGame")
@@ -242,35 +243,6 @@ class TheaterConfiguration(QtWidgets.QWizardPage):
self.setPixmap(QtWidgets.QWizard.WatermarkPixmap,
QtGui.QPixmap('./resources/ui/wizard/watermark3.png'))
# Terrain selection
terrainGroup = QtWidgets.QGroupBox("Terrain")
terrainCaucasusSmall = QtWidgets.QRadioButton("Caucasus - Western Georgia")
terrainCaucasusSmall.setIcon(QtGui.QIcon(CONST.ICONS["Terrain_Caucasus"]))
terrainRussia = QtWidgets.QRadioButton("Caucasus - Russia Small")
terrainRussia.setIcon(QtGui.QIcon(CONST.ICONS["Terrain_Caucasus"]))
terrainCaucasus = QtWidgets.QRadioButton("Caucasus - Full map [NOT RECOMMENDED]")
terrainCaucasus.setIcon(QtGui.QIcon(CONST.ICONS["Terrain_Caucasus"]))
terrainCaucasusNorth = QtWidgets.QRadioButton("Caucasus - North")
terrainCaucasusNorth.setIcon(QtGui.QIcon(CONST.ICONS["Terrain_Caucasus"]))
terrainPg = QtWidgets.QRadioButton("Persian Gulf - Full Map [NOT RECOMMENDED]")
terrainPg.setIcon(QtGui.QIcon(CONST.ICONS["Terrain_Persian_Gulf"]))
terrainIran = QtWidgets.QRadioButton("Persian Gulf - Invasion of Iran")
terrainIran.setIcon(QtGui.QIcon(CONST.ICONS["Terrain_Persian_Gulf"]))
terrainEmirates = QtWidgets.QRadioButton("Persian Gulf - Emirates")
terrainEmirates.setIcon(QtGui.QIcon(CONST.ICONS["Terrain_Persian_Gulf"]))
terrainNttr = QtWidgets.QRadioButton("Nevada - North Nevada")
terrainNttr.setIcon(QtGui.QIcon(CONST.ICONS["Terrain_Nevada"]))
terrainNormandy = QtWidgets.QRadioButton("Normandy")
terrainNormandy.setIcon(QtGui.QIcon(CONST.ICONS["Terrain_Normandy"]))
terrainNormandySmall = QtWidgets.QRadioButton("Normandy Small")
terrainNormandySmall.setIcon(QtGui.QIcon(CONST.ICONS["Terrain_Normandy"]))
terrainChannel = QtWidgets.QRadioButton("The Channel : Start in Dunkirk")
terrainChannel.setIcon(QtGui.QIcon(CONST.ICONS["Terrain_Channel"]))
terrainChannelComplete = QtWidgets.QRadioButton("The Channel : Battle of Britain")
terrainChannelComplete.setIcon(QtGui.QIcon(CONST.ICONS["Terrain_Channel"]))
terrainCaucasusSmall.setChecked(True)
# List of campaigns
campaignList = QCampaignList()
self.registerField("selectedCampaign", campaignList)
@@ -284,8 +256,6 @@ class TheaterConfiguration(QtWidgets.QWizardPage):
campaignList.selectionModel().selectionChanged.connect(on_campaign_selected)
on_campaign_selected()
# Campaign settings
mapSettingsGroup = QtWidgets.QGroupBox("Map Settings")
invertMap = QtWidgets.QCheckBox()