Skip to content

Commit

Permalink
fix(skymp5-client): improve anims system correctness
Browse files Browse the repository at this point in the history
  • Loading branch information
Pospelove committed Jun 10, 2024
1 parent 4ae34fc commit dac2364
Showing 1 changed file with 60 additions and 18 deletions.
78 changes: 60 additions & 18 deletions skymp5-client/src/services/services/animDebugService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { AnimDebugSettings } from "../messages_settings/animDebugSettings";
import { ClientListener, CombinedController, Sp } from "./clientListener";
import { ButtonEvent, CameraStateChangedEvent, DxScanCode, Menu } from "skyrimPlatform";

const playerId = 0x14;

export class AnimDebugService extends ClientListener {
constructor(private sp: Sp, private controller: CombinedController) {
super();
Expand All @@ -20,19 +22,19 @@ export class AnimDebugService extends ClientListener {
}
}

const self = this;
this.sp.hooks.sendAnimationEvent.add({
enter: (ctx) => { },
leave: (ctx) => {
self.onSendAnimationEventLeave(ctx);
}
}, playerId, playerId);

if (!this.settings || !this.settings.isActive) return;

if (this.settings.textOutput?.isActive) {
this.queue = new AnimQueueCollection(this.sp, this.settings);
this.sp.storage[AnimQueueCollection.name] = this.queue;

const self = this;
this.sp.hooks.sendAnimationEvent.add({
enter: (ctx) => { },
leave: (ctx) => {
self.onSendAnimationEventLeave(ctx);
}
}, playerId, playerId);
}

if (this.settings.animKeys) {
Expand All @@ -45,6 +47,21 @@ export class AnimDebugService extends ClientListener {
}

private onSendAnimationEventLeave(ctx: { animEventName: string, animationSucceeded: boolean }) {
const animLowerCase = ctx.animEventName.toLowerCase();
if (animLowerCase.startsWith("idle") && !animLowerCase.startsWith("idleforcedefaultstate")) {
this.controller.once("update", () => {
// This is only for player.playidle
if (!this.sp.Ui.isMenuOpen(Menu.Console)) return;

if (this.sp.Game.getPlayer()?.getFurnitureReference()) return;

logTrace(this, `Forcing third person and disabling player controls`);
this.sp.Game.forceThirdPerson();
this.sp.Game.disablePlayerControls(true, false, true, false, false, false, false, false, 0);
this.needsExitingAnim = true;
});
}

if (this.queue === undefined) return;

this.queue.push(ctx.animEventName, ctx.animationSucceeded ? animationSucceededTextColor : animationNotSucceededTextColor);
Expand All @@ -59,11 +76,7 @@ export class AnimDebugService extends ClientListener {
|| e.code === DxScanCode.D) {

if (this.needsExitingAnim) {

this.sp.Debug.sendAnimationEvent(this.sp.Game.getPlayer(), "IdleForceDefaultState");
logTrace(this, `Sent animation event: IdleForceDefaultState`);
this.needsExitingAnim = false;
this.sp.Game.enablePlayerControls(true, false, true, false, false, false, false, false, 0);
this.exitAnim();
}
}
else {
Expand All @@ -81,20 +94,50 @@ export class AnimDebugService extends ClientListener {
if (this.sp.Game.getPlayer()?.isWeaponDrawn()) return;

if (this.sp.Ui.isMenuOpen(Menu.Favorites)) return;
if (this.sp.Ui.isMenuOpen(Menu.Console)) return;

this.sp.Game.forceThirdPerson();
this.sp.Game.disablePlayerControls(true, false, true, false, false, false, false, false, 0);
this.sp.Debug.sendAnimationEvent(this.sp.Game.getPlayer(), this.settings.animKeys![e.code]);
if (this.stopAnimInProgress) return;

this.needsExitingAnim = true;
if (this.sp.Game.getPlayer()?.getFurnitureReference()) return;
if (this.sp.Game.getPlayer()?.isSneaking()) return;
if (this.sp.Game.getPlayer()?.isSwimming()) return;

if (this.settings.animKeys![e.code].toLowerCase() === "idleforcedefaultstate") {
if (this.needsExitingAnim) {
this.exitAnim();
}
}
else {
this.sp.Game.forceThirdPerson();
this.sp.Game.disablePlayerControls(true, false, true, false, false, false, false, false, 0);
this.sp.Debug.sendAnimationEvent(this.sp.Game.getPlayer(), this.settings.animKeys![e.code]);

this.needsExitingAnim = true;
}

logTrace(this, `Sent animation event: ${this.settings.animKeys![e.code]}`);
}

private exitAnim() {
this.sp.Debug.sendAnimationEvent(this.sp.Game.getPlayer(), "IdleForceDefaultState");
logTrace(this, `Sent animation event: IdleForceDefaultState`);
this.needsExitingAnim = false;

this.stopAnimInProgress = true;
this.sp.Utility.wait(0.5).then(() => {
this.sp.Game.enablePlayerControls(true, false, true, false, false, false, false, false, 0);
});
this.sp.Utility.wait(1).then(() => {
this.stopAnimInProgress = false;
});
}

private queue?: AnimQueueCollection;
private settings?: AnimDebugSettings;

private needsExitingAnim = false;

private stopAnimInProgress = false;
}

type AnimListItem = {
Expand All @@ -103,7 +146,6 @@ type AnimListItem = {
color: number[]
}

const playerId = 0x14;
const animationSucceededTextColor = [255, 255, 255, 1];
const animationNotSucceededTextColor = [255, 0, 0, 1];

Expand Down

0 comments on commit dac2364

Please sign in to comment.