ResourceSaver

package
v0.0.0-...-e1beaa7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

A singleton for saving resource types to the filesystem.

It uses the many graphics.gd/classdb/ResourceFormatSaver classes registered in the engine (either built-in or from a plugin) to save resource data to text-based (e.g. .tres or .tscn) or binary files (e.g. .res or .scn).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddResourceFormatSaver

func AddResourceFormatSaver(format_saver ResourceFormatSaver.Instance, at_front bool)

Registers a new graphics.gd/classdb/ResourceFormatSaver. The ResourceSaver will use the ResourceFormatSaver as described in Save.

This method is performed implicitly for ResourceFormatSavers written in GDScript (see graphics.gd/classdb/ResourceFormatSaver for more information).

func AddResourceFormatSaverOptions

func AddResourceFormatSaverOptions(format_saver ResourceFormatSaver.Instance, at_front bool)

Registers a new graphics.gd/classdb/ResourceFormatSaver. The ResourceSaver will use the ResourceFormatSaver as described in Save.

This method is performed implicitly for ResourceFormatSavers written in GDScript (see graphics.gd/classdb/ResourceFormatSaver for more information).

func Advanced

func Advanced() class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

func GetRecognizedExtensions

func GetRecognizedExtensions(atype Resource.Instance) []string

Returns the list of extensions available for saving a resource of a given type.

func GetResourceIdForPath

func GetResourceIdForPath(path string, generate bool) int

Returns the resource ID for the given path. If 'generate' is true, a new resource ID will be generated if one for the path is not found. If 'generate' is false and the path is not found, [Resourceuid.InvalidId] is returned.

func GetResourceIdForPathOptions

func GetResourceIdForPathOptions(path string, generate bool) int

Returns the resource ID for the given path. If 'generate' is true, a new resource ID will be generated if one for the path is not found. If 'generate' is false and the path is not found, [Resourceuid.InvalidId] is returned.

func RemoveResourceFormatSaver

func RemoveResourceFormatSaver(format_saver ResourceFormatSaver.Instance)

Unregisters the given graphics.gd/classdb/ResourceFormatSaver.

func Save

func Save(resource Resource.Instance, path string, flags SaverFlags) error

Saves a resource to disk to the given path, using a graphics.gd/classdb/ResourceFormatSaver that recognizes the resource object. If 'path' is empty, graphics.gd/classdb/ResourceSaver will try to use graphics.gd/classdb/Resource.Instance.ResourcePath.

The 'flags' bitmask can be specified to customize the save behavior.

Returns [Ok] on success.

Note: When the project is running, any generated UID associated with the resource will not be saved as the required code is only executed in editor mode.

func SaveOptions

func SaveOptions(resource Resource.Instance, path string, flags SaverFlags) error

Saves a resource to disk to the given path, using a graphics.gd/classdb/ResourceFormatSaver that recognizes the resource object. If 'path' is empty, graphics.gd/classdb/ResourceSaver will try to use graphics.gd/classdb/Resource.Instance.ResourcePath.

The 'flags' bitmask can be specified to customize the save behavior.

Returns [Ok] on success.

Note: When the project is running, any generated UID associated with the resource will not be saved as the required code is only executed in editor mode.

func SetUid

func SetUid(resource string, uid int) error

Sets the UID of the given 'resource' path to 'uid'. You can generate a new UID using graphics.gd/classdb/ResourceUID.CreateId.

Since resources will normally get a UID automatically, this method is only useful in very specific cases.

Types

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.ResourceSaver

Instance of the class with convieniently typed arguments and results.

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) ID

func (self Instance) ID() ID

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

type SaverFlags

type SaverFlags int //gd:ResourceSaver.SaverFlags
const (
	// No resource saving option.
	FlagNone SaverFlags = 0
	// Save the resource with a path relative to the scene which uses it.
	FlagRelativePaths SaverFlags = 1
	// Bundles external resources.
	FlagBundleResources SaverFlags = 2
	// Changes the [graphics.gd/classdb/Resource.Instance.ResourcePath] of the saved resource to match its new location.
	FlagChangePath SaverFlags = 4
	// Do not save editor-specific metadata (identified by their __editor prefix).
	FlagOmitEditorProperties SaverFlags = 8
	// Save as big endian (see [graphics.gd/classdb/FileAccess.Instance.BigEndian]).
	FlagSaveBigEndian SaverFlags = 16
	// Compress the resource on save using [Fileaccess.CompressionZstd]. Only available for binary resource types.
	FlagCompress SaverFlags = 32
	// Take over the paths of the saved subresources (see [graphics.gd/classdb/Resource.Instance.TakeOverPath]).
	FlagReplaceSubresourcePaths SaverFlags = 64
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL