diff --git a/Torch.Server/Managers/InstanceManager.cs b/Torch.Server/Managers/InstanceManager.cs index 2fb87f8..f807754 100644 --- a/Torch.Server/Managers/InstanceManager.cs +++ b/Torch.Server/Managers/InstanceManager.cs @@ -78,7 +78,10 @@ namespace Torch.Server.Managers try { 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) { @@ -98,6 +101,22 @@ namespace Torch.Server.Managers 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) { DedicatedConfig.LoadWorld = worldPath; @@ -266,11 +285,21 @@ namespace Torch.Server.Managers public long WorldSizeKB { get; } private string _checkpointPath; 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 WorldViewModel(string worldPath) + public WorldViewModel(string worldPath, bool loadFiles = true) { try { @@ -279,7 +308,8 @@ namespace Torch.Server.Managers _checkpointPath = Path.Combine(WorldPath, "Sandbox.sbc"); _worldConfigPath = Path.Combine(WorldPath, "Sandbox_config.sbc"); FolderName = Path.GetFileName(worldPath); - LoadSandbox(); + if (loadFiles) + LoadSandbox(); } catch (ArgumentException ex) { @@ -297,7 +327,7 @@ namespace Torch.Server.Managers MyObjectBuilderSerializer.SerializeXML(f, WorldConfiguration); } - private void LoadSandbox() + public void LoadSandbox() { MyObjectBuilderSerializer.DeserializeXML(_checkpointPath, out MyObjectBuilder_Checkpoint checkpoint); Checkpoint = new CheckpointViewModel(checkpoint); diff --git a/Torch.Server/ViewModels/ConfigDedicatedViewModel.cs b/Torch.Server/ViewModels/ConfigDedicatedViewModel.cs index bb24f6f..491660f 100644 --- a/Torch.Server/ViewModels/ConfigDedicatedViewModel.cs +++ b/Torch.Server/ViewModels/ConfigDedicatedViewModel.cs @@ -26,7 +26,7 @@ namespace Torch.Server.ViewModels public ConfigDedicatedViewModel(MyConfigDedicated configDedicated) { _config = configDedicated; - //_config.IgnoreLastSession = true; + _config.IgnoreLastSession = true; SessionSettings = new SessionSettingsViewModel(_config.SessionSettings); Task.Run(() => UpdateAllModInfosAsync()); } @@ -35,7 +35,7 @@ namespace Torch.Server.ViewModels { Validate(); - _config.SessionSettings = _sessionSettings; + _config.SessionSettings = SessionSettings; // Never ever //_config.IgnoreLastSession = true; _config.Save(path); @@ -58,8 +58,7 @@ namespace Torch.Server.ViewModels return true; } - private SessionSettingsViewModel _sessionSettings; - public SessionSettingsViewModel SessionSettings { get => _sessionSettings; set { _sessionSettings = value; OnPropertyChanged(); } } + public SessionSettingsViewModel SessionSettings { get; set; } public MtObservableList Worlds { get; } = new MtObservableList(); private WorldViewModel _selectedWorld; @@ -69,6 +68,7 @@ namespace Torch.Server.ViewModels set { SetValue(ref _selectedWorld, value); + SessionSettings = value.WorldConfiguration.Settings; LoadWorld = _selectedWorld?.WorldPath; } } diff --git a/Torch.Server/Views/ConfigControl.xaml.cs b/Torch.Server/Views/ConfigControl.xaml.cs index 75c0a5b..96e17e9 100644 --- a/Torch.Server/Views/ConfigControl.xaml.cs +++ b/Torch.Server/Views/ConfigControl.xaml.cs @@ -108,7 +108,7 @@ namespace Torch.Server.Views 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 world = (WorldViewModel)e.AddedItems[0]; + var world = (WorldViewModel)e.AddedItems[0]!; _instanceManager.SelectWorld(world.WorldPath, result != MessageBoxResult.Yes); } } diff --git a/Torch.Server/Views/WorldGeneratorDialog.xaml.cs b/Torch.Server/Views/WorldGeneratorDialog.xaml.cs index 3867b83..6034bae 100644 --- a/Torch.Server/Views/WorldGeneratorDialog.xaml.cs +++ b/Torch.Server/Views/WorldGeneratorDialog.xaml.cs @@ -37,7 +37,7 @@ namespace Torch.Server private PremadeCheckpointItem _currentItem; [ReflectedStaticMethod(Type = typeof(ConfigForm), Name = "LoadLocalization")] - private static Action _loadLocalization; + private static Action _loadLocalization = null!; public WorldGeneratorDialog(InstanceManager instanceManager) { @@ -81,7 +81,9 @@ namespace Torch.Server { string worldName = string.IsNullOrEmpty(WorldName.Text) ? _currentItem.Name : WorldName.Text; +#pragma warning disable CS0618 var worldPath = Path.Combine(TorchBase.Instance.Config.InstancePath, "Saves", worldName); +#pragma warning restore CS0618 var checkpoint = _currentItem.Checkpoint; if (Directory.Exists(worldPath)) { @@ -102,8 +104,7 @@ namespace Torch.Server MyLocalCache.SaveCheckpoint(checkpoint, worldPath); - _instanceManager.SelectWorld(worldPath, false); - _instanceManager.ImportSelectedWorldConfig(); + _instanceManager.SelectCreatedWorld(worldPath); Close(); }