Skip to content

Instantly share code, notes, and snippets.

View lackhand's full-sized avatar

Andrew C lackhand

View GitHub Profile
@lackhand
lackhand / Ancestors.gd
Created September 30, 2025 16:05
Ancestors: Static funcs to find ancestors with type queries
## Static funcs to find ancestors with type queries
## Finds the parent of the given node whose script is a subclass of the given type.
static func find_parent_of(node: Node, cls: Script, depth := INT_MAX) -> Node:
while node and depth > 0:
if is_subscripted(node, cls): return node
node = node.get_parent()
depth -= 1
return null
## As `find_parent_of` but with support for builtins.
@lackhand
lackhand / SpriteFramesFactory.gd
Created June 27, 2025 21:40
Sprite Frame Slicer
@tool
class_name SpriteFramesFactory
extends Resource
const suffix := ".frames.tres"
@export var texture: Texture2D
@export var tile_size:= Vector2i(16, 32)
@export var ul_margin := Vector2i(0, 0)
@lackhand
lackhand / gist:f95aed7a8f76d59b865674edc4beefc8
Created June 16, 2025 19:27
Godot utilities around deque & node hierarchy traversal
## Deque.gd:
## A mutatey double ended queue.
## They can also be pop_front or pop_backed equivalently, as well as
## shuffled off of a stable seed (to avoid messing with global randomizer state).
## Also! Supports use as a channel for fanin via the `take` operations, which are blocking.
class_name Deque
extends RefCounted
var front_stack:Array
var back_stack:Array
import Phaser from 'phaser';
import dragonBones from 'dragonbones-phaser';
import biped_ske_json from './biped_ske.json';
import biped_tex_json from './biped_tex.json';
import biped_tex_png from './biped_tex.png';
export const game = new Phaser.Game({
type: Phaser.WEBGL,
width: 400,
height: 300,
# Just the hack to workaround https://github.com/godotengine/godot/issues/96367
func _hack_into_visibility():
var vp := get_viewport() as Window
var orig_size := vp.size
print("Emulating a resize event to force the minimap to display & update around display size ", orig_size)
@warning_ignore("integer_division")
vp.size = Vector2(orig_size.x, orig_size.y / 2)
await RenderingServer.frame_post_draw
@warning_ignore("integer_division")
extends RayCast3D
## Hacks around https://github.com/godotengine/godot/issues/29727
## "3D CollisionObject signals do not trigger when mouse is in "captured" mode"
## by having a raycast sweep for things and emulate mouse behaviors.
## All else equal, you'll want the configured raycast object to have:
## * All layers in its mask (so you can emulate the way the mouse works)
## * A target of `Vector3(0, 0, -4096)` (or more!) for large depth cast out of the camera.
## Keep a reference to this guy; it's fiesty and jumps to the currently active camera!
/***
Using:
$ npm list phaser
...
phaser@3.50.0-beta.12
...
I get a jserror:
Error: Cannot add a Scene with duplicate key: credits
*/