Skip to content

Instantly share code, notes, and snippets.

package ;
abstract JsonMap<T>({ }) from {} {
public function new() this = {};
public function exists(key:String) return Reflect.hasField(this, key);
@:arrayAccess public function get(key:String) return Reflect.field(this, key);
@:arrayAccess public function set(key:String, value:T):T {
Reflect.setField(this, key, value);
return value;
}
@jasononeil
jasononeil / DispatchTest.hx
Last active December 17, 2015 20:19
A sample to test some more complex routing options of haxe.web.Dispatch. Run with `haxe -x DispatchTest.hx` This is the sample code for this tutorial / blog post: http://jasononeil.com.au/2013/05/29/creating-complex-url-routing-schemes-with-haxe-web-dispatch/
import haxe.ds.StringMap;
import haxe.web.Dispatch;
import haxe.web.Dispatch.DispatchError;
#if sys
import Sys.println;
import Sys.print;
#else
import haxe.Log.trace in println;
import haxe.Log.trace in print;
@Beeblerox
Beeblerox / dumpBits example
Created July 8, 2013 12:17
This is an example of how you can reduce memory usage for Tilesheet class in openfl with dumpBits() method. But you also listen for stage resize event and recreate tilesheet after context loss.
import flash.Lib;
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import openfl.Assets;
import openfl.display.Tilesheet;
import flash.display.Graphics;
import flash.events.Event;
class Particle
typedef FlxGraphicAsset = AcceptOneOfFive<String, Class<Dynamic>, CachedGraphics, TextureRegion, BitmapData>;
abstract AcceptOneOfFive<T1, T2, T3, T4, T5>(EitherOfFive<T1, T2, T3, T4, T5>)
{
public inline function new(e:EitherOfFive<T1, T2, T3, T4, T5>)
{
this = e;
}
public var value(get, never):Dynamic;
@nadako
nadako / Main.hx
Last active November 27, 2020 16:08
Signal builder using new Rest type parameter in Haxe
class Main {
static function main() {
var signal = new Signal<Int,String>();
var conn = signal.connect(function(a, b) {
trace('Well done $a $b');
});
signal.dispatch(10, "lol");
}
}
@magicznyleszek
magicznyleszek / multiply-blending-mode-to-png.md
Created August 20, 2014 11:27
Multiply blending mode to PNG in Photoshop
  1. copy your image (Ctrl+A and Ctrl+C)
  2. make a new document-sized pure-black layer behind it
  3. group the black layer and yor image together
  4. add mask to the group
  5. enter mask edit mode (alt+click on the mask icon/thumbnail)
  6. paste your image in the mask (b/w) and then invert it.
  7. save it as a 24-bit transparent PNG
@jcward
jcward / hxScout testing instructions
Last active August 29, 2015 14:15
Setup testing of hxcpp / hxScout
Instructions for testing hxScout with hxcpp.
FYI, I've tested this using Haxe 3.1.3, OpenFL 2.1.7 (the legacy version, aka _v2, aka not next) in Windows 7. Your mileage may vary. All this is under heavy development, so it may cease working at some point.
1) Git checkout (or download) jcward's hxcpp (integration branch), hxtelemetry, and hxScout:
https://github.com/jcward/hxScout/archive/master.zip
https://github.com/jcward/hxtelemetry/archive/master.zip
https://github.com/jcward/hxcpp/archive/integration.zip
@larsiusprime
larsiusprime / dqbugs.php
Last active August 29, 2015 14:18
A script for calculating the number of "points" in a Github Milestone (using numeric labels as "points" in issues). Written by Adam Perry (@hoursgoby) for Level Up Labs, LLC. milestones.json is an example of the php output, progress.js is an example of the front-end display code
<?php
define("CLIENT_ID", "REDACTED");
define("CLIENT_SECRET", "REDACTED");
define("GITHUB_URL", "ssl://api.github.com");
define("GITHUB_PATH", "/repos/YOUR-NAME-HERE/YOUR-REPO-HERE/");
define("ISSUESTATE_OPEN", "open");
define("OUTPUT_FILENAME", "/path/to/milestones.json");
$milestones = processIssues(loadIssues());
$fp = fopen(OUTPUT_FILENAME, "w+");
@loudoweb
loudoweb / FixTile.hx
Created November 3, 2015 15:56
Fix tile trick to avoid border artifacts between tiles. #haxe #openfl
package;
/**
* Avoid holes or border artifacts between tiles.
* Sometimes the scale by 1.01 trick doesn't work, a greater value should be used. This method finds the correct value for you.
* If you use openfl_legacy, pack your atlas using reduceBorderArtifact option in TexturePacker. There is no need to use this option on openfl_next.
* You should update the scale of your tiles if your resize the screen during the game to always have the best scale value.
* @author loudo
*/
class FixTile
{
@mrcdk
mrcdk / Macros.hx
Created March 31, 2016 00:33
@:enum abstract Something(Int) autoInt() macro
import haxe.macro.Context;
import haxe.macro.Expr;
class Macros {
macro public static function autoInt():Array<Field> {
var fields = Context.getBuildFields();
var t = switch(Context.getLocalClass().get().kind) {
case KAbstractImpl(c):