Skip to content

Commit

Permalink
Add utils functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ink0rr committed Jan 5, 2023
1 parent db33710 commit 5dd92f9
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 1 deletion.
2 changes: 2 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { deepMerge as _deepMerge } from "https://deno.land/[email protected]/collections/deep_merge.ts";
export * as JSONC from "https://deno.land/[email protected]/encoding/jsonc.ts";
export { dirname } from "https://deno.land/[email protected]/path/mod.ts";
export { join } from "https://deno.land/[email protected]/path/posix.ts";
Expand Down
38 changes: 38 additions & 0 deletions lib/utils/addAnimation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { StringOrRecord } from "../schemas/mod.ts";

interface DescriptionLike {
scripts?: {
animate?: StringOrRecord[];
};
animations?: Record<string, string>;
}

/**
* Helper function to add an animation to a description object
*
* @param description A description object that has a scripts and animations property
* @param name Animation name
* @param identifier Animation identifier
* @param condition Molang query. Set to `true` to always run
*/
export function addAnimation(
description: DescriptionLike,
name: string,
identifier: string,
condition?: string | true,
): void {
description.scripts ??= {};
description.scripts.animate ??= [];
description.animations ??= {};

description.animations[name] = identifier;

if (!condition) return;
if (typeof condition === "string") {
description.scripts.animate.push({
[name]: condition,
});
} else {
description.scripts.animate.push(name);
}
}
6 changes: 6 additions & 0 deletions lib/utils/deepMerge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { _deepMerge } from "../../deps.ts";

export function deepMerge<T>(source: T, others: T): T {
// @ts-ignore: deepMerge is not generic
return _deepMerge(source, others);
}
File renamed without changes.
4 changes: 3 additions & 1 deletion mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ export * from "./lib/addon/recipe/Recipe.ts";
export * from "./lib/addon/render_controller/RenderController.ts";
export * from "./lib/core/Identifier.ts";
export * from "./lib/core/Project.ts";
export * from "./lib/core/proxy.ts";
export * from "./lib/fs/file.ts";
export * from "./lib/fs/json.ts";
export * from "./lib/lazuli.ts";
export * from "./lib/schemas/mod.ts";
export * from "./lib/utils/addAnimation.ts";
export * from "./lib/utils/deepMerge.ts";
export * from "./lib/utils/proxy.ts";

0 comments on commit 5dd92f9

Please sign in to comment.