Skip to content

Instantly share code, notes, and snippets.

extends Node
func pack(p:Node)->PackedScene: var v = PackedScene.new(); v.pack(p); return v
class A extends Node:
@export var m: String = "a"
static func instantiate(p:PackedScene):
var v: A = p.instantiate()
v._post_init()
return v
extends Node
var info: Array = []
func _ready() -> void:
add_child_test('Node')
for i in ClassDB.get_inheriters_from_class('Node'):
if not ClassDB.can_instantiate(i): continue
add_child_test(i)
info.sort_custom(func(l, r): return l.time < r.time)
@Gnumaru
Gnumaru / NodePostDelete.gd
Created October 23, 2024 19:54
how to run some code right AFTER an object has been freed
extends Node
func _notification(what: int) -> void:
if what == Object.NOTIFICATION_PREDELETE:
# post_delete is a static method, thus it can be called deferredly even by dying objects. Beware that an object can be "saved" from a queue_free call by calling cancel_free, but a free call (instead of queue_free) should kill it imediatly without chance for survival
post_delete.call_deferred(get_instance_id(), get_path())
static func post_delete(id: int, path: NodePath) -> void:
@Gnumaru
Gnumaru / editor_theme.tres
Created May 8, 2024 21:47
default godot 4 editor theme, but with box and split container separations reduced to the minimum
[gd_resource type="Theme" load_steps=3 format=3 uid="uid://ddcimt5j11lgc"]
[sub_resource type="Image" id="Image_8ojfe"]
data = {
"data": PackedByteArray(0, 0, 0, 0),
"format": "RGBA8",
"height": 1,
"mipmaps": false,
"width": 1
}
RESUMINHO SIMPLES SOBRE ESTRUTURAS DE DADOS
- Em programação existem "dados simples":
- numeros inteiros: -1, 0, 1, etc.
- numeros reais: -1.5, 0.1, 9.9, etc
- valores booleanos: verdadeiro ou falso, que no fim das contas eh um inteiro onde 0 significa falso e qualquer outra coisa eh verdadeiro
- strings (texto): apenas uma sequencia de caracteres, os quais por sua vez sao inteiros
- E existem "dados compostos", que sao criados pelo programador para agrupar dados simples de forma a representar coisas mais complexas. Ex.: para representar uma pessoa podemos criar um dado composto com 2 membros (campos): idade (int) e nome (string)
- Tanto dados simples e compostos podem ser agrupados de forma homogenea em arrays (vetores), que são meramente o agrupamento linear contíguo de N dados daquele mesmo tipo
class_name Utils
static func file_exists_(prespath:String, pforceexactmatch:bool=false)->bool:
if prespath.begins_with('res://') and not pforceexactmatch:
return FileAccess.file_exists(prespath) or FileAccess.file_exists(prespath+'.remap') or FileAccess.file_exists(prespath+'.import')
else:
return FileAccess.file_exists(prespath)
@Gnumaru
Gnumaru / GdscriptCallSequence.txt
Last active March 19, 2024 03:00
The sequence in which methods and signals gets called in gdscript
# as of godot 4.1
_static_init
_init
_notification 20 Node.NOTIFICATION_SCENE_INSTANTIATED # only on instantiated scene roots
_notification 18 Node.NOTIFICATION_PARENTED
_enter_tree
tree_entered signal
_notification 27 Node.NOTIFICATION_POST_ENTER_TREE
_ready
ready signal
@Gnumaru
Gnumaru / CompactEditorTheme.tres
Last active September 21, 2023 20:54
An editor theme for godot that reduces a bit of the wasted space
[gd_resource type="Theme" load_steps=3 format=2]
[sub_resource type="Image" id=3]
data = {
"data": PackedByteArray( 0, 0, 0, 0 ),
"format": "RGBA8",
"height": 1,
"mipmaps": false,
"width": 1
}
@Gnumaru
Gnumaru / ScriptTester.gd
Created August 13, 2023 14:52
"Test" scripts by loading them
# ScriptTester.tscn
# ScriptTester.gd
@tool
extends Node
@export var mtool_do_test_scripts:bool:
get: return false
set(p):
mtool_do_test_scripts = false
if p: tool_do_test_scripts()
func _ready():