Skip to content

Instantly share code, notes, and snippets.

@player-03
player-03 / OrMacro.hx
Last active August 29, 2015 14:27
A macro for finding the first non-null item in a list without evaluating any items after that one.
import haxe.macro.Expr;
class OrMacro {
/**
* @return The first non-null argument.
*/
public static macro function or(options:Array<Expr>):Expr {
var ifElseStatements:Expr = options[options.length - 1];
var i:Int = options.length - 1;
while(i --> 0) {
@player-03
player-03 / GLCheck.hx
Last active October 8, 2015 20:03
A function to help pin down the location of an OpenGL error.
#if !flash
import openfl.errors.Error;
import openfl.gl.GL;
import haxe.PosInfos;
import haxe.Log;
/**
* Usage: Put "GLCheck.check()" before and after anything that you suspect is causing a
* GL error. If the second call displays the error, you've found the problem. If the
@player-03
player-03 / ISODate.hx
Last active January 20, 2016 08:59
A utility to create Date instances from ISO-8601 dates.
/*
* Copyright 2016 Joseph Cloutier
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@player-03
player-03 / Tiles in View
Last active June 23, 2021 05:43
A demo of how to scroll tiles without creating a new array every frame.
package;
import openfl.Assets;
import openfl.Lib;
import openfl.display.Shape;
import openfl.display.Sprite;
import openfl.display.Tile;
import openfl.display.Tilemap;
import openfl.display.Tileset;
import openfl.events.Event;
@player-03
player-03 / SortFunctions.hx
Created December 8, 2016 11:38
Sort functions to pass to Array.sort().
class SortFunctions {
public static function alphabetical(a:String, b:String):Int {
if(a < b) {
return -1;
} else if(a > b) {
return 1;
} else {
return 0;
}
}
@player-03
player-03 / CPPRandomSeed.hx
Created January 19, 2017 01:43
Seed the random number generator in C++.
@:cppInclude('time.h')
class CPPRandomSeed {
public static function seed() {
#if cpp
untyped __cpp__('srand(time(NULL))');
#end
}
}
@player-03
player-03 / ShowAllScale.hx
Created May 29, 2018 10:31
A function to make OpenFL apps scale to fit the window.
package;
import openfl.display.Stage;
import openfl.Lib;
class ShowAllScale {
private static var nominalWidth:Int;
private static var nominalHeight:Int;
/**
@player-03
player-03 / SheetSetup.js
Last active August 19, 2021 20:48
A Roll20 API script allowing players to claim their imported characters.
var SheetSetup = SheetSetup || (function() {
'use strict';
var settings = {
/**
* Set null to disable chat.
*/
chatName: "Sheet Setup",
/**
* Set null to leave player name blank.
@player-03
player-03 / Dragon Form macro.js
Last active April 18, 2024 20:58
Dragon Form (PF2e)
//A spellcasting macro for PF2e in FoundryVTT. Casts the remastered Dragon Form
//spell, giving you both the battle form and the dragon breath action.
//Note: Sea, Sky, and Underworld dragons have burst-shaped dragon breath, which
//the spell does not account for. The macro assumes a 20-foot burst, but this is
//not supported by the rules, so ask your GM before picking these dragons.
//Options
//-------
@player-03
player-03 / Improvised weapon macro.js
Last active June 24, 2024 23:00
A macro to create improvised weapons for PF2e in FoundryVTT.
//A macro for PF2e in FoundryVTT that helps you create improvised weapons
//on the fly. It provides a menu of traits and damage types to pick from,
//and will create and equip the item once you're done.
//As usual, remember that your GM has final say on what an improvised
//weapon does. Work with them to figure out what statistics make sense.
//In particular, it won't always make sense to increase the weapon's
//damage die, even though the macro allows it.
//Options