alias default variable format
This commit is contained in:
parent
58a1893c1d
commit
0b1f80da43
5 changed files with 42 additions and 8 deletions
|
|
@ -15,6 +15,23 @@ export function FormatProperties(properties: any) {
|
|||
property_bag[<Binding>key] = value
|
||||
delete properties[key]
|
||||
}
|
||||
|
||||
if (key.startsWith("$")) {
|
||||
const [varName, varType] = key.split("|")
|
||||
|
||||
switch (varType) {
|
||||
case "d":
|
||||
properties[`${varName}|default`] = value
|
||||
delete properties[key]
|
||||
break
|
||||
|
||||
case "default":
|
||||
break
|
||||
|
||||
default:
|
||||
throw new Error("Invalid variable type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (config.compiler?.fixInventoryItemRenderer && property_bag[BagBinding.ITEM_ID_AUX]) {
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ export function isBinding(input: string) {
|
|||
return /^#\w+$/.test(input)
|
||||
}
|
||||
|
||||
export function isVariable(input: string) {
|
||||
return /^\$\w+$/.test(input)
|
||||
}
|
||||
|
||||
export function isNumber(input: string) {
|
||||
return /^[+-]?(?:\d+|\d+\.\d*|\.\d+)(?:[eE][+-]?\d+)?$/.test(input)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { bs, RandomBindingString, RandomString, ResolveBinding } from "../../components/Utils.js"
|
||||
import { BindingItem } from "../../types/properties/value.js"
|
||||
import { bs, RandomBindingString, RandomString, ResolveBinding, vs } from "../../components/Utils.js"
|
||||
import { Binding, BindingItem, Variable } from "../../types/properties/value.js"
|
||||
import { bindingFuntions } from "../Configuration.js"
|
||||
import { isBinding, isNumber, isString } from "./Checker.js"
|
||||
import { isBinding, isNumber, isString, isVariable } from "./Checker.js"
|
||||
import { Expression, GenBinding } from "./types.js"
|
||||
|
||||
type CallbackRet = {
|
||||
|
|
@ -244,7 +244,15 @@ export const defaultFunctions = {
|
|||
if (!isBinding(input_binding)) throw new Error("Invalid input binding")
|
||||
return {
|
||||
doNotAddParentesis: true,
|
||||
value: bs(<`#${string}`>input_binding),
|
||||
value: bs(<Binding>input_binding),
|
||||
}
|
||||
},
|
||||
|
||||
vs: input_variable => {
|
||||
if (!isVariable(input_variable)) throw new Error("Invalid input binding")
|
||||
return {
|
||||
doNotAddParentesis: true,
|
||||
value: vs(<Variable>input_variable),
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
Reference in a new issue