import { AttrInput } from "@Component/AttrInput/AttrInput"; import { IParameter, IParameterOption, IParameterOptionItem, IParameterValue, IParamValue, isObjectType, isVectorType } from "@Model/Parameter"; import { ObjectID } from "@Model/Renderer"; import { Component, Fragment, ReactNode } from "react"; import { TogglesInput } from "@Component/TogglesInput/TogglesInput"; import { ObjectPicker } from "@Component/ObjectPicker/ObjectPicker"; import { useSettingWithEvent, IMixinSettingProps, Language } from "@Context/Setting"; import { AllI18nKeys } from "@Component/Localization/Localization"; import { Message } from "@Component/Message/Message"; import "./Parameter.scss"; interface IParameterProps

{ option: IParameterOption

; value: IParameterValue

; key: ObjectID; change: (key: K, val: IParamValue) => any; i18n: (option: IParameterOptionItem, language: Language) => string; title?: AllI18nKeys; titleOption?: Record; isFirst?: boolean; } @useSettingWithEvent("language") class Parameter

extends Component & IMixinSettingProps> { private renderParameter (key: K, option: IParameterOptionItem, value: IParamValue): ReactNode { const indexKey = `${this.props.key}-${key}`; const type = option.type; const i18nString = this.props.i18n(option, this.props.setting?.language ?? "EN_US"); if (type === "number") { return ?? 0} valueChange={(val) => { this.props.change(key, parseFloat(val) as IParamValue); }} />; } else if (type === "string") { return ?? ""} valueChange={(val) => { this.props.change(key, val as IParamValue); }} />; } else if (type === "boolean") { return ?? false} valueChange={(val) => { this.props.change(key, val as IParamValue); }} /> } else if (isObjectType(type)) { type IObjectParamValue = IParamValue<"G" | "R" | "LG" | "LR">; const typedValue = value as IObjectParamValue; return { typedValue.picker = obj as IObjectParamValue["picker"]; this.props.change(key, typedValue as IParamValue); }} cleanValue={() => { typedValue.picker = undefined as IObjectParamValue["picker"]; this.props.change(key, typedValue as IParamValue); }} /> } else if (isVectorType(type)) { type IObjectParamValue = IParamValue<"vec">; const typedValue = value as IObjectParamValue; return { typedValue[0] = parseFloat(val); this.props.change(key, typedValue as IParamValue); }} /> { typedValue[1] = parseFloat(val); this.props.change(key, typedValue as IParamValue); }} /> { typedValue[2] = parseFloat(val); this.props.change(key, typedValue as IParamValue); }} /> } else { return } } private renderAllParameter(key: Array) { return key.map((key) => { return this.renderParameter( key, this.props.option[key], this.props.value[key], ); }); } public render(): ReactNode { const allOptionKeys: Array = Object.getOwnPropertyNames(this.props.option); return <> { allOptionKeys.length <= 0 && this.props.title ? : null } { this.renderAllParameter(allOptionKeys) } } } export { Parameter }