Browse Source

Added Global flag to Variable

master
chrisgregan 11 years ago
parent
commit
e379e5b597
  1. 21
      Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs
  2. 28
      Assets/Fungus/Editor/FungusScript/VariablesWindow.cs
  3. 4
      Assets/Fungus/VisualScripting/AddOption.cs
  4. 32
      Assets/Fungus/VisualScripting/Jump.cs
  5. 4
      Assets/Fungus/VisualScripting/Say.cs
  6. 30
      Assets/Fungus/VisualScripting/Set.cs
  7. 39
      Assets/Fungus/VisualScripting/Variable.cs
  8. BIN
      Assets/Shuttle/ShuttleGame.unity

21
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;
}
}
}

28
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));

4
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;
}

32
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;

4
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;
}

30
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;

39
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;
public int integerValue;
public float floatValue;
public string stringValue;
public bool BooleanValue
{
get { return booleanValue; }
set { booleanValue = value; }
}
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)
{

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.
Loading…
Cancel
Save