Skip to content

Instantly share code, notes, and snippets.

View anissen's full-sized avatar

Anders Nissen anissen

View GitHub Profile
@AndreiRudenko
AndreiRudenko / SpriteAnimation.hx
Last active July 24, 2016 20:19
SpriteRenderer, VisualRenderer, and SpriteAnimation Components for Luxeengine
import luxe.Component;
import luxe.Rectangle;
import luxe.Vector;
// import luxe.Sprite;
import phoenix.Texture;
import luxe.Log.*;
@elsassph
elsassph / ResourceGenerator.hx
Created July 3, 2016 13:21
Haxe build macro converting a JSON file into strongly typed, inline/dce friendly, properties
package;
#if macro
import haxe.Json;
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.Type;
import sys.io.File;
import sys.FileSystem;
@josuigoa
josuigoa / Accelerometer.hx
Last active June 21, 2017 21:12
Getting accelerometer values with Luxe engine
package;
import luxe.Input;
typedef AccelEvent = {
timestamp:Float,
value:Float,
axis:Int
}
@francescoagati
francescoagati / Main.hx
Created June 14, 2016 19:09
haxe nested structInit
@:structInit
class A {
var x:Int;
var y:Int;
}
@:structInit
class B {
var a:A;
var k:Int;
import js.Browser.*;
import js.html.CanvasElement;
import js.html.CanvasRenderingContext2D;
import js.html.HTMLDocument;
import js.html.MouseEvent;
import sf.test.Test.Entity;
/**
* @author YellowAfterlife
* http://yal.cc/top-down-bouncing-loot-effects/
@haxiomic
haxiomic / ClassBuild.hx
Last active July 18, 2017 09:04
Recursive version of getSaveData macro for haxe group thread
import haxe.macro.ComplexTypeTools;
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.ExprTools;
import haxe.macro.Type.TInst;
import haxe.macro.TypeTools;
class ClassBuild{
//the entire contents of a class is contained in the class's fields
@EduardoLopes
EduardoLopes / main.hx
Created December 10, 2015 14:21
Luxe Pixel Perfect camera scale
override function onwindowsized( e:WindowEvent ):Void {
zoomRatio.x = Math.floor(Luxe.screen.w / gameResolution.x);
zoomRatio.y = Math.floor(Luxe.screen.h / gameResolution.y);
//get the smallest zoom ratio between zoomRatio.x and zoomRatio.y, and limit it to be greater or equal 1
zoom = Math.floor(Math.max(1, Math.min(zoomRatio.x, zoomRatio.y)));
var width = gameResolution.x * zoom;
var height = gameResolution.y * zoom;
@markknol
markknol / MacroJsonValidator.hx
Created December 4, 2015 13:23
Macro - validate a JSON compiletime
/**
* @author Mark Knol
*/
class MacroJsonValidator {
public static macro function validateJson(path:String) {
if (sys.FileSystem.exists(path)) {
var content = sys.io.File.getContent(path);
try {
// Test the json by parsing it.
// It will throw an error when you made a mistake.
@mrcdk
mrcdk / OneOf.hx
Last active July 9, 2020 03:20
OneOf abstract: An abstract that uses haxe.ds.Either as its base type and hides the explicit use of it. http://try.haxe.org/#c0557
import haxe.ds.Either;
abstract OneOf<A, B>(Either<A, B>) from Either<A, B> to Either<A, B> {
@:from inline static function fromA<A, B>(a:A) : OneOf<A, B> return Left(a);
@:from inline static function fromB<A, B>(b:B) : OneOf<A, B> return Right(b);
@:to inline function toA():Null<A> return switch(this) {case Left(a): a; default: null;}
@:to inline function toB():Null<B> return switch(this) {case Right(b): b; default: null;}
}
@anissen
anissen / Main.hx
Last active November 26, 2015 13:13 — forked from francescoagati/Main.hx
Import JSON in Haxe at compile time
#if macro
import haxe.macro.Context;
#end
class Main {
macro static function load_json(file :String) {
var data = sys.io.File.getContent(file);
var json = haxe.Json.parse(data);
return Context.makeExpr(json, Context.currentPos());