Skip to content

Instantly share code, notes, and snippets.

@PrestonKnopp
PrestonKnopp / optional.gd
Last active September 20, 2023 21:15
Attempt at Optionals in GDScript
# optional.gd
#
# Caveat
# ------
# This only works with types inheriting from Object. Built-in types don't work
# with the call api. Built-ins can still be fetched but they cannot be operated
# on.
#
# This can be fixed by subclassing optional and adding type specific methods
# that wrap the builtin type.
@PrestonKnopp
PrestonKnopp / test_drag_and_drop.tscn
Created June 8, 2019 00:04
Examples of Godot's Control drag and drop functionality. Test it out by downloading this tscn and adding it to a Godot project. It is entirely self contained in one scene.
[gd_scene load_steps=6 format=2]
[sub_resource type="GDScript" id=1]
script/source = "extends Control
class DragDataColor:
var sender: Object
var color: Color"
[sub_resource type="GDScript" id=3]
@PrestonKnopp
PrestonKnopp / get_piped_stdin_only_if_available.dart
Created October 23, 2019 23:40
Get piped in stdin if available
import 'dart:io' show stdin;
import 'dart:convert' show utf8;
main() async {
try {
String input = await stdin.timeout(Duration.zero).transform(utf8.decoder).first;
print(input);
} on TimeoutException {
print('No input was piped into stdin');
}
@PrestonKnopp
PrestonKnopp / echogdscriptbuiltins.nim
Last active February 22, 2024 19:35
Echo gdscript builtins from @GDScript.xml and @GlobalScope.xml for nvim-treesitter gdscript queries.
## Run: `nim r <thisfile>`
##
## Run this from the root of godot git repo.
##
## Parses and echos to stdout builtins from @GDScript.xml and @GlobalScope.xml
## in a format that is easy to include in
## https://github.com/nvim-treesitter/nvim-treesitter gdscript queries.
##
## - methods <methods><method name="EXTRACT_ME"></method>
## - members which are singletons <members><member name="EXTRACT_ME"></member></members>