Scene re-read through SceneManager.ReloadContent

This commit is contained in:
cthangover committed 2026-10-22 19:14:55 +02:00
1 parent 972df5ccff
commit 3b2c1ddb95
5 files changed
+11 -22

No files matched your search

+1 -1
View File
@@ -246,7 +246,7 @@ namespace Cthangover.Core.UI.Tool.ScenarioEditor
_editTabs.SaveCurrentFile();
// The running game caches scenario headers and texts: drop them, so a new or
// edited scenario plays on the next entry into its scene without a mod reload.
SceneFileService.RefreshGame();
SceneManager.ReloadContent();
SetStatus(string.Format(ToolUi.Tr("tools/common/saved"), ScenarioFileService.GetDisplayPath(modId, relativePath)), ToolStatusKind.Ok);
_infoPanel.Update(text);
_thumbPanel.Load(text);
+4 -4
View File
@@ -29,7 +29,7 @@ namespace Cthangover.Tools.SceneEditor
/// one of them — the file of the mod chosen in "Save to": the scene's own file when
/// that mod defines it, otherwise a new file that adds to a foreign scene without
/// touching the foreign mod. Backgrounds of the other files are shown locked, with
/// their mod. After saving the game re-reads scenes (<see cref="SceneFileService.RefreshGame"/>),
/// their mod. After saving the game re-reads scenes (<see cref="SceneManager.ReloadContent"/>),
/// so a new scene can be entered at once with "Go to scene".
/// </summary>
public partial class SceneEditorWindow : ToolWindow
@@ -466,7 +466,7 @@ namespace Cthangover.Tools.SceneEditor
}
var created = _isNew;
SceneFileService.RefreshGame();
SceneManager.ReloadContent();
var name = _sceneName;
var mod = _target.ModId;
LoadSources();
@@ -496,7 +496,7 @@ namespace Cthangover.Tools.SceneEditor
}
var path = _target.ModId + "/" + _target.RelativePath;
SceneFileService.RefreshGame();
SceneManager.ReloadContent();
LoadSources();
if (FilesOf(_sceneName).Any())
{
@@ -558,7 +558,7 @@ namespace Cthangover.Tools.SceneEditor
SetStatus(ToolUi.Tr("tools/common/readonly"), ToolStatusKind.Error);
return;
}
SceneFileService.RefreshGame();
SceneManager.ReloadContent();
RefreshAll();
OpenScenarioEditor(key);
SetStatus(string.Format(ToolUi.Tr("tools/scene_editor/scenario_created"), key), ToolStatusKind.Ok);
+3 -14
View File
@@ -10,11 +10,9 @@ namespace Cthangover.Tools.Services
{
/// <summary>
/// Scene files (<c>scenes/**.json</c>) of the loaded mods for the scene editor: reading
/// them per mod in load order (the order the game merges them in), writing one, and
/// making the running game see the change at once. The game caches scene definitions
/// and scenario headers; <see cref="RefreshGame"/> drops those caches and lets
/// <see cref="SceneManager"/> rescan, the same steps the scenario studio takes after
/// creating a scene in its layer, so a new scene can be entered without a mod reload.
/// them per mod in load order (the order the game merges them in), writing and deleting
/// one. After a write the caller runs <see cref="SceneManager.ReloadContent"/>, so a new
/// scene can be entered without a mod reload.
/// </summary>
public static class SceneFileService
{
@@ -62,15 +60,6 @@ namespace Cthangover.Tools.Services
return true;
}
/// <summary>Makes the running game re-read scene files and scenario headers.</summary>
public static void RefreshGame()
{
ScenarioDefs.Invalidate();
ModManager.Instance.GetResolver<SceneDefinitionResolver>()?.ClearCache();
AppServices.Current.SceneDefs.Clear();
SceneManager.RescanScenes();
}
private static void Collect(IModFileProvider provider, string modId, string directory, List<SceneFileEntry> result)
{
foreach (var entry in provider.ListFiles(directory))