mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-06 07:50:22 +01:00
Use static typing in all demos (#1063)
This leads to code that is easier to understand and runs faster thanks to GDScript's typed instructions. The untyped declaration warning is now enabled on all projects where type hints were added. All projects currently run without any untyped declration warnings. Dodge the Creeps and Squash the Creeps demos intentionally don't use type hints to match the documentation, where type hints haven't been adopted yet (given its beginner focus).
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
extends Node
|
||||
|
||||
|
||||
func _on_OpenShellWeb_pressed():
|
||||
func _on_open_shell_web_pressed() -> void:
|
||||
OS.shell_open("https://example.com")
|
||||
|
||||
|
||||
func _on_OpenShellFolder_pressed():
|
||||
var path = OS.get_environment("HOME")
|
||||
func _on_open_shell_folder_pressed() -> void:
|
||||
var path := OS.get_environment("HOME")
|
||||
if path == "":
|
||||
# Windows-specific.
|
||||
path = OS.get_environment("USERPROFILE")
|
||||
@@ -18,17 +17,21 @@ func _on_OpenShellFolder_pressed():
|
||||
OS.shell_open(path)
|
||||
|
||||
|
||||
func _on_ChangeWindowTitle_pressed():
|
||||
func _on_change_window_title_pressed() -> void:
|
||||
DisplayServer.window_set_title("Modified window title. Unicode characters for testing: é € × Ù ¨")
|
||||
|
||||
|
||||
func _on_ChangeWindowIcon_pressed():
|
||||
var image = Image.create(128, 128, false, Image.FORMAT_RGB8)
|
||||
func _on_change_window_icon_pressed() -> void:
|
||||
if not DisplayServer.has_feature(DisplayServer.FEATURE_ICON):
|
||||
OS.alert("Changing the window icon is not supported by the current display server (%s)." % DisplayServer.get_name())
|
||||
return
|
||||
|
||||
var image := Image.create(128, 128, false, Image.FORMAT_RGB8)
|
||||
image.fill(Color(1, 0.6, 0.3))
|
||||
DisplayServer.set_icon(image)
|
||||
|
||||
|
||||
func _on_MoveWindowToForeground_pressed():
|
||||
func _on_move_window_to_foreground_pressed() -> void:
|
||||
DisplayServer.window_set_title("Will move window to foreground in 5 seconds, try unfocusing the window...")
|
||||
await get_tree().create_timer(5).timeout
|
||||
DisplayServer.window_move_to_foreground()
|
||||
@@ -36,7 +39,7 @@ func _on_MoveWindowToForeground_pressed():
|
||||
DisplayServer.window_set_title(ProjectSettings.get_setting("application/config/name"))
|
||||
|
||||
|
||||
func _on_RequestAttention_pressed():
|
||||
func _on_request_attention_pressed() -> void:
|
||||
DisplayServer.window_set_title("Will request attention in 5 seconds, try unfocusing the window...")
|
||||
await get_tree().create_timer(5).timeout
|
||||
DisplayServer.window_request_attention()
|
||||
@@ -44,36 +47,44 @@ func _on_RequestAttention_pressed():
|
||||
DisplayServer.window_set_title(ProjectSettings.get_setting("application/config/name"))
|
||||
|
||||
|
||||
func _on_VibrateDeviceShort_pressed():
|
||||
func _on_vibrate_device_short_pressed() -> void:
|
||||
Input.vibrate_handheld(200)
|
||||
|
||||
|
||||
func _on_VibrateDeviceLong_pressed():
|
||||
func _on_vibrate_device_long_pressed() -> void:
|
||||
Input.vibrate_handheld(1000)
|
||||
|
||||
|
||||
func _on_AddGlobalMenuItems_pressed():
|
||||
func _on_add_global_menu_items_pressed() -> void:
|
||||
if not DisplayServer.has_feature(DisplayServer.FEATURE_GLOBAL_MENU):
|
||||
OS.alert("Global menus are not supported by the current display server (%s)." % DisplayServer.get_name())
|
||||
return
|
||||
|
||||
# Add a menu to the main menu bar.
|
||||
DisplayServer.global_menu_add_submenu_item("_main", "Hello", "_main/Hello")
|
||||
DisplayServer.global_menu_add_item(
|
||||
"_main/Hello",
|
||||
"World",
|
||||
func(tag): print("Clicked main 1 " + str(tag)),
|
||||
func(tag): print("Key main 1 " + str(tag)),
|
||||
func(tag: String) -> void: print("Clicked main 1 " + str(tag)),
|
||||
func(tag: String) -> void: print("Key main 1 " + str(tag)),
|
||||
null,
|
||||
(KEY_MASK_META | KEY_1) as Key
|
||||
)
|
||||
DisplayServer.global_menu_add_separator("_main/Hello")
|
||||
DisplayServer.global_menu_add_item("_main/Hello", "World2", func(tag): print("Clicked main 2 " + str(tag)))
|
||||
DisplayServer.global_menu_add_item("_main/Hello", "World2", func(tag: String) -> void: print("Clicked main 2 " + str(tag)))
|
||||
|
||||
# Add a menu to the Dock context menu.
|
||||
DisplayServer.global_menu_add_submenu_item("_dock", "Hello", "_dock/Hello")
|
||||
DisplayServer.global_menu_add_item("_dock/Hello", "World", func(tag): print("Clicked dock 1 " + str(tag)))
|
||||
DisplayServer.global_menu_add_item("_dock/Hello", "World", func(tag: String) -> void: print("Clicked dock 1 " + str(tag)))
|
||||
DisplayServer.global_menu_add_separator("_dock/Hello")
|
||||
DisplayServer.global_menu_add_item("_dock/Hello", "World2", func(tag): print("Clicked dock 2 " + str(tag)))
|
||||
DisplayServer.global_menu_add_item("_dock/Hello", "World2", func(tag: String) -> void: print("Clicked dock 2 " + str(tag)))
|
||||
|
||||
|
||||
func _on_RemoveGlobalMenuItem_pressed():
|
||||
func _on_remove_global_menu_item_pressed() -> void:
|
||||
if not DisplayServer.has_feature(DisplayServer.FEATURE_GLOBAL_MENU):
|
||||
OS.alert("Global menus are not supported by the current display server (%s)." % DisplayServer.get_name())
|
||||
return
|
||||
|
||||
DisplayServer.global_menu_remove_item("_main/Hello", 2)
|
||||
DisplayServer.global_menu_remove_item("_main/Hello", 1)
|
||||
DisplayServer.global_menu_remove_item("_main/Hello", 0)
|
||||
@@ -85,17 +96,25 @@ func _on_RemoveGlobalMenuItem_pressed():
|
||||
DisplayServer.global_menu_remove_item("_dock", 0)
|
||||
|
||||
|
||||
func _on_GetClipboard_pressed():
|
||||
func _on_get_clipboard_pressed() -> void:
|
||||
if not DisplayServer.has_feature(DisplayServer.FEATURE_CLIPBOARD):
|
||||
OS.alert("Clipboard I/O is not supported by the current display server (%s)." % DisplayServer.get_name())
|
||||
return
|
||||
|
||||
OS.alert("Clipboard contents:\n\n%s" % DisplayServer.clipboard_get())
|
||||
|
||||
|
||||
func _on_SetClipboard_pressed():
|
||||
func _on_set_clipboard_pressed() -> void:
|
||||
if not DisplayServer.has_feature(DisplayServer.FEATURE_CLIPBOARD):
|
||||
OS.alert("Clipboard I/O is not supported by the current display server (%s)." % DisplayServer.get_name())
|
||||
return
|
||||
|
||||
DisplayServer.clipboard_set("Modified clipboard contents. Unicode characters for testing: é € × Ù ¨")
|
||||
|
||||
|
||||
func _on_DisplayAlert_pressed():
|
||||
func _on_display_alert_pressed() -> void:
|
||||
OS.alert("Hello from Godot! Close this dialog to resume the main window.")
|
||||
|
||||
|
||||
func _on_KillCurrentProcess_pressed():
|
||||
func _on_kill_current_process_pressed() -> void:
|
||||
OS.kill(OS.get_process_id())
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
extends Node
|
||||
|
||||
@onready var rtl = $HBoxContainer/Features
|
||||
@onready var csharp_test = $CSharpTest
|
||||
|
||||
@onready var rtl: RichTextLabel = $HBoxContainer/Features
|
||||
@onready var csharp_test: Node = $CSharpTest
|
||||
|
||||
# Returns a human-readable string from a date and time, date, or time dictionary.
|
||||
func datetime_to_string(date):
|
||||
func datetime_to_string(date: Dictionary) -> void:
|
||||
if (
|
||||
date.has("year")
|
||||
and date.has("month")
|
||||
@@ -39,27 +38,34 @@ func datetime_to_string(date):
|
||||
})
|
||||
|
||||
|
||||
func scan_midi_devices():
|
||||
func scan_midi_devices() -> String:
|
||||
OS.open_midi_inputs()
|
||||
var devices = ", ".join(OS.get_connected_midi_inputs())
|
||||
var devices := ", ".join(OS.get_connected_midi_inputs())
|
||||
OS.close_midi_inputs()
|
||||
return devices
|
||||
|
||||
|
||||
func add_header(header):
|
||||
func add_header(header: String) -> void:
|
||||
rtl.append_text("\n[font_size=24][color=#6df]{header}[/color][/font_size]\n\n".format({
|
||||
header = header,
|
||||
}))
|
||||
|
||||
|
||||
func add_line(key, value):
|
||||
func add_line(key: String, value: Variant) -> void:
|
||||
if typeof(value) == TYPE_BOOL:
|
||||
# Colorize boolean values.
|
||||
value = "[color=8f8]true[/color]" if value else "[color=#f88]false[/color]"
|
||||
|
||||
rtl.append_text("[color=#adf]{key}:[/color] {value}\n".format({
|
||||
key = key,
|
||||
value = value if str(value) != "" else "[color=#fff8](empty)[/color]",
|
||||
}))
|
||||
|
||||
|
||||
func _ready():
|
||||
func _ready() -> void:
|
||||
# Grab focus so that the list can be scrolled (for keyboard/controller-friendly navigation).
|
||||
rtl.grab_focus()
|
||||
|
||||
add_header("Audio")
|
||||
add_line("Mix rate", "%d Hz" % AudioServer.get_mix_rate())
|
||||
add_line("Output latency", "%f ms" % (AudioServer.get_output_latency() * 1000))
|
||||
@@ -115,7 +121,7 @@ func _ready():
|
||||
|
||||
add_header("Input")
|
||||
add_line("Device has touch screen", DisplayServer.is_touchscreen_available())
|
||||
var has_virtual_keyboard = DisplayServer.has_feature(DisplayServer.FEATURE_VIRTUAL_KEYBOARD)
|
||||
var has_virtual_keyboard := DisplayServer.has_feature(DisplayServer.FEATURE_VIRTUAL_KEYBOARD)
|
||||
add_line("Device has virtual keyboard", has_virtual_keyboard)
|
||||
if has_virtual_keyboard:
|
||||
add_line("Virtual keyboard height", DisplayServer.virtual_keyboard_get_height())
|
||||
@@ -127,7 +133,7 @@ func _ready():
|
||||
add_line("Granted permissions", OS.get_granted_permissions())
|
||||
|
||||
add_header(".NET (C#)")
|
||||
var csharp_enabled = ResourceLoader.exists("res://CSharpTest.cs")
|
||||
var csharp_enabled := ResourceLoader.exists("res://CSharpTest.cs")
|
||||
add_line("Mono module enabled", "Yes" if csharp_enabled else "No")
|
||||
if csharp_enabled:
|
||||
csharp_test.set_script(load("res://CSharpTest.cs"))
|
||||
@@ -163,7 +169,7 @@ func _ready():
|
||||
][RenderingServer.get_video_adapter_type()])
|
||||
add_line("Adapter graphics API version", RenderingServer.get_video_adapter_api_version())
|
||||
|
||||
var video_adapter_driver_info = OS.get_video_adapter_driver_info()
|
||||
var video_adapter_driver_info := OS.get_video_adapter_driver_info()
|
||||
if video_adapter_driver_info.size() > 0:
|
||||
add_line("Adapter driver name", video_adapter_driver_info[0])
|
||||
if video_adapter_driver_info.size() > 1:
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://ds1y65r8ld026"]
|
||||
[gd_scene load_steps=4 format=3 uid="uid://ds1y65r8ld026"]
|
||||
|
||||
[ext_resource type="Script" path="res://os_test.gd" id="1"]
|
||||
[ext_resource type="Script" path="res://actions.gd" id="4"]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_dl4cr"]
|
||||
|
||||
[node name="OSTest" type="Panel"]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
@@ -28,6 +30,8 @@ theme_override_constants/separation = 10
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
focus_mode = 2
|
||||
theme_override_styles/focus = SubResource("StyleBoxEmpty_dl4cr")
|
||||
bbcode_enabled = true
|
||||
|
||||
[node name="Actions" type="VBoxContainer" parent="HBoxContainer"]
|
||||
@@ -134,17 +138,17 @@ text = "Kill Current Process"
|
||||
|
||||
[node name="CSharpTest" type="Node" parent="."]
|
||||
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/OpenShellWeb" to="HBoxContainer/Actions" method="_on_OpenShellWeb_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/OpenShellFolder" to="HBoxContainer/Actions" method="_on_OpenShellFolder_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/ChangeWindowTitle" to="HBoxContainer/Actions" method="_on_ChangeWindowTitle_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/ChangeWindowIcon" to="HBoxContainer/Actions" method="_on_ChangeWindowIcon_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/MoveWindowToForeground" to="HBoxContainer/Actions" method="_on_MoveWindowToForeground_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/RequestAttention" to="HBoxContainer/Actions" method="_on_RequestAttention_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/VibrateDeviceShort" to="HBoxContainer/Actions" method="_on_VibrateDeviceShort_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/VibrateDeviceLong" to="HBoxContainer/Actions" method="_on_VibrateDeviceLong_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/AddGlobalMenuItems" to="HBoxContainer/Actions" method="_on_AddGlobalMenuItems_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/RemoveGlobalMenuItem" to="HBoxContainer/Actions" method="_on_RemoveGlobalMenuItem_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/GetClipboard" to="HBoxContainer/Actions" method="_on_GetClipboard_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/SetClipboard" to="HBoxContainer/Actions" method="_on_SetClipboard_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/DisplayAlert" to="HBoxContainer/Actions" method="_on_DisplayAlert_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/KillCurrentProcess" to="HBoxContainer/Actions" method="_on_KillCurrentProcess_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/OpenShellWeb" to="HBoxContainer/Actions" method="_on_open_shell_web_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/OpenShellFolder" to="HBoxContainer/Actions" method="_on_open_shell_folder_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/ChangeWindowTitle" to="HBoxContainer/Actions" method="_on_change_window_title_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/ChangeWindowIcon" to="HBoxContainer/Actions" method="_on_change_window_icon_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/MoveWindowToForeground" to="HBoxContainer/Actions" method="_on_move_window_to_foreground_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/RequestAttention" to="HBoxContainer/Actions" method="_on_request_attention_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/VibrateDeviceShort" to="HBoxContainer/Actions" method="_on_vibrate_device_short_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/VibrateDeviceLong" to="HBoxContainer/Actions" method="_on_vibrate_device_long_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/AddGlobalMenuItems" to="HBoxContainer/Actions" method="_on_add_global_menu_items_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/RemoveGlobalMenuItem" to="HBoxContainer/Actions" method="_on_remove_global_menu_item_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/GetClipboard" to="HBoxContainer/Actions" method="_on_get_clipboard_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/SetClipboard" to="HBoxContainer/Actions" method="_on_set_clipboard_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/DisplayAlert" to="HBoxContainer/Actions" method="_on_display_alert_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/KillCurrentProcess" to="HBoxContainer/Actions" method="_on_kill_current_process_pressed"]
|
||||
|
||||
@@ -23,6 +23,11 @@ config/features=PackedStringArray("4.2")
|
||||
run/low_processor_mode=true
|
||||
config/icon="res://icon.webp"
|
||||
|
||||
[debug]
|
||||
|
||||
gdscript/warnings/untyped_declaration=1
|
||||
gdscript/warnings/int_as_enum_without_match=0
|
||||
|
||||
[display]
|
||||
|
||||
window/stretch/mode="canvas_items"
|
||||
|
||||
Reference in New Issue
Block a user