Started moving single player campaign logic to an abstract CampaignMode class to make it reusable in the eventual multiplayer campaign

This commit is contained in:
Joonas Rikkonen
2017-08-28 18:45:08 +03:00
parent 729108c7b9
commit a75fd12020
17 changed files with 202 additions and 189 deletions
@@ -15,7 +15,7 @@ namespace Barotrauma
{
get
{
SinglePlayerMode mode = (gameMode as SinglePlayerMode);
SinglePlayerCampaign mode = (GameMode as SinglePlayerCampaign);
return (mode == null) ? null : mode.Map;
}
}
@@ -132,21 +132,21 @@ namespace Barotrauma
{
infoButton.AddToGUIUpdateList();
if (gameMode != null) gameMode.AddToGUIUpdateList();
if (GameMode != null) GameMode.AddToGUIUpdateList();
if (infoFrame != null) infoFrame.AddToGUIUpdateList();
}
public void Update(float deltaTime)
{
TaskManager.Update(deltaTime);
EventManager.Update(deltaTime);
if (GUI.DisableHUD) return;
//guiRoot.Update(deltaTime);
infoButton.Update(deltaTime);
if (gameMode != null) gameMode.Update(deltaTime);
if (GameMode != null) GameMode.Update(deltaTime);
if (Mission != null) Mission.Update(deltaTime);
if (infoFrame != null)
{
@@ -165,23 +165,26 @@ namespace Barotrauma
infoButton.Draw(spriteBatch);
if (gameMode != null) gameMode.Draw(spriteBatch);
if (GameMode != null) GameMode.Draw(spriteBatch);
if (infoFrame != null) infoFrame.Draw(spriteBatch);
}
public void Save(string filePath)
{
if (!(GameMode is CampaignMode))
{
throw new NotSupportedException("GameSessions can only be saved when playing in a campaign mode.");
}
XDocument doc = new XDocument(
new XElement("Gamesession"));
var now = DateTime.Now;
doc.Root.Add(new XAttribute("savetime", now.ToShortTimeString() + ", " + now.ToShortDateString()));
doc.Root.Add(new XAttribute("submarine", submarine == null ? "" : submarine.Name));
doc.Root.Add(new XAttribute("mapseed", Map.Seed));
((SinglePlayerMode)gameMode).Save(doc.Root);
((CampaignMode)GameMode).Save(doc.Root);
try
{