summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/classes/Animation.xml4
-rw-r--r--doc/classes/CanvasItem.xml11
-rw-r--r--doc/classes/Font.xml1
-rw-r--r--doc/classes/String.xml5
-rw-r--r--main/main.cpp82
-rw-r--r--modules/gdscript/gdscript_analyzer.cpp2
-rw-r--r--modules/regex/doc_classes/RegEx.xml13
-rw-r--r--tests/test_main.cpp58
-rw-r--r--tests/test_main.h5
9 files changed, 61 insertions, 120 deletions
diff --git a/doc/classes/Animation.xml b/doc/classes/Animation.xml
index 09811d5617..68f0a630ef 100644
--- a/doc/classes/Animation.xml
+++ b/doc/classes/Animation.xml
@@ -7,10 +7,10 @@
An Animation resource contains data used to animate everything in the engine. Animations are divided into tracks, and each track must be linked to a node. The state of that node can be changed through time, by adding timed keys (events) to the track.
[codeblock]
# This creates an animation that makes the node "Enemy" move to the right by
- # 100 pixels in 1 second.
+ # 100 pixels in 0.5 seconds.
var animation = Animation.new()
var track_index = animation.add_track(Animation.TYPE_VALUE)
- animation.track_set_path(track_index, "Enemy:position.x")
+ animation.track_set_path(track_index, "Enemy:position:x")
animation.track_insert_key(track_index, 0.0, 0)
animation.track_insert_key(track_index, 0.5, 100)
[/codeblock]
diff --git a/doc/classes/CanvasItem.xml b/doc/classes/CanvasItem.xml
index cac4d6f36e..899988022f 100644
--- a/doc/classes/CanvasItem.xml
+++ b/doc/classes/CanvasItem.xml
@@ -316,7 +316,16 @@
<argument index="4" name="clip_w" type="int" default="-1">
</argument>
<description>
- Draws a string using a custom font.
+ Draws [code]text[/code] using the specified [code]font[/code] at the [code]position[/code] (top-left corner). The text will have its color multiplied by [code]modulate[/code]. If [code]clip_w[/code] is greater than or equal to 0, the text will be clipped if it exceeds the specified width.
+ [b]Example using the default project font:[/b]
+ [codeblock]
+ # If using this method in a script that redraws constantly, move the
+ # `default_font` declaration to a member variable assigned in `_ready()`
+ # so the Control is only created once.
+ var default_font = Control.new().get_font("font")
+ draw_string(default_font, Vector2(64, 64), "Hello world")
+ [/codeblock]
+ See also [method Font.draw].
</description>
</method>
<method name="draw_style_box">
diff --git a/doc/classes/Font.xml b/doc/classes/Font.xml
index 30b8c1fe76..ce6a25e191 100644
--- a/doc/classes/Font.xml
+++ b/doc/classes/Font.xml
@@ -26,6 +26,7 @@
</argument>
<description>
Draw [code]string[/code] into a canvas item using the font at a given position, with [code]modulate[/code] color, and optionally clipping the width. [code]position[/code] specifies the baseline, not the top. To draw from the top, [i]ascent[/i] must be added to the Y axis.
+ See also [method CanvasItem.draw_string].
</description>
</method>
<method name="draw_char" qualifiers="const">
diff --git a/doc/classes/String.xml b/doc/classes/String.xml
index 7e55f8bd9a..ded64761d0 100644
--- a/doc/classes/String.xml
+++ b/doc/classes/String.xml
@@ -895,8 +895,8 @@
<argument index="2" name="maxsplit" type="int" default="0">
</argument>
<description>
- Splits the string by a [code]delimiter[/code] string and returns an array of the substrings.
- If [code]maxsplit[/code] is specified, it defines the number of splits to do from the left up to [code]maxsplit[/code]. The default value of 0 means that all items are split.
+ Splits the string by a [code]delimiter[/code] string and returns an array of the substrings. The [code]delimiter[/code] can be of any length.
+ If [code]maxsplit[/code] is specified, it defines the number of splits to do from the left up to [code]maxsplit[/code]. The default value of [code]0[/code] means that all items are split.
Example:
[codeblock]
var some_string = "One,Two,Three,Four"
@@ -905,6 +905,7 @@
print(some_array[0]) # Prints "One"
print(some_array[1]) # Prints "Two,Three,Four"
[/codeblock]
+ If you need to split strings with more complex rules, use the [RegEx] class instead.
</description>
</method>
<method name="split_floats">
diff --git a/main/main.cpp b/main/main.cpp
index 9978be7ab7..5f791159f9 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -262,25 +262,20 @@ void Main::print_help(const char *p_binary) {
OS::get_singleton()->print(" -h, --help Display this help message.\n");
OS::get_singleton()->print(" --version Display the version string.\n");
OS::get_singleton()->print(" -v, --verbose Use verbose stdout mode.\n");
- OS::get_singleton()->print(
- " --quiet Quiet mode, silences stdout messages. Errors are still displayed.\n");
+ OS::get_singleton()->print(" --quiet Quiet mode, silences stdout messages. Errors are still displayed.\n");
OS::get_singleton()->print("\n");
OS::get_singleton()->print("Run options:\n");
#ifdef TOOLS_ENABLED
OS::get_singleton()->print(" -e, --editor Start the editor instead of running the scene.\n");
- OS::get_singleton()->print(
- " -p, --project-manager Start the project manager, even if a project is auto-detected.\n");
+ OS::get_singleton()->print(" -p, --project-manager Start the project manager, even if a project is auto-detected.\n");
#endif
OS::get_singleton()->print(" -q, --quit Quit after the first iteration.\n");
- OS::get_singleton()->print(
- " -l, --language <locale> Use a specific locale (<locale> being a two-letter code).\n");
- OS::get_singleton()->print(
- " --path <directory> Path to a project (<directory> must contain a 'project.godot' file).\n");
+ OS::get_singleton()->print(" -l, --language <locale> Use a specific locale (<locale> being a two-letter code).\n");
+ OS::get_singleton()->print(" --path <directory> Path to a project (<directory> must contain a 'project.godot' file).\n");
OS::get_singleton()->print(" -u, --upwards Scan folders upwards for project.godot file.\n");
OS::get_singleton()->print(" --main-pack <file> Path to a pack (.pck) file to load.\n");
- OS::get_singleton()->print(
- " --render-thread <mode> Render thread mode ('unsafe', 'safe', 'separate').\n");
+ OS::get_singleton()->print(" --render-thread <mode> Render thread mode ('unsafe', 'safe', 'separate').\n");
OS::get_singleton()->print(" --remote-fs <address> Remote filesystem (<host/IP>[:<port>] address).\n");
OS::get_singleton()->print(" --remote-fs-password <password> Password for remote filesystem.\n");
@@ -321,12 +316,9 @@ void Main::print_help(const char *p_binary) {
OS::get_singleton()->print(" --resolution <W>x<H> Request window resolution.\n");
OS::get_singleton()->print(" --position <X>,<Y> Request window position.\n");
OS::get_singleton()->print(" --low-dpi Force low-DPI mode (macOS and Windows only).\n");
- OS::get_singleton()->print(
- " --no-window Disable window creation (Windows only). Useful together with --script.\n");
- OS::get_singleton()->print(
- " --enable-vsync-via-compositor When vsync is enabled, vsync via the OS' window compositor (Windows only).\n");
- OS::get_singleton()->print(
- " --disable-vsync-via-compositor Disable vsync via the OS' window compositor (Windows only).\n");
+ OS::get_singleton()->print(" --no-window Disable window creation (Windows only). Useful together with --script.\n");
+ OS::get_singleton()->print(" --enable-vsync-via-compositor When vsync is enabled, vsync via the OS' window compositor (Windows only).\n");
+ OS::get_singleton()->print(" --disable-vsync-via-compositor Disable vsync via the OS' window compositor (Windows only).\n");
OS::get_singleton()->print(" --single-window Use a single window (no separate subwindows).\n");
OS::get_singleton()->print(" --tablet-driver Tablet input driver (");
for (int i = 0; i < OS::get_singleton()->get_tablet_driver_count(); i++) {
@@ -340,62 +332,38 @@ void Main::print_help(const char *p_binary) {
OS::get_singleton()->print("Debug options:\n");
OS::get_singleton()->print(" -d, --debug Debug (local stdout debugger).\n");
- OS::get_singleton()->print(
- " -b, --breakpoints Breakpoint list as source::line comma-separated pairs, no spaces (use %%20 instead).\n");
+ OS::get_singleton()->print(" -b, --breakpoints Breakpoint list as source::line comma-separated pairs, no spaces (use %%20 instead).\n");
OS::get_singleton()->print(" --profiling Enable profiling in the script debugger.\n");
- OS::get_singleton()->print(
- " --gpu-abort Abort on GPU errors (usually validation layer errors), may help see the problem if your system freezes.\n");
- OS::get_singleton()->print(
- " --remote-debug <uri> Remote debug (<protocol>://<host/IP>[:<port>], e.g. tcp://127.0.0.1:6007).\n");
+ OS::get_singleton()->print(" --gpu-abort Abort on GPU errors (usually validation layer errors), may help see the problem if your system freezes.\n");
+ OS::get_singleton()->print(" --remote-debug <uri> Remote debug (<protocol>://<host/IP>[:<port>], e.g. tcp://127.0.0.1:6007).\n");
#if defined(DEBUG_ENABLED) && !defined(SERVER_ENABLED)
OS::get_singleton()->print(" --debug-collisions Show collision shapes when running the scene.\n");
OS::get_singleton()->print(" --debug-navigation Show navigation polygons when running the scene.\n");
#endif
- OS::get_singleton()->print(
- " --frame-delay <ms> Simulate high CPU load (delay each frame by <ms> milliseconds).\n");
- OS::get_singleton()->print(
- " --time-scale <scale> Force time scale (higher values are faster, 1.0 is normal speed).\n");
- OS::get_singleton()->print(
- " --disable-render-loop Disable render loop so rendering only occurs when called explicitly from script.\n");
- OS::get_singleton()->print(
- " --disable-crash-handler Disable crash handler when supported by the platform code.\n");
- OS::get_singleton()->print(
- " --fixed-fps <fps> Force a fixed number of frames per second. This setting disables real-time synchronization.\n");
+ OS::get_singleton()->print(" --frame-delay <ms> Simulate high CPU load (delay each frame by <ms> milliseconds).\n");
+ OS::get_singleton()->print(" --time-scale <scale> Force time scale (higher values are faster, 1.0 is normal speed).\n");
+ OS::get_singleton()->print(" --disable-render-loop Disable render loop so rendering only occurs when called explicitly from script.\n");
+ OS::get_singleton()->print(" --disable-crash-handler Disable crash handler when supported by the platform code.\n");
+ OS::get_singleton()->print(" --fixed-fps <fps> Force a fixed number of frames per second. This setting disables real-time synchronization.\n");
OS::get_singleton()->print(" --print-fps Print the frames per second to the stdout.\n");
OS::get_singleton()->print("\n");
OS::get_singleton()->print("Standalone tools:\n");
OS::get_singleton()->print(" -s, --script <script> Run a script.\n");
- OS::get_singleton()->print(
- " --check-only Only parse for errors and quit (use with --script).\n");
+ OS::get_singleton()->print(" --check-only Only parse for errors and quit (use with --script).\n");
#ifdef TOOLS_ENABLED
- OS::get_singleton()->print(
- " --export <preset> <path> Export the project using the given preset and matching release template. The preset name should match one defined in export_presets.cfg.\n");
- OS::get_singleton()->print(
- " <path> should be absolute or relative to the project directory, and include the filename for the binary (e.g. 'builds/game.exe'). The target directory should exist.\n");
+ OS::get_singleton()->print(" --export <preset> <path> Export the project using the given preset and matching release template. The preset name should match one defined in export_presets.cfg.\n");
+ OS::get_singleton()->print(" <path> should be absolute or relative to the project directory, and include the filename for the binary (e.g. 'builds/game.exe'). The target directory should exist.\n");
OS::get_singleton()->print(" --export-debug <preset> <path> Same as --export, but using the debug template.\n");
- OS::get_singleton()->print(
- " --export-pack <preset> <path> Same as --export, but only export the game pack for the given preset. The <path> extension determines whether it will be in PCK or ZIP format.\n");
- OS::get_singleton()->print(
- " --doctool <path> Dump the engine API reference to the given <path> in XML format, merging if existing files are found.\n");
- OS::get_singleton()->print(
- " --no-docbase Disallow dumping the base types (used with --doctool).\n");
- OS::get_singleton()->print(
- " --build-solutions Build the scripting solutions (e.g. for C# projects). Implies --editor and requires a valid project to edit.\n");
+ OS::get_singleton()->print(" --export-pack <preset> <path> Same as --export, but only export the game pack for the given preset. The <path> extension determines whether it will be in PCK or ZIP format.\n");
+ OS::get_singleton()->print(" --doctool <path> Dump the engine API reference to the given <path> in XML format, merging if existing files are found.\n");
+ OS::get_singleton()->print(" --no-docbase Disallow dumping the base types (used with --doctool).\n");
+ OS::get_singleton()->print(" --build-solutions Build the scripting solutions (e.g. for C# projects). Implies --editor and requires a valid project to edit.\n");
#ifdef DEBUG_METHODS_ENABLED
- OS::get_singleton()->print(
- " --gdnative-generate-json-api Generate JSON dump of the Godot API for GDNative bindings.\n");
+ OS::get_singleton()->print(" --gdnative-generate-json-api Generate JSON dump of the Godot API for GDNative bindings.\n");
#endif
#ifdef TESTS_ENABLED
- OS::get_singleton()->print(" --test <test> Run a unit test [");
- const char **test_names = tests_get_names();
- const char *comma = "";
- while (*test_names) {
- OS::get_singleton()->print("%s'%s'", comma, *test_names);
- test_names++;
- comma = ", ";
- }
- OS::get_singleton()->print("].\n");
+ OS::get_singleton()->print(" --test [--help] Run unit tests. Use --test --help for more information.\n");
#endif
OS::get_singleton()->print("\n");
#endif
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp
index 4098425518..597a79a40c 100644
--- a/modules/gdscript/gdscript_analyzer.cpp
+++ b/modules/gdscript/gdscript_analyzer.cpp
@@ -2019,7 +2019,7 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod
GDScriptParser::ClassNode *outer = base_class->outer;
while (outer != nullptr) {
if (outer->has_member(name)) {
- const GDScriptParser::ClassNode::Member &member = base_class->get_member(name);
+ const GDScriptParser::ClassNode::Member &member = outer->get_member(name);
if (member.type == GDScriptParser::ClassNode::Member::CONSTANT) {
// TODO: Make sure loops won't cause problem. And make special error message for those.
// For out-of-order resolution:
diff --git a/modules/regex/doc_classes/RegEx.xml b/modules/regex/doc_classes/RegEx.xml
index c00fa96b2e..312275842a 100644
--- a/modules/regex/doc_classes/RegEx.xml
+++ b/modules/regex/doc_classes/RegEx.xml
@@ -11,7 +11,7 @@
regex.compile("\\w-(\\d+)")
[/codeblock]
The search pattern must be escaped first for GDScript before it is escaped for the expression. For example, [code]compile("\\d+")[/code] would be read by RegEx as [code]\d+[/code]. Similarly, [code]compile("\"(?:\\\\.|[^\"])*\"")[/code] would be read as [code]"(?:\\.|[^"])*"[/code].
- Using [method search] you can find the pattern within the given text. If a pattern is found, [RegExMatch] is returned and you can retrieve details of the results using functions such as [method RegExMatch.get_string] and [method RegExMatch.get_start].
+ Using [method search], you can find the pattern within the given text. If a pattern is found, [RegExMatch] is returned and you can retrieve details of the results using methods such as [method RegExMatch.get_string] and [method RegExMatch.get_start].
[codeblock]
var regex = RegEx.new()
regex.compile("\\w-(\\d+)")
@@ -19,7 +19,7 @@
if result:
print(result.get_string()) # Would print n-0123
[/codeblock]
- The results of capturing groups [code]()[/code] can be retrieved by passing the group number to the various functions in [RegExMatch]. Group 0 is the default and will always refer to the entire pattern. In the above example, calling [code]result.get_string(1)[/code] would give you [code]0123[/code].
+ The results of capturing groups [code]()[/code] can be retrieved by passing the group number to the various methods in [RegExMatch]. Group 0 is the default and will always refer to the entire pattern. In the above example, calling [code]result.get_string(1)[/code] would give you [code]0123[/code].
This version of RegEx also supports named capturing groups, and the names can be used to retrieve the results. If two or more groups have the same name, the name would only refer to the first one with a match.
[codeblock]
var regex = RegEx.new()
@@ -34,6 +34,15 @@
print(result.get_string("digit"))
# Would print 01 03 0 3f 42
[/codeblock]
+ [b]Example of splitting a string using a RegEx:[/b]
+ [codeblock]
+ var regex = RegEx.new()
+ regex.compile("\\S+") # Negated whitespace character class.
+ var results = []
+ for match in regex.search_all("One Two \n\tThree"):
+ results.push_back(match.get_string())
+ # The `results` array now contains "One", "Two", "Three".
+ [/codeblock]
[b]Note:[/b] Godot's regex implementation is based on the [url=https://www.pcre.org/]PCRE2[/url] library. You can view the full pattern reference [url=https://www.pcre.org/current/doc/html/pcre2pattern.html]here[/url].
[b]Tip:[/b] You can use [url=https://regexr.com/]Regexr[/url] to test regular expressions online.
</description>
diff --git a/tests/test_main.cpp b/tests/test_main.cpp
index 84d2fe1f6c..7c656517b6 100644
--- a/tests/test_main.cpp
+++ b/tests/test_main.cpp
@@ -32,8 +32,6 @@
#include "core/list.h"
-#ifdef DEBUG_ENABLED
-
#include "test_astar.h"
#include "test_basis.h"
#include "test_class_db.h"
@@ -54,37 +52,12 @@
#include "thirdparty/doctest/doctest.h"
-const char **tests_get_names() {
- static const char *test_names[] = {
- "*",
- "all",
- "math",
- "basis",
- "physics_2d",
- "physics_3d",
- "render",
- "oa_hash_map",
- "class_db",
- "gui",
- "shaderlang",
- "gd_tokenizer",
- "gd_parser",
- "gd_compiler",
- "gd_bytecode",
- "ordered_hash_map",
- "astar",
- nullptr
- };
-
- return test_names;
-}
-
int test_main(int argc, char *argv[]) {
- // doctest runner for when legacy unit tests are no found
+ // Doctest runner.
doctest::Context test_context;
List<String> valid_arguments;
- // clean arguments of --test from the args
+ // Clean arguments of "--test" from the args.
int argument_count = 0;
for (int x = 0; x < argc; x++) {
if (strncmp(argv[x], "--test", 6) != 0) {
@@ -92,15 +65,14 @@ int test_main(int argc, char *argv[]) {
argument_count++;
}
}
-
- // convert godot command line arguments back to standard arguments.
+ // Convert Godot command line arguments back to standard arguments.
char **args = new char *[valid_arguments.size()];
for (int x = 0; x < valid_arguments.size(); x++) {
- // operation to convert godot string to non wchar string
+ // Operation to convert Godot string to non wchar string.
const char *str = valid_arguments[x].utf8().ptr();
- // allocate the string copy
+ // Allocate the string copy.
args[x] = new char[strlen(str) + 1];
- // copy this into memory
+ // Copy this into memory.
std::memcpy(args[x], str, strlen(str) + 1);
}
@@ -109,22 +81,8 @@ int test_main(int argc, char *argv[]) {
test_context.setOption("order-by", "name");
test_context.setOption("abort-after", 5);
test_context.setOption("no-breaks", true);
- delete[] args;
- return test_context.run();
-}
-#else
-
-const char **tests_get_names() {
- static const char *test_names[] = {
- nullptr
- };
-
- return test_names;
-}
+ delete[] args;
-int test_main(int argc, char *argv[]) {
- return 0;
+ return test_context.run();
}
-
-#endif
diff --git a/tests/test_main.h b/tests/test_main.h
index 8273b74eac..983bfde402 100644
--- a/tests/test_main.h
+++ b/tests/test_main.h
@@ -31,11 +31,6 @@
#ifndef TEST_MAIN_H
#define TEST_MAIN_H
-#include "core/list.h"
-#include "core/os/main_loop.h"
-#include "core/ustring.h"
-
-const char **tests_get_names();
int test_main(int argc, char *argv[]);
#endif // TEST_MAIN_H