pandemonium_engine_docs/03_usage/07_io/data_paths.md

178 lines
8.8 KiB
Markdown
Raw Normal View History

2023-01-12 20:49:14 +01:00
2024-03-16 20:56:52 +01:00
File paths in Pandemonium projects
============================
2024-03-16 20:56:52 +01:00
This page explains how file paths work inside Pandemonium projects. You will learn how
2023-01-12 19:43:03 +01:00
to access paths in your projects using the `res://` and `user://` notations,
2024-03-16 20:56:52 +01:00
and where Pandemonium stores project and editor files on your and your users' systems.
Path separators
---------------
2024-03-16 20:56:52 +01:00
To make supporting multiple platforms easier, Pandemonium uses **UNIX-style path
2023-01-12 19:43:03 +01:00
separators** (forward slash `/`). These work on all platforms, **including
Windows**.
2024-03-16 20:56:52 +01:00
Instead of writing paths like `C:\Projects\Game`, in Pandemonium, you should write
2023-01-12 19:43:03 +01:00
`C:/Projects/Game`.
2023-01-12 19:43:03 +01:00
Windows-style path separators (backward slash `\`) are also supported in some
path-related methods, but they need to be doubled (`\\`), as `\` is normally
used as an escape for characters with a special meaning.
This makes it possible to work with paths returned by other Windows
applications. We still recommend using only forward slashes in your own code to
guarantee that everything will work as intended.
2023-01-12 19:43:03 +01:00
Accessing files in the project folder (`res://`)
--------------------------------------------------
2024-03-16 20:56:52 +01:00
Pandemonium considers that a project exists in any folder that contains a
`project.pandemonium` text file, even if the file is empty. The folder that contains
this file is your project's root folder.
You can access any file relative to it by writing paths starting with
2023-01-12 19:43:03 +01:00
`res://`, which stands for resources. For example, you can access an image
2023-01-12 20:16:00 +01:00
file `character.png)` located in the project's root folder in code with the
following path: `res://character.png)`.
2023-01-12 19:43:03 +01:00
Accessing persistent user data (`user://`)
--------------------------------------------
To store persistent data files, like the player's save or settings, you want to
2023-01-12 19:43:03 +01:00
use `user://` instead of `res://` as your path's prefix. This is because
when the game is running, the project's file system will likely be read-only.
2023-01-12 19:43:03 +01:00
The `user://` prefix points to a different directory on the user's device.
Unlike `res://`, the directory pointed at by `user://` is created
automatically and *guaranteed* to be writable to, even in an exported project.
2023-01-12 19:43:03 +01:00
The location of the `user://` folder depends on what is configured in the
Project Settings:
2024-03-16 20:56:52 +01:00
- By default, the `user://` folder is created within Pandemonium's
2023-01-12 20:47:54 +01:00
`editor data path ( doc_data_paths_editor_data_paths )` in the
2023-01-12 19:43:03 +01:00
`app_userdata/[project_name]` folder. This is the default so that prototypes
2024-03-16 20:56:52 +01:00
and test projects stay self-contained within Pandemonium's data folder.
2023-01-12 19:30:47 +01:00
- If `application/config/use_custom_user_dir`
2023-01-12 19:43:03 +01:00
is enabled in the Project Settings, the `user://` folder is created **next
2024-03-16 20:56:52 +01:00
to** Pandemonium's editor data path, i.e. in the standard location for applications
data.
* By default, the folder name will be inferred from the project name, but it
can be further customized with
2023-01-12 19:30:47 +01:00
`application/config/custom_user_dir_name`.
This path can contain path separators, so you can use it e.g. to group
2023-01-12 19:43:03 +01:00
projects of a given studio with a `Studio Name/Game Name` structure.
2023-01-12 19:43:03 +01:00
On desktop platforms, the actual directory paths for `user://` are:
+---------------------+------------------------------------------------------------------------------+
| Type | Location |
+=====================+==============================================================================+
2024-03-16 20:56:52 +01:00
| Default | | Windows: `%APPDATA%\Pandemonium\app_userdata\[project_name]` |
| | | macOS: `~/Library/Application Support/Pandemonium/app_userdata/[project_name]` |
| | | Linux: `~/.local/share/pandemonium/app_userdata/[project_name]` |
+---------------------+------------------------------------------------------------------------------+
2023-01-12 19:43:03 +01:00
| Custom dir | | Windows: `%APPDATA%\[project_name]` |
| | | macOS: `~/Library/Application Support/[project_name]` |
| | | Linux: `~/.local/share/[project_name]` |
+---------------------+------------------------------------------------------------------------------+
2023-01-12 19:43:03 +01:00
| Custom dir and name | | Windows: `%APPDATA%\[custom_user_dir_name]` |
| | | macOS: `~/Library/Application Support/[custom_user_dir_name]` |
| | | Linux: `~/.local/share/[custom_user_dir_name]` |
+---------------------+------------------------------------------------------------------------------+
2023-01-12 19:43:03 +01:00
`[project_name]` is based on the application name defined in the Project Settings, but
2023-01-12 20:47:54 +01:00
you can override it on a per-platform basis using `feature tags ( doc_feature_tags )`.
On mobile platforms, this path is unique to the project and is not accessible
by other applications for security reasons.
2023-01-12 19:43:03 +01:00
On HTML5 exports, `user://` will refer to a virtual filesystem stored on the
device via IndexedDB. (Interaction with the main filesystem can still be performed
2023-01-12 19:30:47 +01:00
through the `JavaScript` singleton.)
Converting paths to absolute paths or "local" paths
---------------------------------------------------
2023-01-12 19:30:47 +01:00
You can use `ProjectSettings.globalize_path()`
2023-01-12 19:43:03 +01:00
to convert a "local" path like `res://path/to/file.txt` to an absolute OS path.
2023-01-12 19:30:47 +01:00
For example, `ProjectSettings.globalize_path()`
can be used to open "local" paths in the OS file manager
2023-01-12 19:30:47 +01:00
using `OS.shell_open()` since it only accepts
native OS paths.
2023-01-12 19:43:03 +01:00
To convert an absolute OS path to a "local" path starting with `res://`
or `user://`, use `ProjectSettings.localize_path()`.
This only works for absolute paths that point to files or folders in your
2023-01-12 19:43:03 +01:00
project's root or `user://` folders.
2023-01-12 20:49:14 +01:00
Editor data paths
-----------------
The editor uses different paths for editor data, editor settings, and cache,
depending on the platform. By default, these paths are:
+-----------------+---------------------------------------------------+
| Type | Location |
+=================+===================================================+
2024-03-16 20:56:52 +01:00
| Editor data | | Windows: `%APPDATA%\Pandemonium\` |
| | | macOS: `~/Library/Application Support/Pandemonium/` |
| | | Linux: `~/.local/share/pandemonium/` |
+-----------------+---------------------------------------------------+
2024-03-16 20:56:52 +01:00
| Editor settings | | Windows: `%APPDATA%\Pandemonium\` |
| | | macOS: `~/Library/Application Support/Pandemonium/` |
| | | Linux: `~/.config/pandemonium/` |
+-----------------+---------------------------------------------------+
2024-03-16 20:56:52 +01:00
| Cache | | Windows: `%TEMP%\Pandemonium\` |
| | | macOS: `~/Library/Caches/Pandemonium/` |
| | | Linux: `~/.cache/pandemonium/` |
+-----------------+---------------------------------------------------+
- **Editor data** contains export templates and project-specific data.
- **Editor settings** contains the main editor settings configuration file as
well as various other user-specific customizations (editor layouts, feature
profiles, script templates, etc.).
- **Cache** contains data generated by the editor, or stored temporarily.
2024-03-16 20:56:52 +01:00
It can safely be removed when Pandemonium is closed.
2024-03-16 20:56:52 +01:00
Pandemonium complies with the `XDG Base Directory Specification
2023-01-12 20:39:50 +01:00
( https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html )`
on all platforms. You can override environment variables following the
specification to change the editor and project data paths.
2023-01-12 20:55:57 +01:00
Note:
2024-03-16 20:56:52 +01:00
If you use `Pandemonium packaged as a Flatpak
( https://flathub.org/apps/details/org.pandemoniumengine.Pandemonium )`, the
editor data paths will be located in subfolders in
2024-03-16 20:56:52 +01:00
`~/.var/app/org.pandemoniumengine.Pandemonium/`.
2023-01-12 20:49:14 +01:00
Self-contained mode
~~~~~~~~~~~~~~~~~~~
2023-01-12 20:57:31 +01:00
If you create a file called `._sc_` or `sc_` in the same directory as the
2024-03-16 20:56:52 +01:00
editor binary (or in `MacOS/Contents/` for a macOS editor .app bundle), Pandemonium
will enable *self-contained mode*.
2024-03-16 20:56:52 +01:00
This mode makes Pandemonium write all editor data, settings, and cache to a directory
2023-01-12 19:43:03 +01:00
named `editor_data/` in the same directory as the editor binary.
You can use it to create a portable installation of the editor.
2024-03-16 20:56:52 +01:00
The `Steam release of Pandemonium ( https://store.steampowered.com/app/404790/ )` uses
self-contained mode by default.
2023-01-12 20:55:57 +01:00
Note:
Self-contained mode is not supported in exported projects yet.
To read and write files relative to the executable path, use
2023-01-12 19:30:47 +01:00
`OS.get_executable_path()`.
Note that writing files in the executable path only works if the executable
is placed in a writable location (i.e. **not** Program Files or another
directory that is read-only for regular users).