Merge JigsawX

This commit is contained in:
2022-06-26 19:53:26 +00:00
parent d739f2a6cf
commit 41af3009bb
48 changed files with 8654 additions and 0 deletions

View File

@@ -0,0 +1,296 @@
package zpartanlite;
class DispatchTo
{
// don't use an array unless there are lots of signals.
// have to return dynamic because sometimes need to allow a return type not void
private var func0: Void -> Void ;
private var times0: Int;
private var func: Array<Void -> Void> ;
private var times: Array<Int> ;
public var length( get_length, null ): Int ;
// Allows events like mouse down to be added removed.
public var tellEnabled: Void -> Void;
public var tellDisabled: Void -> Void;
public var kill: Void -> Void;
public function enableKill()
{
kill = killAll;
}
public function disableKill()
{
kill = function()
{
trace("Can't kill other listeners unless enableKill");
}
}
private function get_length(): Int
{
if( func == null )
if( func0 != null )
{
return 1;
}
else
{
return null;
}
return func.length;
}
public function new()
{
// by default...
disableKill();
}
public function add( f_: Void -> Void, ?once: Bool, ?amount: Int )
{
// Store first...
if( length == null )
{
func0 = f_;
if( tellEnabled != null )
{
tellEnabled();
}
if( once != null )
{
if( once == true )
{
times0 = 1;
}
else
{
times0 = -1;
}
}
else if( amount != null )
{
times0 = amount;
}
else
{
times0 = -1;
}
return;
}
else if( func == null )
{
func = new Array() ;
times = new Array() ;
func.push( func0 );
times.push( times0 );
func0 = null;
times0 = null;
}
// Store second...
func.push( f_ ) ;
if( once != null )
{
if( once == true )
{
times.push( 1 ) ;
}
else
{
times.push( -1 ) ;
}
}
else if( amount != null )
{
times.push( amount ) ;
}
else
{
times.push( -1 ) ;
}
}
public function swap( current_: Void -> Void, new_: Void -> Void )
{
remove( current_ );
add( new_ );
}
public function remove( f_: Void -> Void )
{
if( length == null ) return;
if( length == 1 )
{
if( Reflect.compareMethods( f_, func0 ) )
{
func0 = null;
times0 = null;
if( tellDisabled != null )
{
tellDisabled();
}
}
return;
}
for( i in 0...func.length )
{
if( Reflect.compareMethods( func[ i ], f_ ) )
{
func.splice( i, 1 ) ;
times.splice( i, 1 ) ;
}
}
if( length == 1 )
{
func0 = func[0];
times0 = times[0];
func = null;
times0 = null;
}
}
// This is private by default and accessed by kill if enableKill
// seems over the top but should not be able to remove all listeners by default
// only in special cases.
private function killAll()
{
if( length == 1 )
{
func0 = null;
times0 = null;
return;
}
for( i in 0...func.length )
{
func.splice( i, 1 ) ;
times.splice( i, 1 ) ;
}
func = new Array() ;
times = new Array() ;
}
public function dispatch()
{
if( length == null ) return;
var count: Int ;
if( length == 1 )
{
func0();
if( times0 == -1 )
{
// don't remove if -1 as implies infinite Signal use until removed.
}
else
{
times0--;
if( times0 == 0 )
{
remove( func0 );
}
}
return;
}
for( i in 0...func.length )
{
func[ i ]() ;
count = times[ i ] ;
if( count == -1 )
{
// don't remove if -1 as implies infinite Signal use until removed.
}
else
{
count--;
times[ i ] = count ;
if( count == 0 )
{
remove( func[ i ] );
//func.splice( i, 1 ) ;
//times.splice( i, 1 ) ;
}
}
}
}
}

View File

@@ -0,0 +1,24 @@
package zpartanlite;
enum Compass
{
North;
South;
East;
West;
}
enum Orientation
{
Horizontal;
Vertical;
}
enum Travel
{
Forward;
Back;
}
class Enumerables{}

View File

@@ -0,0 +1,305 @@
package zpartanlite;
import zpartanlite.Enumerables;
class Pages<T>
{
private var index: Int ;
private var lastIndex: Int ;
private var len: Int ;
private var order: Array<T> ;
private var history: Array<Int> ;
public var circle: Bool ;
public var last: T ;
public var curr: T ;
public var pageChange: DispatchTo ;
public var hideNext: DispatchTo ;
public var hidePrev: DispatchTo ;
public var dir: Travel;
public var looped: DispatchTo ;
public function new( ?arr_: Array<T>, ?circle_: Bool = false )
{
circle = circle_ ;
pageChange = new DispatchTo() ;
hideNext = new DispatchTo() ;
hidePrev = new DispatchTo() ;
looped = new DispatchTo() ;
reset( arr_ ) ;
}
public function reset( ?arr_: Array<T> ) : Void
{
if( arr_ == null )
{
order = new Array() ;
}
else
{
order = arr_ ;
}
index = 0;
len = order.length;
history = new Array() ;
}
public function next() : T
{
lastIndex = index ;
last = order[ index ];
dir = Forward;
index++ ;
if( index == len )
{
if( circle )
{
index = 0 ;
looped.dispatch();
}
else
{
index = len - 1 ;
}
}
curr = order[ index ] ;
if( lastIndex != index )
{
history.push( index ) ;
if( !circle )
{
if( !hasNext() )
{
hideNext.dispatch();
}
}
pageChange.dispatch();
}
return curr;
}
public function previous(): T
{
lastIndex = index ;
last = order[ index ];
dir = Back;
index-- ;
if( index == -1 )
{
if( circle )
{
index = len - 1 ;
}
else
{
index = 0 ;
}
}
curr = order[ index ];
if( lastIndex != index )
{
history.push( index ) ;
if( !circle )
{
if( !hasPrevious() )
{
hidePrev.dispatch();
}
}
pageChange.dispatch();
}
return curr;
}
public function getCurrent(): T
{
return order[ index ] ;
}
public function hasPrevious(): Bool
{
if( circle )
{
return true ;
}
if( index == 0 )
{
return false ;
}
return true ;
}
public function hasNext() : Bool
{
if( circle )
{
return true ;
}
if( index == len )
{
return false ;
}
return true ;
}
public function goto( index_: Int ): T
{
lastIndex = index ;
last = order[ index ] ;
index = index_ ;
curr = order[ index ];
if( lastIndex != index )
{
history.push( index ) ;
if( !circle )
{
if( !hasNext() )
{
hideNext.dispatch();
}
if( !hasPrevious() )
{
hidePrev.dispatch();
}
}
pageChange.dispatch();
}
return curr;
}
public function back(): T
{
lastIndex = index ;
last = order[ index ] ;
index = history.pop() ;
if( lastIndex != index )
{
if( !circle )
{
if( !hasNext() )
{
hideNext.dispatch() ;
}
if( !hasPrevious() )
{
hidePrev.dispatch() ;
}
}
pageChange.dispatch() ;
}
curr = order[ index ] ;
return curr;
}
public function isLast():Bool
{
if( index == len - 1 ) return true;
return false;
}
public function getIndex(): Int
{
return index ;
}
public function getLastIndex(): Int
{
return lastIndex;
}
}