Player class is no longer dependent on UserInputManager

This commit is contained in:
Hanusiak Piotr 2022-01-17 11:37:28 +01:00
parent 173d10738d
commit 28543be121
2 changed files with 5 additions and 9 deletions

View File

@ -1691,7 +1691,6 @@ ${escapedMessage}
texturesPromise, texturesPromise,
PlayerAnimationDirections.Down, PlayerAnimationDirections.Down,
false, false,
this.userInputManager,
this.companion, this.companion,
this.companion !== null ? lazyLoadCompanionResource(this.load, this.companion) : undefined this.companion !== null ? lazyLoadCompanionResource(this.load, this.companion) : undefined
); );
@ -1811,7 +1810,7 @@ ${escapedMessage}
update(time: number, delta: number): void { update(time: number, delta: number): void {
this.dirty = false; this.dirty = false;
this.currentTick = time; this.currentTick = time;
this.CurrentPlayer.moveUser(delta); this.CurrentPlayer.moveUser(delta, this.userInputManager.getEventListForGameTick());
// Let's handle all events // Let's handle all events
while (this.pendingEvents.length !== 0) { while (this.pendingEvents.length !== 0) {

View File

@ -1,8 +1,7 @@
import { PlayerAnimationDirections } from "./Animation"; import { PlayerAnimationDirections } from "./Animation";
import type { GameScene } from "../Game/GameScene"; import type { GameScene } from "../Game/GameScene";
import { ActiveEventList, UserInputEvent, UserInputManager } from "../UserInput/UserInputManager"; import { ActiveEventList, UserInputEvent } from "../UserInput/UserInputManager";
import { Character } from "../Entity/Character"; import { Character } from "../Entity/Character";
import type { RemotePlayer } from "../Entity/RemotePlayer";
import { get } from "svelte/store"; import { get } from "svelte/store";
import { userMovingStore } from "../../Stores/GameStore"; import { userMovingStore } from "../../Stores/GameStore";
@ -20,7 +19,6 @@ export class Player extends Character {
texturesPromise: Promise<string[]>, texturesPromise: Promise<string[]>,
direction: PlayerAnimationDirections, direction: PlayerAnimationDirections,
moving: boolean, moving: boolean,
private userInputManager: UserInputManager,
companion: string | null, companion: string | null,
companionTexturePromise?: Promise<string> companionTexturePromise?: Promise<string>
) { ) {
@ -100,12 +98,11 @@ export class Player extends Character {
return [xMovement, yMovement]; return [xMovement, yMovement];
} }
public moveUser(delta: number): void { public moveUser(delta: number, activeUserInputEvents: ActiveEventList): void {
const activeEvents = this.userInputManager.getEventListForGameTick();
const state = get(followStateStore); const state = get(followStateStore);
const role = get(followRoleStore); const role = get(followRoleStore);
if (activeEvents.get(UserInputEvent.Follow)) { if (activeUserInputEvents.get(UserInputEvent.Follow)) {
if (state === "off" && this.scene.groups.size > 0) { if (state === "off" && this.scene.groups.size > 0) {
this.sendFollowRequest(); this.sendFollowRequest();
} else if (state === "active") { } else if (state === "active") {
@ -118,7 +115,7 @@ export class Player extends Character {
if ((state === "active" || state === "ending") && role === "follower") { if ((state === "active" || state === "ending") && role === "follower") {
[x, y] = this.computeFollowMovement(); [x, y] = this.computeFollowMovement();
} }
this.inputStep(activeEvents, x, y); this.inputStep(activeUserInputEvents, x, y);
} }
public sendFollowRequest() { public sendFollowRequest() {