Skip to content

Commit

Permalink
Fixed asteroid objects not using id for asteroid object identification
Browse files Browse the repository at this point in the history
  • Loading branch information
8vogt committed Mar 3, 2021
1 parent 8c09e70 commit bf66767
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public override bool TryLoadObject(MySystemAsteroids asteroid)
{
if (m_loadedRings.ContainsKey(asteroid.Id)) return false;

var ring = MyFileUtils.ReadXmlFileFromWorld<MyAsteroidRingData>(GetFileName(asteroid.DisplayName), typeof(MyAsteroidRingProvider));
var ring = MyFileUtils.ReadXmlFileFromWorld<MyAsteroidRingData>(GetFileName(asteroid), typeof(MyAsteroidRingProvider));

if (ring == null) return false;

Expand All @@ -145,7 +145,7 @@ public override void OnSave()

var instance = MyStarSystemGenerator.Static.StarSystem.GetObjectById(ringId);
if (instance == null) continue;
MyFileUtils.WriteXmlFileToWorld(m_loadedRings[ringId], GetFileName(instance.DisplayName), typeof(MyAsteroidRingProvider));
MyFileUtils.WriteXmlFileToWorld(m_loadedRings[ringId], GetFileName(instance as MySystemAsteroids), typeof(MyAsteroidRingProvider));
}
}

Expand Down Expand Up @@ -197,7 +197,7 @@ public override bool RemoveInstance(MySystemAsteroids systemInstance)

m_loadedRings.Remove(systemInstance.Id);

MyFileUtils.DeleteFileInWorldStorage(GetFileName(systemInstance.DisplayName), typeof(MyAsteroidRingProvider));
MyFileUtils.DeleteFileInWorldStorage(GetFileName(systemInstance), typeof(MyAsteroidRingProvider));

PluginEventHandler.Static.RaiseStaticEvent(NotifyRemoveInstance, systemInstance.Id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public override void OnSave()

var instance = MyStarSystemGenerator.Static.StarSystem.GetObjectById(sphere.Key);
if (instance == null) continue;
MyFileUtils.WriteXmlFileToWorld(sphere.Value, GetFileName(instance.DisplayName), typeof(MyAsteroidSphereProvider));
MyFileUtils.WriteXmlFileToWorld(sphere.Value, GetFileName(instance as MySystemAsteroids), typeof(MyAsteroidSphereProvider));
}
}

Expand All @@ -93,7 +93,7 @@ public override bool RemoveInstance(MySystemAsteroids systemInstance)

m_loadedSpheres.Remove(systemInstance.Id);

MyFileUtils.DeleteFileInWorldStorage(GetFileName(systemInstance.DisplayName), typeof(MyAsteroidSphereProvider));
MyFileUtils.DeleteFileInWorldStorage(GetFileName(systemInstance), typeof(MyAsteroidSphereProvider));

PluginEventHandler.Static.RaiseStaticEvent(NotifyRemoveInstance, systemInstance.Id);

Expand All @@ -106,9 +106,9 @@ public override bool TryLoadObject(MySystemAsteroids asteroid)
{
if (m_loadedSpheres.ContainsKey(asteroid.Id)) return false;

if (!MyFileUtils.FileExistsInWorldStorage(GetFileName(asteroid.DisplayName), typeof(MyAsteroidSphereProvider))) return false;
if (!MyFileUtils.FileExistsInWorldStorage(GetFileName(asteroid), typeof(MyAsteroidSphereProvider))) return false;

var data = MyFileUtils.ReadXmlFileFromWorld<MyAsteroidSphereData>(GetFileName(asteroid.DisplayName), typeof(MyAsteroidSphereProvider));
var data = MyFileUtils.ReadXmlFileFromWorld<MyAsteroidSphereData>(GetFileName(asteroid), typeof(MyAsteroidSphereProvider));

m_loadedSpheres.Add(asteroid.Id, data);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ public IMyAsteroidAdminMenuCreator GetAdminMenuCreator()
/// <summary>
/// Converts an asteroid object name to a file name.
/// </summary>
/// <param name="objectName">The asteroid object name</param>
/// <param name="obj">The asteroid object</param>
/// <returns>The file name for the asteroid object</returns>
protected string GetFileName(string objectName)
protected string GetFileName(MySystemAsteroids obj)
{
return objectName.Replace(" ", "_") + ".roid";
return (obj.DisplayName + obj.Id.ToString()).Replace(" ", "_") + ".roid";
}
}
}

0 comments on commit bf66767

Please sign in to comment.