mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-04 23:10:08 +01:00
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).
41 lines
812 B
GDScript
41 lines
812 B
GDScript
extends Control
|
|
|
|
const MAX_ENTRIES = 100
|
|
|
|
var _entry_template: Label
|
|
|
|
|
|
func _enter_tree() -> void:
|
|
Log.entry_logged.connect(_on_log_entry)
|
|
|
|
_entry_template = get_child(0)
|
|
remove_child(_entry_template)
|
|
|
|
|
|
func _exit_tree() -> void:
|
|
_entry_template.free()
|
|
|
|
|
|
func clear() -> void:
|
|
while get_child_count():
|
|
var entry: Label = get_child(get_child_count() - 1)
|
|
remove_child(entry)
|
|
entry.queue_free()
|
|
|
|
|
|
func _on_log_entry(message: String, type: Log.LogType) -> void:
|
|
var new_entry: Label = _entry_template.duplicate()
|
|
|
|
new_entry.text = message
|
|
if type == Log.LogType.ERROR:
|
|
new_entry.modulate = Color.RED
|
|
else:
|
|
new_entry.modulate = Color.WHITE
|
|
|
|
if get_child_count() >= MAX_ENTRIES:
|
|
var first_entry: Label = get_child(0)
|
|
remove_child(first_entry)
|
|
first_entry.queue_free()
|
|
|
|
add_child(new_entry)
|