Skip to content

Commit

Permalink
feat(core): applyAnimation speed, time params, export animateUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
dockfries committed Jul 6, 2024
1 parent 1cbd44b commit 00ca113
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
11 changes: 6 additions & 5 deletions packages/core/src/controllers/player/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {

import type { IClientResRaw } from "../../interfaces";
import type { TPos } from "../../types";
import { getAnimateDurationByLibName } from "../../utils/animateUtils";
import { isValidAnimateName } from "../../utils/animateUtils";
import * as h from "../../utils/helperUtils";
import { logger } from "../../logger";

Expand Down Expand Up @@ -548,25 +548,26 @@ export class Player {
applyAnimation(
animLib: string,
animName: string,
speed = 4.1,
loop = false,
lockX = true,
lockY = true,
freeze = false,
time = 0,
forceSync: boolean | ForceSyncEnum = false,
): void {
const duration = getAnimateDurationByLibName(animLib, animName);
if (duration === undefined)
if (!isValidAnimateName(animLib, animName))
return logger.error("[Player]: Invalid anim library or name");
w.ApplyAnimation(
this.id,
animLib,
animName,
4.1,
speed,
loop,
lockX,
lockY,
freeze,
loop ? 0 : duration,
time,
+forceSync,
);
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from "./types";
export * from "./enums";
export { rgba } from "./utils/colorUtils";
export * from "./utils/keyUtils";
export * from "./utils/animateUtils";
3 changes: 2 additions & 1 deletion packages/core/src/utils/animateUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IAnimateInfo } from "core/interfaces";

const animateLib = new Map<string, Array<IAnimateInfo>>([
export const animateLib = new Map<string, Array<IAnimateInfo>>([
["AIRPORT", [{ n: "thrw_barl_thrw", d: 2.0 }]],
[
"Attractors",
Expand Down Expand Up @@ -2496,6 +2496,7 @@ export const isValidAnimateLib = (lib: string) => {
export const isValidAnimateName = (lib: string, name: string) => {
const animLib = isValidAnimateLib(lib);
if (!animLib) return;
if (name === "null") return true;
return animLib.some((anim) => anim.n === name);
};

Expand Down

0 comments on commit 00ca113

Please sign in to comment.