fixed world configuration updating
This commit is contained in:
@@ -78,7 +78,10 @@ namespace Torch.Server.Managers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(f) && File.Exists(Path.Combine(f, "Sandbox.sbc")))
|
if (!string.IsNullOrEmpty(f) && File.Exists(Path.Combine(f, "Sandbox.sbc")))
|
||||||
DedicatedConfig.Worlds.Add(new WorldViewModel(f));
|
{
|
||||||
|
var worldViewModel = new WorldViewModel(f, DedicatedConfig.LoadWorld == f);
|
||||||
|
DedicatedConfig.Worlds.Add(worldViewModel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -98,6 +101,22 @@ namespace Torch.Server.Managers
|
|||||||
InstanceLoaded?.Invoke(DedicatedConfig);
|
InstanceLoaded?.Invoke(DedicatedConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SelectCreatedWorld(string worldPath)
|
||||||
|
{
|
||||||
|
WorldViewModel worldViewModel;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
worldViewModel = new(worldPath);
|
||||||
|
DedicatedConfig.Worlds.Add(worldViewModel);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex, "Failed to load world at path: " + worldPath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SelectWorld(worldViewModel, false);
|
||||||
|
}
|
||||||
|
|
||||||
public void SelectWorld(string worldPath, bool modsOnly = true)
|
public void SelectWorld(string worldPath, bool modsOnly = true)
|
||||||
{
|
{
|
||||||
DedicatedConfig.LoadWorld = worldPath;
|
DedicatedConfig.LoadWorld = worldPath;
|
||||||
@@ -266,11 +285,21 @@ namespace Torch.Server.Managers
|
|||||||
public long WorldSizeKB { get; }
|
public long WorldSizeKB { get; }
|
||||||
private string _checkpointPath;
|
private string _checkpointPath;
|
||||||
private string _worldConfigPath;
|
private string _worldConfigPath;
|
||||||
public CheckpointViewModel Checkpoint { get; private set; }
|
private CheckpointViewModel _checkpoint;
|
||||||
|
|
||||||
|
public CheckpointViewModel Checkpoint
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_checkpoint is null) LoadSandbox();
|
||||||
|
return _checkpoint;
|
||||||
|
}
|
||||||
|
private set => _checkpoint = value;
|
||||||
|
}
|
||||||
|
|
||||||
public WorldConfigurationViewModel WorldConfiguration { get; private set; }
|
public WorldConfigurationViewModel WorldConfiguration { get; private set; }
|
||||||
|
|
||||||
public WorldViewModel(string worldPath)
|
public WorldViewModel(string worldPath, bool loadFiles = true)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -279,6 +308,7 @@ namespace Torch.Server.Managers
|
|||||||
_checkpointPath = Path.Combine(WorldPath, "Sandbox.sbc");
|
_checkpointPath = Path.Combine(WorldPath, "Sandbox.sbc");
|
||||||
_worldConfigPath = Path.Combine(WorldPath, "Sandbox_config.sbc");
|
_worldConfigPath = Path.Combine(WorldPath, "Sandbox_config.sbc");
|
||||||
FolderName = Path.GetFileName(worldPath);
|
FolderName = Path.GetFileName(worldPath);
|
||||||
|
if (loadFiles)
|
||||||
LoadSandbox();
|
LoadSandbox();
|
||||||
}
|
}
|
||||||
catch (ArgumentException ex)
|
catch (ArgumentException ex)
|
||||||
@@ -297,7 +327,7 @@ namespace Torch.Server.Managers
|
|||||||
MyObjectBuilderSerializer.SerializeXML(f, WorldConfiguration);
|
MyObjectBuilderSerializer.SerializeXML(f, WorldConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadSandbox()
|
public void LoadSandbox()
|
||||||
{
|
{
|
||||||
MyObjectBuilderSerializer.DeserializeXML(_checkpointPath, out MyObjectBuilder_Checkpoint checkpoint);
|
MyObjectBuilderSerializer.DeserializeXML(_checkpointPath, out MyObjectBuilder_Checkpoint checkpoint);
|
||||||
Checkpoint = new CheckpointViewModel(checkpoint);
|
Checkpoint = new CheckpointViewModel(checkpoint);
|
||||||
|
@@ -26,7 +26,7 @@ namespace Torch.Server.ViewModels
|
|||||||
public ConfigDedicatedViewModel(MyConfigDedicated<MyObjectBuilder_SessionSettings> configDedicated)
|
public ConfigDedicatedViewModel(MyConfigDedicated<MyObjectBuilder_SessionSettings> configDedicated)
|
||||||
{
|
{
|
||||||
_config = configDedicated;
|
_config = configDedicated;
|
||||||
//_config.IgnoreLastSession = true;
|
_config.IgnoreLastSession = true;
|
||||||
SessionSettings = new SessionSettingsViewModel(_config.SessionSettings);
|
SessionSettings = new SessionSettingsViewModel(_config.SessionSettings);
|
||||||
Task.Run(() => UpdateAllModInfosAsync());
|
Task.Run(() => UpdateAllModInfosAsync());
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ namespace Torch.Server.ViewModels
|
|||||||
{
|
{
|
||||||
Validate();
|
Validate();
|
||||||
|
|
||||||
_config.SessionSettings = _sessionSettings;
|
_config.SessionSettings = SessionSettings;
|
||||||
// Never ever
|
// Never ever
|
||||||
//_config.IgnoreLastSession = true;
|
//_config.IgnoreLastSession = true;
|
||||||
_config.Save(path);
|
_config.Save(path);
|
||||||
@@ -58,8 +58,7 @@ namespace Torch.Server.ViewModels
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SessionSettingsViewModel _sessionSettings;
|
public SessionSettingsViewModel SessionSettings { get; set; }
|
||||||
public SessionSettingsViewModel SessionSettings { get => _sessionSettings; set { _sessionSettings = value; OnPropertyChanged(); } }
|
|
||||||
|
|
||||||
public MtObservableList<WorldViewModel> Worlds { get; } = new MtObservableList<WorldViewModel>();
|
public MtObservableList<WorldViewModel> Worlds { get; } = new MtObservableList<WorldViewModel>();
|
||||||
private WorldViewModel _selectedWorld;
|
private WorldViewModel _selectedWorld;
|
||||||
@@ -69,6 +68,7 @@ namespace Torch.Server.ViewModels
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
SetValue(ref _selectedWorld, value);
|
SetValue(ref _selectedWorld, value);
|
||||||
|
SessionSettings = value.WorldConfiguration.Settings;
|
||||||
LoadWorld = _selectedWorld?.WorldPath;
|
LoadWorld = _selectedWorld?.WorldPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -108,7 +108,7 @@ namespace Torch.Server.Views
|
|||||||
if (e.AddedItems.Count > 0)
|
if (e.AddedItems.Count > 0)
|
||||||
{
|
{
|
||||||
var result = MessageBoxResult.Yes; //MessageBox.Show("Do you want to import the session settings from the selected world?", "Import Config", MessageBoxButton.YesNo);
|
var result = MessageBoxResult.Yes; //MessageBox.Show("Do you want to import the session settings from the selected world?", "Import Config", MessageBoxButton.YesNo);
|
||||||
var world = (WorldViewModel)e.AddedItems[0];
|
var world = (WorldViewModel)e.AddedItems[0]!;
|
||||||
_instanceManager.SelectWorld(world.WorldPath, result != MessageBoxResult.Yes);
|
_instanceManager.SelectWorld(world.WorldPath, result != MessageBoxResult.Yes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -37,7 +37,7 @@ namespace Torch.Server
|
|||||||
private PremadeCheckpointItem _currentItem;
|
private PremadeCheckpointItem _currentItem;
|
||||||
|
|
||||||
[ReflectedStaticMethod(Type = typeof(ConfigForm), Name = "LoadLocalization")]
|
[ReflectedStaticMethod(Type = typeof(ConfigForm), Name = "LoadLocalization")]
|
||||||
private static Action _loadLocalization;
|
private static Action _loadLocalization = null!;
|
||||||
|
|
||||||
public WorldGeneratorDialog(InstanceManager instanceManager)
|
public WorldGeneratorDialog(InstanceManager instanceManager)
|
||||||
{
|
{
|
||||||
@@ -81,7 +81,9 @@ namespace Torch.Server
|
|||||||
{
|
{
|
||||||
string worldName = string.IsNullOrEmpty(WorldName.Text) ? _currentItem.Name : WorldName.Text;
|
string worldName = string.IsNullOrEmpty(WorldName.Text) ? _currentItem.Name : WorldName.Text;
|
||||||
|
|
||||||
|
#pragma warning disable CS0618
|
||||||
var worldPath = Path.Combine(TorchBase.Instance.Config.InstancePath, "Saves", worldName);
|
var worldPath = Path.Combine(TorchBase.Instance.Config.InstancePath, "Saves", worldName);
|
||||||
|
#pragma warning restore CS0618
|
||||||
var checkpoint = _currentItem.Checkpoint;
|
var checkpoint = _currentItem.Checkpoint;
|
||||||
if (Directory.Exists(worldPath))
|
if (Directory.Exists(worldPath))
|
||||||
{
|
{
|
||||||
@@ -102,8 +104,7 @@ namespace Torch.Server
|
|||||||
MyLocalCache.SaveCheckpoint(checkpoint, worldPath);
|
MyLocalCache.SaveCheckpoint(checkpoint, worldPath);
|
||||||
|
|
||||||
|
|
||||||
_instanceManager.SelectWorld(worldPath, false);
|
_instanceManager.SelectCreatedWorld(worldPath);
|
||||||
_instanceManager.ImportSelectedWorldConfig();
|
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user