diff --git a/source/Behavior/Behavior.ts b/source/Behavior/Behavior.ts index 0309072..15c2dad 100644 --- a/source/Behavior/Behavior.ts +++ b/source/Behavior/Behavior.ts @@ -5,9 +5,10 @@ import { Brownian } from "./Brownian"; import { BoundaryConstraint } from "./BoundaryConstraint"; const AllBehaviors: IAnyBehaviorRecorder[] = [ + new BehaviorRecorder(Template), new BehaviorRecorder(Dynamics), new BehaviorRecorder(Brownian), - new BehaviorRecorder(BoundaryConstraint) + new BehaviorRecorder(BoundaryConstraint), ] /** diff --git a/source/Behavior/BoundaryConstraint.ts b/source/Behavior/BoundaryConstraint.ts index 4e36d70..bf1cb59 100644 --- a/source/Behavior/BoundaryConstraint.ts +++ b/source/Behavior/BoundaryConstraint.ts @@ -26,8 +26,7 @@ class BoundaryConstraint extends Behavior { - return obj instanceof Range - }) as any; - } + let rangeList: Range[] = this.parameter.range.objects; for (let i = 0; i < rangeList.length; i++) { let rx = rangeList[i].position[0] - individual.position[0]; diff --git a/source/Behavior/Template.ts b/source/Behavior/Template.ts index b862559..916c5eb 100644 --- a/source/Behavior/Template.ts +++ b/source/Behavior/Template.ts @@ -4,7 +4,14 @@ import { Individual } from "@Model/Individual"; import { Model } from "@Model/Model"; type ITemplateBehaviorParameter = { - + testNumber: "number"; + testString: "string"; + testBoolean: "boolean"; + testR: "R"; + testG: "G"; + testLR: "LR"; + testLG: "LG"; + testVec: "vec"; } type ITemplateBehaviorEvent = {} @@ -21,6 +28,53 @@ class Template extends Behavior> = { "$Title": { "ZH_CN": "行为", @@ -29,6 +83,10 @@ class Template extends Behavior; infoI18n?: AllI18nKeys; disableI18n?: AllI18nKeys; disableI18nOption?: Record; @@ -82,7 +83,7 @@ class TextField extends Component { return <>
- +
{ diff --git a/source/Context/Status.tsx b/source/Context/Status.tsx index d7cefcb..42b5ba0 100644 --- a/source/Context/Status.tsx +++ b/source/Context/Status.tsx @@ -136,6 +136,17 @@ class Status extends Emitter { this.model.on("individualChange", () => { this.emit("individualChange"); }); + + // 当模型中的标签和对象改变时,更新全部行为参数中的受控对象 + const updateBehaviorParameter = () => { + this.model.updateBehaviorParameter(); + } + this.on("objectChange", updateBehaviorParameter); + this.on("behaviorChange", updateBehaviorParameter); + this.on("labelChange", updateBehaviorParameter); + this.on("groupLabelChange", updateBehaviorParameter); + this.on("rangeLabelChange", updateBehaviorParameter); + this.on("behaviorAttrChange", updateBehaviorParameter); } public bindRenderer(renderer: AbstractRenderer) { @@ -198,15 +209,16 @@ class Status extends Emitter { * 修改群属性 */ public changeBehaviorAttrib> - (id: ObjectID, key: P, val: IParamValue) { + (id: ObjectID, key: P, val: IParamValue, noParameter?: boolean) { const behavior = this.model.getBehaviorById(id); if (behavior) { - if (key === "color") { - behavior.color = val as number[]; - } else if (key === "name") { - behavior.name = val as string; + if (noParameter) { + behavior[key as keyof Behavior] = val as never; } else { behavior.parameter[key] = val; + behavior.parameterOption[key]?.onChange ? + behavior.parameterOption[key]?.onChange!(val) : + undefined; } this.emit("behaviorAttrChange"); } diff --git a/source/Localization/EN-US.ts b/source/Localization/EN-US.ts index d28b7f9..b172fad 100644 --- a/source/Localization/EN-US.ts +++ b/source/Localization/EN-US.ts @@ -113,5 +113,9 @@ const EN_US = { "Panel.Info.Label.List.Error.Nodata": "There are no labels in the model, click the button to create", "Panel.Info.Behavior.Details.Error.Not.Behavior": "Please specify a behavior first to view the details", "Panel.Info.Behavior.Details.Behavior.Props": "{behavior} parameter", + "Panel.Info.Behavior.Details.Parameter.Key": "{key}", + "Panel.Info.Behavior.Details.Parameter.Key.Vec.X": "{key} X", + "Panel.Info.Behavior.Details.Parameter.Key.Vec.Y": "{key} Y", + "Panel.Info.Behavior.Details.Parameter.Key.Vec.Z": "{key} Z", } export default EN_US; \ No newline at end of file diff --git a/source/Localization/ZH-CN.ts b/source/Localization/ZH-CN.ts index c28978a..add0744 100644 --- a/source/Localization/ZH-CN.ts +++ b/source/Localization/ZH-CN.ts @@ -113,5 +113,9 @@ const ZH_CN = { "Panel.Info.Label.List.Error.Nodata": "模型中没有标签,点击按钮以创建", "Panel.Info.Behavior.Details.Error.Not.Behavior": "请先指定一个行为以查看详情", "Panel.Info.Behavior.Details.Behavior.Props": "{behavior}参数", + "Panel.Info.Behavior.Details.Parameter.Key": "{key}", + "Panel.Info.Behavior.Details.Parameter.Key.Vec.X": "{key} X 坐标", + "Panel.Info.Behavior.Details.Parameter.Key.Vec.Y": "{key} Y 坐标", + "Panel.Info.Behavior.Details.Parameter.Key.Vec.Z": "{key} Z 坐标", } export default ZH_CN; \ No newline at end of file diff --git a/source/Model/Behavior.ts b/source/Model/Behavior.ts index f25a612..37618ff 100644 --- a/source/Model/Behavior.ts +++ b/source/Model/Behavior.ts @@ -24,7 +24,7 @@ type IMapObjectParamTypeKeyToType = { "R": IObjectParamCacheType; "G": IObjectParamCacheType; "LR": IObjectParamCacheType