Skip to content

Commit

Permalink
Refactor ConstructFishAttribute.cs to improve code readability and ma…
Browse files Browse the repository at this point in the history
…intainability
  • Loading branch information
NATSUME Hiroaki committed May 21, 2024
1 parent 95b90c8 commit c0a75a9
Showing 1 changed file with 36 additions and 21 deletions.
57 changes: 36 additions & 21 deletions Tunny/Component/Operation/ConstructFishAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,36 +71,51 @@ private void GetInputData(IGH_DataAccess DA, int paramCount, Dictionary<string,
switch (i)
{
case 1:
var direction = new List<int>();
if (DA.GetDataList(i, direction))
{
if (direction.Any(x => x != 1 && x != -1))
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Direction must be either 1(maximize) or -1(minimize).");
return;
}
dict.Add(key, direction);
}
SetDirectionDataList(DA, dict, i, key);
break;
case 2:
var constraint = new List<double>();
if (DA.GetDataList(i, constraint))
{
dict.Add(key, constraint);
}
SetConstraintDataList(DA, dict, i, key);
break;
default:
var list = new List<object>();
if (!DA.GetDataList(i, list))
{
continue;
}
dict.Add(key, list);
SetGenericDataList(DA, dict, i, key);
break;
}
}
}

private static void SetGenericDataList(IGH_DataAccess DA, Dictionary<string, object> dict, int i, string key)
{
var list = new List<object>();
if (!DA.GetDataList(i, list))
{
return;
}
dict.Add(key, list);
}

private static void SetConstraintDataList(IGH_DataAccess DA, Dictionary<string, object> dict, int i, string key)
{
var constraint = new List<double>();
if (DA.GetDataList(i, constraint))
{
dict.Add(key, constraint);
}
}

private void SetDirectionDataList(IGH_DataAccess DA, Dictionary<string, object> dict, int i, string key)
{
var direction = new List<int>();
if (DA.GetDataList(i, direction))
{
if (direction.Any(x => x != 1 && x != -1))
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Direction must be either 1(maximize) or -1(minimize).");
return;
}
dict.Add(key, direction);
}
}

//FIXME: Should be modified to capture and check for change events.
private bool CheckIsNicknameDuplicated()
{
Expand Down

0 comments on commit c0a75a9

Please sign in to comment.