(1968ab79f) v0.9.9.1

This commit is contained in:
Joonas Rikkonen
2020-04-30 14:09:23 +03:00
parent ac37a3b0e4
commit ce4ccd99ac
23 changed files with 131 additions and 55 deletions
@@ -166,6 +166,11 @@ namespace Barotrauma
private set;
}
public List<Entity> EntitiesBeforeGenerate { get; private set; } = new List<Entity>();
public int EntityCountBeforeGenerate { get; private set; }
public int EntityCountAfterGenerate { get; private set; }
public float Difficulty
{
get;
@@ -281,8 +286,11 @@ namespace Barotrauma
public void Generate(bool mirror)
{
if (loaded != null) loaded.Remove();
if (loaded != null) { loaded.Remove(); }
loaded = this;
EntitiesBeforeGenerate = GetEntityList();
EntityCountBeforeGenerate = EntitiesBeforeGenerate.Count();
levelObjectManager = new LevelObjectManager();
@@ -759,6 +767,8 @@ namespace Barotrauma
DebugConsole.NewMessage("Generated level with the seed " + seed + " (type: " + generationParams.Name + ")", Color.White);
}
EntityCountAfterGenerate = Entity.GetEntityList().Count();
//assign an ID to make entity events work
ID = FindFreeID();
}
@@ -215,7 +215,7 @@ namespace Barotrauma
public override string ToString()
{
return "Barotrauma.Submarine (" + Info?.Name ?? "[NULL INFO]" + ")";
return "Barotrauma.Submarine (" + (Info?.Name ?? "[NULL INFO]") + ", " + IdOffset + ")";
}
public override bool Removed
@@ -1231,9 +1231,12 @@ namespace Barotrauma
public bool SaveAs(string filePath, MemoryStream previewImage = null)
{
var newInfo = new SubmarineInfo(this);
newInfo.FilePath = filePath;
newInfo.Name = Path.GetFileNameWithoutExtension(filePath);
var newInfo = new SubmarineInfo(this)
{
GameVersion = GameMain.Version,
FilePath = filePath,
Name = Path.GetFileNameWithoutExtension(filePath)
};
Info.Dispose(); Info = newInfo;
return newInfo.SaveAs(filePath, previewImage);
@@ -101,7 +101,11 @@ namespace Barotrauma
set;
}
public readonly XElement SubmarineElement;
public XElement SubmarineElement
{
get;
private set;
}
public override string ToString()
{
@@ -180,28 +184,7 @@ namespace Barotrauma
if (element == null && tryLoad)
{
XDocument doc = null;
int maxLoadRetries = 4;
for (int i = 0; i <= maxLoadRetries; i++)
{
doc = OpenFile(filePath, out Exception e);
if (e != null && !(e is IOException)) { break; }
if (doc != null || i == maxLoadRetries || !File.Exists(filePath)) { break; }
DebugConsole.NewMessage("Opening submarine file \"" + filePath + "\" failed, retrying in 250 ms...");
Thread.Sleep(250);
}
if (doc == null || doc.Root == null)
{
IsFileCorrupted = true;
return;
}
if (string.IsNullOrWhiteSpace(hash))
{
StartHashDocTask(doc);
}
SubmarineElement = doc.Root;
Reload();
}
else
{
@@ -215,6 +198,7 @@ namespace Barotrauma
public SubmarineInfo(Submarine sub) : this(sub.Info)
{
GameVersion = GameMain.Version;
SubmarineElement = new XElement("Submarine");
sub.SaveToXElement(SubmarineElement);
Init();
@@ -242,6 +226,30 @@ namespace Barotrauma
#endif
}
public void Reload()
{
XDocument doc = null;
int maxLoadRetries = 4;
for (int i = 0; i <= maxLoadRetries; i++)
{
doc = OpenFile(FilePath, out Exception e);
if (e != null && !(e is IOException)) { break; }
if (doc != null || i == maxLoadRetries || !File.Exists(FilePath)) { break; }
DebugConsole.NewMessage("Opening submarine file \"" + FilePath + "\" failed, retrying in 250 ms...");
Thread.Sleep(250);
}
if (doc == null || doc.Root == null)
{
IsFileCorrupted = true;
return;
}
if (hash == null)
{
StartHashDocTask(doc);
}
SubmarineElement = doc.Root;
}
private void Init()
{
DisplayName = TextManager.Get("Submarine.Name." + Name, true);