moved gettingSnapshot logic into TexturesHelper
This commit is contained in:
parent
8eaacdf2e5
commit
bbe539b785
3 changed files with 49 additions and 43 deletions
|
@ -11,6 +11,7 @@ import { DEPTH_INGAME_TEXT_INDEX } from "../Game/DepthIndexes";
|
|||
import type OutlinePipelinePlugin from "phaser3-rex-plugins/plugins/outlinepipeline-plugin.js";
|
||||
import { isSilentStore } from "../../Stores/MediaStore";
|
||||
import { lazyLoadPlayerCharacterTextures, loadAllDefaultModels } from "./PlayerTexturesLoadingManager";
|
||||
import { TexturesHelper } from "../Helpers/TexturesHelper";
|
||||
|
||||
const playerNameY = -25;
|
||||
|
||||
|
@ -118,33 +119,18 @@ export abstract class Character extends Container {
|
|||
}
|
||||
|
||||
public async getSnapshot(): Promise<string> {
|
||||
const rt = this.scene.make.renderTexture({}, false);
|
||||
if (rt.renderer instanceof Phaser.Renderer.Canvas.CanvasRenderer) {
|
||||
rt.destroy();
|
||||
const sprites = Array.from(this.sprites.values()).map((sprite) => {
|
||||
return { sprite, frame: 1 };
|
||||
});
|
||||
return TexturesHelper.getSnapshot(this.scene, ...sprites).catch((reason) => {
|
||||
console.warn(reason);
|
||||
for (const sprite of this.sprites.values()) {
|
||||
// we can be sure that either predefined woka or body texture is at this point loaded
|
||||
if (sprite.texture.key.includes("color") || sprite.texture.key.includes("male")) {
|
||||
return this.scene.textures.getBase64(sprite.texture.key);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const sprite of this.sprites.values()) {
|
||||
sprite.setFrame(1);
|
||||
rt.draw(sprite, sprite.displayWidth * 0.5, sprite.displayHeight * 0.5);
|
||||
}
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
try {
|
||||
rt.snapshot(
|
||||
(url) => {
|
||||
resolve((url as HTMLImageElement).src);
|
||||
rt.destroy();
|
||||
},
|
||||
"image/png",
|
||||
1
|
||||
);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
return "male1";
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue