Skip to content

Instantly share code, notes, and snippets.

View willnationsdev's full-sized avatar

Will Nations willnationsdev

View GitHub Profile
@willnationsdev
willnationsdev / example.gd
Last active June 9, 2024 22:29
GDScript Result class with usage example.
# Example usage
static func example_connect_to_network() -> Result:
return Result.fail(ERR_CANT_CONNECT)
static func example_load_file(conn: ENetConnection) -> Error:
return ERR_FILE_CORRUPT
class ApiResult:
extends RefCounted
@willnationsdev
willnationsdev / git_examples.sh
Last active May 6, 2020 15:39
Git Cheatsheet
# get list of files and their status (unversioned, edited, added in working directory, etc.)
$ git status
# Get a detailed list of prior commits. Get information on where other branches are, relative to each other and the current HEAD.
$ git log
# Get a summarized list of commit hashes/messages starting from the HEAD all the way back to <branch>'s place in history.
$ git log --pretty=oneline <branch>
# When used from the root directory of a repo, adds all edited files to working directory.
# Make sure to only run this *after* you've got an updated .gitignore file. Otherwise, you will need to remove unwanted items from the working directory to prevent committing them.
$ git add .
# To quickly commit something with a summary.
@willnationsdev
willnationsdev / LootTable.gd
Last active September 5, 2020 15:57
Have a LootTable resource that exports an Array of LootElement script instances
tool
class_name LootTable
extends Resource
export var _element_type: Script = null setget set_element_type
export var data := [] setget set_data
func set_data(p_value: Array) -> void:
# Validate element types.
# Only necessary because Godot doesn't yet have typed Arrays
# or exportable user-defined Resource types. Hopefully coming for 4.0.
for i in len(p_value):
# InputManager.gd
extends Node
export var wait_time := 0.5
export var merge_time := 0.1
var player_index := 0
var buffer := []
var _buf_timer: Timer = null
@willnationsdev
willnationsdev / my_node.gd
Last active September 13, 2019 19:30
animation on input sample
extends KinematicBody
var rotation_x_delta = 0.0
var rotation_y_delta = 0.0
func _unhandled_input(event):
if event is InputEventKey and not event.is_echo():
match event.scancode:
KEY_A:
@willnationsdev
willnationsdev / enums.gd
Created August 27, 2019 19:07
Examples of exporting integers in Godot to generate GUI elements
# enum - generates radio buttons
enum {
SUIT_HEARTS,
SUIT_DIAMONDS,
SUIT_SPADES,
SUIT_CLUBS
}
export(int, "Hearts", "Diamonds", "Spades", "Clubs") var suit := SUIT_HEARTS
# flag enum - generates checkboxes
@willnationsdev
willnationsdev / init.gd
Created July 29, 2019 21:30
vim_editor_plugin
var c = Control.new()
add_control_to_container(EditorPlugin.CONTAINER_TOOLBAR, c)
for a_child in c.get_parent().get_children():
if a_child is HBoxContainer:
for a_btn in a_child.get_children():
if a_btn is BaseButton and a_btn.text == "Vim":
main_screen_btn = a_btn
break
if main_screen_btn:
break
# copying this from an Unlicense repository
# https://github.com/xiosolox/Godot_PoissonDiskSampling/blob/master/GDscript/PoissonDisk.gd
extends Node
class_name PoissonDisk
export var width = 1024
@willnationsdev
willnationsdev / v_box_item_list.gd
Last active August 20, 2018 00:21
VBoxItemList: A vertical list of Controls. + button to append new Control to list. X button beside each Control to remove that item. Optional enumerated label can be defined.
tool
extends VBoxContainer
class_name VBoxItemList
signal item_inserted(p_index, p_data)
signal item_removed(p_index, p_data)
const ICON_ADD: Texture = preload("../icons/icon_add.svg")
const ICON_DELETE: Texture = preload("../icons/icon_import_fail.svg")
@willnationsdev
willnationsdev / thread_execute.gd
Last active July 31, 2018 16:16
GDScript threading example with an asynchronous "blocking" OS.execute that doesn't block the main thread.
extends Node
signal thread_finished(t)
var t
func _ready():
t = Thread.new()
connect("thread_finished", self, "_on_thread_finished")
var params = {