Skip to content

Commit 9f8fcdc

Browse files
Merge pull request #157 from C7-Game/FixSAVsNotLoading
Fix SAVs not loading
2 parents 2035f7e + efdb8c6 commit 9f8fcdc

File tree

2 files changed

+56
-33
lines changed

2 files changed

+56
-33
lines changed

C7/Game.cs

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public override void _EnterTree()
5151
}
5252

5353
// Called when the node enters the scene tree for the first time.
54+
// The catch should always catch any error, as it's the general catch
55+
// that gives an error if we fail to load for some reason.
5456
public override void _Ready()
5557
{
5658
Global = GetNode<GlobalSingleton>("/root/GlobalSingleton");
@@ -84,34 +86,37 @@ public override void _Ready()
8486
catch {
8587
ComponentManager.Instance.GetComponent<TurnCounterComponent>().SetTurnCounter();
8688
}
89+
90+
// Hide slideout bar on startup
91+
_on_SlideToggle_toggled(false);
92+
93+
// Set initial camera location. If the UI controller has any cities, focus on their capital. Otherwise, focus on their starting
94+
// settler.
95+
if (controller.cities.Count > 0)
96+
{
97+
City capital = controller.cities.Find(c => c.IsCapital());
98+
if (capital != null)
99+
mapView.centerCameraOnTile(capital.location);
100+
}
101+
else
102+
{
103+
MapUnit startingSettler = controller.units.Find(u => u.unitType.canFoundCity);
104+
if (startingSettler != null)
105+
mapView.centerCameraOnTile(startingSettler.location);
106+
}
107+
108+
GD.Print("Now in game!");
109+
110+
loadTimer.Stop();
111+
TimeSpan stopwatchElapsed = loadTimer.Elapsed;
112+
GD.Print("Game scene load time: " + Convert.ToInt32(stopwatchElapsed.TotalMilliseconds) + " ms");
87113
}
88114
catch(Exception ex) {
89115
errorOnLoad = true;
90116
PopupOverlay popupOverlay = GetNode<PopupOverlay>(PopupOverlay.NodePath);
91117
popupOverlay.ShowPopup(new ErrorMessage(ex.Message), PopupOverlay.PopupCategory.Advisor);
92118
GD.PrintErr(ex);
93119
}
94-
95-
// Hide slideout bar on startup
96-
_on_SlideToggle_toggled(false);
97-
98-
// Set initial camera location. If the UI controller has any cities, focus on their capital. Otherwise, focus on their starting
99-
// settler.
100-
if (controller.cities.Count > 0) {
101-
City capital = controller.cities.Find(c => c.IsCapital());
102-
if (capital != null)
103-
mapView.centerCameraOnTile(capital.location);
104-
} else {
105-
MapUnit startingSettler = controller.units.Find(u => u.unitType.canFoundCity);
106-
if (startingSettler != null)
107-
mapView.centerCameraOnTile(startingSettler.location);
108-
}
109-
110-
GD.Print("Now in game!");
111-
112-
loadTimer.Stop();
113-
TimeSpan stopwatchElapsed = loadTimer.Elapsed;
114-
GD.Print("Game scene load time: " + Convert.ToInt32(stopwatchElapsed.TotalMilliseconds) + " ms");
115120
}
116121

117122
// Must only be called while holding the game data mutex

C7GameData/ImportCiv3.cs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public static C7SaveFormat ImportSav(string savePath, string defaultBicPath)
3030

3131
ImportCiv3TerrainTypes(theBiq, c7Save);
3232
Dictionary<int, Resource> resourcesByIndex = ImportCiv3Resources(civ3Save.Bic, c7Save);
33-
SetMapDimensions(civ3Save, theBiq, c7Save);
34-
SetWorldWrap(theBiq, c7Save);
33+
SetMapDimensions(civ3Save, c7Save);
34+
SetWorldWrap(civ3Save, c7Save);
3535

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

8686
ImportCiv3TerrainTypes(theBiq, c7Save);
8787
Dictionary<int, Resource> resourcesByIndex = ImportCiv3Resources(theBiq, c7Save);
88-
SetMapDimensions(null, theBiq, c7Save);
88+
SetMapDimensions(theBiq, c7Save);
8989
SetWorldWrap(theBiq, c7Save);
9090

9191
// Import tiles
@@ -187,22 +187,40 @@ private static void ImportCiv3TerrainTypes(BiqData theBiq, C7SaveFormat c7Save)
187187
}
188188
}
189189

190+
private static void SetWorldWrap(SavData civ3Save, C7SaveFormat c7Save)
191+
{
192+
if (civ3Save != null && civ3Save.Wrld.Height > 0 && civ3Save.Wrld.Width > 0)
193+
{
194+
c7Save.GameData.map.wrapHorizontally = civ3Save.Wrld.XWrapping;
195+
c7Save.GameData.map.wrapVertically = civ3Save.Wrld.YWrapping;
196+
}
197+
}
198+
190199
private static void SetWorldWrap(BiqData biq, C7SaveFormat c7Save)
191200
{
192-
c7Save.GameData.map.wrapHorizontally = biq.Wmap[0].XWrapping;
193-
c7Save.GameData.map.wrapVertically = biq.Wmap[0].YWrapping;
194-
}
195201

196-
private static void SetMapDimensions(SavData civ3Save, BiqData biq, C7SaveFormat c7Save)
197-
{
198-
if (biq != null && biq.Wmap != null && biq.Wmap.Length > 0) {
199-
c7Save.GameData.map.numTilesTall = biq.Wmap[0].Height;
200-
c7Save.GameData.map.numTilesWide = biq.Wmap[0].Width;
202+
if (biq != null && biq.Wmap != null && biq.Wmap.Length > 0)
203+
{
204+
c7Save.GameData.map.wrapHorizontally = biq.Wmap[0].XWrapping;
205+
c7Save.GameData.map.wrapVertically = biq.Wmap[0].YWrapping;
201206
}
207+
}
208+
209+
private static void SetMapDimensions(SavData civ3Save, C7SaveFormat c7Save)
210+
{
202211
if (civ3Save != null && civ3Save.Wrld.Height > 0 && civ3Save.Wrld.Width > 0) {
203212
c7Save.GameData.map.numTilesTall = civ3Save.Wrld.Height;
204213
c7Save.GameData.map.numTilesWide = civ3Save.Wrld.Width;
205214
}
206215
}
207-
}
216+
217+
private static void SetMapDimensions(BiqData biq, C7SaveFormat c7Save)
218+
{
219+
if (biq != null && biq.Wmap != null && biq.Wmap.Length > 0)
220+
{
221+
c7Save.GameData.map.numTilesTall = biq.Wmap[0].Height;
222+
c7Save.GameData.map.numTilesWide = biq.Wmap[0].Width;
223+
}
224+
}
225+
}
208226
}

0 commit comments

Comments
 (0)