Big project cleanup with overhaul of file responsibilities (KISS) and code (DRY, YAGNI)
This commit is contained in:
+11
-31
@@ -10,6 +10,7 @@ public class IfNode : ProgramNode
|
||||
{
|
||||
DisplayText = "If";
|
||||
}
|
||||
|
||||
public override NodeResult Execute(Robot robot, double delta)
|
||||
{
|
||||
if (selectedItem == null)
|
||||
@@ -19,27 +20,21 @@ public class IfNode : ProgramNode
|
||||
}
|
||||
|
||||
bool isConditionFulfilled = DetermineCondition();
|
||||
return isConditionFulfilled? NodeResult.SUCCESS : NodeResult.CONDITIONFALSE;
|
||||
return isConditionFulfilled ? NodeResult.SUCCESS : NodeResult.CONDITIONFALSE;
|
||||
}
|
||||
|
||||
private bool DetermineCondition()
|
||||
{
|
||||
int inventoryAmount = GameData.inventory.GetItemAmount(selectedItem.data.Id);
|
||||
switch (comparator)
|
||||
return comparator switch
|
||||
{
|
||||
case "is bigger than":
|
||||
return inventoryAmount > amount;
|
||||
case "is less than":
|
||||
return inventoryAmount < amount;
|
||||
case "is not":
|
||||
return inventoryAmount != amount;
|
||||
case "is less than or equal to":
|
||||
return inventoryAmount <= amount;
|
||||
case "is bigger than or equal to":
|
||||
return inventoryAmount >= amount;
|
||||
default:
|
||||
return inventoryAmount == amount;
|
||||
}
|
||||
"is bigger than" => inventoryAmount > amount,
|
||||
"is less than" => inventoryAmount < amount,
|
||||
"is not" => inventoryAmount != amount,
|
||||
"is less than or equal to" => inventoryAmount <= amount,
|
||||
"is bigger than or equal to" => inventoryAmount >= amount,
|
||||
_ => inventoryAmount == amount
|
||||
};
|
||||
}
|
||||
|
||||
public override ProgramNode Duplicate()
|
||||
@@ -63,21 +58,6 @@ public class IfNode : ProgramNode
|
||||
Dictionary<StringName, ProgramNode> availableNodes
|
||||
)
|
||||
{
|
||||
nextNode = null;
|
||||
NegativeNode = null;
|
||||
|
||||
foreach (Godot.Collections.Dictionary connection in connections)
|
||||
{
|
||||
int port = (int)connection["from_port"];
|
||||
ProgramNode connectedNode = GetConnectedNode(connection, availableNodes);
|
||||
if (port == 0)
|
||||
{
|
||||
nextNode = connectedNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
NegativeNode = connectedNode;
|
||||
}
|
||||
}
|
||||
SetBranchNodes(connections, availableNodes);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user