diff --git a/package.json b/package.json index 186dafb..0153208 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "asajs", - "version": "4.1.8", + "version": "4.1.13", "description": "Create your Minecraft JSON-UI resource packs using JavaScript", "keywords": [ "Minecraft", diff --git a/src/compilers/Configuration.ts b/src/compilers/Configuration.ts index 938d879..c06d5d2 100644 --- a/src/compilers/Configuration.ts +++ b/src/compilers/Configuration.ts @@ -66,9 +66,9 @@ export const unLinked = options["unlink"] ?? !(config.compiler?.autoImport ?? tr export const buildFolder = config.compiler?.buildFolder || "build" export const uiBuildFolder = config.compiler?.uiBuildFolder || "asajs" export const isNotObfuscate = debugMode || !(config.compiler?.obfuscateStringName ?? false) -export const allowRandomStringName = !debugMode || (config.compiler?.allowRandomStringName ?? true) -export const namespaceCount = debugMode ? 5 : (config.compiler?.namespaceCount ?? 15) -export const forceRandomStringLength = debugMode ? 10 : config.compiler?.forceRandomStringLength +export const allowRandomStringName = !(debugMode || !(config.compiler?.allowRandomStringName ?? true)) +export const namespaceCount = config.compiler?.namespaceCount ?? 15 +export const forceRandomStringLength = config.compiler?.forceRandomStringLength export const bindingFuntions = config.binding_functions diff --git a/src/compilers/FormatProperties.ts b/src/compilers/FormatProperties.ts index 2a1b2f0..69c990d 100644 --- a/src/compilers/FormatProperties.ts +++ b/src/compilers/FormatProperties.ts @@ -18,7 +18,7 @@ export function FormatProperties(properties: any) { if (key.startsWith("$")) { const [varName, varType] = key.split("|") - + if (!varType) break switch (varType) { case "d": properties[`${varName}|default`] = value diff --git a/src/components/AnimationKeyframe.ts b/src/components/AnimationKeyframe.ts index 3ad805a..6e702e2 100644 --- a/src/components/AnimationKeyframe.ts +++ b/src/components/AnimationKeyframe.ts @@ -1,13 +1,21 @@ +import { config, isNotObfuscate, uiBuildFolder } from "../compilers/Configuration.js" import { FormatAnimationProperties } from "../compilers/FormatProperties.js" import { Memory } from "../compilers/Memory.js" import { AnimType } from "../types/enums/AnimType.js" import { KeyframeAnimationProperties } from "../types/properties/element/Animation.js" import { Animation } from "./Animation.js" import { Class } from "./Class.js" -import { RandomNamespace, RandomString } from "./Utils.js" +import { defaultNamespace, RandomNamespace, RandomString } from "./Utils.js" +import nodepath from "path" import util from "node:util" +const fileExt = config.compiler?.fileExtension + ? config.compiler.fileExtension.startsWith(".") + ? config.compiler.fileExtension + : `.${config.compiler.fileExtension}` + : ".json" + export class AnimationKeyframe extends Class { readonly path: string readonly name: string @@ -21,6 +29,7 @@ export class AnimationKeyframe extends Class { name?: string, namespace?: string, path?: string, + allowObfuscate?: boolean, ) { super() @@ -29,14 +38,16 @@ export class AnimationKeyframe extends Class { process.exit(1) } - if (namespace && !/^\w+$/.test(namespace)) { - console.error(`The '${namespace}' cannot be used as a namespace`) - process.exit(1) + if (isNotObfuscate || !(allowObfuscate ?? true)) { + this.name = name?.match(/^(\w|\/)+/)?.[0] || RandomString(16) + this.namespace = namespace || defaultNamespace || RandomNamespace() + } else { + this.name = RandomString(16) + this.namespace = RandomNamespace() } - this.name = name || RandomString(16) - this.namespace = namespace || RandomNamespace() - this.path = path || `asajs/${this.namespace}.json` + if (!path) this.path = nodepath.join(uiBuildFolder, `${this.namespace}${fileExt}`) + else this.path = path Memory.add(this) } diff --git a/src/components/Utils.ts b/src/components/Utils.ts index 9af6086..790733f 100644 --- a/src/components/Utils.ts +++ b/src/components/Utils.ts @@ -203,9 +203,9 @@ export function RandomBindingString(length: number = 16, base: number = 32, forc } let rndVarBind = 1 -export function RandomVariableBinding(length: number = 16, base: number = 32, force?: boolean): Variable { +export function RandomVariableString(length: number = 16, base: number = 32, force?: boolean): Variable { if (force || allowRandomStringName) return `$${GenRandomString(length, base)}` - else return `$${StringID}_binding_${rndVarBind++}` + else return `$${StringID}_variable_${rndVarBind++}` } const rndMap = new Map() @@ -244,7 +244,7 @@ export function vs(input: Variable): Variable { else { if (rndMap.has(input)) return `${rndMap.get(input)}${mode}` else { - const ret = RandomVariableBinding() + const ret = RandomVariableString() rndMap.set(input, ret) return `${ret}${mode}` }