Update screenshot code

This commit is contained in:
Bill 2021-06-14 11:12:22 -04:00
parent 67c9c58570
commit 2b1e75b06f
4 changed files with 28 additions and 7 deletions

View File

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

View File

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

View File

@ -0,0 +1,4 @@
import { Rectangle } from 'pixi.js';
export class NitroRectangle extends Rectangle
{}

View File

@ -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';