2013-09-08 10:24:41 +00:00
|
|
|
Phaser.LinkedList = function () {
|
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.LinkedList.prototype = {
|
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
next: null,
|
|
|
|
prev: null,
|
2013-09-08 10:24:41 +00:00
|
|
|
first: null,
|
|
|
|
last: null,
|
2013-09-08 21:38:19 +00:00
|
|
|
total: 0,
|
2013-09-08 10:24:41 +00:00
|
|
|
sprite: { name: 'HD' },
|
|
|
|
|
|
|
|
add: function (child) {
|
|
|
|
|
|
|
|
// If the list is empty
|
2013-09-08 21:38:19 +00:00
|
|
|
if (this.total == 0 && this.first == null && this.last == null)
|
2013-09-08 10:24:41 +00:00
|
|
|
{
|
|
|
|
this.first = child;
|
|
|
|
this.last = child;
|
2013-09-08 12:23:21 +00:00
|
|
|
this.next = child;
|
|
|
|
child.prev = this;
|
2013-09-08 21:38:19 +00:00
|
|
|
this.total++;
|
2013-09-08 10:24:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get gets appended to the end of the list, regardless of anything, and it won't have any children of its own (non-nested list)
|
2013-09-08 12:23:21 +00:00
|
|
|
this.last.next = child;
|
2013-09-08 10:24:41 +00:00
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
child.prev = this.last;
|
2013-09-08 10:24:41 +00:00
|
|
|
|
|
|
|
this.last = child;
|
|
|
|
|
2013-09-08 21:38:19 +00:00
|
|
|
this.total++;
|
|
|
|
|
|
|
|
return child;
|
|
|
|
|
2013-09-08 10:24:41 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
remove: function (child) {
|
|
|
|
|
|
|
|
// If the list is empty
|
|
|
|
if (this.first == null && this.last == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-08 21:38:19 +00:00
|
|
|
this.total--;
|
|
|
|
|
2013-09-08 10:24:41 +00:00
|
|
|
// The only node?
|
|
|
|
if (this.first == child && this.last == child)
|
|
|
|
{
|
|
|
|
this.first = null;
|
|
|
|
this.last = null;
|
2013-09-08 12:23:21 +00:00
|
|
|
this.next = null;
|
|
|
|
child.next = null;
|
|
|
|
child.prev = null;
|
2013-09-08 10:24:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
var childPrev = child.prev;
|
2013-09-08 10:24:41 +00:00
|
|
|
|
|
|
|
// Tail node?
|
2013-09-08 12:23:21 +00:00
|
|
|
if (child.next)
|
2013-09-08 10:24:41 +00:00
|
|
|
{
|
|
|
|
// Has another node after it?
|
2013-09-08 12:23:21 +00:00
|
|
|
child.next.prev = child.prev;
|
2013-09-08 10:24:41 +00:00
|
|
|
}
|
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
childPrev.next = child.next;
|
2013-09-08 10:24:41 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
dump: function () {
|
|
|
|
|
|
|
|
console.log("\nNode\t\t|\t\tNext\t\t|\t\tPrev\t\t|\t\tFirst\t\t|\t\tLast");
|
|
|
|
console.log("\t\t\t|\t\t\t\t\t|\t\t\t\t\t|\t\t\t\t\t|");
|
|
|
|
|
|
|
|
var nameNext = '-';
|
|
|
|
var namePrev = '-';
|
|
|
|
var nameFirst = '-';
|
|
|
|
var nameLast = '-';
|
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
if (this.next)
|
2013-09-08 10:24:41 +00:00
|
|
|
{
|
2013-09-08 12:23:21 +00:00
|
|
|
nameNext = this.next.sprite.name;
|
2013-09-08 10:24:41 +00:00
|
|
|
}
|
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
if (this.prev)
|
2013-09-08 10:24:41 +00:00
|
|
|
{
|
2013-09-08 12:23:21 +00:00
|
|
|
namePrev = this.prev.sprite.name;
|
2013-09-08 10:24:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.first)
|
|
|
|
{
|
|
|
|
nameFirst = this.first.sprite.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.last)
|
|
|
|
{
|
|
|
|
nameLast = this.last.sprite.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof nameNext === 'undefined')
|
|
|
|
{
|
|
|
|
nameNext = '-';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof namePrev === 'undefined')
|
|
|
|
{
|
|
|
|
namePrev = '-';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof nameFirst === 'undefined')
|
|
|
|
{
|
|
|
|
nameFirst = '-';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof nameLast === 'undefined')
|
|
|
|
{
|
|
|
|
nameLast = '-';
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('HD' + '\t\t\t|\t\t' + nameNext + '\t\t\t|\t\t' + namePrev + '\t\t\t|\t\t' + nameFirst + '\t\t\t|\t\t' + nameLast);
|
|
|
|
|
|
|
|
var entity = this;
|
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
var testObject = entity.last.next;
|
2013-09-08 10:24:41 +00:00
|
|
|
entity = entity.first;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
var name = entity.sprite.name || '*';
|
|
|
|
var nameNext = '-';
|
|
|
|
var namePrev = '-';
|
|
|
|
var nameFirst = '-';
|
|
|
|
var nameLast = '-';
|
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
if (entity.next)
|
2013-09-08 10:24:41 +00:00
|
|
|
{
|
2013-09-08 12:23:21 +00:00
|
|
|
nameNext = entity.next.sprite.name;
|
2013-09-08 10:24:41 +00:00
|
|
|
}
|
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
if (entity.prev)
|
2013-09-08 10:24:41 +00:00
|
|
|
{
|
2013-09-08 12:23:21 +00:00
|
|
|
namePrev = entity.prev.sprite.name;
|
2013-09-08 10:24:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (entity.first)
|
|
|
|
{
|
|
|
|
nameFirst = entity.first.sprite.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entity.last)
|
|
|
|
{
|
|
|
|
nameLast = entity.last.sprite.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof nameNext === 'undefined')
|
|
|
|
{
|
|
|
|
nameNext = '-';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof namePrev === 'undefined')
|
|
|
|
{
|
|
|
|
namePrev = '-';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof nameFirst === 'undefined')
|
|
|
|
{
|
|
|
|
nameFirst = '-';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof nameLast === 'undefined')
|
|
|
|
{
|
|
|
|
nameLast = '-';
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(name + '\t\t\t|\t\t' + nameNext + '\t\t\t|\t\t' + namePrev + '\t\t\t|\t\t' + nameFirst + '\t\t\t|\t\t' + nameLast);
|
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
entity = entity.next;
|
2013-09-08 10:24:41 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
while(entity != testObject)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|