saving players avatar textures to the texturesManager
This commit is contained in:
parent
923a134270
commit
b3d4230354
@ -64,6 +64,7 @@ export abstract class Character extends Container {
|
|||||||
this.addTextures(textures, frame);
|
this.addTextures(textures, frame);
|
||||||
this.invisible = false;
|
this.invisible = false;
|
||||||
this.playAnimation(direction, moving);
|
this.playAnimation(direction, moving);
|
||||||
|
this.emit('textures-loaded');
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
return lazyLoadPlayerCharacterTextures(scene.load, ["color_22", "eyes_23"]).then((textures) => {
|
return lazyLoadPlayerCharacterTextures(scene.load, ["color_22", "eyes_23"]).then((textures) => {
|
||||||
@ -117,8 +118,15 @@ export abstract class Character extends Container {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private getOutlinePlugin(): OutlinePipelinePlugin | undefined {
|
public saveCharacterToTexture(saveAs: string): void {
|
||||||
return this.scene.plugins.get("rexOutlinePipeline") as unknown as OutlinePipelinePlugin | undefined;
|
const bounds = this.getBounds();
|
||||||
|
const rt = this.scene.make.renderTexture({ x: 300, y: 300, width: bounds.width, height: bounds.height}, true);
|
||||||
|
for (const sprite of this.sprites.values()) {
|
||||||
|
rt.draw(sprite, sprite.displayWidth * 0.5, sprite.displayHeight * 0.5);
|
||||||
|
}
|
||||||
|
// P.H. NOTE: Change of avatar will update saved texture. We can then send it again to the backend
|
||||||
|
rt.saveTexture(saveAs);
|
||||||
|
rt.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public addCompanion(name: string, texturePromise?: Promise<string>): void {
|
public addCompanion(name: string, texturePromise?: Promise<string>): void {
|
||||||
@ -154,6 +162,10 @@ export abstract class Character extends Container {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getOutlinePlugin(): OutlinePipelinePlugin | undefined {
|
||||||
|
return this.scene.plugins.get("rexOutlinePipeline") as unknown as OutlinePipelinePlugin | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
private getPlayerAnimations(name: string): AnimationData[] {
|
private getPlayerAnimations(name: string): AnimationData[] {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
import type { Subscription } from "rxjs";
|
import type { Subscription } from "rxjs";
|
||||||
import { userMessageManager } from "../../Administration/UserMessageManager";
|
|
||||||
import { iframeListener } from "../../Api/IframeListener";
|
|
||||||
import { connectionManager } from "../../Connexion/ConnectionManager";
|
|
||||||
import type {
|
import type {
|
||||||
GroupCreatedUpdatedMessageInterface,
|
GroupCreatedUpdatedMessageInterface,
|
||||||
MessageUserJoined,
|
MessageUserJoined,
|
||||||
@ -12,14 +9,23 @@ import type {
|
|||||||
PositionInterface,
|
PositionInterface,
|
||||||
RoomJoinedMessageInterface,
|
RoomJoinedMessageInterface,
|
||||||
} from "../../Connexion/ConnexionModels";
|
} from "../../Connexion/ConnexionModels";
|
||||||
import { DEBUG_MODE, JITSI_PRIVATE_MODE, MAX_PER_GROUP, POSITION_DELAY } from "../../Enum/EnvironmentVariable";
|
import type { UserMovedMessage } from "../../Messages/generated/messages_pb";
|
||||||
|
import type { RoomConnection } from "../../Connexion/RoomConnection";
|
||||||
|
import type { ActionableItem } from "../Items/ActionableItem";
|
||||||
|
import type { ItemFactoryInterface } from "../Items/ItemFactoryInterface";
|
||||||
|
import type { ITiledMap, ITiledMapLayer, ITiledMapProperty, ITiledMapObject, ITiledTileSet } from "../Map/ITiledMap";
|
||||||
|
import type { AddPlayerInterface } from "./AddPlayerInterface";
|
||||||
|
import type { HasPlayerMovedEvent } from "../../Api/Events/HasPlayerMovedEvent";
|
||||||
|
import type { Character } from '../Entity/Character';
|
||||||
|
|
||||||
|
import { userMessageManager } from "../../Administration/UserMessageManager";
|
||||||
|
import { iframeListener } from "../../Api/IframeListener";
|
||||||
|
import { connectionManager } from "../../Connexion/ConnectionManager";
|
||||||
|
import { DEBUG_MODE, JITSI_PRIVATE_MODE, MAX_PER_GROUP, POSITION_DELAY } from "../../Enum/EnvironmentVariable";
|
||||||
import { Queue } from "queue-typescript";
|
import { Queue } from "queue-typescript";
|
||||||
import { Box, ON_ACTION_TRIGGER_BUTTON } from "../../WebRtc/LayoutManager";
|
import { Box, ON_ACTION_TRIGGER_BUTTON } from "../../WebRtc/LayoutManager";
|
||||||
import { CoWebsite, coWebsiteManager } from "../../WebRtc/CoWebsiteManager";
|
import { CoWebsite, coWebsiteManager } from "../../WebRtc/CoWebsiteManager";
|
||||||
import type { UserMovedMessage } from "../../Messages/generated/messages_pb";
|
|
||||||
import { ProtobufClientUtils } from "../../Network/ProtobufClientUtils";
|
import { ProtobufClientUtils } from "../../Network/ProtobufClientUtils";
|
||||||
import type { RoomConnection } from "../../Connexion/RoomConnection";
|
|
||||||
import { Room } from "../../Connexion/Room";
|
import { Room } from "../../Connexion/Room";
|
||||||
import { jitsiFactory } from "../../WebRtc/JitsiFactory";
|
import { jitsiFactory } from "../../WebRtc/JitsiFactory";
|
||||||
import { urlManager } from "../../Url/UrlManager";
|
import { urlManager } from "../../Url/UrlManager";
|
||||||
@ -31,16 +37,12 @@ import { SimplePeer } from "../../WebRtc/SimplePeer";
|
|||||||
import { Loader } from "../Components/Loader";
|
import { Loader } from "../Components/Loader";
|
||||||
import { lazyLoadPlayerCharacterTextures, loadCustomTexture } from "../Entity/PlayerTexturesLoadingManager";
|
import { lazyLoadPlayerCharacterTextures, loadCustomTexture } from "../Entity/PlayerTexturesLoadingManager";
|
||||||
import { RemotePlayer } from "../Entity/RemotePlayer";
|
import { RemotePlayer } from "../Entity/RemotePlayer";
|
||||||
import type { ActionableItem } from "../Items/ActionableItem";
|
|
||||||
import type { ItemFactoryInterface } from "../Items/ItemFactoryInterface";
|
|
||||||
import { SelectCharacterScene, SelectCharacterSceneName } from "../Login/SelectCharacterScene";
|
import { SelectCharacterScene, SelectCharacterSceneName } from "../Login/SelectCharacterScene";
|
||||||
import type { ITiledMap, ITiledMapLayer, ITiledMapProperty, ITiledMapObject, ITiledTileSet } from "../Map/ITiledMap";
|
|
||||||
import { PlayerAnimationDirections } from "../Player/Animation";
|
import { PlayerAnimationDirections } from "../Player/Animation";
|
||||||
import { hasMovedEventName, Player, requestEmoteEventName } from "../Player/Player";
|
import { hasMovedEventName, Player, requestEmoteEventName } from "../Player/Player";
|
||||||
import { ErrorSceneName } from "../Reconnecting/ErrorScene";
|
import { ErrorSceneName } from "../Reconnecting/ErrorScene";
|
||||||
import { ReconnectingSceneName } from "../Reconnecting/ReconnectingScene";
|
import { ReconnectingSceneName } from "../Reconnecting/ReconnectingScene";
|
||||||
import { UserInputManager } from "../UserInput/UserInputManager";
|
import { UserInputManager } from "../UserInput/UserInputManager";
|
||||||
import type { AddPlayerInterface } from "./AddPlayerInterface";
|
|
||||||
import { gameManager } from "./GameManager";
|
import { gameManager } from "./GameManager";
|
||||||
import { GameMap } from "./GameMap";
|
import { GameMap } from "./GameMap";
|
||||||
import { PlayerMovement } from "./PlayerMovement";
|
import { PlayerMovement } from "./PlayerMovement";
|
||||||
@ -61,7 +63,6 @@ import { joystickBaseImg, joystickBaseKey, joystickThumbImg, joystickThumbKey }
|
|||||||
import { waScaleManager } from "../Services/WaScaleManager";
|
import { waScaleManager } from "../Services/WaScaleManager";
|
||||||
import { EmoteManager } from "./EmoteManager";
|
import { EmoteManager } from "./EmoteManager";
|
||||||
import EVENT_TYPE = Phaser.Scenes.Events;
|
import EVENT_TYPE = Phaser.Scenes.Events;
|
||||||
import type { HasPlayerMovedEvent } from "../../Api/Events/HasPlayerMovedEvent";
|
|
||||||
|
|
||||||
import AnimatedTiles from "phaser-animated-tiles";
|
import AnimatedTiles from "phaser-animated-tiles";
|
||||||
import { StartPositionCalculator } from "./StartPositionCalculator";
|
import { StartPositionCalculator } from "./StartPositionCalculator";
|
||||||
@ -89,7 +90,6 @@ import { get } from "svelte/store";
|
|||||||
import { contactPageStore } from "../../Stores/MenuStore";
|
import { contactPageStore } from "../../Stores/MenuStore";
|
||||||
import { GameMapProperties } from "./GameMapProperties";
|
import { GameMapProperties } from "./GameMapProperties";
|
||||||
import SpriteSheetFile = Phaser.Loader.FileTypes.SpriteSheetFile;
|
import SpriteSheetFile = Phaser.Loader.FileTypes.SpriteSheetFile;
|
||||||
|
|
||||||
export interface GameSceneInitInterface {
|
export interface GameSceneInitInterface {
|
||||||
initPosition: PointInterface | null;
|
initPosition: PointInterface | null;
|
||||||
reconnecting: boolean;
|
reconnecting: boolean;
|
||||||
@ -1498,6 +1498,9 @@ ${escapedMessage}
|
|||||||
this.companion,
|
this.companion,
|
||||||
this.companion !== null ? lazyLoadCompanionResource(this.load, this.companion) : undefined
|
this.companion !== null ? lazyLoadCompanionResource(this.load, this.companion) : undefined
|
||||||
);
|
);
|
||||||
|
this.CurrentPlayer.once('textures-loaded', () => {
|
||||||
|
this.savePlayerAvatarPicture(this.CurrentPlayer, 'hero-avatar');
|
||||||
|
});
|
||||||
this.CurrentPlayer.on("pointerdown", (pointer: Phaser.Input.Pointer) => {
|
this.CurrentPlayer.on("pointerdown", (pointer: Phaser.Input.Pointer) => {
|
||||||
if (pointer.wasTouch && (pointer.event as TouchEvent).touches.length > 1) {
|
if (pointer.wasTouch && (pointer.event as TouchEvent).touches.length > 1) {
|
||||||
return; //we don't want the menu to open when pinching on a touch screen.
|
return; //we don't want the menu to open when pinching on a touch screen.
|
||||||
@ -1525,6 +1528,12 @@ ${escapedMessage}
|
|||||||
this.createCollisionWithPlayer();
|
this.createCollisionWithPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private savePlayerAvatarPicture(character: Character, key: string): void {
|
||||||
|
character.saveCharacterToTexture(key);
|
||||||
|
console.log(key);
|
||||||
|
this.add.image(200, 200, key);
|
||||||
|
}
|
||||||
|
|
||||||
pushPlayerPosition(event: HasPlayerMovedEvent) {
|
pushPlayerPosition(event: HasPlayerMovedEvent) {
|
||||||
if (this.lastMoveEventSent === event) {
|
if (this.lastMoveEventSent === event) {
|
||||||
return;
|
return;
|
||||||
@ -1626,9 +1635,11 @@ ${escapedMessage}
|
|||||||
break;
|
break;
|
||||||
case "AddPlayerEvent":
|
case "AddPlayerEvent":
|
||||||
this.doAddPlayer(event.event);
|
this.doAddPlayer(event.event);
|
||||||
|
console.log('ADD PLAYER');
|
||||||
break;
|
break;
|
||||||
case "RemovePlayerEvent":
|
case "RemovePlayerEvent":
|
||||||
this.doRemovePlayer(event.userId);
|
this.doRemovePlayer(event.userId);
|
||||||
|
console.log('REMOVE PLAYER');
|
||||||
break;
|
break;
|
||||||
case "UserMovedEvent":
|
case "UserMovedEvent":
|
||||||
this.doUpdatePlayerPosition(event.event);
|
this.doUpdatePlayerPosition(event.event);
|
||||||
@ -1668,6 +1679,7 @@ ${escapedMessage}
|
|||||||
*/
|
*/
|
||||||
private doInitUsersPosition(usersPosition: MessageUserPositionInterface[]): void {
|
private doInitUsersPosition(usersPosition: MessageUserPositionInterface[]): void {
|
||||||
const currentPlayerId = this.connection?.getUserId();
|
const currentPlayerId = this.connection?.getUserId();
|
||||||
|
console.log(currentPlayerId);
|
||||||
this.removeAllRemotePlayers();
|
this.removeAllRemotePlayers();
|
||||||
// load map
|
// load map
|
||||||
usersPosition.forEach((userPosition: MessageUserPositionInterface) => {
|
usersPosition.forEach((userPosition: MessageUserPositionInterface) => {
|
||||||
@ -1712,6 +1724,9 @@ ${escapedMessage}
|
|||||||
addPlayerData.companion,
|
addPlayerData.companion,
|
||||||
addPlayerData.companion !== null ? lazyLoadCompanionResource(this.load, addPlayerData.companion) : undefined
|
addPlayerData.companion !== null ? lazyLoadCompanionResource(this.load, addPlayerData.companion) : undefined
|
||||||
);
|
);
|
||||||
|
player.once('textures-loaded', () => {
|
||||||
|
this.savePlayerAvatarPicture(player, `${addPlayerData.userId}-player-avatar`);
|
||||||
|
});
|
||||||
this.MapPlayers.add(player);
|
this.MapPlayers.add(player);
|
||||||
this.MapPlayersByKey.set(player.userId, player);
|
this.MapPlayersByKey.set(player.userId, player);
|
||||||
player.updatePosition(addPlayerData.position);
|
player.updatePosition(addPlayerData.position);
|
||||||
|
Loading…
Reference in New Issue
Block a user