Add getAllObjects() query for the object store

This commit is contained in:
Casper Warden
2018-10-19 16:39:24 +01:00
parent 2852c76cb0
commit 2efd01dca5
10 changed files with 95 additions and 5 deletions

View File

@@ -515,7 +515,49 @@ export class ObjectStoreLite implements IObjectStore
}
}
getNumberOfObjects()
getAllObjects(): GameObject[]
{
const results = [];
const found: {[key: string]: GameObject} = {};
for (const k of Object.keys(this.objects))
{
const go = this.objects[parseInt(k, 10)];
if (go.PCode !== PCode.Avatar && (go.IsAttachment === undefined || go.IsAttachment === false))
{
try
{
const parent = this.findParent(go);
if (parent.PCode !== PCode.Avatar && (parent.IsAttachment === undefined || parent.IsAttachment === false))
{
const uuid = parent.FullID.toString();
if (found[uuid] === undefined)
{
found[uuid] = parent;
results.push(parent);
}
}
}
catch (error)
{
console.log('Failed to find parent for ' + go.FullID.toString());
console.error(error);
// Unable to find parent, full object probably not fully loaded yet
}
}
}
// Now populate children of each found object
for (const obj of results)
{
this.populateChildren(obj);
}
return results;
}
getNumberOfObjects(): number
{
return Object.keys(this.objects).length;
}