This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node | |
var dice_regex = RegEx.new() | |
func _ready() -> void: | |
randomize() | |
dice_regex.compile("(?<dice>[0-9]*)?d(?<sides>[0-9]+)(?: ?(?<operator>\\+|-) ?(?<modifier>[0-9]*))?") | |
func rand_dice(dice: String) -> int: | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# originally by GogetaX (Discord: @274253761399095297) | |
func LineSpliter(txt,MaxTextLength): | |
var Finish = false | |
var a = -1 | |
var Lines = [] | |
var t = "" | |
var LastBreak = -1 | |
while !Finish: | |
a += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Useful functions for calculating distances between angles | |
static func lerp_angle(from: float, to: float, weight: float) -> float: | |
return from + short_angle_dist(from, to) * weight | |
static func short_angle_dist(from: float, to: float) -> float: | |
var difference = fmod(to - from, PI * 2) | |
return fmod(2 * difference, PI * 2) - difference | |
# A chunk of code I came up with for more snappy angle lerping |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Pattern, Match | |
import re | |
# This pattern matches words separated by whitespace or hyphens. | |
_pattern: Pattern = r"([A-Za-z0-9']+)" | |
_regex: Match = re.compile(_pattern) | |
def obnoxiousify(text: str) -> str: | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This helps a lot when trying to use Controls to represent a translated CollisionShape2D for a tool script | |
# I don't know if it's useful for anything else | |
static func pos_to_margin(position: Vector2, extents: Vector2) -> Dictionary: | |
var margin_left := position.x - extents.x | |
var margin_right := position.x + extents.x | |
var margin_top := position.y - extents.y | |
var margin_bottom := position.y + extents.y | |
return { | |
"margin_left": margin_left, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is an awful solution, but NodePath is missing an important method, so there's no great alternative that I've found. | |
# Try me with get_node_property(self, "Control/Spatial/CollisionShape2D:shape:extents:x") | |
func get_node_property(from: Node, path: NodePath): | |
assert ":" in path as String # Causes a hard crash | |
path = path as NodePath | |
var node_path = get_as_node_path(path) | |
var property_path = (path.get_concatenated_subnames() as NodePath).get_as_property_path() | |
return from.get_node(node_path).get_indexed(property_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var moving := Vector2() | |
func _physics_process(delta: float) -> void: | |
# Input singleton should only be used from _physics_process | |
update_moving() | |
func update_moving() -> void: | |
# This makes moving a little more intuitive with the arrow keys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tool | |
extends MeshInstance | |
class_name MeshInstanceUV | |
var _time := Vector2() | |
export var speed := Vector2(1.0, 1.0) | |
export var sinusoid_factor := Vector2(1.0, 1.0) | |
export var linear_factor := Vector2(1.0, 1.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func randfb(curve: Curve) -> float: | |
# Returns a float mapped onto a symmetric distribution using a curve | |
# Also known as: a poor man's Beta distribution ;) | |
return symmetric_interpolate(randf(), curve) | |
func symmetric_interpolate(f: float, curve: Curve) -> float: | |
# Returns a float mapped onto a curve as if the curve were symmetric | |
return 0.5 + curve.interpolate(f) / (2 if randi()%2==0 else -2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node | |
class_name Test | |
# Base class for automated test autoloads | |
enum { | |
MODE_IGNORE, | |
MODE_WARN, | |
MODE_ASSERT, | |
MODE_CRASH | |
} |
OlderNewer