Add kill individual api
This commit is contained in:
parent
851ca149b9
commit
30a785eabb
@ -51,6 +51,7 @@ const EN_US = {
|
|||||||
"Common.Attr.Title.Basic": "Basic properties",
|
"Common.Attr.Title.Basic": "Basic properties",
|
||||||
"Common.Attr.Title.Spatial": "Spatial property",
|
"Common.Attr.Title.Spatial": "Spatial property",
|
||||||
"Common.Attr.Title.Individual.Generation": "Individual generation",
|
"Common.Attr.Title.Individual.Generation": "Individual generation",
|
||||||
|
"Common.Attr.Title.Individual.kill": "Individual kill",
|
||||||
"Common.Attr.Key.Display.Name": "Display name",
|
"Common.Attr.Key.Display.Name": "Display name",
|
||||||
"Common.Attr.Key.Position.X": "Position X",
|
"Common.Attr.Key.Position.X": "Position X",
|
||||||
"Common.Attr.Key.Position.Y": "Position Y",
|
"Common.Attr.Key.Position.Y": "Position Y",
|
||||||
@ -79,6 +80,8 @@ const EN_US = {
|
|||||||
"Common.Attr.Key.Generation.Error.Empty.Range.List": "The specified label does not contain any scope objects",
|
"Common.Attr.Key.Generation.Error.Empty.Range.List": "The specified label does not contain any scope objects",
|
||||||
"Common.Attr.Key.Generation.Error.Invalid.Range": "The specified scope object is invalid",
|
"Common.Attr.Key.Generation.Error.Invalid.Range": "The specified scope object is invalid",
|
||||||
"Common.Attr.Key.Generation.Error.Invalid.Label": "The specified label has expired",
|
"Common.Attr.Key.Generation.Error.Invalid.Label": "The specified label has expired",
|
||||||
|
"Common.Attr.Key.Kill.Random": "Random kill",
|
||||||
|
"Common.Attr.Key.Kill.Count": "Kill count",
|
||||||
"Panel.Info.Range.Details.Attr.Error.Not.Range": "Object is not a Range",
|
"Panel.Info.Range.Details.Attr.Error.Not.Range": "Object is not a Range",
|
||||||
"Panel.Info.Range.Details.Attr.Error.Unspecified": "Unspecified range object",
|
"Panel.Info.Range.Details.Attr.Error.Unspecified": "Unspecified range object",
|
||||||
"Panel.Info.Group.Details.Attr.Error.Not.Group": "Object is not a Group",
|
"Panel.Info.Group.Details.Attr.Error.Not.Group": "Object is not a Group",
|
||||||
|
@ -50,7 +50,8 @@ const ZH_CN = {
|
|||||||
"Common.No.Unknown.Error": "未知错误",
|
"Common.No.Unknown.Error": "未知错误",
|
||||||
"Common.Attr.Title.Basic": "基础属性",
|
"Common.Attr.Title.Basic": "基础属性",
|
||||||
"Common.Attr.Title.Spatial": "空间属性",
|
"Common.Attr.Title.Spatial": "空间属性",
|
||||||
"Common.Attr.Title.Individual.Generation": "个体生成",
|
"Common.Attr.Title.Individual.Generation": "生成个体",
|
||||||
|
"Common.Attr.Title.Individual.kill": "消除个体",
|
||||||
"Common.Attr.Key.Display.Name": "显示名称",
|
"Common.Attr.Key.Display.Name": "显示名称",
|
||||||
"Common.Attr.Key.Position.X": "X 坐标",
|
"Common.Attr.Key.Position.X": "X 坐标",
|
||||||
"Common.Attr.Key.Position.Y": "Y 坐标",
|
"Common.Attr.Key.Position.Y": "Y 坐标",
|
||||||
@ -79,6 +80,8 @@ const ZH_CN = {
|
|||||||
"Common.Attr.Key.Generation.Error.Empty.Range.List": "指定的标签中没有包含任何范围对象",
|
"Common.Attr.Key.Generation.Error.Empty.Range.List": "指定的标签中没有包含任何范围对象",
|
||||||
"Common.Attr.Key.Generation.Error.Invalid.Range": "指定的范围对象已失效",
|
"Common.Attr.Key.Generation.Error.Invalid.Range": "指定的范围对象已失效",
|
||||||
"Common.Attr.Key.Generation.Error.Invalid.Label": "指定的标签已失效",
|
"Common.Attr.Key.Generation.Error.Invalid.Label": "指定的标签已失效",
|
||||||
|
"Common.Attr.Key.Kill.Random": "随机消除",
|
||||||
|
"Common.Attr.Key.Kill.Count": "消除数量",
|
||||||
"Panel.Info.Range.Details.Attr.Error.Not.Range": "对象不是一个范围",
|
"Panel.Info.Range.Details.Attr.Error.Not.Range": "对象不是一个范围",
|
||||||
"Panel.Info.Range.Details.Attr.Error.Unspecified": "未指定范围对象",
|
"Panel.Info.Range.Details.Attr.Error.Unspecified": "未指定范围对象",
|
||||||
"Panel.Info.Group.Details.Attr.Error.Not.Group": "对象不是一个群",
|
"Panel.Info.Group.Details.Attr.Error.Not.Group": "对象不是一个群",
|
||||||
|
@ -49,6 +49,11 @@ class Group extends CtrlObject {
|
|||||||
*/
|
*/
|
||||||
public genErrorMessageShowCount: number = 0;
|
public genErrorMessageShowCount: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除个数
|
||||||
|
*/
|
||||||
|
public killCount: number = 1;
|
||||||
|
|
||||||
private genInSingleRange(count: number, range: Range) {
|
private genInSingleRange(count: number, range: Range) {
|
||||||
for (let i = 0; i < count; i++) {
|
for (let i = 0; i < count; i++) {
|
||||||
let individual = new Individual(this);
|
let individual = new Individual(this);
|
||||||
@ -188,6 +193,42 @@ class Group extends CtrlObject {
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 随机杀死个体
|
||||||
|
*/
|
||||||
|
public killIndividuals(): boolean {
|
||||||
|
let success = false;
|
||||||
|
let killCount = this.killCount;
|
||||||
|
if (killCount > this.individuals.size) {
|
||||||
|
killCount = this.individuals.size;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成索引数组
|
||||||
|
const allIndex = new Array(this.individuals.size).fill(0).map((_, i) => i);
|
||||||
|
const deleteIndex: Set<number> = new Set();
|
||||||
|
|
||||||
|
for (let i = 0; i < killCount; i++) {
|
||||||
|
let randomIndex = Math.floor(Math.random() * allIndex.length);
|
||||||
|
deleteIndex.add(allIndex[randomIndex]);
|
||||||
|
allIndex.splice(randomIndex, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
let j = 0;
|
||||||
|
this.individuals.forEach((individual) => {
|
||||||
|
if (deleteIndex.has(j)) {
|
||||||
|
this.remove(individual);
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
j++;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
this.model.emit("individualChange", this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return success
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建个体
|
* 创建个体
|
||||||
* @param count 创建数量
|
* @param count 创建数量
|
||||||
|
@ -136,6 +136,24 @@ class GroupDetails extends Component<IGroupDetailsProps & IMixinStatusProps> {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<Message i18nKey="Common.Attr.Title.Individual.kill" isTitle/>
|
||||||
|
|
||||||
|
<AttrInput
|
||||||
|
id={group.id} isNumber={true} step={1} keyI18n="Common.Attr.Key.Kill.Count"
|
||||||
|
value={group.killCount} min={1} max={1000}
|
||||||
|
valueChange={(val) => {
|
||||||
|
this.props.status?.changeGroupAttrib(group.id, "killCount", (val as any) / 1);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TogglesInput
|
||||||
|
keyI18n="Common.Attr.Key.Generation"
|
||||||
|
onIconName="RemoveFilter" offIconName="RemoveFilter"
|
||||||
|
valueChange={() => {
|
||||||
|
group.killIndividuals()
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user