aboutsummaryrefslogtreecommitdiffstats
path: root/src/VideoList.hx
blob: e2d88d543a210132343e839c42588749526fb2f8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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;
	}

	public function itemsByUser(client:Client):Int {
		var i = 0;
		for (item in this) if (item.author == client.name) i++;
		return i;
	}

}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage