Skip to content

Instantly share code, notes, and snippets.

@mrcdk
mrcdk / shader_stylebox.gd
Created February 25, 2024 10:43
A StyleBox that uses a Material to render
@tool
class_name StyleBoxShader extends StyleBox
@export var material:Material
@export var texture:Texture2D
# the canvas item we are going to use
var canvas_item_rid:RID
@mrcdk
mrcdk / example.gd
Last active August 19, 2024 22:23
Quick and dirty Godot 4.x plugin to add buttons to the inspector
@tool
extends Node
func _add_inspector_buttons() -> Array:
var buttons = []
buttons.push_back({
"name": "Test button",
"icon": preload("res://icon.svg"),
"pressed": _on_test_button_pressed
@mrcdk
mrcdk / open_project_settings.gd
Created October 22, 2023 05:45
Godot 4.1 open the project settings and select an entry
@tool
extends EditorScript
func _run() -> void:
var interface = get_editor_interface()
var base = interface.get_base_control()
# Find the Project Settings Editor
var settings = base.find_child('*ProjectSettingsEditor*', true, false)
@mrcdk
mrcdk / globals.gd
Created August 16, 2023 13:28
Godot 4.x example of how to launch multiple instances and tile them by using an editor debugger plugin to communicate with each instance
# res://globals.gd added as an autoload
extends Node
func _ready() -> void:
EngineDebugger.register_message_capture("tile-instances", _on_tile_instances)
EngineDebugger.send_message.call_deferred("tile-instances:get_id", [])
@mrcdk
mrcdk / Macros.hx
Created March 31, 2016 00:33
@:enum abstract Something(Int) autoInt() macro
import haxe.macro.Context;
import haxe.macro.Expr;
class Macros {
macro public static function autoInt():Array<Field> {
var fields = Context.getBuildFields();
var t = switch(Context.getLocalClass().get().kind) {
case KAbstractImpl(c):
@mrcdk
mrcdk / Main.cs
Created December 17, 2015 20:54
[haxe] Java and C# inline problems
#pragma warning disable 109, 114, 219, 429, 168, 162
public class EntryPoint__Main {
public static void Main() {
global::cs.Boot.init();
global::Main.main();
}
}
public class Main : global::haxe.lang.HxObject {
@mrcdk
mrcdk / OneOf.hx
Last active July 9, 2020 03:20
OneOf abstract: An abstract that uses haxe.ds.Either as its base type and hides the explicit use of it. http://try.haxe.org/#c0557
import haxe.ds.Either;
abstract OneOf<A, B>(Either<A, B>) from Either<A, B> to Either<A, B> {
@:from inline static function fromA<A, B>(a:A) : OneOf<A, B> return Left(a);
@:from inline static function fromB<A, B>(b:B) : OneOf<A, B> return Right(b);
@:to inline function toA():Null<A> return switch(this) {case Left(a): a; default: null;}
@:to inline function toB():Null<B> return switch(this) {case Right(b): b; default: null;}
}
@mrcdk
mrcdk / Main.hx
Last active November 25, 2015 17:30 — forked from evanw/Main.hx
class Assert {
public static inline function assert(truth: Bool) {
#if debug
if (!truth) {
trace('assert failed');
}
#end
}
}
@mrcdk
mrcdk / MacroEnum.hx
Last active December 24, 2015 11:43
abstract enum toString() macro
package ;
#if macro
import haxe.macro.Context;
import haxe.macro.Printer;
import haxe.macro.Expr;
class MacroEnum {
macro public static function buildToString():Array<Field> {
@mrcdk
mrcdk / FlxPhysicsDemo.hx
Created October 1, 2013 18:50
FlxNapeDemo mobile targets
//change line 39 to this
super(Math.floor(stageWidth / ratio), Math.floor(stageHeight / ratio), Piramid, ratio, 30, 30);