Skip to content

Instantly share code, notes, and snippets.

View Shilo's full-sized avatar

Shilo Shilo

View GitHub Profile
@Shilo
Shilo / toggle_button.gd
Last active October 5, 2024 10:59
Godot toggle button for toggle state icon.
@tool
class_name ToggleButton extends Button
@export var icon_toggled: Texture2D
@onready var _icon: Texture2D = icon
func _ready() -> void:
toggle_mode = true
if not theme_type_variation:
theme_type_variation = &"ToggleButton"
@Shilo
Shilo / polygon_circle.gd
Last active July 22, 2024 09:55
Polygon circle example. (Godot 4)
@tool
extends Node2D
@export var radius = 50.0:
set(value):
radius = value
queue_redraw()
@export var start_angle_deg = 0.0:
set(value):
@Shilo
Shilo / circle_2d.gd
Last active July 22, 2024 13:12
Dynamic circle polygon shape with start and end angles. (Godot 4)
@tool
class_name Circle2D extends Polygon2D
@export_range(0.0, 360.0, 0.001, "or_greater", "or_less") var start_degree: float = 0.0:
set(value):
start_degree = _wrap_degree(value)
queue_update()
@export_range(0.0, 360.0, 0.001, "or_greater", "or_less") var end_degree: float = 360.0:
set(value):
@Shilo
Shilo / color_util.gd
Last active June 26, 2024 06:23
Color utility methods. [Godot 4]
class_name ColorUtil extends Object
static func parse_html(rgba_or_preset: String, ignore_alpha: bool = false, default_color: Variant = null) -> Color:
var color: Variant = PRESET.get(rgba_or_preset.to_upper())
if color == null and Color.html_is_valid(rgba_or_preset):
color = Color.html(rgba_or_preset)
if color == null:
return default_color
@Shilo
Shilo / eval.gd
Created June 26, 2024 02:31
Godot GDScript eval helper function.
func eval(code: String) -> Error:
var script := GDScript.new()
script.source_code = "static func _static_init(): pass; " + code.strip_edges().replace("\n", ";")
return script.reload()
Summary How to control (or Understand) your GIST page's files list order.
Notice not official documentation.
@Shilo
Shilo / value_holder.gd
Last active June 25, 2024 04:39
Godot 4 generic wrapper for holding any value. Allows passing a value between functions by reference instead of value (copy).
## Generic wrapper for holding any value.
## Allows passing a value between functions by reference instead of value (copy).
class_name ValueHolder extends RefCounted
## Triggers when value is updated. Current and previous values are passed.
signal changed(value: Variant, last_value: Variant)
## Current value. Changing this value will emit changed() signal.
var value: Variant:
set(new_value):
@Shilo
Shilo / align_node2d_to_mouse_editor_script.gd
Created June 23, 2024 06:10
Godot EditorScript to align selected Node2Ds to current mouse position.
@tool
extends EditorScript
# Align selected Node2Ds to current mouse position.
# Ctrl+Shift+X to run.
func _run():
var editor_interface = get_editor_interface()
var mouse_position = editor_interface.get_editor_viewport_2d().get_mouse_position()
@Shilo
Shilo / twitch_redeem_reward.js
Last active June 18, 2024 20:23
Twitch Javascript injected script to simulate reward redemption.
// Twitch Javascript injected script to simulate reward redemption.
// Note: Class names may need to be changed if outdated.
// Index of reward to click.
var rewardButtonIndex = 0
var amountOfRedeems = 1
// Class names for elements.
var rewardsListButtonClass = "ScCoreButton-sc-ocjdkq-0 ScCoreButtonText-sc-ocjdkq-3 ljgEdo fuXDrj"
var specificRewardButtonClass = "ScInteractableBase-sc-ofisyf-0 ScInteractableDefault-sc-ofisyf-1 dsnvLR etibmD tw-interactable"
@Shilo
Shilo / export_inspector_toggle_example.gd
Created April 1, 2024 03:53
Godot 4 example on how to toggle @export visibility and readonly.
@tool
extends Node2D
@export var show_number: bool = false:
set(value):
show_number = value
notify_property_list_changed()
@export var editable_number: bool = false:
set(value):