mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
Project user settings, load recent scenes, properly cleanup ScriptEngine when switching scenes
This commit is contained in:
@@ -19,12 +19,17 @@ class Project
|
||||
|
||||
[BonIgnore]
|
||||
private String _scriptFolder ~ delete _;
|
||||
|
||||
[BonIgnore]
|
||||
private ProjectUserSettings _userSettings ~ delete _;
|
||||
|
||||
public StringView Name => _projectName;
|
||||
public StringView WorkspacePath => _workspacePath;
|
||||
|
||||
public StringView AssetsFolder => _assetsFolder;
|
||||
|
||||
public ProjectUserSettings UserSettings => _userSettings;
|
||||
|
||||
[AllowAppend]
|
||||
private this(StringView workspacePath)
|
||||
{
|
||||
@@ -32,13 +37,62 @@ class Project
|
||||
|
||||
_assetsFolder = new String();
|
||||
PathInProject(_assetsFolder, "Assets");
|
||||
}
|
||||
|
||||
InitUserSettings();
|
||||
}
|
||||
|
||||
/// Writes the the absolute path of the give project-file into target.
|
||||
/// @param target The string that will contain the full path.
|
||||
/// @param relativePath The path of the file relative to the workspace folder.
|
||||
public void PathInProject(String target, StringView relativePath)
|
||||
{
|
||||
Path.Combine(target, WorkspacePath, relativePath);
|
||||
}
|
||||
|
||||
/// Creates a new scoped string that contains the absolute path of the give project-file
|
||||
/// @param relativePath The path of the file relative to the workspace folder.
|
||||
public mixin GetScopedPath(StringView relativePath)
|
||||
{
|
||||
String target = scope:mixin String();
|
||||
|
||||
PathInProject(target, relativePath);
|
||||
|
||||
target
|
||||
}
|
||||
|
||||
/// Loads or creates the user specific settings for this project.
|
||||
private void InitUserSettings()
|
||||
{
|
||||
_userSettings = new ProjectUserSettings();
|
||||
|
||||
String userSettingsFile = scope .();
|
||||
PathInProject(userSettingsFile, ProjectUserSettings.FileName);
|
||||
|
||||
// It's not a problem if we couldn't find or deserialize the settings. We will simply restore the defaults.
|
||||
if (Bon.DeserializeFromFile(ref _userSettings, userSettingsFile) case .Err)
|
||||
{
|
||||
// Log anyway, just in case...
|
||||
Log.EngineLogger.Info($"Failed to deserialize project user settings file \"{userSettingsFile}\".");
|
||||
_userSettings.RestoreDefaults();
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveUserSettings()
|
||||
{
|
||||
if (_userSettings == null || !_userSettings.SettignsDirty)
|
||||
return;
|
||||
|
||||
String userSettingsFile = scope .();
|
||||
PathInProject(userSettingsFile, ProjectUserSettings.FileName);
|
||||
|
||||
// It's not a big problem, if we fail to serialize this file.
|
||||
if (Bon.SerializeIntoFile(_userSettings, userSettingsFile) case .Err)
|
||||
{
|
||||
// Log anyway, just in case...
|
||||
Log.EngineLogger.Error($"Failed to deserialize project user settings file \"{userSettingsFile}\".");
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new project with the given directory and name.
|
||||
public static Project CreateNew(StringView projectDirectory, StringView projectName)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user