Skip to content

Instantly share code, notes, and snippets.

View hiulit's full-sized avatar
💻
Working

hiulit

💻
Working
View GitHub Profile
@hiulit
hiulit / audio_stream_player_with_counter.gd
Created September 8, 2022 09:05
AudioStreamPlayer with a counter, which counts the seconds elapsed and emits a signal each second
extends AudioStreamPlayer
class_name AudioStreamPlayerWithCounter
signal playback_position_reached(number)
var counter: int
var previous_counter: int
func _ready() -> void:
@hiulit
hiulit / enable_disable_input.gd
Created September 6, 2022 14:52
Enable/disable input for the whole game/app
func disable_input(actions_allowed = []) -> void:
for action in InputMap.get_actions():
# Allow some input actions.
if action in actions_allowed:
continue
# Remove the action and its events.
InputMap.action_erase_events(action)
InputMap.erase_action(action)
# To avoid the error: The InputMap action "xxx" doesn't exist.
@hiulit
hiulit / geometry_calibration.gd
Last active May 27, 2022 17:37
Creates a pattern of squares (with optional dots in the center of the squares) to calibrate the geometry of the monitor
extends Node2D
export (bool) var dots = false
var viewport_size = Vector2(
ProjectSettings.get_setting("display/window/size/width"),
ProjectSettings.get_setting("display/window/size/height")
)
var square_size = gcd(viewport_size.x, viewport_size.y)
var amount_x = (viewport_size.x / square_size) + 1.0
@hiulit
hiulit / filter_includes.gd
Last active January 8, 2023 03:18
Filter an array that includes every/some of the elements of a given array
func filter_includes(type: String, base_array: Array, filter_array: Array, filter_key: String = "") -> Array:
var filtered_array := []
for base_item in base_array:
var count = 0
var search_item = base_item
if filter_key:
search_item = base_item[filter_key]
func get_all_files(path: String, file_ext := "", files := []):
var dir = Directory.new()
if dir.open(path) == OK:
dir.list_dir_begin(true, true)
var file_name = dir.get_next()
while file_name != "":
if dir.current_is_dir():
@hiulit
hiulit / get_surrounding_tiles.gd
Last active February 19, 2024 17:46
Get the surrounding tiles from a given tile (in grid-based coordinates)
func get_surrounding_tiles(current_tile):
var surrounding_tiles = []
var target_tile
for y in 3:
for x in 3:
target_tile = current_tile + Vector2(x - 1, y - 1)
if current_tile == target_tile:
continue
@hiulit
hiulit / create_polygon_from_sprite.gd
Created June 8, 2020 12:41
Create a Polygon2D from a Sprite in Godot
# Thanks to Justo Delgado - a.k.a mrcdk (https://github.com/mrcdk) - for the function this one is based on.
# It can be found here https://github.com/godotengine/godot/issues/31323
# The sprite parameter must be a Sprite node.
func create_polygon_from_sprite(sprite):
# Get the sprite's texture.
var texture = sprite.texture
# Get the sprite texture's size.
var texture_size = sprite.texture.get_size()
# Get the image from the sprite's texture.
@hiulit
hiulit / outline-gles2.shader
Created September 20, 2019 19:08
Godot 3 Outline Shader GLES2
shader_type canvas_item;
uniform float width;
uniform vec4 outline_color : hint_color;
void fragment()
{
vec2 size = (vec2(width) * TEXTURE_PIXEL_SIZE);
vec4 sprite_color = texture(TEXTURE, UV);
@hiulit
hiulit / light-shader.shader
Last active October 11, 2020 11:02
Godot 3 light interact with shader
shader_type canvas_item;
uniform vec4 dawn_color : hint_color = vec4(0.86, 0.70, 0.70, 1.0);
uniform vec4 day_color : hint_color = vec4(1.0, 1.0, 1.0, 1.0);
uniform vec4 dusk_color : hint_color = vec4(0.59, 0.66, 0.78, 1.0);
uniform vec4 night_color : hint_color = vec4(0.07, 0.09, 0.38, 1.0);
uniform float brightness : hint_range(0.0, 10.0, 0.01) = 1.0;
uniform float contrast : hint_range(0.0, 10.0, 0.01) = 1.0;
uniform float saturation : hint_range(0.0, 10.0, 0.01) = 1.0;
@hiulit
hiulit / install-virtualbox-guest-additions-linux.md
Last active July 12, 2018 13:41
Install VirtualBox Guest Additions on Linux
  1. In VirtualBox, choose Insert Guest Additions CD image... from the Devices menu.
  2. Next, you'll need to install the Guest Additions in a Terminal window.
    sudo sh /media/cdrom[n]/VBoxLinuxGuestAdditions.run
  3. Reboot.
  4. After rebooting, open a new Terminal and use the following command.
    lxrandr