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

@@ -45,6 +45,7 @@ export declare class ObjectStoreLite implements IObjectStore {
shutdown(): void;
protected findParent(go: GameObject): GameObject;
private populateChildren;
getAllObjects(): GameObject[];
getNumberOfObjects(): number;
getObjectsInArea(minX: number, maxX: number, minY: number, maxY: number, minZ: number, maxZ: number): GameObject[];
getObjectByUUID(fullID: UUID | string): GameObject;

View File

@@ -365,6 +365,33 @@ class ObjectStoreLite {
obj.children.push(child);
}
}
getAllObjects() {
const results = [];
const found = {};
for (const k of Object.keys(this.objects)) {
const go = this.objects[parseInt(k, 10)];
if (go.PCode !== PCode_1.PCode.Avatar && (go.IsAttachment === undefined || go.IsAttachment === false)) {
try {
const parent = this.findParent(go);
if (parent.PCode !== PCode_1.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);
}
}
}
for (const obj of results) {
this.populateChildren(obj);
}
return results;
}
getNumberOfObjects() {
return Object.keys(this.objects).length;
}

File diff suppressed because one or more lines are too long

View File

@@ -10,6 +10,7 @@ export declare class RegionCommands extends CommandsBase {
countObjects(): number;
selectObjects(objects: GameObject[]): Promise<ObjectPropertiesMessage | undefined>;
private resolveObjects;
getAllObjects(resolve?: boolean): Promise<GameObject[]>;
getObjectsInArea(minX: number, maxX: number, minY: number, maxY: number, minZ: number, maxZ: number, resolve?: boolean): Promise<GameObject[]>;
grabObject(localID: number | UUID, grabOffset?: Vector3, uvCoordinate?: Vector3, stCoordinate?: Vector3, faceIndex?: number, position?: Vector3, normal?: Vector3, binormal?: Vector3): Promise<void>;
deGrabObject(localID: number | UUID, grabOffset?: Vector3, uvCoordinate?: Vector3, stCoordinate?: Vector3, faceIndex?: number, position?: Vector3, normal?: Vector3, binormal?: Vector3): Promise<void>;

View File

@@ -242,11 +242,19 @@ class RegionCommands extends CommandsBase_1.CommandsBase {
}
});
}
getAllObjects(resolve = false) {
return __awaiter(this, void 0, void 0, function* () {
const objs = this.currentRegion.objects.getAllObjects();
if (resolve) {
yield this.resolveObjects(objs);
}
return objs;
});
}
getObjectsInArea(minX, maxX, minY, maxY, minZ, maxZ, resolve = false) {
return __awaiter(this, void 0, void 0, function* () {
const objs = this.currentRegion.objects.getObjectsInArea(minX, maxX, minY, maxY, minZ, maxZ);
if (resolve) {
console.log('Resolving ' + objs.length + ' objects');
yield this.resolveObjects(objs);
}
return objs;

File diff suppressed because one or more lines are too long

View File

@@ -9,4 +9,5 @@ export interface IObjectStore {
getObjectByUUID(fullID: UUID): GameObject;
getObjectByLocalID(ID: number): GameObject;
getNumberOfObjects(): number;
getAllObjects(): GameObject[];
}

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;
}

View File

@@ -302,12 +302,21 @@ export class RegionCommands extends CommandsBase
}
}
async getAllObjects(resolve: boolean = false): Promise<GameObject[]>
{
const objs = this.currentRegion.objects.getAllObjects();
if (resolve)
{
await this.resolveObjects(objs);
}
return objs;
}
async getObjectsInArea(minX: number, maxX: number, minY: number, maxY: number, minZ: number, maxZ: number, resolve: boolean = false): Promise<GameObject[]>
{
const objs = this.currentRegion.objects.getObjectsInArea(minX, maxX, minY, maxY, minZ, maxZ);
if (resolve)
{
console.log('Resolving ' + objs.length + ' objects');
await this.resolveObjects(objs);
}
return objs;

View File

@@ -11,4 +11,5 @@ export interface IObjectStore
getObjectByUUID(fullID: UUID): GameObject;
getObjectByLocalID(ID: number): GameObject;
getNumberOfObjects(): number;
getAllObjects(): GameObject[];
}