Separate parameter model

This commit is contained in:
MrKBear 2022-04-07 15:16:58 +08:00
parent dd1811a795
commit 74b2df49ad
2 changed files with 130 additions and 121 deletions

View File

@ -1,128 +1,11 @@
import { IAnyObject } from "./Renderer";
import { Emitter, EventType } from "./Emitter"; import { Emitter, EventType } from "./Emitter";
import type { Individual } from "./Individual"; import type { Individual } from "./Individual";
import type { Group } from "./Group"; import type { Group } from "./Group";
import type { Model } from "./Model"; import type { Model } from "./Model";
import type { Range } from "./Range"; import {
import type { Label } from "./Label"; IParamValue, isObjectType, isVectorType,
IBehaviorParameterOptionItem, IBehaviorParameter, IBehaviorParameterOption, IBehaviorParameterValue
type IObjectParamCacheType<P, Q = P> = { } from "./Parameter";
picker: P;
objects: Q;
}
/**
*
*/
type IMapBasicParamTypeKeyToType = {
"number": number;
"string": string;
"boolean": boolean;
}
type IMapObjectParamTypeKeyToType = {
"R": IObjectParamCacheType<Range | undefined>;
"G": IObjectParamCacheType<Group | undefined>;
"LR": IObjectParamCacheType<Label | Range | undefined, Range[]>;
"LG": IObjectParamCacheType<Label | Group | undefined, Group[]>;
}
type IMapVectorParamTypeKeyToType = {
"vec": number[];
}
/**
*
*/
type AllMapType = IMapBasicParamTypeKeyToType & IMapObjectParamTypeKeyToType & IMapVectorParamTypeKeyToType;
type IParamType = keyof AllMapType;
type IObjectType = keyof IMapObjectParamTypeKeyToType;
type IVectorType = keyof IMapVectorParamTypeKeyToType;
type IParamValue<K extends IParamType> = AllMapType[K];
/**
*
*/
const objectTypeListEnumSet = new Set<IParamType>(["R", "G", "LR", "LG"]);
/**
*
*/
function isObjectType(key: IParamType): key is IVectorType {
return objectTypeListEnumSet.has(key);
}
/**
*
*/
function isVectorType(key: IParamType): key is IObjectType {
return key === "vec";
}
/**
*
*/
interface IBehaviorParameterOptionItem<T extends IParamType = IParamType> {
/**
*
*/
type: T | string;
/**
*
*/
defaultValue?: IParamValue<T>;
/**
*
*/
onChange?: (value: IParamValue<T>) => any;
/**
*
*/
name: string;
/**
*
*/
maxLength?: number;
/**
*
*/
numberStep?: number;
/**
*
*/
numberMax?: number;
numberMin?: number;
/**
*
*/
iconName?: string;
}
interface IBehaviorParameter {
[x: string]: IParamType;
}
/**
*
*/
type IBehaviorParameterOption<P extends IBehaviorParameter> = {
[X in keyof P]: IBehaviorParameterOptionItem<P[X]>;
}
/**
*
*/
type IBehaviorParameterValue<P extends IBehaviorParameter> = {
[X in keyof P]: IParamValue<P[X]>
}
/** /**
* *

126
source/Model/Parameter.ts Normal file
View File

@ -0,0 +1,126 @@
import type { Group } from "./Group";
import type { Range } from "./Range";
import type { Label } from "./Label";
type IObjectParamCacheType<P, Q = P> = {
picker: P;
objects: Q;
}
/**
*
*/
type IMapBasicParamTypeKeyToType = {
"number": number;
"string": string;
"boolean": boolean;
}
type IMapObjectParamTypeKeyToType = {
"R": IObjectParamCacheType<Range | undefined>;
"G": IObjectParamCacheType<Group | undefined>;
"LR": IObjectParamCacheType<Label | Range | undefined, Range[]>;
"LG": IObjectParamCacheType<Label | Group | undefined, Group[]>;
}
type IMapVectorParamTypeKeyToType = {
"vec": number[];
}
/**
*
*/
type AllMapType = IMapBasicParamTypeKeyToType & IMapObjectParamTypeKeyToType & IMapVectorParamTypeKeyToType;
type IParamType = keyof AllMapType;
type IObjectType = keyof IMapObjectParamTypeKeyToType;
type IVectorType = keyof IMapVectorParamTypeKeyToType;
type IParamValue<K extends IParamType> = AllMapType[K];
/**
*
*/
const objectTypeListEnumSet = new Set<IParamType>(["R", "G", "LR", "LG"]);
/**
*
*/
function isObjectType(key: IParamType): key is IVectorType {
return objectTypeListEnumSet.has(key);
}
/**
*
*/
function isVectorType(key: IParamType): key is IObjectType {
return key === "vec";
}
/**
*
*/
interface IBehaviorParameterOptionItem<T extends IParamType = IParamType> {
/**
*
*/
type: T | string;
/**
*
*/
defaultValue?: IParamValue<T>;
/**
*
*/
onChange?: (value: IParamValue<T>) => any;
/**
*
*/
name: string;
/**
*
*/
maxLength?: number;
/**
*
*/
numberStep?: number;
/**
*
*/
numberMax?: number;
numberMin?: number;
/**
*
*/
iconName?: string;
}
interface IBehaviorParameter {
[x: string]: IParamType;
}
/**
*
*/
type IBehaviorParameterOption<P extends IBehaviorParameter> = {
[X in keyof P]: IBehaviorParameterOptionItem<P[X]>;
}
/**
*
*/
type IBehaviorParameterValue<P extends IBehaviorParameter> = {
[X in keyof P]: IParamValue<P[X]>
}
export {
IParamType, IParamValue, isObjectType, isVectorType,
IBehaviorParameterOptionItem, IBehaviorParameter, IBehaviorParameterOption, IBehaviorParameterValue
}