DocumentFiles class
The file of the level being edited and the files around it.
Knows where the level is kept and under which name the game knows it, makes new levels, opens, saves and exports them, and asks about unsaved changes. Owns the recovery copy of the unsaved changes (see AutosaveService), the lock against two editors editing the same file, the script next to the file with the events it describes, and watches the script and the tile sets of the level for changes made by other programs. Shows the file in the title of the window too.
Constructors, destructors, conversion operators
- DocumentFiles(IEditorContext& context, IDocumentFilesHost& host, IRootController& root)
- Creates the files of the level of an editor,
rootopens another level or leaves the editor. - ~DocumentFiles()
- DocumentFiles(const DocumentFiles&) deleted
Public functions
- auto operator=(const DocumentFiles&) -> DocumentFiles& deleted
- auto GetFilePath() const -> StringView
- Returns the path of the level file, may be empty.
- auto GetLevelName() const -> StringView
- Returns the name of the level as episode/level, may be empty.
- void SetFile(StringView path, StringView levelName)
- Sets the file the level is edited as, and its name, the recovery copy belongs to it then.
- void OnDocumentReplaced(StringView path, StringView levelName)
- Sets the file another level replacing the one edited until now is edited as.
- auto CanSaveInPlace() const -> bool
- Returns
trueif the level can be saved to its file. - void GetFileRoots(bool forSaving, SmallVectorImpl<FileRoot>& roots)
- Returns the places levels are opened from or saved to.
- void GetImageRoots(bool forSaving, SmallVectorImpl<FileRoot>& roots)
- Returns the places images are opened from or saved to, outside of the content of the game too.
- auto FindDefaultTileSet() -> String
- Returns a tile set to make a new level with.
- void OpenFile(StringView path)
- Opens a level file in a new editor, asking about unsaved changes first.
- void OpenRecoveryCopy(StringView recoveryPath)
- Restores a recovery copy into the editor, asking about unsaved changes first, see RestoreRecoveryCopy().
- auto RestoreRecoveryCopy(StringView recoveryPath, StringView filePath, StringView levelName) -> bool
- Replaces the level being edited by a recovery copy, with the history of its changes.
- auto OfferRecovery() -> bool
- Offers to restore a recovery copy of the level, returns
falseif there is none. - void ConfirmDiscard(Function<void()>&& proceed)
- Asks whether to save unsaved changes, then proceeds unless cancelled.
- void ExitEditor()
- Leaves the editor for the main menu, asking about unsaved changes first.
- void ShowOpenDialog()
- Shows a dialog to open a level.
- void ShowNewLevelDialog()
- Shows a dialog to make a new level.
- void Save()
- Saves the level to its file, or as a new file if it can't be saved there.
- auto SaveTo(StringView path, bool exportOnly) -> bool
- Saves the level to a file, with
exportOnlywithout the data only the editor uses. - auto SaveAsFile(StringView path, bool move) -> bool
- Saves the level into another file and edits that one from then on, as Save As does.
- void ShowSaveAsDialog(bool exportOnly, Function<void()>&& onSaved = {})
- Shows a dialog to save the level as a new file, or to export it,
onSavedis called once it's saved. - void ShowExportDialog()
- Checks the level and shows a dialog to export it.
- void NoteLevelFileMoved(StringView from, StringView to)
- Tells that a level file was moved or renamed outside of Save As, its place among the recent files goes along.
- void SetExportNotEditable(bool value)
- Sets whether the next export is marked so the editor doesn't open it,
LevelFlags::NotEditable. - void UpdateAutosave(float timeMult)
- Writes the recovery copy when it's time to, unless the copy kept from before wasn't chosen about.
- void SaveRecoveryCopyNow()
- Writes the recovery copy now, before the application may be ended, unless the copy kept from before wasn't chosen about.
- auto GetAutosave() -> AutosaveService&
- Returns what keeps the recovery copy.
- auto GetScriptPath() const -> String
- Returns the path of the script of the level, next to its file, empty if it wasn't saved yet.
- auto GetUnsavedScript() const -> String
- Returns the script of the level with the lines of the weapons of the script as they're now, empty if they're as in its file.
- void EditScript()
- Opens the script of the level in the program of
EditorSettings::ScriptEditoror the one the system has for it. - void LoadEventExtensions(bool packs)
- Describes the events of event packs, with
packs, and of the script of the level, see EventCatalog::LoadExtensions(). - void ShowEventExtensionErrors()
- Tells how many descriptions of events from outside of the game couldn't be read, if any.
- void WatchFiles()
- Remembers when the script and the tile sets of the level were changed on disk, see UpdateFileWatches().
- auto UpdateFileWatches(float timeMult) -> bool
- Reads the script again once it changed, offers to load a tile set again once it changed, keeps the lock fresh.
- void NoteTileSetWritten(StringView name)
- Tells that the editor itself wrote a tile set, it isn't asked about.
- void AcquireLock()
- Takes the lock of the level file against two editors editing it,
<file>.locknext to it. - void ReleaseLock()
- Releases the lock of the level file, if it's the lock of this editor.
- void UpdateWindowTitle(bool force = false)
- Updates the title of the window, it's made again only when the name, the file or the unsaved changes changed, or with
force(after something else set it, as a play-test).
Function documentation
void Jazz2:: Editor:: DocumentFiles:: OnDocumentReplaced(StringView path,
StringView levelName)
Sets the file another level replacing the one edited until now is edited as.
The recovery copy kept without a choice belongs to the file edited until now, as in OfferRecovery().
bool Jazz2:: Editor:: DocumentFiles:: RestoreRecoveryCopy(StringView recoveryPath,
StringView filePath,
StringView levelName)
Replaces the level being edited by a recovery copy, with the history of its changes.
The level is then edited as filePath, which may be empty, and is unsaved. Returns false if the copy can't be read.
bool Jazz2:: Editor:: DocumentFiles:: SaveAsFile(StringView path,
bool move)
Saves the level into another file and edits that one from then on, as Save As does.
The script of the level goes along. With move, the file the level was in is removed, with its script and its place among the recent files — unless the level can't be saved where it is (see CanSaveInPlace()), as a level of the cache, it's only copied then. Returns false if the level couldn't be saved, nothing is changed then.
String Jazz2:: Editor:: DocumentFiles:: GetUnsavedScript() const
Returns the script of the level with the lines of the weapons of the script as they're now, empty if they're as in its file.
They're written into the file only when the level is saved, a play-test runs this text in place of the file.
void Jazz2:: Editor:: DocumentFiles:: EditScript()
Opens the script of the level in the program of EditorSettings::ScriptEditor or the one the system has for it.
A script that doesn't exist yet is made from a template first, once the user agrees to it.
bool Jazz2:: Editor:: DocumentFiles:: UpdateFileWatches(float timeMult)
Reads the script again once it changed, offers to load a tile set again once it changed, keeps the lock fresh.
Returns true in the frames the files are looked at, once a second.
void Jazz2:: Editor:: DocumentFiles:: AcquireLock()
Takes the lock of the level file against two editors editing it, <file>.lock next to it.
The lock of the previous file is released. It's written again every half a minute, a level that seems to be open in another editor is asked about.