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(); _editTabs.SaveCurrentFile();
// The running game caches scenario headers and texts: drop them, so a new or // 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. // 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); SetStatus(string.Format(ToolUi.Tr("tools/common/saved"), ScenarioFileService.GetDisplayPath(modId, relativePath)), ToolStatusKind.Ok);
_infoPanel.Update(text); _infoPanel.Update(text);
_thumbPanel.Load(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 /// 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 /// 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 /// 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". /// so a new scene can be entered at once with "Go to scene".
/// </summary> /// </summary>
public partial class SceneEditorWindow : ToolWindow public partial class SceneEditorWindow : ToolWindow
@@ -466,7 +466,7 @@ namespace Cthangover.Tools.SceneEditor
} }
var created = _isNew; var created = _isNew;
SceneFileService.RefreshGame(); SceneManager.ReloadContent();
var name = _sceneName; var name = _sceneName;
var mod = _target.ModId; var mod = _target.ModId;
LoadSources(); LoadSources();
@@ -496,7 +496,7 @@ namespace Cthangover.Tools.SceneEditor
} }
var path = _target.ModId + "/" + _target.RelativePath; var path = _target.ModId + "/" + _target.RelativePath;
SceneFileService.RefreshGame(); SceneManager.ReloadContent();
LoadSources(); LoadSources();
if (FilesOf(_sceneName).Any()) if (FilesOf(_sceneName).Any())
{ {
@@ -558,7 +558,7 @@ namespace Cthangover.Tools.SceneEditor
SetStatus(ToolUi.Tr("tools/common/readonly"), ToolStatusKind.Error); SetStatus(ToolUi.Tr("tools/common/readonly"), ToolStatusKind.Error);
return; return;
} }
SceneFileService.RefreshGame(); SceneManager.ReloadContent();
RefreshAll(); RefreshAll();
OpenScenarioEditor(key); OpenScenarioEditor(key);
SetStatus(string.Format(ToolUi.Tr("tools/scene_editor/scenario_created"), key), ToolStatusKind.Ok); 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> /// <summary>
/// Scene files (<c>scenes/**.json</c>) of the loaded mods for the scene editor: reading /// 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 /// them per mod in load order (the order the game merges them in), writing and deleting
/// making the running game see the change at once. The game caches scene definitions /// one. After a write the caller runs <see cref="SceneManager.ReloadContent"/>, so a new
/// and scenario headers; <see cref="RefreshGame"/> drops those caches and lets /// scene can be entered without a mod reload.
/// <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.
/// </summary> /// </summary>
public static class SceneFileService public static class SceneFileService
{ {
@@ -62,15 +60,6 @@ namespace Cthangover.Tools.Services
return true; 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) private static void Collect(IModFileProvider provider, string modId, string directory, List<SceneFileEntry> result)
{ {
foreach (var entry in provider.ListFiles(directory)) foreach (var entry in provider.ListFiles(directory))
@@ -107,7 +107,7 @@ namespace Cthangover.Tools.Tests.NovelFlow
townOriginal = ModFileService.ReadText(Mod, TownScenario); townOriginal = ModFileService.ReadText(Mod, TownScenario);
File.WriteAllText(ProjectSettings.GlobalizePath(Backup), townOriginal ?? string.Empty); File.WriteAllText(ProjectSettings.GlobalizePath(Backup), townOriginal ?? string.Empty);
DeleteParkFiles(); DeleteParkFiles();
SceneFileService.RefreshGame(); SceneManager.ReloadContent();
Check(townOriginal != null && !Scenes.HasScene(Park), "the novel runs in the town, no park yet"); Check(townOriginal != null && !Scenes.HasScene(Park), "the novel runs in the town, no park yet");
OpenToolFromToolbar("tools/scene_editor/title"); OpenToolFromToolbar("tools/scene_editor/title");
Next(); Next();
@@ -351,7 +351,7 @@ namespace Cthangover.Tools.Tests.NovelFlow
ModFileService.WriteText(Mod, TownScenario, townOriginal); ModFileService.WriteText(Mod, TownScenario, townOriginal);
File.Delete(ProjectSettings.GlobalizePath(Backup)); File.Delete(ProjectSettings.GlobalizePath(Backup));
DeleteParkFiles(); DeleteParkFiles();
SceneFileService.RefreshGame(); SceneManager.ReloadContent();
GameLogger.Log("TEST", $"[TEST_RESULT] name=novel_flow passed={passed} failed={failures.Count}"); GameLogger.Log("TEST", $"[TEST_RESULT] name=novel_flow passed={passed} failed={failures.Count}");
GetTree().Quit(failures.Count == 0 ? 0 : 1); GetTree().Quit(failures.Count == 0 ? 0 : 1);
} }
@@ -155,7 +155,7 @@ namespace Cthangover.Tools.Tests.Windows
finally finally
{ {
DeleteLeftovers(scenePath, scenarioPath); DeleteLeftovers(scenePath, scenarioPath);
SceneFileService.RefreshGame(); SceneManager.ReloadContent();
} }
} }