Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

File system

Introduzione

Un file system gestisce come le risorse sono memorizzate e come vi si accede. Un file system ben progettato permette anche a più sviluppatori di modificare gli stessi file sorgente e le risorse mentre si collabora. Godot memorizza tutte le risorse come file nel suo file system.

Implementazione

The file system stores resources on disk. Anything, from a script, to a scene or a PNG image is a resource to the engine. If a resource contains properties that reference other resources on disk, the paths to those resources are also included. If a resource has sub-resources that are built-in, the resource is saved in a single file together with all the bundled sub-resources. For example, a font resource is often bundled together with the font textures.

Il file system di Godot evita di usare file di metadati. I gestori di risorse e VCS esistenti sono migliori di qualsiasi cosa possiamo implementare, quindi Godot fa del suo meglio per integrarsi con Subversion, Git, Mercurial, ecc.

Esempio di contenuto di un file system:

/project.godot
/enemy/enemy.tscn
/enemy/enemy.gd
/enemy/enemysprite.png
/player/player.gd

project.godot

Il file project.godot è il file di descrizione del progetto, e si trova sempre alla radice del progetto. Infatti, la sua posizione definisce dove si trova la radice. Questo è il primo file che Godot cerca quando apre un progetto.

Questo file contiene la configurazione del progetto in testo semplice, usando il formato win.ini. Anche un progetto.godot vuoto può funzionare come definizione di base di un progetto vuoto.

Delimitatore di percorso

Godot supporta solo / come delimitatore di percorso. Questo è fatto per ragioni di portabilità. Tutti i sistemi operativi lo supportano, anche Windows, quindi un percorso come C:\project\project.godot deve essere digitato come C:/project/project.godot.

Percorso delle risorse

When accessing resources, using the host OS file system layout can be cumbersome and non-portable. To solve this problem, the special path res:// was created.

Il percorso res:// punterà sempre alla radice del progetto (dove si trova project.godot, quindi res://project.godot è sempre valido).

This file system is read-write only when running the project locally from the editor. When exported or when running on different devices (such as phones or consoles, or running from DVD), the file system will become read-only and writing will no longer be permitted.

Percorso dell'utente

Writing to disk is still needed for tasks such as saving game state or downloading content packs. To this end, the engine ensures that there is a special path user:// that is always writable. This path resolves differently depending on the OS the project is running on. Local path resolution is further explained in Percorsi di file nei progetti di Godot.

File system dell'host

Alternatively host file system paths can also be used, but this is not recommended for a released product as these paths are not guaranteed to work on all platforms. However, using host file system paths can be useful when writing development tools in Godot.

Svantaggi

There are some drawbacks to this file system design. The first issue is that moving assets around (renaming them or moving them from one path to another inside the project) will break existing references to these assets. These references will have to be re-defined to point at the new asset location.

To avoid this, do all your move, delete and rename operations from within Godot, on the FileSystem dock. When you delete files in Godot, it will prompt you with a confirmation dialog listing all selected files and any scenes that depend on those files. Never move assets from outside Godot, or dependencies will have to be fixed manually (Godot detects this and helps you fix them anyway, but why go the hard route?).

The second is that, under Windows and macOS, file and path names are case insensitive. If a developer working in a case insensitive host file system saves an asset as myfile.PNG, but then references it as myfile.png, it will work fine on their platform, but not on other platforms, such as Linux, Android, etc. This may also apply to exported binaries, which use a compressed package to store all files.

It is recommended that your team clearly define a naming convention for files when working with Godot. One fool-proof convention is to only allow lowercase file and path names.