Skip to content

Commit

Permalink
Cleanup lot save a little
Browse files Browse the repository at this point in the history
  • Loading branch information
riperiperi committed Oct 28, 2023
1 parent 91a031b commit 78f4be5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 33 deletions.
2 changes: 1 addition & 1 deletion TSOClient/tso.client/UI/Panels/UILotControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ private void SaveLot()
try {
var exporter = new VMWorldExporter();
exporter.SaveHouse(vm, Path.Combine(FSOEnvironment.UserDir, ("Blueprints/"+LotSaveDialog.ResponseText+".xml")));
var marshal = vm.Save();
var marshal = vm.Save(!(UIScreen.Current is SandboxGameScreen));
Directory.CreateDirectory(Path.Combine(FSOEnvironment.UserDir, "LocalHouse/"));
using (var output = new FileStream(Path.Combine(FSOEnvironment.UserDir, "LocalHouse/"+LotSaveDialog.ResponseText+".fsov"), FileMode.Create))
{
Expand Down
15 changes: 0 additions & 15 deletions TSOClient/tso.client/UI/Screens/CoreGameScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -822,21 +822,6 @@ private void VMDebug_OnButtonClick(UIElement button)

}

private void SaveHouseButton_OnButtonClick(UIElement button)
{
if (vm == null) return;

var exporter = new VMWorldExporter();
exporter.SaveHouse(vm, GameFacade.GameFilePath("housedata/blueprints/house_00.xml"));
var marshal = vm.Save();
Directory.CreateDirectory(Path.Combine(FSOEnvironment.UserDir, "LocalHouse/"));
using (var output = new FileStream(Path.Combine(FSOEnvironment.UserDir, "LocalHouse/house_00.fsov"), FileMode.Create))
{
marshal.SerializeInto(new BinaryWriter(output));
}
if (vm.GlobalLink != null) ((VMTSOGlobalLinkStub)vm.GlobalLink).Database.Save();
}

public void CloseInbox()
{
Inbox.Visible = false;
Expand Down
15 changes: 0 additions & 15 deletions TSOClient/tso.client/UI/Screens/SandboxGameScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -678,20 +678,5 @@ private void VMRefreshed()
LotControl.ActiveEntity = null;
LotControl.RefreshCut();
}

private void SaveHouseButton_OnButtonClick(UIElement button)
{
if (vm == null) return;

var exporter = new VMWorldExporter();
exporter.SaveHouse(vm, GameFacade.GameFilePath("housedata/blueprints/house_00.xml"));
var marshal = vm.Save();
Directory.CreateDirectory(Path.Combine(FSOEnvironment.UserDir, "LocalHouse/"));
using (var output = new FileStream(Path.Combine(FSOEnvironment.UserDir, "LocalHouse/house_00.fsov"), FileMode.Create))
{
marshal.SerializeInto(new BinaryWriter(output));
}
if (vm.GlobalLink != null) ((VMTSOGlobalLinkStub)vm.GlobalLink).Database.Save();
}
}
}
3 changes: 2 additions & 1 deletion TSOClient/tso.simantics/Entities/VMEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1822,7 +1822,8 @@ public enum VMMovementFlags
PlayersCanMove = 1 << 1,
SelfPropelled = 1 << 2, //unused
PlayersCanDelete = 1 << 3,
StaysAfterEvict = 1 << 4
StaysAfterEvict = 1 << 4,
FSOExcludeUserSave = 1 << 8
}

[Flags]
Expand Down
13 changes: 12 additions & 1 deletion TSOClient/tso.simantics/VM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ public void SandboxRestore(VMSandboxRestoreState state)
}

#region VM Marshalling Functions
public VMMarshal Save()
public VMMarshal Save(bool user = false)
{
var ents = new VMEntityMarshal[Entities.Count];
var threads = new VMThreadMarshal[Entities.Count];
Expand All @@ -673,6 +673,11 @@ public VMMarshal Save()
int i = 0;
foreach (var ent in Entities)
{
if (user && ((VMMovementFlags)ent.GetValue(VMStackObjectVariable.MovementFlags)).HasFlag(VMMovementFlags.FSOExcludeUserSave))
{
continue;
}

if (ent is VMAvatar)
{
ents[i] = ((VMAvatar)ent).Save();
Expand All @@ -688,6 +693,12 @@ public VMMarshal Save()
}
}

if (i != ents.Length)
{
Array.Resize(ref ents, i);
Array.Resize(ref threads, i);
}

return new VMMarshal
{
Context = Context.Save(),
Expand Down

0 comments on commit 78f4be5

Please sign in to comment.