Skip to content

Instantly share code, notes, and snippets.

@nonunknown
nonunknown / StateMachine.cs
Last active July 9, 2023 11:58
[Godot 4] C# State Machine - Performant
using System;
using System.Reflection;
using System.Collections.Generic;
public partial class StateMachine : RefCounted
{
private Action<double> currentState;
private int currentStateID = 0;
private Dictionary<int, Action> statesEnter,statesExit;
private Dictionary<int, Action<double>> statesUpdate;
@nonunknown
nonunknown / AnimatedToAnimation.gd
Created September 19, 2021 20:49
[Godot 4] Convert AnimatedSprite to AnimationPlayer
@tool
extends Control
@export var gen:bool = false :
set(value):
if !value: return
print("test")
self.convert()
gen = false
@nonunknown
nonunknown / ColorRangeSwap.shader
Last active September 23, 2021 23:22
Color Range Swap
shader_type canvas_item;
uniform float _min;
uniform float _max;
uniform vec4 color : hint_color;
vec3 rgb2hsv(vec3 c)
{
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
@nonunknown
nonunknown / deal_with_async_in_godot.md
Last active September 23, 2021 12:34
Godot & Javascript - How to deal with async results

Godot & Javascript - How to deal with async results

My task: Get a function of godot called by Javascript! The Problem: godot's javascript class, doesnt support functions which doesnt return the value immediately

So, this is a step by step of what I've done, I'm using Node.js with a godot application which needs to get data from that node.js server!

First Step

@nonunknown
nonunknown / StateMachine4.gd
Created September 18, 2021 19:48
[Godot 4] State machine
extends RefCounted
class_name StateMachine
## This is a state machine implementation, very optimize w/ code organization on your side
var _states_enter:Array[StringName]
var _states_update:Array[StringName]
var _states_exit:Array[StringName]
var _current_state:int = 0
@nonunknown
nonunknown / StateMachine.gd
Last active August 25, 2021 23:37
A statemachine for godot!
extends Reference
class_name StateMachine
var target = null
var machine:Dictionary = {
state = null,
last_state = null,
funcs={
enter={},
update={},