asajs 4.0.7-indev → 4.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/config.d.ts CHANGED
@@ -1,4 +1,9 @@
1
- import { Variable } from "./src/types/properties/value.ts"
1
+ import { BindingItem, Variable } from "./src/types/properties/value.ts"
2
+
3
+ export interface RetBindingValue {
4
+ generate_bindings?: Array<{ source_property_name: string; target_property_name: string }>
5
+ return_value: string
6
+ }
2
7
 
3
8
  export interface Config {
4
9
  compiler?: {
@@ -27,4 +32,5 @@ export interface Config {
27
32
  }[]
28
33
  }
29
34
  global_variables?: Record<Variable, string>
35
+ binding_functions?: Record<string, (...args: string[]) => RetBindingValue>
30
36
  }
@@ -1,21 +1,48 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
3
  import { createRequire } from "module";
4
+ const options = {};
5
+ for (const arg of process.argv) {
6
+ if (arg.startsWith("--"))
7
+ options[arg.slice(2)] = true;
8
+ }
9
+ export const isTestMode = !fs.existsSync("node_modules/asajs");
4
10
  if (!fs.existsSync("asajs.config.js")) {
5
- fs.copyFileSync("node_modules/asajs/resources/asajs.config.js", "asajs.config.js");
11
+ if (isTestMode) {
12
+ fs.writeFileSync("asajs.config.js", [
13
+ `export function RandomBindingString(length, base = 32) {
14
+ const chars = "0123456789abcdefghijklmnopqrstuvwxyz".slice(0, base)
15
+ const out = new Array()
16
+
17
+ try {
18
+ const buffer = new Uint8Array(length)
19
+ crypto.getRandomValues(buffer)
20
+ for (let i = 0; i < length; i++) {
21
+ out[i] = chars[buffer[i] % base]
22
+ }
23
+ } catch {
24
+ for (let i = 0; i < length; i++) {
25
+ out[i] = chars[Math.floor(Math.random() * base)]
26
+ }
27
+ }
28
+
29
+ return \`#$\{out.join("")}\`
30
+ }\n`,
31
+ fs.readFileSync("resources/asajs.config.js", "utf-8").replace("asajs/", "./"),
32
+ ].join("\n"));
33
+ }
34
+ else {
35
+ fs.writeFileSync("asajs.config.js", [
36
+ 'import { RandomBindingString } from "asajs"\n',
37
+ fs.readFileSync("node_modules/asajs/resources/asajs.config.js", "utf-8"),
38
+ ].join("\n"));
39
+ }
6
40
  }
41
+ export const config = createRequire(import.meta.url)(path.resolve(process.cwd(), "asajs.config.js")).config;
42
+ export const isBuildMode = options["build"] ?? config.compiler?.enabled ?? false;
43
+ export const isLinkMode = options["link"] ?? config.compiler?.autoImport ?? false;
44
+ export const unLinked = options["unlink"] ?? !(config.compiler?.autoImport ?? true);
45
+ export const bindingFuntions = config.binding_functions;
7
46
  if (!fs.existsSync(".gitignore")) {
8
47
  fs.writeFileSync(".gitignore", `node_modules`, "utf-8");
9
48
  }
10
- export const config = createRequire(import.meta.url)(path.resolve(process.cwd(), "asajs.config.js")).config;
11
- export let isBuildMode = config.compiler?.enabled ?? false;
12
- export let isLinkMode = config.compiler?.autoImport ?? false;
13
- export let unLinked = !(config.compiler?.autoImport ?? true);
14
- for (const arg of process.argv) {
15
- if (arg === "--build")
16
- isBuildMode = true;
17
- if (arg === "--link")
18
- isLinkMode = true;
19
- else if (arg === "--unlink")
20
- unLinked = true;
21
- }
@@ -1,4 +1,5 @@
1
- import { RandomBindingString } from "../../components/Utils.js";
1
+ import { RandomBindingString, ResolveBinding } from "../../components/Utils.js";
2
+ import { bindingFuntions } from "../Configuration.js";
2
3
  export const FunctionMap = new Map();
