From 9afdeda1b63b68b9175c03ae1bc9edac9a34abda Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Wed, 6 Aug 2014 16:11:19 +0100 Subject: [PATCH] Set command supports operators. --- .../Fungus/Editor/FungusScript/SetEditor.cs | 88 ++++++++++++++++++ Assets/Fungus/VisualScripting/Set.cs | 77 ++++++++++++++- Assets/Shuttle/ShuttleGame.unity | Bin 77764 -> 78148 bytes 3 files changed, 161 insertions(+), 4 deletions(-) diff --git a/Assets/Fungus/Editor/FungusScript/SetEditor.cs b/Assets/Fungus/Editor/FungusScript/SetEditor.cs index ee21179e..d3604e0f 100644 --- a/Assets/Fungus/Editor/FungusScript/SetEditor.cs +++ b/Assets/Fungus/Editor/FungusScript/SetEditor.cs @@ -36,7 +36,95 @@ namespace Fungus.Script { return; } + + List operatorsList = new List(); + operatorsList.Add(new GUIContent("=")); + if (variableType == VariableType.Boolean) + { + operatorsList.Add(new GUIContent("!")); + } + else if (variableType == VariableType.Integer || + variableType == VariableType.Float) + { + operatorsList.Add(new GUIContent("+")); + operatorsList.Add(new GUIContent("-")); + operatorsList.Add(new GUIContent("*")); + operatorsList.Add(new GUIContent("/")); + } + + int selectedIndex = 0; + switch (t.setOperator) + { + default: + case Set.SetOperator.Assign: + selectedIndex = 0; + break; + case Set.SetOperator.Negate: + selectedIndex = 1; + break; + case Set.SetOperator.Add: + selectedIndex = 1; + break; + case Set.SetOperator.Subtract: + selectedIndex = 2; + break; + case Set.SetOperator.Multiply: + selectedIndex = 3; + break; + case Set.SetOperator.Divide: + selectedIndex = 4; + break; + } + + selectedIndex = EditorGUILayout.Popup(new GUIContent("Operator", "Arithmetic operator to use"), selectedIndex, operatorsList.ToArray()); + + Set.SetOperator setOperator = Set.SetOperator.Assign; + switch (variableType) + { + default: + case VariableType.Boolean: + case VariableType.String: + switch (selectedIndex) + { + default: + case 0: + setOperator = Set.SetOperator.Assign; + break; + case 1: + setOperator = Set.SetOperator.Negate; + break; + } + break; + case VariableType.Integer: + case VariableType.Float: + switch (selectedIndex) + { + default: + case 0: + setOperator = Set.SetOperator.Assign; + break; + case 1: + setOperator = Set.SetOperator.Add; + break; + case 2: + setOperator = Set.SetOperator.Subtract; + break; + case 3: + setOperator = Set.SetOperator.Multiply; + break; + case 4: + setOperator = Set.SetOperator.Divide; + break; + } + break; + } + if (setOperator != t.setOperator) + { + Undo.RecordObject(t, "Set Operator"); + t.setOperator = setOperator; + } + bool booleanValue = t.booleanData.value; int integerValue = t.integerData.value; float floatValue = t.floatData.value; diff --git a/Assets/Fungus/VisualScripting/Set.cs b/Assets/Fungus/VisualScripting/Set.cs index 6a808ba4..6882e615 100644 --- a/Assets/Fungus/VisualScripting/Set.cs +++ b/Assets/Fungus/VisualScripting/Set.cs @@ -6,8 +6,20 @@ namespace Fungus.Script public class Set : FungusCommand { + public enum SetOperator + { + Assign, // = + Negate, // ! + Add, // + + Subtract, // - + Multiply, // * + Divide // / + } + public string variableKey; + public SetOperator setOperator; + public BooleanData booleanData; public IntegerData integerData; @@ -34,16 +46,73 @@ namespace Fungus.Script switch (v.type) { case VariableType.Boolean: - v.booleanValue = booleanData.value; + switch (setOperator) + { + default: + case SetOperator.Assign: + v.booleanValue = booleanData.value; + break; + case SetOperator.Negate: + v.booleanValue = !booleanData.value; + break; + } break; case VariableType.Integer: - v.integerValue = integerData.value; + switch (setOperator) + { + default: + case SetOperator.Assign: + v.integerValue = integerData.value; + break; + case SetOperator.Negate: + v.integerValue = -integerData.value; + break; + case SetOperator.Add: + v.integerValue += integerData.value; + break; + case SetOperator.Subtract: + v.integerValue -= integerData.value; + break; + case SetOperator.Multiply: + v.integerValue *= integerData.value; + break; + case SetOperator.Divide: + v.integerValue /= integerData.value; + break; + } break; case VariableType.Float: - v.floatValue = floatData.value; + switch (setOperator) + { + default: + case SetOperator.Assign: + v.floatValue = floatData.value; + break; + case SetOperator.Negate: + v.floatValue = -floatData.value; + break; + case SetOperator.Add: + v.floatValue += floatData.value; + break; + case SetOperator.Subtract: + v.floatValue -= floatData.value; + break; + case SetOperator.Multiply: + v.floatValue *= floatData.value; + break; + case SetOperator.Divide: + v.floatValue /= floatData.value; + break; + } break; case VariableType.String: - v.stringValue = stringData.value; + switch (setOperator) + { + default: + case SetOperator.Assign: + v.stringValue = stringData.value; + break; + } break; } } diff --git a/Assets/Shuttle/ShuttleGame.unity b/Assets/Shuttle/ShuttleGame.unity index ce9ccb4b417a512a54b5584b14383504e87a4cce..6450ab0a27132ab3cfa82865ab200a14d5c4da9b 100644 GIT binary patch delta 1343 zcmZA1Ur19?90%~Maks2-iq9ur&Tm&D7qOu4*=)8SzkiONI@ViFG=TYU&9bl*?4iz_ z-x~r^2hmv=Yr_Rg!DQ}hZMb0_PNHtyE81`kvjGjUx`ntuTESKs2aD+nw!xxaq88X+E$%RE64nk=v@zqDKkeO2^gIH{Z{aL3 z1=O$lJ*;g@VZjfu7))RAqs)crbLV7kZQ-KlVdJn)^py`Bk>{QQ`s)6pv`?@&O#dz{ zz|32T!dkM7`wWZ1jLT`7O0uXiWW5R&t|a5?4g z%fR$ccLf&Mwb(d+#@(=Sm|S35+v=+@|L#KTfjxuikHqm|w2$`47r5bnV<)f!sBi3o zJ%e?i33}wdlGZg(ZSnt-ZR1jPpPk(W0XU0-fX8+|BPxEG zRiB-GTb3>_S59Wg39e!c=c(XLhZFs)ayj0m4=UsGCyS|H-pebQvGeX?W_7EFZ{VkE YJ^tuMGKxCs;VNUGiD)jF_VCp5e=bvhM*si- delta 1109 zcmY+@Ur19?90%~Y0=ASeQM*3ipu#v&6nOTxP2wRZk zQ&@+(6ME2x-U^Zt>m~3(aBn5#bIU9jJp`E%rmgSQySjTg+;czY_xqhc_uPdQY2m#j z6RlSe`xc03FZ#-y{Km}X$&7icSS+eGZV-+NC%eV0*&+@kZ0r&KghPx}$l^wsBnA`J z;xYP<5>{>$;WCSOo!HM_u~cjkUlZlRT4@#Xw9H3@W7^I>!SMT%nU&;hWpIi6lHb>S zQY?hYH*&e$O+2^HUN{%A6OEz2rCS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