used the vent system to remove the dependency of Player on Connexion

This commit is contained in:
kharhamel 2020-05-02 16:54:52 +02:00
parent d2f94e9406
commit ad65de75fd
3 changed files with 22 additions and 13 deletions

View file

@ -1,10 +1,11 @@
import {getPlayerAnimations, playAnimation, PlayerAnimationNames} from "./Animation";
import {GameSceneInterface, Textures} from "../Game/GameScene";
import {ConnexionInstance} from "../Game/GameManager";
import {MessageUserPositionInterface} from "../../Connexion";
import {ActiveEventList, UserInputEvent, UserInputManager} from "../UserInput/UserInputManager";
import {PlayableCaracter} from "../Entity/PlayableCaracter";
export const hasMovedEventName = "hasMoved";
export interface CurrentGamerInterface extends PlayableCaracter{
userId : string;
PlayerValue : string;
@ -88,15 +89,11 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
direction = PlayerAnimationNames.None;
this.stop();
}
this.sharePosition(direction);
}
private sharePosition(direction: string) {
if (ConnexionInstance) {
ConnexionInstance.sharePosition(this.x, this.y, direction);
}
this.emit(hasMovedEventName, {direction, x: this.x, y: this.y});
}
//todo: put this method into the NonPlayer class instead
updatePosition(MessageUserPosition: MessageUserPositionInterface) {
playAnimation(this, MessageUserPosition.position.direction);
this.setX(MessageUserPosition.position.x);