Skip to content

Instantly share code, notes, and snippets.

View hazzard993's full-sized avatar

Jason McKenzie hazzard993

View GitHub Profile
@hazzard993
hazzard993 / composition.gml
Last active December 23, 2024 01:07
Inline pasteable functional functions for some functional programming in GameMaker (at least to my understanding of FP).
///
/// Performs right-to-left function composition.
///
/// @param {Function[]} ...functions The pipeline of functions to send values through.
/// @returns The head of this pipeline.
var compose = function() {
var functions = [];
for (var i = 0; i < argument_count; ++i) {
array_push(functions, argument[i]);
}
@hazzard993
hazzard993 / assertions.gml
Last active November 6, 2024 03:26
Inline pasteable checks for testing behaviour in GameMaker.
var assert_is_callable = function(actual) {
if is_callable(actual) return;
show_error($"Expected callable. Got {actual}", true);
};
var assert_is_array = function(actual) {
if is_array(actual) return;
show_error($"Expected callable. Got {actual}", true);
@hazzard993
hazzard993 / priority_queue.d.ts
Last active December 23, 2020 05:29 — forked from LukeMS/priority_queue.lua
Priority Queue implemented in lua, based on a binary heap.
declare function create<T>(this: void): PriorityQueue<T>;
interface PriorityQueue<T> {
empty(): boolean;
size(): number;
/**
* Swim up on the tree and fix the order heap property.
*/
swim(): void;
put(v: T, priority: number): void;
@hazzard993
hazzard993 / inspect.d.ts
Created November 26, 2020 23:20
TSTL import inspect
declare function inspect(this: void, value: any): string;
declare namespace inspect {
const prop: string;
}
export = inspect;

PICO-8 Transformer

  • Disallows LuaLibs
  • Disallows classes
  • Disallows iifes if (x = 0)
  • Disallows non-tuple return methods

for loops

Image Registry

LÖVE 2D can load images.

love.graphics.newImage("img/Player.png");

What is stopping you in TypeScript? The ImageRegistry.

Effect Registry

LÖVE 2D allows Effects to be added to the audio that is playing. Each effect is added with a name which can be used to obtain the audio effect later.

love.audio.setEffect("myEffect", {...});
love.audio.getEffect("myEffect");

To aid TypeScript, an EffectRegistry interface has been provided to keep track of the audio effects planned to be set.

Filepath Registry

LÖVE 2D can interact with the file system.

love.filesystem.getLastModified("file.txt");

However, there likely is a FileRegistry stopping you.

Registries

LÖVE 2D can interact with many things through the use of strings.

love.audio.getEffect("anEffect");
// Nothing crashes if anEffect didn't exist

love.filesystem.readFile("file.txt");
// No crash, just returns an error
@hazzard993
hazzard993 / pairs.ts
Created April 9, 2019 03:49
In TSTL, iterate using pairs, not Symbol.Iterator
// Works on 0.17.0
/**
* @tupleReturn
* @luaIterator
*/
declare function pairs(object: object): Iterable<[string, any]>;
declare const print: any;