Skip to content

Instantly share code, notes, and snippets.

View josuigoa's full-sized avatar

Josu Igoa josuigoa

View GitHub Profile
@thejustinwalsh
thejustinwalsh / Hashlink AppCenter
Last active April 4, 2024 17:45
Build script for building a heaps based project on iOS
@haxiomic
haxiomic / Partial.hx
Last active February 26, 2023 11:44
Haxe macro to make all fields of a type optional (similar to Typescript's Partial<T>)
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.TypeTools;
#if !macro
@:genericBuild(PartialMacro.build())
#end
class Partial<T> {}
class PartialMacro {
@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;
import haxe.macro.Context;
import haxe.macro.Expr;
class FunctionArgMacro {
macro static function build():Array<Field> {
var fields = Context.getBuildFields();
for (field in fields) {
switch (field.kind) {
case FFun(fun):
var checks = [];
@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
@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;}
}
@hamaluik
hamaluik / !Profiler.hx
Last active April 6, 2020 23:11
Simple Haxe Profiler
package ;
import haxe.ds.StringMap;
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.Printer;
import haxe.macro.Type.ClassType;
import neko.Lib;
using haxe.macro.ExprTools;
@hamaluik
hamaluik / ThreadPool.hx
Last active December 19, 2023 09:59
Platform-agnostic thread pool for Haxe / OpenFL
package com.blazingmammothgames.util;
#if neko
import neko.vm.Thread;
import neko.vm.Mutex;
#elseif cpp
import cpp.vm.Thread;
import cpp.vm.Mutex;
#end
@KeyMaster-
KeyMaster- / IsoCamSetup
Created October 5, 2014 13:22
Isometric view in the luxe engine
//Rotate the camera such that z points up and x to the right
var o:Quaternion = new Quaternion().setFromEuler(new Vector().set_xyz(-90, 0, 0).radians());
//Rotate by Arctan(sin(45°)) (grabbed from wikipedia) around x, to get the top-down part
var q:Quaternion = new Quaternion().setFromEuler(new Vector().set_xyz(Math.atan(Math.sin(45 * Maths.DEG2RAD)), 0, 0));
//Rotate around z by -45° to get the side-on part
var p:Quaternion = new Quaternion().setFromEuler(new Vector().set_xyz(0, 0, -45).radians());
//Combine the rotations and apply to the camera