From 2efceb62ea1c369d7fafc11c18dc9fcbd1e90329 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Wed, 3 Sep 2014 17:34:10 +0100 Subject: [PATCH] Implemented If, Else, EndIf logic --- Assets/Fungus/FungusScript/Commands/Else.cs | 27 ++++++- Assets/Fungus/FungusScript/Commands/If.cs | 72 ++++++------------ .../FungusScript/Editor/FungusScriptEditor.cs | 9 ++- Assets/Fungus/FungusScript/Editor/IfEditor.cs | 23 ------ .../FungusScript/Scripts/FungusCommand.cs | 7 +- Assets/Shuttle/ShuttleGame.unity | Bin 129876 -> 129988 bytes 6 files changed, 64 insertions(+), 74 deletions(-) diff --git a/Assets/Fungus/FungusScript/Commands/Else.cs b/Assets/Fungus/FungusScript/Commands/Else.cs index 1f10e185..d999aec1 100644 --- a/Assets/Fungus/FungusScript/Commands/Else.cs +++ b/Assets/Fungus/FungusScript/Commands/Else.cs @@ -12,9 +12,32 @@ namespace Fungus.Script { public override void OnEnter() { - Continue(); - } + // Find the next EndIf command at the same indent level as this Else command + bool foundThisCommand = false; + int indent = indentLevel; + foreach(FungusCommand command in parentSequence.commandList) + { + if (foundThisCommand && + command.indentLevel == indent) + { + System.Type type = command.GetType(); + if (type == typeof(EndIf)) + { + // Execute command immediately after the EndIf command + Continue(command); + return; + } + } + else if (command == this) + { + foundThisCommand = true; + } + } + // No matching EndIf command found, so just stop the sequence + Stop(); + } + public override int GetPreIndent() { return -1; diff --git a/Assets/Fungus/FungusScript/Commands/If.cs b/Assets/Fungus/FungusScript/Commands/If.cs index 7eb1bd64..d36d1018 100644 --- a/Assets/Fungus/FungusScript/Commands/If.cs +++ b/Assets/Fungus/FungusScript/Commands/If.cs @@ -16,7 +16,7 @@ namespace Fungus.Script [CommandInfo("Scripting", "If", - "Execute another sequence IF a condition is true. Sequences can be specified for both true (THEN) and false (ELSE) conditions.", + "If the test expression is true, execute the following block of commands.", 253, 253, 150)] public class If : FungusCommand { @@ -32,10 +32,6 @@ namespace Fungus.Script public StringData stringValue; - public Sequence thenSequence; - - public Sequence elseSequence; - public override void OnEnter() { bool condition = false; @@ -135,36 +131,38 @@ namespace Fungus.Script if (condition) { - if (thenSequence != null) - { - ExecuteSequence(thenSequence); - return; - } + Continue(); } else { - if (elseSequence != null) + // Find the next Else or EndIf command at the same indent level as this If command + bool foundThisCommand = false; + int indent = indentLevel; + foreach(FungusCommand command in parentSequence.commandList) { - ExecuteSequence(elseSequence); - return; + if (foundThisCommand && + command.indentLevel == indent) + { + System.Type type = command.GetType(); + if (type == typeof(Else) || + type == typeof(EndIf)) + { + // Execute command immediately after the Else or EndIf command + Continue(command); + return; + } + } + else if (command == this) + { + foundThisCommand = true; + } } - } - Continue(); - } - - public override void GetConnectedSequences(ref List connectedSequences) - { - if (thenSequence != null) - { - connectedSequences.Add(thenSequence); - } - if (elseSequence != null) - { - connectedSequences.Add(elseSequence); + // No matching EndIf command found, so just stop the sequence + Stop(); } } - + public override string GetSummary() { if (variable == null) @@ -212,26 +210,6 @@ namespace Fungus.Script summary += stringValue.GetDescription(); } - summary += " THEN "; - - if (thenSequence == null) - { - summary += ""; - } - else - { - summary += thenSequence.name; - } - summary += " ELSE "; - if (elseSequence == null) - { - summary += ""; - } - else - { - summary += elseSequence.name; - } - return summary; } diff --git a/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs b/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs index 463177e5..64807a53 100644 --- a/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs @@ -26,7 +26,14 @@ namespace Fungus.Script if (Application.isPlaying) { - t.selectedCommand = t.executingSequence.activeCommand; + if (t.executingSequence == null) + { + t.selectedCommand = null; + } + else + { + t.selectedCommand = t.executingSequence.activeCommand; + } } EditorGUI.BeginChangeCheck(); diff --git a/Assets/Fungus/FungusScript/Editor/IfEditor.cs b/Assets/Fungus/FungusScript/Editor/IfEditor.cs index 0dbd02ab..b4f56a5b 100644 --- a/Assets/Fungus/FungusScript/Editor/IfEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/IfEditor.cs @@ -76,29 +76,6 @@ namespace Fungus.Script EditorGUILayout.PropertyField(serializedObject.FindProperty("stringValue")); } - EditorGUILayout.Separator(); - - Sequence thenSequence = SequenceEditor.SequenceField(new GUIContent("Then", "Sequence to execute if comparision is true"), - new GUIContent(""), - t.GetFungusScript(), - t.thenSequence); - - Sequence elseSequence = SequenceEditor.SequenceField(new GUIContent("Else", "Sequence to execute if comparision is false"), - new GUIContent(""), - t.GetFungusScript(), - t.elseSequence); - - if (thenSequence != t.thenSequence) - { - Undo.RecordObject(t, "Set Then Sequence"); - t.thenSequence = thenSequence; - } - if (elseSequence != t.elseSequence) - { - Undo.RecordObject(t, "Set Else Sequence"); - t.elseSequence = elseSequence; - } - serializedObject.ApplyModifiedProperties(); } } diff --git a/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs b/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs index 99de459e..333fb9f8 100644 --- a/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs +++ b/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs @@ -80,9 +80,14 @@ namespace Fungus.Script } public virtual void Continue() + { + Continue(this); + } + + public virtual void Continue(FungusCommand currentCommand) { OnExit(); - parentSequence.ExecuteNextCommand(this); + parentSequence.ExecuteNextCommand(currentCommand); } public virtual void Stop() diff --git a/Assets/Shuttle/ShuttleGame.unity b/Assets/Shuttle/ShuttleGame.unity index ab1321076ba0b3bcdf0346442942f4418984c82a..2ce356e13e2407fe981a85e1f5d1f9b111a81c17 100644 GIT binary patch delta 7329 zcmZA64SW;j9l-H>w9vXCrcxkCfmEOtS|ETzwt*A@Em&xZPztS5kU`M`1u8AbNOgd5 z78)q!BBBj`oOaHa@Bt0Z4Z>s}JLk5lxOJOAK+u9f>kCrxh5er7u09t&pX=Ry^S|fi z|Ge}Xj((kZ28gxOWeM8-w!YLPT1EY_-c)KAoSKaQJ3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