added Tags class for list of classes
This commit is contained in:
parent
1d60e13792
commit
2dd85c2b26
49
src/lib/Tags.hx
Normal file
49
src/lib/Tags.hx
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package lib;
|
||||||
|
|
||||||
|
import lib.PaN;
|
||||||
|
|
||||||
|
using Lambda;
|
||||||
|
using lua.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Represents a list a minecraft tags.
|
||||||
|
|
||||||
|
Needed because tags are SOMETIMES retuned not as arrays.
|
||||||
|
**/
|
||||||
|
@:forward
|
||||||
|
enum abstract Tags(Array<PaN>) from Array<PaN> to Array<PaN> {
|
||||||
|
inline public function new(arr:Array<String>) {
|
||||||
|
this = arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
From values that are object with the tag as the filed and the value set to true.
|
||||||
|
**/
|
||||||
|
@:from
|
||||||
|
public static function fromBoolTable(from:Table<String, Bool>) {
|
||||||
|
var rtn = [];
|
||||||
|
for (k => _ in Table.toMap(from)) {
|
||||||
|
rtn.push(k);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Tags(rtn);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
From values that are lua arrays.
|
||||||
|
**/
|
||||||
|
@:from
|
||||||
|
public static function fromIntTable(from:Table<Int, String>) {
|
||||||
|
return new Tags(from.toArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sortByName():Tags {
|
||||||
|
var copy = this.copy();
|
||||||
|
|
||||||
|
copy.sort((a:String, b:String) -> {
|
||||||
|
return if (a < b) -1 else 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user