From 2dd85c2b26d803e04410606bbfb42af732d8b915 Mon Sep 17 00:00:00 2001 From: Niklas Kapelle Date: Sun, 20 Oct 2024 22:18:23 +0200 Subject: [PATCH] added Tags class for list of classes --- src/lib/Tags.hx | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/lib/Tags.hx diff --git a/src/lib/Tags.hx b/src/lib/Tags.hx new file mode 100644 index 0000000..d7e79c5 --- /dev/null +++ b/src/lib/Tags.hx @@ -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) from Array to Array { + inline public function new(arr:Array) { + 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) { + 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) { + 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; + } +}