asajs v4.1.13

This commit is contained in:
Asaki Yuki 2026-02-24 05:42:24 +07:00
parent 2e9de68b55
commit 3dba9225e7
5 changed files with 26 additions and 15 deletions

View file

@ -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",

View file

@ -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

View file

@ -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

View file

@ -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<T extends AnimType> extends Class {
readonly path: string
readonly name: string
@ -21,6 +29,7 @@ export class AnimationKeyframe<T extends AnimType> extends Class {
name?: string,
namespace?: string,
path?: string,
allowObfuscate?: boolean,
) {
super()
@ -29,14 +38,16 @@ export class AnimationKeyframe<T extends AnimType> 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)
}

View file

@ -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<string, string>()
@ -244,7 +244,7 @@ export function vs(input: Variable): Variable {
else {
if (rndMap.has(input)) return <Variable>`${rndMap.get(input)}${mode}`
else {
const ret = RandomVariableBinding()
const ret = RandomVariableString()
rndMap.set(input, ret)
return <Variable>`${ret}${mode}`
}