Skip to content

Instantly share code, notes, and snippets.

View apples's full-sized avatar
🏳️‍🌈

Apples apples

🏳️‍🌈
View GitHub Profile
@apples
apples / int_observer.gd
Created April 19, 2025 14:53
Godot implementation of Unity ScriptableObject pattern for observable values.
class_name IntObserver
extends Node
signal value_changed(value: int)
@export var observable: ObservableInt:
set(v):
if observable:
observable.changed.disconnect(_emit)
observable = v
@apples
apples / web_socket_client.gd
Last active December 17, 2024 02:50
Godot WebSocket client node.
class_name WebSocketClient
extends Node
signal recv_text(message: String)
signal recv_binary(message: PackedByteArray)
signal connected()
signal disconnected()
const TRACE = true
@apples
apples / future.gd
Created December 11, 2024 09:07
A simple and memory-efficient implementation of futures/promises in GDScript.
class_name Future
extends RefCounted
static var _UNFULFILLED = RefCounted.new()
static var _initial_state = [_UNFULFILLED]
static var _fulfilled_signal = _FulfilledSignal.new()
func _init() -> void:
push_error("Static class. Do not instantiate.")
@apples
apples / shallow_resource_loader.gd
Last active August 10, 2024 11:06
Shallow resource loader designed to load PackedScene files without loading their external resource dependencies.
@tool
extends RefCounted
## ShallowResourceLoader
##
## Shallowly loads a resource without loading external dependencies.
## Dependencies are replaced by an instance of PlaceholderExternalResource.
## Dependencies which have already been loaded and which are in the cache are not replaced.
## Placeholder resources will be stored in the cache using the resource_path they are replacing.
##
@apples
apples / lobby.gd
Last active August 10, 2024 10:55
Godot multiplayer lobby system with simple client verification.
extends Node
##
## Manages multiplayer connections.
##
## Emitted when a client player joins the session. Only emitted on the server.
## Also emitted for the local player when the server starts.
signal player_joined(unique_id: int)
## Emitted when a client player leaves the session (or is kicked). Only emitted on the server.
@apples
apples / LICENSE.txt
Last active January 3, 2024 00:22
Wave Function Collapse implementation in pure GDScript
MIT License
Copyright (c) 2024 Apples
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@apples
apples / dice_roll.gd
Last active September 26, 2023 05:19
GDScript Dice Notation Parser and Calculator
class_name DiceRoll
extends RefCounted
## Usage
## [codeblock]
## var dice := DiceRoll.new("1d4 + 2 * X")
## if not dice.is_valid():
## print("Invalid dice.")
## print("Range: %s ~ %s" % [dice.min(), dice.max()])
## print("Sample roll: %s" % [dice.roll({ X = 2 })])
@apples
apples / android_godot.md
Last active September 24, 2023 07:23
A tutorial on setting up the Godot 4.0 editor on Android with Git and Termux.

Godot Editor on Android

Overview

This tutorial is designed to set up a complete Git workflow on Android, complete with LFS, and use it with the Godot editor.

The storage usage is minimal.

Be prepared to get a bit technical. You should be familiar with command line tools,

@apples
apples / CopperSession.cs
Last active December 10, 2021 04:54
Copper Token - cryptographically secure tokens for ASP.NET Core WebAPI.
using System;
using System.Security.Claims;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
namespace Copper
{
public static class CopperSession
{
@apples
apples / Copy.cs
Last active December 9, 2021 23:04
C# Shallow copy function
using System;
using System.Reflection;
namespace Mealplan
{
public static class Copy
{
public static T Shallow<T>(object src, Type? srcType = null, object? defaultValues = null, object? forceValues = null)
where T : new()
{