Pony

Haxe open-cross-library
for all occasions

Manual

Installation

Signals

DeltaTime

Priority

Declarator

Reference book

Explore more feature

GitHub

View the Project on GitHub AxGord/Pony

Manual

Installation

Stable version

haxelib install pony

Unstable version

haxelib git pony https://github.com/AxGord/Pony

Signals

For develop perfect event-driven-system

Simple usage

var signal = new Signal();
signal.add(function() trace('tada'));
signal.dispatch();//=> tada

Send arguments

var signal = new Signal();
signal.add(function(n:Int, t:String) trace(n+t));
signal.dispatch(5, 'a');//=> 5a
signal.dispatch(7, 'b');//=> 7b

Send target

this.v = 1;
var signal = new Signal(this);
signal.add(function(n:Int, target) trace(n+target.v));
signal.dispatch(5);//=> 6
this.v = 2;
signal.dispatch(7);//=> 9

Build sub signals

var signal = new Signal();
signal.sub(5).add(function(t:String) trace('First sub: '+t));
signal.sub(7).add(function(t:String) trace('Second sub: '+t));
signal.dispatch(5, 'a');//=> First sub: a
signal.dispatch(7, 'b');//=> Second sub: b

Strict typed signals

Stop testing code on run time - start testing on compile time!

var signal:Signal2<Void, Int, String> = Signal.createEmpty();
signal.add(function(n:Int, t:String) trace(n+t));
signal.dispatch(5, 'a');//=> 5a
signal.dispatch(7, 'b');//=> 7b

And with target

var signal:Signal2<TargetClass, Int, String> = Signal.create(this);
signal.add(function(n:Int, target:TargetClass) trace(n+target.v));
signal.dispatch(5);//=> 6
this.v = 2;
signal.dispatch(7);//=> 9

DeltaTime

For develop interactive or realtime systems

Detect FPS example

var dts:Float = 0;
var frames:Int = 0;
DeltaTime.update.add(function(dt:Float) {
	frames++;
	dts += dt;
	if (dts >= 1) {
		dts--;
		show(clips);
		clips = 0;
	}
});

Activate for Unity3d

Just connect pony.unity3d.DeltaTimeHelper to any GameObject

Priority

Class for create priority lists

var priority = new Priority<String>();
priority.add('Keyword', 0);
priority.add('Multyset', 8);
priority.add('Music Box', 3);
priority.add('Double inside', 8);
trace(priority);//=>['Keyword', 'Multyset', 'Double inside', 'Music Box']

Declarator

Use this for set args without constructor and replays set class var to new or __init__ functions.

Static example

class DeclaratorStaticExample implements Declarator {
static public var a:String = 'hello';
static public var b:String;
static public function __init__():Void b = a;//b = 'hello'
}

Constructor example

class DeclaratorExample implements Declarator {
@:arg private var i:Int;
@:arg private var j:Int = 3;
public function sum():Int return i + j;
}
new DeclaratorExample(2).sum();//=> 5
new DeclaratorExample(2,7).sum();//=> 9