diff options
Diffstat (limited to 'doc')
-rw-r--r-- | doc/classes/DirAccess.xml (renamed from doc/classes/Directory.xml) | 43 | ||||
-rw-r--r-- | doc/classes/EditorTranslationParserPlugin.xml | 2 | ||||
-rw-r--r-- | doc/classes/FileAccess.xml (renamed from doc/classes/File.xml) | 85 | ||||
-rw-r--r-- | doc/classes/OS.xml | 2 | ||||
-rw-r--r-- | doc/classes/PackedByteArray.xml | 6 | ||||
-rw-r--r-- | doc/classes/ResourceSaver.xml | 4 | ||||
-rw-r--r-- | doc/classes/StreamPeerBuffer.xml | 2 |
7 files changed, 77 insertions, 67 deletions
diff --git a/doc/classes/Directory.xml b/doc/classes/DirAccess.xml index c9a9f346a5..ddb98030eb 100644 --- a/doc/classes/Directory.xml +++ b/doc/classes/DirAccess.xml @@ -1,18 +1,18 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="Directory" inherits="RefCounted" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> +<class name="DirAccess" inherits="RefCounted" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> <brief_description> Type used to handle the filesystem. </brief_description> <description> Directory type. It is used to manage directories and their content (not restricted to the project folder). - When creating a new [Directory], it must be explicitly opened using [method open] before most methods can be used. However, [method file_exists] and [method dir_exists] can be used without opening a directory. If so, they use a path relative to [code]res://[/code]. + [DirAccess] can't be instantiated directly. Instead it is created with a static method that takes a path for which it will be opened. [b]Note:[/b] Many resources types are imported (e.g. textures or sound files), and their source asset will not be included in the exported game, as only the imported version is used. Use [ResourceLoader] to access imported resources. Here is an example on how to iterate through the files of a directory: [codeblocks] [gdscript] func dir_contents(path): - var dir = Directory.new() - if dir.open(path) == OK: + var dir = DirAccess.open(path) + if dir: dir.list_dir_begin() var file_name = dir.get_next() while file_name != "": @@ -27,8 +27,8 @@ [csharp] public void DirContents(string path) { - var dir = new Directory(); - if (dir.Open(path) == Error.Ok) + var dir = DirAccess.Open(path); + if (dir != null) { dir.ListDirBegin(); string fileName = dir.GetNext(); @@ -69,8 +69,10 @@ <return type="int" enum="Error" /> <param index="0" name="from" type="String" /> <param index="1" name="to" type="String" /> + <param index="2" name="chmod_flags" type="int" default="-1" /> <description> Copies the [param from] file to the [param to] destination. Both arguments should be paths to files, either relative or absolute. If the destination file exists and is not access-protected, it will be overwritten. + If [param chmod_flags] is different than [code]-1[/code], the unix permissions for the destination path will be set to the provided value, if available on the current operating system. Returns one of the [enum Error] code constants ([code]OK[/code] on success). </description> </method> @@ -85,7 +87,7 @@ <param index="0" name="path" type="String" /> <description> Returns whether the target directory exists. The argument can be relative to the current directory, or an absolute path. - If the [Directory] is not open, the path is relative to [code]res://[/code]. + If the [DirAccess] is not open, the path is relative to [code]res://[/code]. </description> </method> <method name="file_exists"> @@ -93,11 +95,12 @@ <param index="0" name="path" type="String" /> <description> Returns whether the target file exists. The argument can be relative to the current directory, or an absolute path. - If the [Directory] is not open, the path is relative to [code]res://[/code]. + If the [DirAccess] is not open, the path is relative to [code]res://[/code]. </description> </method> - <method name="get_current_dir"> + <method name="get_current_dir" qualifiers="const"> <return type="String" /> + <param index="0" name="include_drive" type="bool" default="true" /> <description> Returns the absolute path to the currently opened directory (e.g. [code]res://folder[/code] or [code]C:\tmp\folder[/code]). </description> @@ -144,8 +147,14 @@ <method name="get_next"> <return type="String" /> <description> - Returns the next element (file or directory) in the current directory (including [code].[/code] and [code]..[/code], unless [code]skip_navigational[/code] was given to [method list_dir_begin]). - The name of the file or directory is returned (and not its full path). Once the stream has been fully processed, the method returns an empty String and closes the stream automatically (i.e. [method list_dir_end] would not be mandatory in such a case). + Returns the next element (file or directory) in the current directory. + The name of the file or directory is returned (and not its full path). Once the stream has been fully processed, the method returns an empty [String] and closes the stream automatically (i.e. [method list_dir_end] would not be mandatory in such a case). + </description> + </method> + <method name="get_open_error" qualifiers="static"> + <return type="int" enum="Error" /> + <description> + Returns the result of the last [method open] call in the current thread. </description> </method> <method name="get_space_left"> @@ -184,12 +193,12 @@ Returns one of the [enum Error] code constants ([code]OK[/code] on success). </description> </method> - <method name="open"> - <return type="int" enum="Error" /> + <method name="open" qualifiers="static"> + <return type="DirAccess" /> <param index="0" name="path" type="String" /> <description> - Opens an existing directory of the filesystem. The [param path] argument can be within the project tree ([code]res://folder[/code]), the user directory ([code]user://folder[/code]) or an absolute path of the user filesystem (e.g. [code]/tmp/folder[/code] or [code]C:\tmp\folder[/code]). - Returns one of the [enum Error] code constants ([code]OK[/code] on success). + Creates a new [DirAccess] object and opens an existing directory of the filesystem. The [param path] argument can be within the project tree ([code]res://folder[/code]), the user directory ([code]user://folder[/code]) or an absolute path of the user filesystem (e.g. [code]/tmp/folder[/code] or [code]C:\tmp\folder[/code]). + Returns [code]null[/code] if opening the directory failed. You can use [method get_open_error] to check the error that ocurred. </description> </method> <method name="remove"> @@ -212,11 +221,11 @@ </method> </methods> <members> - <member name="include_hidden" type="bool" setter="set_include_hidden" getter="get_include_hidden" default="false"> + <member name="include_hidden" type="bool" setter="set_include_hidden" getter="get_include_hidden"> If [code]true[/code], hidden files are included when the navigating directory. Affects [method list_dir_begin], [method get_directories] and [method get_files]. </member> - <member name="include_navigational" type="bool" setter="set_include_navigational" getter="get_include_navigational" default="false"> + <member name="include_navigational" type="bool" setter="set_include_navigational" getter="get_include_navigational"> If [code]true[/code], [code].[/code] and [code]..[/code] are included when navigating the directory. Affects [method list_dir_begin] and [method get_directories]. </member> diff --git a/doc/classes/EditorTranslationParserPlugin.xml b/doc/classes/EditorTranslationParserPlugin.xml index d028996db8..08986781cd 100644 --- a/doc/classes/EditorTranslationParserPlugin.xml +++ b/doc/classes/EditorTranslationParserPlugin.xml @@ -72,7 +72,7 @@ msgidsContextPlural.Add(new Godot.Collections.Array{"Only with context", "a friendly context", ""}); [/csharp] [/codeblocks] - [b]Note:[/b] If you override parsing logic for standard script types (GDScript, C#, etc.), it would be better to load the [code]path[/code] argument using [method ResourceLoader.load]. This is because built-in scripts are loaded as [Resource] type, not [File] type. + [b]Note:[/b] If you override parsing logic for standard script types (GDScript, C#, etc.), it would be better to load the [code]path[/code] argument using [method ResourceLoader.load]. This is because built-in scripts are loaded as [Resource] type, not [FileAccess] type. For example: [codeblocks] [gdscript] diff --git a/doc/classes/File.xml b/doc/classes/FileAccess.xml index 76c6a4871c..61377fb13a 100644 --- a/doc/classes/File.xml +++ b/doc/classes/FileAccess.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="File" inherits="RefCounted" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> +<class name="FileAccess" inherits="RefCounted" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> <brief_description> Type to handle file reading and writing operations. </brief_description> @@ -9,39 +9,36 @@ [codeblocks] [gdscript] func save(content): - var file = File.new() - file.open("user://save_game.dat", File.WRITE) + var file = FileAccess.open("user://save_game.dat", FileAccess.WRITE) file.store_string(content) - file.close() func load(): - var file = File.new() - file.open("user://save_game.dat", File.READ) + var file = FileAccess.open("user://save_game.dat", FileAccess.READ) var content = file.get_as_text() - file.close() return content [/gdscript] [csharp] public void Save(string content) { - var file = new File(); - file.Open("user://save_game.dat", File.ModeFlags.Write); + var file = FileAccess.Open("user://save_game.dat", File.ModeFlags.Write); file.StoreString(content); - file.Close(); } public string Load() { - var file = new File(); - file.Open("user://save_game.dat", File.ModeFlags.Read); + var file = FileAccess.Open("user://save_game.dat", File.ModeFlags.Read); string content = file.GetAsText(); - file.Close(); return content; } [/csharp] [/codeblocks] In the example above, the file will be saved in the user data folder as specified in the [url=$DOCS_URL/tutorials/io/data_paths.html]Data paths[/url] documentation. - [b]Note:[/b] To access project resources once exported, it is recommended to use [ResourceLoader] instead of the [File] API, as some files are converted to engine-specific formats and their original source files might not be present in the exported PCK package. + There is no method to close a file in order to free it from use. Instead, [FileAccess] will close when it's freed, which happens when it goes out of scope or when it gets assigned with [code]null[/code]. + [codeblock] + var file = FileAccess.open("res://something") # File is opened and locked for use. + file = null # File is closed. + [/codeblock] + [b]Note:[/b] To access project resources once exported, it is recommended to use [ResourceLoader] instead of the [FileAccess] API, as some files are converted to engine-specific formats and their original source files might not be present in the exported PCK package. [b]Note:[/b] Files are automatically closed only if the process exits "normally" (such as by clicking the window manager's close button or pressing [b]Alt + F4[/b]). If you stop the project execution by pressing [b]F8[/b] while the project is running, the file won't be closed as the game process will be killed. You can work around this by calling [method flush] at regular intervals. </description> <tutorials> @@ -49,12 +46,6 @@ <link title="3D Voxel Demo">https://godotengine.org/asset-library/asset/676</link> </tutorials> <methods> - <method name="close"> - <return type="void" /> - <description> - Closes the currently opened file and prevents subsequent read/write operations. Use [method flush] to persist the data to disk without closing the file. - </description> - </method> <method name="eof_reached" qualifiers="const"> <return type="bool" /> <description> @@ -85,7 +76,7 @@ <method name="flush"> <return type="void" /> <description> - Writes the file's buffer to disk. Flushing is automatically performed when the file is closed. This means you don't need to call [method flush] manually before closing a file using [method close]. Still, calling [method flush] can be used to ensure the data is safe even if the project crashes instead of being closed gracefully. + Writes the file's buffer to disk. Flushing is automatically performed when the file is closed. This means you don't need to call [method flush] manually before closing a file. Still, calling [method flush] can be used to ensure the data is safe even if the project crashes instead of being closed gracefully. [b]Note:[/b] Only call [method flush] when you actually need it. Otherwise, it will decrease performance due to constant disk writes. </description> </method> @@ -174,20 +165,26 @@ Text is interpreted as being UTF-8 encoded. </description> </method> - <method name="get_md5" qualifiers="const"> + <method name="get_md5" qualifiers="static"> <return type="String" /> <param index="0" name="path" type="String" /> <description> Returns an MD5 String representing the file at the given path or an empty [String] on failure. </description> </method> - <method name="get_modified_time" qualifiers="const"> + <method name="get_modified_time" qualifiers="static"> <return type="int" /> <param index="0" name="file" type="String" /> <description> Returns the last time the [param file] was modified in Unix timestamp format or returns a [String] "ERROR IN [code]file[/code]". This Unix timestamp can be converted to another format using the [Time] singleton. </description> </method> + <method name="get_open_error" qualifiers="static"> + <return type="int" enum="Error" /> + <description> + Returns the result of the last [method open] call in the current thread. + </description> + </method> <method name="get_pascal_string"> <return type="String" /> <description> @@ -219,7 +216,7 @@ Returns the next bits from the file as a floating-point number. </description> </method> - <method name="get_sha256" qualifiers="const"> + <method name="get_sha256" qualifiers="static"> <return type="String" /> <param index="0" name="path" type="String" /> <description> @@ -240,41 +237,45 @@ Returns [code]true[/code] if the file is currently opened. </description> </method> - <method name="open"> - <return type="int" enum="Error" /> + <method name="open" qualifiers="static"> + <return type="FileAccess" /> <param index="0" name="path" type="String" /> - <param index="1" name="flags" type="int" enum="File.ModeFlags" /> + <param index="1" name="flags" type="int" enum="FileAccess.ModeFlags" /> <description> - Opens the file for writing or reading, depending on the flags. + Creates a new [FileAccess] object and opens the file for writing or reading, depending on the flags. + Returns [code]null[/code] if opening the file failed. You can use [method get_open_error] to check the error that ocurred. </description> </method> - <method name="open_compressed"> - <return type="int" enum="Error" /> + <method name="open_compressed" qualifiers="static"> + <return type="FileAccess" /> <param index="0" name="path" type="String" /> - <param index="1" name="mode_flags" type="int" enum="File.ModeFlags" /> - <param index="2" name="compression_mode" type="int" enum="File.CompressionMode" default="0" /> + <param index="1" name="mode_flags" type="int" enum="FileAccess.ModeFlags" /> + <param index="2" name="compression_mode" type="int" enum="FileAccess.CompressionMode" default="0" /> <description> - Opens a compressed file for reading or writing. + Creates a new [FileAccess] object and opens a compressed file for reading or writing. [b]Note:[/b] [method open_compressed] can only read files that were saved by Godot, not third-party compression formats. See [url=https://github.com/godotengine/godot/issues/28999]GitHub issue #28999[/url] for a workaround. + Returns [code]null[/code] if opening the file failed. You can use [method get_open_error] to check the error that ocurred. </description> </method> - <method name="open_encrypted"> - <return type="int" enum="Error" /> + <method name="open_encrypted" qualifiers="static"> + <return type="FileAccess" /> <param index="0" name="path" type="String" /> - <param index="1" name="mode_flags" type="int" enum="File.ModeFlags" /> + <param index="1" name="mode_flags" type="int" enum="FileAccess.ModeFlags" /> <param index="2" name="key" type="PackedByteArray" /> <description> - Opens an encrypted file in write or read mode. You need to pass a binary key to encrypt/decrypt it. + Creates a new [FileAccess] object and opens an encrypted file in write or read mode. You need to pass a binary key to encrypt/decrypt it. [b]Note:[/b] The provided key must be 32 bytes long. + Returns [code]null[/code] if opening the file failed. You can use [method get_open_error] to check the error that ocurred. </description> </method> - <method name="open_encrypted_with_pass"> - <return type="int" enum="Error" /> + <method name="open_encrypted_with_pass" qualifiers="static"> + <return type="FileAccess" /> <param index="0" name="path" type="String" /> - <param index="1" name="mode_flags" type="int" enum="File.ModeFlags" /> + <param index="1" name="mode_flags" type="int" enum="FileAccess.ModeFlags" /> <param index="2" name="pass" type="String" /> <description> - Opens an encrypted file in write or read mode. You need to pass a password to encrypt/decrypt it. + Creates a new [FileAccess] object and opens an encrypted file in write or read mode. You need to pass a password to encrypt/decrypt it. + Returns [code]null[/code] if opening the file failed. You can use [method get_open_error] to check the error that ocurred. </description> </method> <method name="seek"> @@ -432,7 +433,7 @@ </method> </methods> <members> - <member name="big_endian" type="bool" setter="set_big_endian" getter="is_big_endian" default="false"> + <member name="big_endian" type="bool" setter="set_big_endian" getter="is_big_endian"> If [code]true[/code], the file is read with big-endian [url=https://en.wikipedia.org/wiki/Endianness]endianness[/url]. If [code]false[/code], the file is read with little-endian endianness. If in doubt, leave this to [code]false[/code] as most files are written with little-endian endianness. [b]Note:[/b] [member big_endian] is only about the file format, not the CPU type. The CPU endianness doesn't affect the default endianness for files written. [b]Note:[/b] This is always reset to [code]false[/code] whenever you open the file. Therefore, you must set [member big_endian] [i]after[/i] opening the file, not before. diff --git a/doc/classes/OS.xml b/doc/classes/OS.xml index 54f31d7918..d920c45de4 100644 --- a/doc/classes/OS.xml +++ b/doc/classes/OS.xml @@ -522,7 +522,7 @@ <return type="int" enum="Error" /> <param index="0" name="path" type="String" /> <description> - Moves the file or directory to the system's recycle bin. See also [method Directory.remove]. + Moves the file or directory to the system's recycle bin. See also [method DirAccess.remove]. The method takes only global paths, so you may need to use [method ProjectSettings.globalize_path]. Do not use it for files in [code]res://[/code] as it will not work in exported project. [b]Note:[/b] If the user has disabled the recycle bin on their system, the file will be permanently deleted instead. [codeblock] diff --git a/doc/classes/PackedByteArray.xml b/doc/classes/PackedByteArray.xml index efb559522a..ccf012f82c 100644 --- a/doc/classes/PackedByteArray.xml +++ b/doc/classes/PackedByteArray.xml @@ -65,7 +65,7 @@ <return type="PackedByteArray" /> <param index="0" name="compression_mode" type="int" default="0" /> <description> - Returns a new [PackedByteArray] with the data compressed. Set the compression mode using one of [enum File.CompressionMode]'s constants. + Returns a new [PackedByteArray] with the data compressed. Set the compression mode using one of [enum FileAccess.CompressionMode]'s constants. </description> </method> <method name="count" qualifiers="const"> @@ -173,7 +173,7 @@ <param index="0" name="buffer_size" type="int" /> <param index="1" name="compression_mode" type="int" default="0" /> <description> - Returns a new [PackedByteArray] with the data decompressed. Set [param buffer_size] to the size of the uncompressed data. Set the compression mode using one of [enum File.CompressionMode]'s constants. + Returns a new [PackedByteArray] with the data decompressed. Set [param buffer_size] to the size of the uncompressed data. Set the compression mode using one of [enum FileAccess.CompressionMode]'s constants. </description> </method> <method name="decompress_dynamic" qualifiers="const"> @@ -181,7 +181,7 @@ <param index="0" name="max_output_size" type="int" /> <param index="1" name="compression_mode" type="int" default="0" /> <description> - Returns a new [PackedByteArray] with the data decompressed. Set the compression mode using one of [enum File.CompressionMode]'s constants. [b]This method only accepts gzip and deflate compression modes.[/b] + Returns a new [PackedByteArray] with the data decompressed. Set the compression mode using one of [enum FileAccess.CompressionMode]'s constants. [b]This method only accepts gzip and deflate compression modes.[/b] This method is potentially slower than [code]decompress[/code], as it may have to re-allocate its output buffer multiple times while decompressing, whereas [code]decompress[/code] knows it's output buffer size from the beginning. GZIP has a maximal compression ratio of 1032:1, meaning it's very possible for a small compressed payload to decompress to a potentially very large output. To guard against this, you may provide a maximum size this function is allowed to allocate in bytes via [param max_output_size]. Passing -1 will allow for unbounded output. If any positive value is passed, and the decompression exceeds that amount in bytes, then an error will be returned. </description> diff --git a/doc/classes/ResourceSaver.xml b/doc/classes/ResourceSaver.xml index b0c9056cbc..8cd701e0d8 100644 --- a/doc/classes/ResourceSaver.xml +++ b/doc/classes/ResourceSaver.xml @@ -62,10 +62,10 @@ Do not save editor-specific metadata (identified by their [code]__editor[/code] prefix). </constant> <constant name="FLAG_SAVE_BIG_ENDIAN" value="16" enum="SaverFlags" is_bitfield="true"> - Save as big endian (see [member File.big_endian]). + Save as big endian (see [member FileAccess.big_endian]). </constant> <constant name="FLAG_COMPRESS" value="32" enum="SaverFlags" is_bitfield="true"> - Compress the resource on save using [constant File.COMPRESSION_ZSTD]. Only available for binary resource types. + Compress the resource on save using [constant FileAccess.COMPRESSION_ZSTD]. Only available for binary resource types. </constant> <constant name="FLAG_REPLACE_SUBRESOURCE_PATHS" value="64" enum="SaverFlags" is_bitfield="true"> Take over the paths of the saved subresources (see [method Resource.take_over_path]). diff --git a/doc/classes/StreamPeerBuffer.xml b/doc/classes/StreamPeerBuffer.xml index 4bef9f44b7..f33c38e595 100644 --- a/doc/classes/StreamPeerBuffer.xml +++ b/doc/classes/StreamPeerBuffer.xml @@ -4,7 +4,7 @@ Data buffer stream peer. </brief_description> <description> - Data buffer stream peer that uses a byte array as the stream. This object can be used to handle binary data from network sessions. To handle binary data stored in files, [File] can be used directly. + Data buffer stream peer that uses a byte array as the stream. This object can be used to handle binary data from network sessions. To handle binary data stored in files, [FileAccess] can be used directly. A [StreamPeerBuffer] object keeps an internal cursor which is the offset in bytes to the start of the buffer. Get and put operations are performed at the cursor position and will move the cursor accordingly. </description> <tutorials> |