From 58a1893c1dc5f8888c346e2304905997b4c4a1f5 Mon Sep 17 00:00:00 2001 From: Asaki Yuki Date: Mon, 23 Feb 2026 17:28:53 +0700 Subject: [PATCH] add variable generate function --- package.json | 2 +- src/compilers/ui/builder.ts | 2 +- src/components/Utils.ts | 24 +++++++++++++++++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 9ed6f89..b26ebf3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "asajs", - "version": "4.1.5", + "version": "4.1.6", "description": "Create your Minecraft JSON-UI resource packs using JavaScript", "keywords": [ "Minecraft", diff --git a/src/compilers/ui/builder.ts b/src/compilers/ui/builder.ts index 40c1e9d..6a5e286 100644 --- a/src/compilers/ui/builder.ts +++ b/src/compilers/ui/builder.ts @@ -16,7 +16,7 @@ async function buildUI() { const build = Memory.build() build.set("ui/_ui_defs.json", { - ui_defs: Array.from(build.keys()), + ui_defs: Array.from(build.keys(), v => v.replace(/\\/g, "/")), }) if (config.global_variables) build.set("ui/_global_variables.json", config.global_variables) diff --git a/src/components/Utils.ts b/src/components/Utils.ts index f5bf3ef..463412a 100644 --- a/src/components/Utils.ts +++ b/src/components/Utils.ts @@ -1,5 +1,5 @@ import { Type } from "../types/enums/Type.js" -import { Array3, Binding, BindingItem } from "../types/properties/value.js" +import { Array3, Binding, BindingItem, Variable } from "../types/properties/value.js" import { ModifyUI, UI } from "./UI.js" import { Renderer } from "../types/enums/Renderer.js" @@ -202,6 +202,12 @@ export function RandomBindingString(length: number = 16, base: number = 32, forc else return `#${StringID}_binding_${rndStrBind++}` } +let rndVarBind = 1 +export function RandomVariableBinding(length: number = 16, base: number = 32, force?: boolean): Variable { + if (force || allowRandomStringName) return `$${GenRandomString(length, base)}` + else return `$${StringID}_binding_${rndVarBind++}` +} + const rndMap = new Map() export function s(input: string) { @@ -216,10 +222,10 @@ export function s(input: string) { } } -export function bs(input: `#${string}`): `#${string}` { +export function bs(input: Binding): Binding { if (isNotObfuscate) return input else { - if (rndMap.has(input)) return rndMap.get(input) as `#${string}` + if (rndMap.has(input)) return rndMap.get(input) else { const ret = RandomBindingString() rndMap.set(input, ret) @@ -228,6 +234,18 @@ export function bs(input: `#${string}`): `#${string}` { } } +export function vs(input: Variable): Variable { + if (isNotObfuscate) return input + else { + if (rndMap.has(input)) return rndMap.get(input) + else { + const ret = RandomVariableBinding() + rndMap.set(input, ret) + return ret + } + } +} + export function GetItemByAuxID(auxID: number) { const item = ItemAuxID[auxID] if (item) return `minecraft:${item.toLowerCase()}`