mylingo3d
Version:
Lingo3D is a React/Vue 3d game development framework that ships with a complete visual editor
33 lines (27 loc) • 1.13 kB
text/typescript
import getDefaultValue from "../../interface/utils/getDefaultValue"
import nonEditorSchemaSet from "../../interface/utils/nonEditorSchemaSet"
export default (schema: any, defaults: any, target: any) => {
const params: Record<string, any> = {}
for (const [key, value] of Object.entries(schema)) {
if (nonEditorSchemaSet.has(key)) continue
let currentVal = target[key]
if (value === Function || typeof currentVal === "function") continue
if (
value === Object ||
(typeof currentVal === "object" && !Array.isArray(currentVal))
)
if (
!currentVal ||
typeof currentVal.x !== "number" ||
typeof currentVal.y !== "number"
)
continue
currentVal ??= getDefaultValue(defaults, key, true)
if (currentVal === Infinity) currentVal = 999999999
else if (currentVal === -Infinity) currentVal = -999999999
else if (Array.isArray(currentVal))
currentVal = JSON.stringify(currentVal)
params[key] = currentVal
}
return params
}