Skip to content

Commit

Permalink
Merge pull request #157 from C7-Game/FixSAVsNotLoading
Browse files Browse the repository at this point in the history
Fix SAVs not loading
  • Loading branch information
QuintillusCFC authored Mar 23, 2022
2 parents 2035f7e + efdb8c6 commit 9f8fcdc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 33 deletions.
47 changes: 26 additions & 21 deletions C7/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public override void _EnterTree()
}

// Called when the node enters the scene tree for the first time.
// The catch should always catch any error, as it's the general catch
// that gives an error if we fail to load for some reason.
public override void _Ready()
{
Global = GetNode<GlobalSingleton>("/root/GlobalSingleton");
Expand Down Expand Up @@ -84,34 +86,37 @@ public override void _Ready()
catch {
ComponentManager.Instance.GetComponent<TurnCounterComponent>().SetTurnCounter();
}

// Hide slideout bar on startup
_on_SlideToggle_toggled(false);

// Set initial camera location. If the UI controller has any cities, focus on their capital. Otherwise, focus on their starting
// settler.
if (controller.cities.Count > 0)
{
City capital = controller.cities.Find(c => c.IsCapital());
if (capital != null)
mapView.centerCameraOnTile(capital.location);
}
else
{
MapUnit startingSettler = controller.units.Find(u => u.unitType.canFoundCity);
if (startingSettler != null)
mapView.centerCameraOnTile(startingSettler.location);
}

GD.Print("Now in game!");

loadTimer.Stop();
TimeSpan stopwatchElapsed = loadTimer.Elapsed;
GD.Print("Game scene load time: " + Convert.ToInt32(stopwatchElapsed.TotalMilliseconds) + " ms");
}
catch(Exception ex) {
errorOnLoad = true;
PopupOverlay popupOverlay = GetNode<PopupOverlay>(PopupOverlay.NodePath);
popupOverlay.ShowPopup(new ErrorMessage(ex.Message), PopupOverlay.PopupCategory.Advisor);
GD.PrintErr(ex);
}

// Hide slideout bar on startup
_on_SlideToggle_toggled(false);

// Set initial camera location. If the UI controller has any cities, focus on their capital. Otherwise, focus on their starting
// settler.
if (controller.cities.Count > 0) {
City capital = controller.cities.Find(c => c.IsCapital());
if (capital != null)
mapView.centerCameraOnTile(capital.location);
} else {
MapUnit startingSettler = controller.units.Find(u => u.unitType.canFoundCity);
if (startingSettler != null)
mapView.centerCameraOnTile(startingSettler.location);
}

GD.Print("Now in game!");

loadTimer.Stop();
TimeSpan stopwatchElapsed = loadTimer.Elapsed;
GD.Print("Game scene load time: " + Convert.ToInt32(stopwatchElapsed.TotalMilliseconds) + " ms");
}

// Must only be called while holding the game data mutex
Expand Down
42 changes: 30 additions & 12 deletions C7GameData/ImportCiv3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public static C7SaveFormat ImportSav(string savePath, string defaultBicPath)

ImportCiv3TerrainTypes(theBiq, c7Save);
Dictionary<int, Resource> resourcesByIndex = ImportCiv3Resources(civ3Save.Bic, c7Save);
SetMapDimensions(civ3Save, theBiq, c7Save);
SetWorldWrap(theBiq, c7Save);
SetMapDimensions(civ3Save, c7Save);
SetWorldWrap(civ3Save, c7Save);

// Import tiles. This is similar to, but different from the BIQ version as tile contents may have changed in-game.
int i = 0;
Expand Down Expand Up @@ -85,7 +85,7 @@ public static C7SaveFormat ImportBiq(string biqPath, string defaultBiqPath)

ImportCiv3TerrainTypes(theBiq, c7Save);
Dictionary<int, Resource> resourcesByIndex = ImportCiv3Resources(theBiq, c7Save);
SetMapDimensions(null, theBiq, c7Save);
SetMapDimensions(theBiq, c7Save);
SetWorldWrap(theBiq, c7Save);

// Import tiles
Expand Down Expand Up @@ -187,22 +187,40 @@ private static void ImportCiv3TerrainTypes(BiqData theBiq, C7SaveFormat c7Save)
}
}

private static void SetWorldWrap(SavData civ3Save, C7SaveFormat c7Save)
{
if (civ3Save != null && civ3Save.Wrld.Height > 0 && civ3Save.Wrld.Width > 0)
{
c7Save.GameData.map.wrapHorizontally = civ3Save.Wrld.XWrapping;
c7Save.GameData.map.wrapVertically = civ3Save.Wrld.YWrapping;
}
}

private static void SetWorldWrap(BiqData biq, C7SaveFormat c7Save)
{
c7Save.GameData.map.wrapHorizontally = biq.Wmap[0].XWrapping;
c7Save.GameData.map.wrapVertically = biq.Wmap[0].YWrapping;
}

private static void SetMapDimensions(SavData civ3Save, BiqData biq, C7SaveFormat c7Save)
{
if (biq != null && biq.Wmap != null && biq.Wmap.Length > 0) {
c7Save.GameData.map.numTilesTall = biq.Wmap[0].Height;
c7Save.GameData.map.numTilesWide = biq.Wmap[0].Width;
if (biq != null && biq.Wmap != null && biq.Wmap.Length > 0)
{
c7Save.GameData.map.wrapHorizontally = biq.Wmap[0].XWrapping;
c7Save.GameData.map.wrapVertically = biq.Wmap[0].YWrapping;
}
}

private static void SetMapDimensions(SavData civ3Save, C7SaveFormat c7Save)
{
if (civ3Save != null && civ3Save.Wrld.Height > 0 && civ3Save.Wrld.Width > 0) {
c7Save.GameData.map.numTilesTall = civ3Save.Wrld.Height;
c7Save.GameData.map.numTilesWide = civ3Save.Wrld.Width;
}
}
}

private static void SetMapDimensions(BiqData biq, C7SaveFormat c7Save)
{
if (biq != null && biq.Wmap != null && biq.Wmap.Length > 0)
{
c7Save.GameData.map.numTilesTall = biq.Wmap[0].Height;
c7Save.GameData.map.numTilesWide = biq.Wmap[0].Width;
}
}
}
}

0 comments on commit 9f8fcdc

Please sign in to comment.