Finalizing strict mode fixes
This commit is contained in:
parent
6f69a62d4d
commit
b82b13e351
9 changed files with 139 additions and 110 deletions
|
@ -2,39 +2,21 @@ import {PlayerAnimationNames} from "./Animation";
|
|||
import {GameScene, Textures} from "../Game/GameScene";
|
||||
import {MessageUserPositionInterface, PointInterface} from "../../Connection";
|
||||
import {ActiveEventList, UserInputEvent, UserInputManager} from "../UserInput/UserInputManager";
|
||||
import {PlayableCharacter} from "../Entity/PlayableCharacter";
|
||||
import {Character} from "../Entity/Character";
|
||||
|
||||
|
||||
export const hasMovedEventName = "hasMoved";
|
||||
export interface CurrentGamerInterface extends PlayableCharacter{
|
||||
export interface CurrentGamerInterface extends Character{
|
||||
moveUser(delta: number) : void;
|
||||
say(text : string) : void;
|
||||
}
|
||||
|
||||
export interface GamerInterface extends PlayableCharacter{
|
||||
userId : string;
|
||||
updatePosition(position: PointInterface): void;
|
||||
say(text : string) : void;
|
||||
}
|
||||
|
||||
interface AnimationData {
|
||||
key: string;
|
||||
frameRate: number;
|
||||
repeat: number;
|
||||
frameModel: string; //todo use an enum
|
||||
frameStart: number;
|
||||
frameEnd: number;
|
||||
}
|
||||
|
||||
|
||||
export class Player extends PlayableCharacter implements CurrentGamerInterface, GamerInterface {
|
||||
userId: string;
|
||||
export class Player extends Character implements CurrentGamerInterface {
|
||||
userInputManager: UserInputManager;
|
||||
previousDirection: string;
|
||||
wasMoving: boolean;
|
||||
|
||||
constructor(
|
||||
userId: string,
|
||||
Scene: GameScene,
|
||||
x: number,
|
||||
y: number,
|
||||
|
@ -43,62 +25,13 @@ export class Player extends PlayableCharacter implements CurrentGamerInterface,
|
|||
direction: string,
|
||||
moving: boolean
|
||||
) {
|
||||
super(Scene, x, y, PlayerTexture, name, 1);
|
||||
super(Scene, x, y, PlayerTexture, name, direction, moving, 1);
|
||||
|
||||
//create input to move
|
||||
this.userInputManager = new UserInputManager(Scene);
|
||||
|
||||
//set data
|
||||
this.userId = userId;
|
||||
|
||||
//the current player model should be push away by other players to prevent conflict
|
||||
this.setImmovable(false);
|
||||
this.initAnimation();
|
||||
|
||||
this.playAnimation(direction, moving);
|
||||
}
|
||||
|
||||
private initAnimation(): void {
|
||||
this.getPlayerAnimations(this.PlayerTexture).forEach(d => {
|
||||
this.scene.anims.create({
|
||||
key: d.key,
|
||||
frames: this.scene.anims.generateFrameNumbers(d.frameModel, {start: d.frameStart, end: d.frameEnd}),
|
||||
frameRate: d.frameRate,
|
||||
repeat: d.repeat
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
private getPlayerAnimations(name: string): AnimationData[] {
|
||||
return [{
|
||||
key: `${name}-${PlayerAnimationNames.WalkDown}`,
|
||||
frameModel: name,
|
||||
frameStart: 0,
|
||||
frameEnd: 2,
|
||||
frameRate: 10,
|
||||
repeat: -1
|
||||
}, {
|
||||
key: `${name}-${PlayerAnimationNames.WalkLeft}`,
|
||||
frameModel: name,
|
||||
frameStart: 3,
|
||||
frameEnd: 5,
|
||||
frameRate: 10,
|
||||
repeat: -1
|
||||
}, {
|
||||
key: `${name}-${PlayerAnimationNames.WalkRight}`,
|
||||
frameModel: name,
|
||||
frameStart: 6,
|
||||
frameEnd: 8,
|
||||
frameRate: 10,
|
||||
repeat: -1
|
||||
}, {
|
||||
key: `${name}-${PlayerAnimationNames.WalkUp}`,
|
||||
frameModel: name,
|
||||
frameStart: 9,
|
||||
frameEnd: 11,
|
||||
frameRate: 10,
|
||||
repeat: -1
|
||||
}];
|
||||
}
|
||||
|
||||
moveUser(delta: number): void {
|
||||
|
@ -146,24 +79,4 @@ export class Player extends PlayableCharacter implements CurrentGamerInterface,
|
|||
}
|
||||
this.wasMoving = moving;
|
||||
}
|
||||
|
||||
//todo: put this method into the NonPlayer class instead
|
||||
updatePosition(position: PointInterface): void {
|
||||
this.playAnimation(position.direction, position.moving);
|
||||
this.setX(position.x);
|
||||
this.setY(position.y);
|
||||
this.setDepth(position.y);
|
||||
}
|
||||
|
||||
private playAnimation(direction : string, moving: boolean): void {
|
||||
if (moving && (!this.anims.currentAnim || this.anims.currentAnim.key !== direction)) {
|
||||
this.play(this.PlayerTexture+'-'+direction, true);
|
||||
} else if (!moving) {
|
||||
/*if (this.anims.currentAnim) {
|
||||
this.anims.stop();
|
||||
}*/
|
||||
this.play(this.PlayerTexture+'-'+direction, true);
|
||||
this.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue