From e379e5b5977205297115771ae10ab7b406945f9c Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Wed, 6 Aug 2014 18:20:38 +0100 Subject: [PATCH] Added Global flag to Variable --- .../Editor/FungusScript/FungusScriptEditor.cs | 21 +++++++--- .../Editor/FungusScript/VariablesWindow.cs | 28 ++++++++++--- Assets/Fungus/VisualScripting/AddOption.cs | 4 +- Assets/Fungus/VisualScripting/Jump.cs | 32 +++++++------- Assets/Fungus/VisualScripting/Say.cs | 4 +- Assets/Fungus/VisualScripting/Set.cs | 30 +++++++------- Assets/Fungus/VisualScripting/Variable.cs | 39 ++++++++++++++++-- Assets/Shuttle/ShuttleGame.unity | Bin 78148 -> 77860 bytes 8 files changed, 108 insertions(+), 50 deletions(-) diff --git a/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs b/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs index 36d53ef7..767c9bcc 100644 --- a/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs +++ b/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs @@ -16,19 +16,29 @@ namespace Fungus.Script { SerializedProperty keyProp = property.FindPropertyRelative("key"); SerializedProperty typeProp = property.FindPropertyRelative("type"); + SerializedProperty scopeProp = property.FindPropertyRelative("scope"); // Draw the text field control GUI. EditorGUI.BeginChangeCheck(); + float width1 = position.width * 0.5f; + float width2 = position.width * 0.25f; + float width3 = position.width * 0.25f; + Rect keyRect = position; - keyRect.width *= 0.5f; + keyRect.width = width1; Rect typeRect = position; - typeRect.x += keyRect.width; - typeRect.width -= keyRect.width; + typeRect.x += width1; + typeRect.width = width2; + + Rect scopeRect = position; + scopeRect.x += width1 + width2; + scopeRect.width = width3; string keyValue = EditorGUI.TextField(keyRect, label, keyProp.stringValue); - int selectedEnum = (int)(VariableType)EditorGUI.EnumPopup(typeRect, (VariableType)typeProp.enumValueIndex); + int typeValue = (int)(VariableType)EditorGUI.EnumPopup(typeRect, (VariableType)typeProp.enumValueIndex); + int scopeValue = (int)(VariableScope)EditorGUI.EnumPopup(scopeRect, (VariableScope)scopeProp.enumValueIndex); if (EditorGUI.EndChangeCheck ()) { @@ -37,7 +47,8 @@ namespace Fungus.Script keyValue = new string(arr); keyProp.stringValue = keyValue; - typeProp.enumValueIndex = selectedEnum; + typeProp.enumValueIndex = typeValue; + scopeProp.enumValueIndex = scopeValue; } } } diff --git a/Assets/Fungus/Editor/FungusScript/VariablesWindow.cs b/Assets/Fungus/Editor/FungusScript/VariablesWindow.cs index 3e6afcb8..e25b5bd2 100644 --- a/Assets/Fungus/Editor/FungusScript/VariablesWindow.cs +++ b/Assets/Fungus/Editor/FungusScript/VariablesWindow.cs @@ -28,13 +28,14 @@ namespace Fungus.Script bool showValues = Application.isPlaying; - float columnWidth = (position.width - 40) / (showValues ? 3 : 2); + float columnWidth = (position.width - 40) / (showValues ? 4 : 3); scrollPos = GUILayout.BeginScrollView(scrollPos); GUILayout.BeginHorizontal(); GUILayout.Label("Key", GUILayout.Width(columnWidth)); GUILayout.Label("Type", GUILayout.Width(columnWidth)); + GUILayout.Label("Scope", GUILayout.Width(columnWidth)); if (showValues) { GUILayout.Label("Value", GUILayout.Width(columnWidth)); @@ -53,37 +54,52 @@ namespace Fungus.Script string keyString = variable.key; string typeString = ""; + string scopeString = ""; string valueString = ""; + switch (variable.scope) + { + default: + case VariableScope.Local: + scopeString = "Local"; + break; + case VariableScope.Global: + scopeString = "Global"; + break; + } + switch (variable.type) { case VariableType.Boolean: typeString = "Boolean"; - valueString = variable.booleanValue ? "True" : "False"; + valueString = variable.BooleanValue ? "True" : "False"; break; case VariableType.Integer: typeString = "Integer"; - valueString = variable.integerValue.ToString(); + valueString = variable.IntegerValue.ToString(); break; case VariableType.Float: typeString = "Float"; - valueString = variable.floatValue.ToString(); + valueString = variable.FloatValue.ToString(); break; case VariableType.String: typeString = "String"; - if (variable.stringValue.Length == 0) + + if (variable.StringValue == null || + variable.StringValue.Length == 0) { valueString = "\"\""; } else { - valueString = variable.stringValue; + valueString = variable.StringValue; } break; } GUILayout.Label(keyString, GUILayout.Width(columnWidth)); GUILayout.Label(typeString, GUILayout.Width(columnWidth)); + GUILayout.Label(scopeString, GUILayout.Width(columnWidth)); if (showValues) { GUILayout.Label(valueString, GUILayout.Width(columnWidth)); diff --git a/Assets/Fungus/VisualScripting/AddOption.cs b/Assets/Fungus/VisualScripting/AddOption.cs index d8f8c6c5..f9a40566 100644 --- a/Assets/Fungus/VisualScripting/AddOption.cs +++ b/Assets/Fungus/VisualScripting/AddOption.cs @@ -47,12 +47,12 @@ namespace Fungus.Script else { if (showCondition == ShowCondition.BooleanIsTrue && - v.booleanValue != true) + v.BooleanValue != true) { showOption = false; } else if (showCondition == ShowCondition.BooleanIsFalse && - v.booleanValue != false) + v.BooleanValue != false) { showOption = false; } diff --git a/Assets/Fungus/VisualScripting/Jump.cs b/Assets/Fungus/VisualScripting/Jump.cs index 23980db4..c9ed145f 100644 --- a/Assets/Fungus/VisualScripting/Jump.cs +++ b/Assets/Fungus/VisualScripting/Jump.cs @@ -61,11 +61,11 @@ namespace Fungus.Script switch (compareOperator) { case CompareOperator.Equals: - condition = (v.booleanValue == booleanData.value); + condition = (v.BooleanValue == booleanData.value); break; case CompareOperator.NotEquals: default: - condition = (v.booleanValue != booleanData.value); + condition = (v.BooleanValue != booleanData.value); break; } break; @@ -73,22 +73,22 @@ namespace Fungus.Script switch (compareOperator) { case CompareOperator.Equals: - condition = (v.integerValue == integerData.value); + condition = (v.IntegerValue == integerData.value); break; case CompareOperator.NotEquals: - condition = (v.integerValue != integerData.value); + condition = (v.IntegerValue != integerData.value); break; case CompareOperator.LessThan: - condition = (v.integerValue < integerData.value); + condition = (v.IntegerValue < integerData.value); break; case CompareOperator.GreaterThan: - condition = (v.integerValue > integerData.value); + condition = (v.IntegerValue > integerData.value); break; case CompareOperator.LessThanOrEquals: - condition = (v.integerValue <= integerData.value); + condition = (v.IntegerValue <= integerData.value); break; case CompareOperator.GreaterThanOrEquals: - condition = (v.integerValue >= integerData.value); + condition = (v.IntegerValue >= integerData.value); break; } break; @@ -96,22 +96,22 @@ namespace Fungus.Script switch (compareOperator) { case CompareOperator.Equals: - condition = (v.floatValue == floatData.value); + condition = (v.FloatValue == floatData.value); break; case CompareOperator.NotEquals: - condition = (v.floatValue != floatData.value); + condition = (v.FloatValue != floatData.value); break; case CompareOperator.LessThan: - condition = (v.floatValue < floatData.value); + condition = (v.FloatValue < floatData.value); break; case CompareOperator.GreaterThan: - condition = (v.floatValue > floatData.value); + condition = (v.FloatValue > floatData.value); break; case CompareOperator.LessThanOrEquals: - condition = (v.floatValue <= floatData.value); + condition = (v.FloatValue <= floatData.value); break; case CompareOperator.GreaterThanOrEquals: - condition = (v.floatValue >= floatData.value); + condition = (v.FloatValue >= floatData.value); break; } break; @@ -119,11 +119,11 @@ namespace Fungus.Script switch (compareOperator) { case CompareOperator.Equals: - condition = (v.stringValue == stringData.value); + condition = (v.StringValue == stringData.value); break; case CompareOperator.NotEquals: default: - condition = (v.stringValue != stringData.value); + condition = (v.StringValue != stringData.value); break; } break; diff --git a/Assets/Fungus/VisualScripting/Say.cs b/Assets/Fungus/VisualScripting/Say.cs index cab79c29..0e34b2bc 100644 --- a/Assets/Fungus/VisualScripting/Say.cs +++ b/Assets/Fungus/VisualScripting/Say.cs @@ -54,12 +54,12 @@ namespace Fungus.Script else { if (showCondition == ShowCondition.BooleanIsTrue && - v.booleanValue != true) + v.BooleanValue != true) { showSayText = false; } else if (showCondition == ShowCondition.BooleanIsFalse && - v.booleanValue != false) + v.BooleanValue != false) { showSayText = false; } diff --git a/Assets/Fungus/VisualScripting/Set.cs b/Assets/Fungus/VisualScripting/Set.cs index 6882e615..7fed6d32 100644 --- a/Assets/Fungus/VisualScripting/Set.cs +++ b/Assets/Fungus/VisualScripting/Set.cs @@ -50,10 +50,10 @@ namespace Fungus.Script { default: case SetOperator.Assign: - v.booleanValue = booleanData.value; + v.BooleanValue = booleanData.value; break; case SetOperator.Negate: - v.booleanValue = !booleanData.value; + v.BooleanValue = !booleanData.value; break; } break; @@ -62,22 +62,22 @@ namespace Fungus.Script { default: case SetOperator.Assign: - v.integerValue = integerData.value; + v.IntegerValue = integerData.value; break; case SetOperator.Negate: - v.integerValue = -integerData.value; + v.IntegerValue = -integerData.value; break; case SetOperator.Add: - v.integerValue += integerData.value; + v.IntegerValue += integerData.value; break; case SetOperator.Subtract: - v.integerValue -= integerData.value; + v.IntegerValue -= integerData.value; break; case SetOperator.Multiply: - v.integerValue *= integerData.value; + v.IntegerValue *= integerData.value; break; case SetOperator.Divide: - v.integerValue /= integerData.value; + v.IntegerValue /= integerData.value; break; } break; @@ -86,22 +86,22 @@ namespace Fungus.Script { default: case SetOperator.Assign: - v.floatValue = floatData.value; + v.FloatValue = floatData.value; break; case SetOperator.Negate: - v.floatValue = -floatData.value; + v.FloatValue = -floatData.value; break; case SetOperator.Add: - v.floatValue += floatData.value; + v.FloatValue += floatData.value; break; case SetOperator.Subtract: - v.floatValue -= floatData.value; + v.FloatValue -= floatData.value; break; case SetOperator.Multiply: - v.floatValue *= floatData.value; + v.FloatValue *= floatData.value; break; case SetOperator.Divide: - v.floatValue /= floatData.value; + v.FloatValue /= floatData.value; break; } break; @@ -110,7 +110,7 @@ namespace Fungus.Script { default: case SetOperator.Assign: - v.stringValue = stringData.value; + v.StringValue = stringData.value; break; } break; diff --git a/Assets/Fungus/VisualScripting/Variable.cs b/Assets/Fungus/VisualScripting/Variable.cs index fceb88fd..7c6af58d 100644 --- a/Assets/Fungus/VisualScripting/Variable.cs +++ b/Assets/Fungus/VisualScripting/Variable.cs @@ -13,16 +13,47 @@ namespace Fungus.Script String }; + public enum VariableScope + { + Local, + Global + }; + [Serializable] public class Variable { public string key; public VariableType type; + public VariableScope scope; + + bool booleanValue; + int integerValue; + float floatValue; + string stringValue; + + public bool BooleanValue + { + get { return booleanValue; } + set { booleanValue = value; } + } - public bool booleanValue; - public int integerValue; - public float floatValue; - public string stringValue; + public int IntegerValue + { + get { return integerValue; } + set { integerValue = value; } + } + + public float FloatValue + { + get { return floatValue; } + set { floatValue = value; } + } + + public string StringValue + { + get { return stringValue; } + set { stringValue = value; } + } public bool IsSameType(Variable other) { diff --git a/Assets/Shuttle/ShuttleGame.unity b/Assets/Shuttle/ShuttleGame.unity index 6450ab0a27132ab3cfa82865ab200a14d5c4da9b..e80b8d6bffa755b809b116f63cfa7af278d371d8 100644 GIT binary patch delta 766 zcmY+?J1j#{7zgn0=pBfnTdzs$QSYSjib1GnFk)zgq=LkoV(1{b7ExQHLpvBqj3Q|o zVUctY>1dIdq$n*0iB~$H{#Vb9bBB|A&+mMXbI!eIx6*!0G7-Ich}lbtCz_WQ=0?L^svO(z|0M;*}ya=tQb|7MAa^T9sOw4f1WY$^u3(c(SfdBvi delta 821 zcmY+APiPZS5XR@lZHbc9EgPEzLTyc}=^ruvD;^A{8YT7Aih2+Qqo!?eO`5nu4~6!m zJqG5m9t1DmymSd-4vGkZ6+F~~SE;3Hsx}9!60lak?QV4QV0iESzHesUn+J>1izP`W zT1%7IpCF>GIL{dJBM%QpB!1<27&teS)sE1WTux1=vgcFkEm&df=E0C6XR;b0(qrku zrolbEZI$T4d->+HwZQdb`k8S z&5nb~yNPBTz7u9WFf;du?Mr~w{`=ZD8=nN6+(R@4<8Rw|$~1ERs}h@y5G9~&*vb%; z1+cSVk{$0mKV69Q5Ix1c{`4iV3O`4MWN%}IWhg~3XN3=@8_fBsk6=k|T~(&%`-sL- zyZ(&|lxTk=TLHTZHVI#SRG-1*y+oQL_Y2r8nCf8SEv0HEa}ljM@11!#>s>I5N8pqPPY~<-M(IvR+ zL)-;+8O%AVFj$#Ks){QxP#Ucsl}h)&HFfdSFONRaE=L`?2g7zTjVCLI!;R