Skip to content

Instantly share code, notes, and snippets.

View me2beats's full-sized avatar

Albert me2beats

  • Russia, Yekaterinburg
View GitHub Profile
@me2beats
me2beats / array_utils.gd
Last active September 14, 2021 02:03
Array Utils
static func difference(a:Array, b:Array):
var result = []
var d = {}
for i in b:
d[i] = true
for i in a:
if i in d: continue
result.push_back(i)
return result
@me2beats
me2beats / object_u.gd
Last active September 4, 2021 21:14
Object Utils
static func connect_silent(object:Object, signal_:String, target: Object, method: String, binds:Array=[], flags:int=0):
if object.is_connected(signal_,target, method): return
object.connect(signal_, target, method, binds, flags)
static func disconnect_silent(object:Object, signal_:String, target: Object, method: String):
if !object.is_connected(signal_,target, method): return
object.disconnect(signal_, target, method)
# experimental
static func emit_if_changed(obj:Object, prop:String, signal_name:=''):
@me2beats
me2beats / utils.gd
Last active May 4, 2021 14:06
Show/Hide Tree VScrollbar
# ============== node utils ==============
static func get_child_by_type(node:Node, type):
for child in node.get_children():
if child is type:
return child
# ============== tree utils ==============
@me2beats
me2beats / TypeUtils.gd
Created May 1, 2021 08:12
Type utils class
static func is_any_array(val):
return typeof(val)>=19 and typeof(val)<=26
@me2beats
me2beats / dict.gd
Created April 10, 2021 11:12
Dictionary utils
static func dict_add_recursive(d, path:Array, val, last_is_array: = true)->void:
if !d is Dictionary:
push_warning("first arg (d) is not a Dictionary")
return
var last_key = path.pop_back()
for key in path:
if d.has(key):
d = d[key]
@me2beats
me2beats / scene_tree_editor_u.gd
Last active September 20, 2021 03:53
SceneTreeEditorUtils
static func get_scene_tree_node(plugin:EditorPlugin)->Tree:
var scene_tree_dock:Container= plugin.get_editor_interface().get_base_control().find_node("Scene", 1,0)
return NodeU.get_node_by_class_path(scene_tree_dock, ['SceneTreeEditor', 'Tree']) as Tree
# almost same, just find_child_by_class() used instead of get_node_by_class_path
static func get_scene_tree_control(plugin:EditorPlugin)->Tree:
var empty:Tree
var base: = plugin.get_editor_interface().get_base_control()
var scene_dock = base.find_node("Scene", true, false)
var tree_editor:Control = find_child_by_class(scene_dock, 'SceneTreeEditor')
class_name ScriptEditorU
static func get_script_tab_container(scr_ed:ScriptEditor)->TabContainer:
return NodeU.get_node_by_class_path(scr_ed, ['VBoxContainer', 'HSplitContainer', 'TabContainer']) as TabContainer
static func get_script_tab_container_by_plugin(plugin:EditorPlugin)->TabContainer:
var scr_ed = plugin.get_editor_interface().get_script_editor()
return get_script_tab_container(scr_ed)
@me2beats
me2beats / string_u.gd
Last active November 7, 2021 16:27
String utils
class_name StringU
static func invert_string(s:String)->String:
var chars_pool = PoolStringArray()
var length = s.length()
chars_pool.resize(length)
for i in length:
chars_pool[i] = s[i]
chars_pool.invert()
return chars_pool.join("")
@me2beats
me2beats / node_u.gd
Last active September 24, 2021 00:37
NodeUtils
class_name NodeU
static func get_nodes(node:Node)->Array:
var nodes = []
var stack = [node]
while stack:
var n = stack.pop_back()
nodes.push_back(n)
stack.append_array(n.get_children())