UNPKG

the-world-engine

Version:

three.js based, unity like game engine for browser

105 lines (103 loc) 2.03 kB
class LinkedListNode { value; next=null; prev=null; constructor(t) { this.value = t; } } class LinkedList { tt; et; it; constructor() { this.tt = null; this.et = null; this.it = 0; } get length() { return this.it; } add(t) { const e = new LinkedListNode(t); if (this.tt === null) { this.tt = e; this.et = e; } else { this.et.next = e; e.prev = this.et; this.et = e; } this.it += 1; } st(t) { if (t.prev !== null) { t.prev.next = t.next; } else { this.tt = t.next; } if (t.next !== null) { t.next.prev = t.prev; } else { this.et = t.prev; } this.it -= 1; } remove(t) { let e = this.tt; while (e !== null) { if (e.value === t) { this.st(e); return; } e = e.next; } } removeAll() { this.tt = null; this.et = null; this.it = 0; this.lt = true; } lt=false; forEach(t) { this.lt = false; let e = this.tt; while (e !== null) { t(e.value); if (this.lt) { if (this.tt === null) { return; } else { e = this.tt; this.lt = false; } } else { e = e.next; } } } } export class EventContainer { ht; constructor() { this.ht = new LinkedList; } addListener(t) { this.ht.add(t); } removeListener(t) { this.ht.remove(t); } removeAllListeners() { this.ht.removeAll(); } invoke(...t) { this.ht.forEach((e => { e(...t); })); } get length() { return this.ht.length; } }