Skip to content

Instantly share code, notes, and snippets.

View cgbeutler's full-sized avatar

Cory Beutler cgbeutler

View GitHub Profile
from math import factorial
from sympy.utilities.iterables import multiset_permutations
print("Searching...")
# Numerically balanced dice
# To calculate:
# 1. Find the average value of a face
# 2. Multiply that average by the number of faces touching a vert.
# The result is the value each vert should have.
Number Name
1 Bulbasaur
2 Ivysaur
3 Venusaur
4 Charmander
5 Charmeleon
6 Charizard
7 Squirtle
8 Wartortle
9 Blastoise
@cgbeutler
cgbeutler / EnumExt.cs
Last active October 21, 2022 02:05
A set of useful enumeration extensions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace MonsterVial.Extensions
{
public static class EnumExt
{
@cgbeutler
cgbeutler / CSharpScriptAttribute.cs
Last active June 24, 2022 14:45
Helper for creating custom resources in Godot in C# until bug #38191 is fixed
using System;
using System.Runtime.CompilerServices;
using Godot.Collections;
using Array = Godot.Collections.Array;
/* Example Usage:
// Declare a class with the attribute
[CSharpScript]
public class CustomResource : Resource { ... }
@cgbeutler
cgbeutler / res_ref.gd
Created May 14, 2021 02:31
A typed resource reference class
tool
class_name ResRef extends Reference
####
# Settable in the editor. Hit reset to get a new obj. Tries to never be null.
# Cannot be changed once in-game if `p_set_once` is true.
####
#### EXAMPLE USAGE ####
#var __backer := ResRef.new(MyResource)
#export var my_res :Resource setget set_my_res, get_my_res
@cgbeutler
cgbeutler / help_obj.gd
Created February 4, 2021 23:20
Helper class for Godot's connect and disconnect. Also a proof of concept for a Result class.
tool class_name help_obj
# Like the default connect, but doesn't push error if already connected
static func try_connect( source: Object, sig: String, target: Object, method: String, binds := [], flags := 0 ) -> SignalResult:
if not source.has_signal(sig):
return SignalResult.new( ERR_INVALID_PARAMETER, str("Can't connect: Signal '", sig, "' missing from object.") )
if not(flags & Object.CONNECT_REFERENCE_COUNTED) and source.is_connected(sig, target, method):
return SignalResult.new( ERR_INVALID_PARAMETER, str("Can't connect: Target already connected to signal '", sig, "'.") )
return SignalResult.new( source.connect(sig, target, method, binds, flags), "" )
# Like the default disconnect, but doesn't push error if not connected
@cgbeutler
cgbeutler / ShapePolygon2D.gd
Created January 7, 2021 00:12
A Polygon2D that can take a Shape2D.
tool
class_name ShapePolygon2D extends Polygon2D
func _get_configuration_warning() -> String:
if shape == null:
return "Shape resource is null"
if shape is ConvexPolygonShape2D and len(shape.points) <= 1:
return "ConvexPolygonShape2D has too few points to draw"
if shape is ConcavePolygonShape2D:
@cgbeutler
cgbeutler / Quick Vial Exporter.lua
Last active March 25, 2022 01:55
Quick Exporter for Aseprite that uses layer names to be smarter
----------------------------------------------------------------------
-- Author: Cory Beutler
-- License: MIT (So you can't sue me... Otherwise go wild!)
--
-- Exports the current file using layer name prefixes to be smart.
-- The png and json files are always exported with all their data.
-- Texture png files will be auto-named <filename>.png
-- Json files will be auto-named <filename>.asejson
-- Layer name prefixes it recognizes:
-- _ Hide from all exports. Useful for guide and reference layers.
@cgbeutler
cgbeutler / ExportAsAttribute.cs
Last active June 3, 2020 23:46
ExportAs Attribute for Godot CSharp Projects.
using System.Linq;
using Godot;
using Godot.Collections;
namespace Vial.Export {
[System.AttributeUsage(System.AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
public sealed class ExportAsAttribute : System.Attribute {
# Singleton Time
extends Node
##
# Set this class as a singleton in Godot named Time or similar.
# Setting it near the top will ensure it is processed before
# everything else, giving you consistent values for all nodes
# that use this class.
# this class has a global process and physics process count
# that is very useful when doing things less often.
# A wrapper has provided to make that even quicker: