Skip to content

Instantly share code, notes, and snippets.

View restorer's full-sized avatar

Viachaslau Tratsiak restorer

View GitHub Profile
@KeyMaster-
KeyMaster- / PlyImporter.hx
Last active August 29, 2015 14:08
Importer for PLY files from Blender into Luxe
package;
import luxe.Mesh;
import haxe.io.StringInput;
import luxe.options.MeshOptions;
import luxe.Vector;
import phoenix.Batcher;
import phoenix.geometry.Geometry;
import PlyParser;
import phoenix.geometry.Vertex;
/**
@boozook
boozook / Tools.hx
Last active August 29, 2015 14:18 — forked from nadako/Main.hx
Enum fast extract
class Tools {
public static macro function extract(value:haxe.macro.Expr.ExprOf<EnumValue>, pattern:haxe.macro.Expr) {
return switch (pattern) {
case macro $a => $b:
macro switch ($value) {
case $a:
$b;
default:
throw "no match";
}
@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) {
@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
{
@mattlundstrom
mattlundstrom / gist:3092911
Created July 11, 2012 20:00
AS3 Scale Around Point
function scaleAroundPoint(target:DisplayObject, point:Point, scaleFactor:Number):void
{
var m:Matrix = target.transform.matrix;
m.translate( -point.x, -point.y );
m.scale( scaleFactor, scaleFactor);
m.translate( point.x, point.y );
target.transform.matrix = m;
}
@francescoagati
francescoagati / Main.hx
Created June 14, 2016 00:06
haxe abstract and inline objects
class Getter<T> {
var name:String;
var obj:T;
public inline function new(name:String,obj:T) {
this.name = name;
this.obj = obj;
}
public inline function get() return untyped (obj:haxe.DynamicAccess<Dynamic>)[name];
@RealyUniqueName
RealyUniqueName / KeyValueIterator.hx
Last active October 14, 2016 10:35
Key-value map iterator
class KeyValueIterator<K,V> {
var map:Map<K,V>;
var keys:Iterator<K>;
static public inline function pairs<K,V>(map:Map<K,V>) return new KeyValueIterator(map);
public inline function new(map:Map<K,V>) {
this.map = map;
this.keys = map.keys();
}
@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):
/*
Implements different bin packer algorithms that use the MAXRECTS data structure.
See http://clb.demon.fi/projects/even-more-rectangle-bin-packing
Author: Jukka Jylänki
- Original
Author: Claus Wahlers
- Ported to ActionScript3
@patrickhammond
patrickhammond / EspressoTestRule.java
Last active September 2, 2018 12:14
Hacking through Espresso issues...
import android.app.Activity;
import android.app.Instrumentation;
import android.app.KeyguardManager;
import android.app.KeyguardManager.KeyguardLock;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.support.test.InstrumentationRegistry;