Skip to content

Instantly share code, notes, and snippets.

View derkork's full-sized avatar

Jan Thomä derkork

  • Leipzig, Germany
View GitHub Profile
@derkork
derkork / CustomScript.cs
Last active September 1, 2022 13:36
Godot C# Registering custom node types with an editor plugin
using YoHDot.Utilities;
namespace YoHDot.Addons.CustomScripts
{
using System.Runtime.CompilerServices;
using System;
using Godot;
// This is mostly a workaround for https://github.com/godotengine/godot/issues/38191
using JetBrains.Annotations;
namespace YoHDot.Addons.CustomScripts
{
using System;
using System.Runtime.CompilerServices;
/// <summary>
/// Marks the script as used (because Rider cannot see usages in TSCN files).
/// If <see cref="Icon"/> is given or <see cref="RegisterAsNode"/> is set to true,
public static class ResourceQueue
{
public static async Task<T> Load<T>(string path, [CanBeNull] Delegates.ReportProgress reportProgress = null)
where T : Resource
{
if (ResourceLoader.HasCached(path))
{
GD.Print("Is in cache: " + path);
return ResourceLoader.Load<T>(path);
}

Quick Tip: Refer to nodes the right way

Hello Godotneers! Nodes are the heart of Godot and using them properly in your code will help you a lot in creating and maintaining your code. Here are three ways of referring to nodes that will instantly make your game code better.

One: Create node references in onready variables

In the Godot Discord channel I very often see code like this:

func _process():
@derkork
derkork / resource_queue.gd
Created April 22, 2021 09:45
Godot Resource Queue with Signals
class_name ResourceQueue
extends Node
signal loaded(path,resource)
signal progress(path, current, total)
var _thread:Thread
var _mutex:Mutex
var _sem:Semaphore
var _queue = []
@derkork
derkork / script.js
Created December 14, 2018 06:59
Casual PM: Sum up remaining effort tampermonkey script
// ==UserScript==
// @name Calculate remaining effort
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Sums of the effort of all tasks that are not yet finished. 1 day is counted as 8 hours.
// @author Jan Thomä
// @match https://app.casual.pm/*
// @grant none
// ==/UserScript==
@derkork
derkork / riderify.sh
Created November 22, 2016 19:49
Quickly add the JetBrains Rider plugin to any Unity project
#!/bin/bash
PROJECT_PATH=$1
if [ "$PROJECT_PATH" == "" ]; then
echo "Usage: riderify.sh <project root>"
exit 1
fi
rm -rf /tmp/riderplugin
mkdir -p /tmp/riderplugin
git clone https://github.com/JetBrains/Unity3dRider.git /tmp/riderplugin
cp -R /tmp/riderplugin/Assets $PROJECT_PATH
@derkork
derkork / gist:eea330079b9f9b2165bd
Last active August 29, 2015 14:19
Recursive hash merge in Ruby
def merge_recursively(a, b)
result = Hash.new
a.each do |key, a_item|
if b.key?(key)
b_item = b[key]
if b_item.is_a? Hash and a_item.is_a? Hash
result[key] = merge_recursively(a_item, b_item)
else
result[key] = b_item.nil? ? a_item : b_item
end
@derkork
derkork / Fragment definition
Created April 14, 2015 18:46
Thymeleaf Fragments vs JSP custom tags
<!-- Thymeleaf fragment declaration -->
<!-- in fragments/form-row.html -->
<div class="row" layout:fragment="form-row(label,id)"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:th="http://www.thymeleaf.org">
<!-- You cannot import the dialect namespaces somehow, you have to define all of these in every file -->
<div class="large-12 columns">
<label th:for="${id}"><span th:text="${label}">Label</span>
@derkork
derkork / Sample.java
Last active April 1, 2021 12:31
Spring constructor dependency injection: Java vs. Kotlin
// With Java, it's a lot of boilerplate code if you want to do it right and have your dependencies
// injected via the constructor instead of annotating private variables.
// see also: http://olivergierke.de/2013/11/why-field-injection-is-evil/
@Component
public class Sample {
private SomeDependency someDependency;
@Autowired
public Sample(SomeDependency someDependency) {