diff --git a/src/nitro/room/IRoomEngine.ts b/src/nitro/room/IRoomEngine.ts index 6cba4698..af24f853 100644 --- a/src/nitro/room/IRoomEngine.ts +++ b/src/nitro/room/IRoomEngine.ts @@ -86,7 +86,7 @@ export interface IRoomEngine extends INitroManager processRoomObjectOperation(objectId: number, category: number, operation: string): boolean; processRoomObjectPlacement(placementSource: string, id: number, category: number, typeId: number, legacyString?: string, stuffData?: IObjectData, state?: number, frameNumber?: number, posture?: string): boolean; dispatchMouseEvent(canvasId: number, x: number, y: number, type: string, altKey: boolean, ctrlKey: boolean, shiftKey: boolean, buttonDown: boolean): void; - createRoomScreenshot(roomId: number, canvasId: number): void; + createRoomScreenshot(roomId: number, canvasId?: number, bounds?: Rectangle): void; modifyRoomObjectData(objectId: number, objectCategory: number, colorHex: string, text: string): boolean; deleteRoomObject(objectId: number, objectCategory: number): boolean; sessionDataManager: ISessionDataManager; diff --git a/src/nitro/room/RoomEngine.ts b/src/nitro/room/RoomEngine.ts index 2911c764..ce8f1807 100644 --- a/src/nitro/room/RoomEngine.ts +++ b/src/nitro/room/RoomEngine.ts @@ -6,6 +6,7 @@ import { NitroManager } from '../../core/common/NitroManager'; import { IConnection } from '../../core/communication/connections/IConnection'; import { IMessageComposer } from '../../core/communication/messages/IMessageComposer'; import { NitroEvent } from '../../core/events/NitroEvent'; +import { TextureUtils } from '../../room'; import { RoomObjectEvent } from '../../room/events/RoomObjectEvent'; import { RoomObjectMouseEvent } from '../../room/events/RoomObjectMouseEvent'; import { IRoomInstance } from '../../room/IRoomInstance'; @@ -3437,17 +3438,32 @@ export class RoomEngine extends NitroManager implements IRoomEngine, IRoomCreato return null; } - public createRoomScreenshot(roomId: number, canvasId: number): void + public createRoomScreenshot(roomId: number, canvasId: number = -1, bounds: Rectangle = null): void { - const canvas = this.getRoomInstanceRenderingCanvas(roomId, canvasId); + let canvas: IRoomRenderingCanvas = null; - if(!canvas) return; + if(canvasId > -1) + { + canvas = this.getRoomInstanceRenderingCanvas(this._activeRoomId, canvasId); + } + else + { + canvas = this.getActiveRoomInstanceRenderingCanvas(); + } - const texture = canvas.getDisplayAsTexture(); + let texture: RenderTexture = null; - const base64 = Nitro.instance.renderer.extract.base64(texture); + if(bounds) + { + texture = TextureUtils.generateTexture(canvas.master, bounds); + } + else + { + texture = canvas.getDisplayAsTexture(); + } - const image = new Image(); + const base64 = TextureUtils.generateImageUrl(texture); + const image = new Image(); image.src = base64; diff --git a/src/room/utils/NitroRectangle.ts b/src/room/utils/NitroRectangle.ts new file mode 100644 index 00000000..9ced33b0 --- /dev/null +++ b/src/room/utils/NitroRectangle.ts @@ -0,0 +1,4 @@ +import { Rectangle } from 'pixi.js'; + +export class NitroRectangle extends Rectangle +{} diff --git a/src/room/utils/index.ts b/src/room/utils/index.ts index 6462d4d3..c4341a71 100644 --- a/src/room/utils/index.ts +++ b/src/room/utils/index.ts @@ -3,6 +3,7 @@ export * from './INitroPoint'; export * from './IRoomGeometry'; export * from './IVector3D'; export * from './NitroPoint'; +export * from './NitroRectangle'; export * from './NumberBank'; export * from './PointMath'; export * from './Rasterizer';