Add some useful GDScript snippets for Godot 4 (#794)

This commit is contained in:
btarg
2025-02-13 15:57:29 +00:00
committed by GitHub
parent 2490d0cdad
commit 8059ba89c2

View File

@@ -6,14 +6,12 @@
"\t$3" "\t$3"
] ]
}, },
"Print messages to console": { "Print messages to console": {
"prefix": "pr", "prefix": "pr",
"body": [ "body": [
"print($1)" "print($1)"
] ]
}, },
"_ready method of Node": { "_ready method of Node": {
"prefix": "ready", "prefix": "ready",
"body": [ "body": [
@@ -21,7 +19,6 @@
"\t${1:pass}" "\t${1:pass}"
] ]
}, },
"_init method of Object": { "_init method of Object": {
"prefix": "init", "prefix": "init",
"body": [ "body": [
@@ -29,195 +26,260 @@
"\t${1:pass}" "\t${1:pass}"
] ]
}, },
"_process method of Node": { "_process method of Node": {
"prefix": "process", "prefix": "process",
"body": [ "body": [
"func _process(delta):", "func _process(delta):",
"\t${1:pass}" "\t${1:pass}"
] ]
}, },
"_physics_process method of Node": { "_physics_process method of Node": {
"prefix": "physics", "prefix": "physics",
"body": [ "body": [
"func _physics_process(delta):", "func _physics_process(delta):",
"\t${1:pass}" "\t${1:pass}"
] ]
}, },
"_input method of Node": { "_input method of Node": {
"prefix": "input", "prefix": "input",
"body": [ "body": [
"func _input(event):", "func _input(event):",
"\t${1:pass}" "\t${1:pass}"
] ]
}, },
"_input_event method of Node": {
"_input_event method of Node": {
"prefix": "inpute", "prefix": "inpute",
"body": [ "body": [
"func _input_event(event):", "func _input_event(event):",
"\t${1:pass}" "\t${1:pass}"
] ]
}, },
"_unhandled_input method of Node": {
"_unhandled_input method of Node": { "prefix": "uinput",
"prefix": "uinput", "body": [
"body": [ "func _unhandled_input(event):",
"func _unhandled_input(event):", "\t${1:pass}"
"\t${1:pass}" ]
] },
}, "_draw method of Node": {
"prefix": "draw",
"_draw method of Node": { "body": [
"prefix": "draw", "func _draw():",
"body": [ "\t${1:pass}"
"func _draw():", ]
"\t${1:pass}" },
] "_gui_input method of Node": {
}, "prefix": "guii",
"body": [
"_gui_input method of Node": { "func _gui_input(event):",
"prefix": "guii", "\t${1:pass}"
"body": [ ]
"func _gui_input(event):", },
"\t${1:pass}"
]
},
"for loop": { "for loop": {
"prefix": "for", "prefix": "for",
"body": [ "body": [
"for $1 in $2:", "for $1 in $2:",
"\t${3:pass}" "\t${3:pass}"
] ]
}, },
"for range loop": {
"for range loop": {
"prefix": "for", "prefix": "for",
"body": [ "body": [
"for $1 in range(${2:start}{$3:,end}):", "for $1 in range(${2:start}{$3:,end}):",
"\t${4:pass}" "\t${4:pass}"
] ]
}, },
"if elif else": {
"if elif else": { "prefix": "if",
"prefix": "if",
"body": [ "body": [
"if ${1:condition}:", "if ${1:condition}:",
"\t${3:pass}", "\t${3:pass}",
"elif ${2:condition}:", "elif ${2:condition}:",
"\t${4:pass}", "\t${4:pass}",
"else:", "else:",
"\t${5:pass}" "\t${5:pass}"
] ]
}, },
"if else": {
"if else": { "prefix": "if",
"prefix": "if",
"body": [ "body": [
"if ${1:condition}:", "if ${1:condition}:",
"\t${2:pass}", "\t${2:pass}",
"else:", "else:",
"\t${3:pass}" "\t${3:pass}"
] ]
}, },
"if": {
"if": { "prefix": "if",
"prefix": "if",
"body": [ "body": [
"if ${1:condition}:", "if ${1:condition}:",
"\t${2:pass}" "\t${2:pass}"
] ]
}, },
"while": {
"while": { "prefix": "while",
"prefix": "while",
"body": [ "body": [
"while ${1:condition}:", "while ${1:condition}:",
"\t${2:pass}" "\t${2:pass}"
] ]
}, },
"function define": {
"function define": { "prefix": "func",
"prefix": "func",
"body": [ "body": [
"func ${1:method}(${2:args}):", "func ${1:method}(${2:args}):",
"\t${3:pass}" "\t${3:pass}"
] ]
}, },
"match": {
"match": { "prefix": "match",
"prefix": "match",
"body": [
"match ${1:expression}:\n\t${2:pattern}:\n\t\t${3}\n\t_:\n\t\t${0:default}"
]
},
"signal declaration": {
"prefix": "signal",
"body": [ "body": [
"signal ${1:signalname}(${2:args})" "match ${1:expression}:\n\t${2:pattern}:\n\t\t${3}\n\t_:\n\t\t${0:default}"
] ]
}, },
"signal declaration": {
"export variables": { "prefix": "signal",
"prefix": "export",
"body": [ "body": [
"export(${1:type}${2:,other_configs}) var ${3:name}${4: = default}${5: setget }" "signal ${1:signalname}(${2:args})"
] ]
}, },
"export variables": {
"define variables": { "prefix": "export",
"prefix": "var",
"body": [ "body": [
"var ${1:name}${2: = default}${3: setget }" "@export(${1:type}${2:,other_configs}) var ${3:name}${4: = default}${5: setget }"
] ]
}, },
"define variables": {
"define onready variables": { "prefix": "var",
"prefix": "onready",
"body": [ "body": [
"onready var ${1:name} = get_node($2)" "var ${1:name}${2: = default}${3: setget }"
] ]
}, },
"define onready variables": {
"Is instance of a class or script": { "prefix": "onready",
"prefix": "is",
"body": [
"${1:instance} is ${2:class}"
]
},
"element in array": {
"prefix": "in",
"body": [ "body": [
"${1:element} in ${$2:array}" "onready var ${1:name} = get_node($2)"
] ]
}, },
"Is instance of a class or script": {
"GDScript template": { "prefix": "is",
"prefix": "gdscript",
"body": [ "body": [
"extends ${1:BaseClass}", "${1:instance} is ${2:class}"
"", ]
"# class member variables go here, for example:", },
"# var a = 2", "element in array": {
"# var b = \"textvar\"", "prefix": "in",
"", "body": [
"func _ready():", "${1:element} in ${$2:array}"
"\t# Called every time the node is added to the scene.", ]
"\t# Initialization here", },
"\tpass", "GDScript template": {
"" "prefix": "gdscript",
] "body": [
}, "extends ${1:BaseClass}",
"",
"pass statement": { "# class member variables go here, for example:",
"prefix": "pass", "# var a = 2",
"body": [ "# var b = \"textvar\"",
"pass" "",
] "func _ready():",
} "\t# Called every time the node is added to the scene.",
"\t# Initialization here",
"\tpass",
""
]
},
"pass statement": {
"prefix": "pass",
"body": [
"pass"
]
},
"GDScript Void": {
"prefix": [
"void"
],
"body": [
"func ${1:function_name}($2) -> void:",
"\t${3:pass}"
],
"description": "Void function"
},
"GDScript Load Resource": {
"prefix": [
"loadres",
"ld"
],
"body": [
"load(\"res://${1:resource_path}\")$0"
],
"description": "Quickly load a resource with the 'res://' prefix"
},
"GDScript Preload Resource": {
"prefix": [
"preloadres",
"pl"
],
"body": [
"preload(\"res://${1:resource_path}\")$0"
],
"description": "Quickly preload a resource with the 'res://' prefix"
},
"GDScript Variable with Getter and Setter": {
"prefix": [
"gs",
"vargetset"
],
"body": [
"var ${1:variable_name}:",
"\tget:",
"\t\treturn ${1:variable_name}",
"\tset(value):",
"\t\t${1:variable_name} = value"
],
"description": "Creates a variable with getter and setter functions in GDScript"
},
"GDScript Variable with Getter and Setter (typed)": {
"prefix": [
"gst",
"vargetsettyped"
],
"body": [
"var ${1:variable_name}: ${2:String}:",
"\tget:",
"\t\treturn ${1:variable_name}",
"\tset(value):",
"\t\t${1:variable_name} = value"
],
"description": "Creates a typed variable with getter and setter functions in GDScript"
},
"GDScript export var": {
"prefix": [
"exportvar",
"xp"
],
"body": [
"export var ${1:variable_name}: ${2:String} = ${3:default_value}"
],
"description": "Creates an exported (typed) variable in GDScript"
},
"GDScript tween": {
"prefix": [
"tween",
"tw"
],
"body": [
"var tween := create_tween()"
],
"description": "Creates a tween object"
},
"GDScript wait": {
"prefix": [
"wait",
"timer"
],
"body": [
"await get_tree().create_timer($1).timeout"
],
"description": "Waits for a given amount of seconds"
}
} }