3
4
  export const defaultFunctions = {
4
5
  /**
@@ -168,3 +169,23 @@ export const defaultFunctions = {
168
169
  },
169
170
  };
170
171
  Object.entries(defaultFunctions).forEach(([key, value]) => FunctionMap.set(key, value));
172
+ if (bindingFuntions)
173
+ Object.entries(bindingFuntions).forEach(([key, value]) => {
174
+ // @ts-ignore
175
+ FunctionMap.set(key, (...args) => {
176
+ const { generate_bindings, return_value } = value(...args);
177
+ if (generate_bindings) {
178
+ const resolve = ResolveBinding(new Map(), ...generate_bindings);
179
+ return {
180
+ genBindings: resolve.map(({ source_property_name, target_property_name }) => ({
181
+ source: source_property_name,
182
+ target: target_property_name,
183
+ })),
184
+ value: return_value,
185
+ };
186
+ }
187
+ return {
188
+ value: return_value,
189
+ };
190
+ });
191
+ });
@@ -1,4 +1,4 @@
1
- import { config, isBuildMode, isLinkMode, unLinked } from "../Configuration.js";
1
+ import { config, isBuildMode, isLinkMode, isTestMode, unLinked } from "../Configuration.js";
2
2
  import { Memory } from "../Memory.js";
3
3
  import { createBuildFolder, gamePath, getBuildFolderName, linkToGame, unlink } from "./linker.js";
4
4
  import { genManifest, version } from "./manifest.js";
@@ -14,7 +14,7 @@ async function buildUI() {
14
14
  });
15
15
  if (config.global_variables)
16
16
  build.set("ui/_global_variables.json", config.global_variables);
17
- const out = await Promise.all(build.entries().map(async ([file, value]) => {
17
+ const out = await Promise.all(Array.from(build.entries()).map(async ([file, value]) => {
18
18
  const outFile = `build/${file}`;
19
19
  await fs
20
20
  .stat(outFile.split(/\\|\//g).slice(0, -1).join("/"))
@@ -39,7 +39,7 @@ async function buildUI() {
39
39
  BuildCache.set("version", version).then(() => Log("INFO", "version set!")),
40
40
  fs
41
41
  .stat("build/pack_icon.png")
42
- .catch(() => fs.copyFile("node_modules/asajs/resources/pack_icon.png", "build/pack_icon.png"))
42
+ .catch(() => fs.copyFile(isTestMode ? "resources/pack_icon.png" : "node_modules/asajs/resources/pack_icon.png", "build/pack_icon.png"))
43
43
  .then(() => Log("INFO", "build/pack_icon.png copied!")),
44
44
  ]);
45
45
  return out.length;
@@ -64,7 +64,7 @@ if (isBuildMode) {
64
64
  console.log("Version:", config.packinfo?.version || [4, 0, 0]);
65
65
  console.log("UUID:", await BuildCache.get("uuid"));
66
66
  if (gamePath)
67
- console.log("Install Path:", `\x1b[32m"${path.join(gamePath, await getBuildFolderName())}"\x1b[0m`);
67
+ console.log("Install Path:", `\x1b[32m"${path.join(gamePath, "development_resource_packs", await getBuildFolderName())}"\x1b[0m`);
68
68
  console.log("=============================================================");
69
69
  }
70
70
  });
@@ -32,7 +32,7 @@ export async function createBuildFolder() {
32
32
  .then(() => clearBuild());
33
33
  }
34
34
  export async function getBuildFolderName() {
35
- return await BuildCache.getWithSetDefault("build-key", () => RandomString(16));
35
+ return await BuildCache.getWithSetDefault("build-key", () => `asajs-build-${RandomString(16)}`);
36
36
  }
37
37
  export let gamePath = null;
38
38
  export async function linkToGame() {
@@ -1,5 +1,7 @@
1
- import { Config } from "../../config.js";
1
+ import { Config, RetBindingValue } from "../../config.js";
2
+ export declare const isTestMode: boolean;
2
3
  export declare const config: Config;
3
- export declare let isBuildMode: boolean;
4
- export declare let isLinkMode: boolean;
5
- export declare let unLinked: boolean;
4
+ export declare const isBuildMode: {};
5
+ export declare const isLinkMode: {};
6
+ export declare const unLinked: {};
7
+ export declare const bindingFuntions: Record<string, (...args: string[]) => RetBindingValue> | undefined;
@@ -15,8 +15,8 @@ export declare class AnimationKeyframe<T extends AnimType> extends Class {
15
15
  clearNext(): this;
16
16
  protected toJsonUI(): KeyframeAnimationProperties<AnimType>;
17
17
  protected toJSON(): (Partial<import("../types/properties/element/Animation.js").DurationAnimation> & import("../types/properties/element/Animation.js").KeyframeAnimationPropertiesItem) | (Partial<import("../types/properties/element/Animation.js").AsepriteFlipBookAnimation> & import("../types/properties/element/Animation.js").KeyframeAnimationPropertiesItem) | {
18
- from?: import("../types/properties/value.js").Array2<string | number> | undefined;
19
- to?: import("../types/properties/value.js").Array2<string | number> | undefined;
18
+ from?: import("../types/properties/value.js").Value<number> | undefined;
19
+ to?: import("../types/properties/value.js").Value<number> | undefined;
20
20
  duration?: import("../types/properties/value.js").Value<number> | undefined;
21
21
  easing?: import("../types/properties/value.js").Value<string | import("../index.js").Easing> | undefined;
22
22
  next?: import("../types/properties/value.js").Value<string | AnimationKeyframe<AnimType> | Animation<AnimType>>;
@@ -33,8 +33,8 @@ export declare class AnimationKeyframe<T extends AnimType> extends Class {
33
33
  wait_until_rendered_to_play?: import("../types/properties/value.js").Value<boolean>;
34
34
  anim_type: T;
35
35
  } | {
36
- from?: import("../types/properties/value.js").Value<number> | undefined;
37
- to?: import("../types/properties/value.js").Value<number> | undefined;
36
+ from?: import("../types/properties/value.js").Array2<string | number> | undefined;
37
+ to?: import("../types/properties/value.js").Array2<string | number> | undefined;
38
38
  duration?: import("../types/properties/value.js").Value<number> | undefined;
39
39
  easing?: import("../types/properties/value.js").Value<string | import("../index.js").Easing> | undefined;
40
40
  next?: import("../types/properties/value.js").Value<string | AnimationKeyframe<AnimType> | Animation<AnimType>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asajs",
3
- "version": "4.0.7-indev",
3
+ "version": "4.0.7",
4
4
  "description": "Create your Minecraft JSON-UI resource packs using JavaScript",
5
5
  "keywords": [
6
6
  "Minecraft",
@@ -1,17 +0,0 @@
1
- /**
2
- * Configuration object for the AsaJS build process.
3
- * @type {import('asajs/config.d.ts').Config}
4
- */
5
- export const config = {
6
- packinfo: {
7
- name: "AsaJS",
8
- description: "Create your Minecraft JSON-UI resource packs using JavaScript.",
9
- version: [4, 0, 1],
10
- },
11
- compiler: {
12
- enabled: true,
13
- autoImport: true,
14
- autoEnable: true,
15
- importToPreview: false,
16
- },
17
- }