aboutsummaryrefslogtreecommitdiffstats
path: root/src/VideoList.hx
diff options
context:
space:
mode:
Diffstat (limited to 'src/VideoList.hx')
-rw-r--r--src/VideoList.hx67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/VideoList.hx b/src/VideoList.hx
new file mode 100644
index 0000000..2f13b6c
--- /dev/null
+++ b/src/VideoList.hx
@@ -0,0 +1,67 @@
+package;
+
+import Types.VideoItem;
+
+// TODO move itemPos to abstract
+// typedef VideoListData = {
+// items:Array<VideoItem>,
+// itemPos:Int
+// }
+
+@:forward
+abstract VideoList(Array<VideoItem>) from Array<VideoItem> to Array<VideoItem> {
+
+ public function new() {
+ this = [];
+ }
+
+ @:arrayAccess
+ public inline function get(i:Int):VideoItem {
+ return this[i];
+ }
+
+ @:arrayAccess
+ public inline function set(k:Int, v:VideoItem):VideoItem {
+ return this[k] = v;
+ }
+
+ public function findIndex(f:(item:VideoItem) -> Bool):Int {
+ var i = 0;
+ for (v in this) {
+ if (f(v)) return i;
+ i++;
+ }
+ return -1;
+ }
+
+ public function addItem(item:VideoItem, atEnd:Bool, itemPos:Int):Void {
+ if (atEnd) this.push(item);
+ else this.insert(itemPos + 1, item);
+ }
+
+ public function setNextItem(pos:Int, itemPos:Int):Void {
+ final next = this[pos];
+ this.remove(next);
+ this.insert(itemPos + 1, next);
+ }
+
+ public function toggleItemType(pos:Int):Void {
+ this[pos].isTemp = !this[pos].isTemp;
+ }
+
+ public function removeItem(index:Int, itemPos:Int):Int {
+ if (index < itemPos) itemPos--;
+ this.remove(this[index]);
+ if (itemPos >= this.length) itemPos = 0;
+ return itemPos;
+ }
+
+ public function skipItem(itemPos:Int):Int {
+ final item = this[itemPos];
+ if (!item.isTemp) itemPos++;
+ else this.remove(item);
+ if (itemPos >= this.length) itemPos = 0;
+ return itemPos;
+ }
+
+}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage