Browse Source

Fixed Break command logic

Now works correctly inside nested conditions
master
chrisgregan 10 years ago
parent
commit
805956e825
  1. 35
      Assets/Fungus/Flowchart/Scripts/Commands/Break.cs

35
Assets/Fungus/Flowchart/Scripts/Commands/Break.cs

@ -13,18 +13,47 @@ namespace Fungus
{ {
public override void OnEnter() public override void OnEnter()
{ {
// Find next End statement at -1 relative indent level // Find index of previous while command
for (int i = commandIndex + 1; i < parentBlock.commandList.Count; ++i) int whileIndex = -1;
int whileIndentLevel = -1;
for (int i = commandIndex - 1; i >=0; --i)
{
While whileCommand = parentBlock.commandList[i] as While;
if (whileCommand != null)
{
whileIndex = i;
whileIndentLevel = whileCommand.indentLevel;
break;
}
}
if (whileIndex == -1)
{
// No enclosing While command found, just continue
Continue();
return;
}
// Find matching End statement at same indent level as While
for (int i = whileIndex + 1; i < parentBlock.commandList.Count; ++i)
{ {
End endCommand = parentBlock.commandList[i] as End; End endCommand = parentBlock.commandList[i] as End;
if (endCommand != null && if (endCommand != null &&
endCommand.indentLevel == indentLevel - 1) endCommand.indentLevel == whileIndentLevel)
{
// Sanity check that break command is actually between the While and End commands
if (commandIndex > whileIndex && commandIndex < endCommand.commandIndex)
{ {
// Continue at next command after End // Continue at next command after End
Continue (endCommand.commandIndex + 1); Continue (endCommand.commandIndex + 1);
return; return;
} }
else
{
break;
}
}
} }
// No matching End command found so just continue // No matching End command found so just continue

Loading…
Cancel
Save