Skip to content

Instantly share code, notes, and snippets.

View bitwes's full-sized avatar

Butch Wesley bitwes

View GitHub Profile
@bitwes
bitwes / load_it_up_and_load_it_out.gd
Created May 14, 2023 00:30
Scene Script that enables all warnings and loads all scripts.
# ------------------------------------------------------------------------------
# Running this code at the command line does not show warnings. Which I found
# odd. But if you make a scene and add this as the script and run it from the
# editor it will:
# Set all debug-gdscript warnings to "warn"
# Load all the .gd files it can find (recursively)
# You get all the warnings you want in the Debugger tab
# ------------------------------------------------------------------------------
extends Node2D
var include_subdirectories = true
[gd_scene load_steps=2 format=2]
[ext_resource path="res://ViewportContainer.gd" type="Script" id=1]
[node name="Node" type="Node"]
script = ExtResource( 1 )
[node name="ViewportContainer" type="ViewportContainer" parent="."]
margin_left = 372.0
margin_top = 150.0
@bitwes
bitwes / open_editors.gd
Last active October 23, 2021 20:20
Godot EditorPlugin utility to track the currently active editor's TextEdit instance
var _script_editor = null
var _num_searched = 0
var _text_edits = []
var _focused = null
signal editor_changed
# Requires reference to the ScriptEditor instance.
func _init(script_edtitor):
_script_editor = script_edtitor
# Hash containing all the built in types in Godot. This provides an English
# name for the types that corosponds with the type constants defined in the
# engine.
var types = {}
func _init_types_dictionary():
types[TYPE_NIL] = 'TYPE_NIL'
types[TYPE_BOOL] = 'Bool'
types[TYPE_INT] = 'Int'
types[TYPE_REAL] = 'Float/Real'
@bitwes
bitwes / gui_object_boxes.gd
Last active May 20, 2021 18:48
Place this in a new Control Node that has a (0, 0) rect_size. Set properties. Custom node outlines can be added in the array. Colors for each custom is kept in the other array.
# ------------------------------------------------------------------------------
# Usage
# Create a Control node in the scene you want to paint boxes for and set the
# script for the Control to this.
#
# Draw Stoppers, Ignores, Passsers:
# When enabled these options will draw rectangles for any object that contains
# the mouse when you click. Stoppers, Ignores, Passers refers to the
# value of mouse_filter.
#
@bitwes
bitwes / test_me.gd
Created February 13, 2021 21:48
Tracking down an memory leak
extends SceneTreee
const SERVER_NODE_PATH := "res://content/scripts/server/server.gd";
# Create and return a server node
func create_server():
# Load relevant server files
var server_script := load(SERVER_NODE_PATH)
@bitwes
bitwes / Godot_iOS_AppStore_Approach.gd
Last active January 10, 2021 20:48
General approach for handling the Apple's StoreKit event queue with Godot
# ------------------------------------------------------------------------------
# iOS app store has a queue of events. Whenever a method that would expect an
# event to show up in this queue the queue_monitor is (re)started and
# will run for _max_wait seconds. The monitor will call the corrosponding event
# handler for any events it finds while running. When _max_wait seconds have
# elapsed then statuses are checked to see if anything is waiting on a response.
# If any are found then the status is changed to ERROR.
#
# There is some room for improvement here, but it seems to be working pretty
# well. There's a lot of edge cases to worry about but I haven't thought of
@bitwes
bitwes / collision_example.gd
Created June 28, 2020 00:20
Example of collision testing using GUT
# This tests sets a car object and a checkpoint object (created in before_each)
# on a collision path and waits 1 second for the collision to occur. It then
# checks a property in the checkpoint to verify the collision happened.
func test_crosses_when_target_car_crosses():
gr.checkpoint.set_position(Vector2(500, 0))
var car = _g.r.TargetCarScene.instance()
car.set_global_position(Vector2(400, 300))
add_child(car)
car.set_speed(200, 0)
@bitwes
bitwes / test_spinner.gd
Created April 8, 2020 15:48
Tests for spinner.gd
extends 'res://addons/gut/test.gd'
var BigSpinner = load('res://<your spinner scene path>')
func test_can_make_one():
assert_not_null(BigSpinner.instance())
func test_get_set_low():
assert_accessors(BigSpinner.instance(), 'low', 0.0, 10.0)
@bitwes
bitwes / spinner.gd
Created April 8, 2020 15:46
Code for a custom spin box.
# Hook this up to a label and two buttons. The label must be named "Value"
# or you can change the code.
extends Control
export var _low = 0.0 setget set_low, get_low
export var _high = 100.0 setget set_high, get_high
export var _step = 1.0 setget set_step, get_step
export var _value = 0.0 setget set_value, get_value
signal value_changed