add variable generate function
This commit is contained in:
parent
8850928388
commit
58a1893c1d
3 changed files with 23 additions and 5 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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<string, string>()
|
||||
|
||||
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 <Binding>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 <Variable>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()}`
|
||||
|
|
|
|||
Reference in a new issue