Add getAllObjects() query for the object store
This commit is contained in:
1
dist/classes/ObjectStoreLite.d.ts
vendored
1
dist/classes/ObjectStoreLite.d.ts
vendored
@@ -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;
|
||||
|
||||
27
dist/classes/ObjectStoreLite.js
vendored
27
dist/classes/ObjectStoreLite.js
vendored
@@ -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;
|
||||
}
|
||||
|
||||
2
dist/classes/ObjectStoreLite.js.map
vendored
2
dist/classes/ObjectStoreLite.js.map
vendored
File diff suppressed because one or more lines are too long
1
dist/classes/commands/RegionCommands.d.ts
vendored
1
dist/classes/commands/RegionCommands.d.ts
vendored
@@ -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>;
|
||||
|
||||
10
dist/classes/commands/RegionCommands.js
vendored
10
dist/classes/commands/RegionCommands.js
vendored
@@ -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;
|
||||
|
||||
2
dist/classes/commands/RegionCommands.js.map
vendored
2
dist/classes/commands/RegionCommands.js.map
vendored
File diff suppressed because one or more lines are too long
1
dist/classes/interfaces/IObjectStore.d.ts
vendored
1
dist/classes/interfaces/IObjectStore.d.ts
vendored
@@ -9,4 +9,5 @@ export interface IObjectStore {
|
||||
getObjectByUUID(fullID: UUID): GameObject;
|
||||
getObjectByLocalID(ID: number): GameObject;
|
||||
getNumberOfObjects(): number;
|
||||
getAllObjects(): GameObject[];
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -11,4 +11,5 @@ export interface IObjectStore
|
||||
getObjectByUUID(fullID: UUID): GameObject;
|
||||
getObjectByLocalID(ID: number): GameObject;
|
||||
getNumberOfObjects(): number;
|
||||
getAllObjects(): GameObject[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user