Browse Source

Fixed copy and paste bug with StringData, etc.

Changed these classes to structs instead of classes so they’d be copied
by value rather than by reference when pasting.
master
chrisgregan 11 years ago
parent
commit
f4adbe631d
  1. 24
      Assets/Fungus/FungusScript/Commands/If.cs
  2. 24
      Assets/Fungus/FungusScript/Editor/IfEditor.cs
  3. 17
      Assets/Fungus/FungusScript/Editor/VariableEditor.cs
  4. 24
      Assets/Fungus/FungusScript/Scripts/BooleanVariable.cs
  5. 24
      Assets/Fungus/FungusScript/Scripts/FloatVariable.cs
  6. 24
      Assets/Fungus/FungusScript/Scripts/IntegerVariable.cs
  7. 24
      Assets/Fungus/FungusScript/Scripts/StringVariable.cs

24
Assets/Fungus/FungusScript/Commands/If.cs

@ -23,13 +23,13 @@ namespace Fungus
public CompareOperator compareOperator; public CompareOperator compareOperator;
public BooleanData booleanValue; public BooleanData booleanData;
public IntegerData integerValue; public IntegerData integerData;
public FloatData floatValue; public FloatData floatData;
public StringData stringValue; public StringData stringData;
public override void OnEnter() public override void OnEnter()
{ {
@ -49,7 +49,7 @@ namespace Fungus
if (variable.GetType() == typeof(BooleanVariable)) if (variable.GetType() == typeof(BooleanVariable))
{ {
bool lhs = (variable as BooleanVariable).Value; bool lhs = (variable as BooleanVariable).Value;
bool rhs = booleanValue.Value; bool rhs = booleanData.Value;
switch (compareOperator) switch (compareOperator)
{ {
@ -65,7 +65,7 @@ namespace Fungus
else if (variable.GetType() == typeof(IntegerVariable)) else if (variable.GetType() == typeof(IntegerVariable))
{ {
int lhs = (variable as IntegerVariable).Value; int lhs = (variable as IntegerVariable).Value;
int rhs = integerValue.Value; int rhs = integerData.Value;
switch (compareOperator) switch (compareOperator)
{ {
@ -92,7 +92,7 @@ namespace Fungus
else if (variable.GetType() == typeof(FloatVariable)) else if (variable.GetType() == typeof(FloatVariable))
{ {
float lhs = (variable as FloatVariable).Value; float lhs = (variable as FloatVariable).Value;
float rhs = floatValue.Value; float rhs = floatData.Value;
switch (compareOperator) switch (compareOperator)
{ {
@ -119,7 +119,7 @@ namespace Fungus
else if (variable.GetType() == typeof(StringVariable)) else if (variable.GetType() == typeof(StringVariable))
{ {
string lhs = (variable as StringVariable).Value; string lhs = (variable as StringVariable).Value;
string rhs = stringValue.Value; string rhs = stringData.Value;
switch (compareOperator) switch (compareOperator)
{ {
@ -199,19 +199,19 @@ namespace Fungus
if (variable.GetType() == typeof(BooleanVariable)) if (variable.GetType() == typeof(BooleanVariable))
{ {
summary += booleanValue.GetDescription(); summary += booleanData.GetDescription();
} }
else if (variable.GetType() == typeof(IntegerVariable)) else if (variable.GetType() == typeof(IntegerVariable))
{ {
summary += integerValue.GetDescription(); summary += integerData.GetDescription();
} }
else if (variable.GetType() == typeof(FloatVariable)) else if (variable.GetType() == typeof(FloatVariable))
{ {
summary += floatValue.GetDescription(); summary += floatData.GetDescription();
} }
else if (variable.GetType() == typeof(StringVariable)) else if (variable.GetType() == typeof(StringVariable))
{ {
summary += stringValue.GetDescription(); summary += stringData.GetDescription();
} }
return summary; return summary;

24
Assets/Fungus/FungusScript/Editor/IfEditor.cs

@ -12,19 +12,19 @@ namespace Fungus
{ {
protected SerializedProperty variableProp; protected SerializedProperty variableProp;
protected SerializedProperty compareOperatorProp; protected SerializedProperty compareOperatorProp;
protected SerializedProperty booleanValueProp; protected SerializedProperty booleanDataProp;
protected SerializedProperty integerValueProp; protected SerializedProperty integerDataProp;
protected SerializedProperty floatValueProp; protected SerializedProperty floatDataProp;
protected SerializedProperty stringValueProp; protected SerializedProperty stringDataProp;
protected virtual void OnEnable() protected virtual void OnEnable()
{ {
variableProp = serializedObject.FindProperty("variable"); variableProp = serializedObject.FindProperty("variable");
compareOperatorProp = serializedObject.FindProperty("compareOperator"); compareOperatorProp = serializedObject.FindProperty("compareOperator");
booleanValueProp = serializedObject.FindProperty("booleanValue"); booleanDataProp = serializedObject.FindProperty("booleanData");
integerValueProp = serializedObject.FindProperty("integerValue"); integerDataProp = serializedObject.FindProperty("integerData");
floatValueProp = serializedObject.FindProperty("floatValue"); floatDataProp = serializedObject.FindProperty("floatData");
stringValueProp = serializedObject.FindProperty("stringValue"); stringDataProp = serializedObject.FindProperty("stringData");
} }
public override void DrawCommandGUI() public override void DrawCommandGUI()
@ -71,19 +71,19 @@ namespace Fungus
if (variableType == typeof(BooleanVariable)) if (variableType == typeof(BooleanVariable))
{ {
EditorGUILayout.PropertyField(booleanValueProp); EditorGUILayout.PropertyField(booleanDataProp);
} }
else if (variableType == typeof(IntegerVariable)) else if (variableType == typeof(IntegerVariable))
{ {
EditorGUILayout.PropertyField(integerValueProp); EditorGUILayout.PropertyField(integerDataProp);
} }
else if (variableType == typeof(FloatVariable)) else if (variableType == typeof(FloatVariable))
{ {
EditorGUILayout.PropertyField(floatValueProp); EditorGUILayout.PropertyField(floatDataProp);
} }
else if (variableType == typeof(StringVariable)) else if (variableType == typeof(StringVariable))
{ {
EditorGUILayout.PropertyField(stringValueProp); EditorGUILayout.PropertyField(stringDataProp);
} }
serializedObject.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties();

17
Assets/Fungus/FungusScript/Editor/VariableEditor.cs

@ -71,8 +71,8 @@ namespace Fungus
{ {
EditorGUI.BeginProperty(position, label, property); EditorGUI.BeginProperty(position, label, property);
SerializedProperty referenceProp = property.FindPropertyRelative("booleanReference"); SerializedProperty referenceProp = property.FindPropertyRelative("booleanRef");
SerializedProperty valueProp = property.FindPropertyRelative("booleanValue"); SerializedProperty valueProp = property.FindPropertyRelative("booleanVal");
const int popupWidth = 65; const int popupWidth = 65;
@ -143,8 +143,8 @@ namespace Fungus
{ {
EditorGUI.BeginProperty(position, label, property); EditorGUI.BeginProperty(position, label, property);
SerializedProperty referenceProp = property.FindPropertyRelative("integerReference"); SerializedProperty referenceProp = property.FindPropertyRelative("integerRef");
SerializedProperty valueProp = property.FindPropertyRelative("integerValue"); SerializedProperty valueProp = property.FindPropertyRelative("integerVal");
const int popupWidth = 65; const int popupWidth = 65;
@ -215,8 +215,8 @@ namespace Fungus
{ {
EditorGUI.BeginProperty(position, label, property); EditorGUI.BeginProperty(position, label, property);
SerializedProperty referenceProp = property.FindPropertyRelative("floatReference"); SerializedProperty referenceProp = property.FindPropertyRelative("floatRef");
SerializedProperty valueProp = property.FindPropertyRelative("floatValue"); SerializedProperty valueProp = property.FindPropertyRelative("floatVal");
const int popupWidth = 65; const int popupWidth = 65;
@ -287,8 +287,8 @@ namespace Fungus
{ {
EditorGUI.BeginProperty(position, label, property); EditorGUI.BeginProperty(position, label, property);
SerializedProperty referenceProp = property.FindPropertyRelative("stringReference"); SerializedProperty referenceProp = property.FindPropertyRelative("stringRef");
SerializedProperty valueProp = property.FindPropertyRelative("stringValue"); SerializedProperty valueProp = property.FindPropertyRelative("stringVal");
const int popupWidth = 65; const int popupWidth = 65;
@ -299,6 +299,7 @@ namespace Fungus
if (referenceProp.objectReferenceValue == null) if (referenceProp.objectReferenceValue == null)
{ {
// StringData stringData = valueProp.serializedObject
valueProp.stringValue = EditorGUI.TextField(valueRect, valueProp.stringValue); valueProp.stringValue = EditorGUI.TextField(valueRect, valueProp.stringValue);
popupRect.x += valueRect.width + 5; popupRect.x += valueRect.width + 5;
popupRect.width = popupWidth; popupRect.width = popupWidth;

24
Assets/Fungus/FungusScript/Scripts/BooleanVariable.cs

@ -7,39 +7,39 @@ namespace Fungus
public class BooleanVariable : Variable public class BooleanVariable : Variable
{ {
protected bool booleanValue; protected bool booleanVal;
public bool Value public bool Value
{ {
get { return (scope == VariableScope.Local) ? booleanValue : GlobalVariables.GetBoolean(key); } get { return (scope == VariableScope.Local) ? booleanVal : GlobalVariables.GetBoolean(key); }
set { if (scope == VariableScope.Local) { booleanValue = value; } else { GlobalVariables.SetBoolean(key, value); } } set { if (scope == VariableScope.Local) { booleanVal = value; } else { GlobalVariables.SetBoolean(key, value); } }
} }
} }
[System.Serializable] [System.Serializable]
public class BooleanData public struct BooleanData
{ {
[SerializeField] [SerializeField]
protected BooleanVariable booleanReference; public BooleanVariable booleanRef;
[SerializeField] [SerializeField]
protected bool booleanValue; public bool booleanVal;
public bool Value public bool Value
{ {
get { return (booleanReference == null) ? booleanValue : booleanReference.Value; } get { return (booleanRef == null) ? booleanVal : booleanRef.Value; }
set { if (booleanReference == null) { booleanValue = value; } else { booleanReference.Value = value; } } set { if (booleanRef == null) { booleanVal = value; } else { booleanRef.Value = value; } }
} }
public virtual string GetDescription() public string GetDescription()
{ {
if (booleanReference == null) if (booleanRef == null)
{ {
return booleanValue.ToString(); return booleanVal.ToString();
} }
else else
{ {
return booleanReference.key; return booleanRef.key;
} }
} }
} }

24
Assets/Fungus/FungusScript/Scripts/FloatVariable.cs

@ -6,39 +6,39 @@ namespace Fungus
public class FloatVariable : Variable public class FloatVariable : Variable
{ {
protected float floatValue; protected float floatVal;
public float Value public float Value
{ {
get { return (scope == VariableScope.Local) ? floatValue : GlobalVariables.GetFloat(key); } get { return (scope == VariableScope.Local) ? floatVal : GlobalVariables.GetFloat(key); }
set { if (scope == VariableScope.Local) { floatValue = value; } else { GlobalVariables.SetFloat(key, value); } } set { if (scope == VariableScope.Local) { floatVal = value; } else { GlobalVariables.SetFloat(key, value); } }
} }
} }
[System.Serializable] [System.Serializable]
public class FloatData public struct FloatData
{ {
[SerializeField] [SerializeField]
protected FloatVariable floatReference; public FloatVariable floatRef;
[SerializeField] [SerializeField]
protected float floatValue; public float floatVal;
public float Value public float Value
{ {
get { return (floatReference == null) ? floatValue : floatReference.Value; } get { return (floatRef == null) ? floatVal : floatRef.Value; }
set { if (floatReference == null) { floatValue = value; } else { floatReference.Value = value; } } set { if (floatRef == null) { floatVal = value; } else { floatRef.Value = value; } }
} }
public virtual string GetDescription() public string GetDescription()
{ {
if (floatReference == null) if (floatRef == null)
{ {
return floatValue.ToString(); return floatVal.ToString();
} }
else else
{ {
return floatReference.key; return floatRef.key;
} }
} }
} }

24
Assets/Fungus/FungusScript/Scripts/IntegerVariable.cs

@ -6,39 +6,39 @@ namespace Fungus
public class IntegerVariable : Variable public class IntegerVariable : Variable
{ {
protected int integerValue; protected int integerVal;
public int Value public int Value
{ {
get { return (scope == VariableScope.Local) ? integerValue : GlobalVariables.GetInteger(key); } get { return (scope == VariableScope.Local) ? integerVal : GlobalVariables.GetInteger(key); }
set { if (scope == VariableScope.Local) { integerValue = value; } else { GlobalVariables.SetInteger(key, value); } } set { if (scope == VariableScope.Local) { integerVal = value; } else { GlobalVariables.SetInteger(key, value); } }
} }
} }
[System.Serializable] [System.Serializable]
public class IntegerData public struct IntegerData
{ {
[SerializeField] [SerializeField]
protected IntegerVariable integerReference; public IntegerVariable integerRef;
[SerializeField] [SerializeField]
protected int integerValue; public int integerVal;
public int Value public int Value
{ {
get { return (integerReference == null) ? integerValue : integerReference.Value; } get { return (integerRef == null) ? integerVal : integerRef.Value; }
set { if (integerReference == null) { integerValue = value; } else { integerReference.Value = value; } } set { if (integerRef == null) { integerVal = value; } else { integerRef.Value = value; } }
} }
public virtual string GetDescription() public string GetDescription()
{ {
if (integerReference == null) if (integerRef == null)
{ {
return integerValue.ToString(); return integerVal.ToString();
} }
else else
{ {
return integerReference.key; return integerRef.key;
} }
} }
} }

24
Assets/Fungus/FungusScript/Scripts/StringVariable.cs

@ -6,39 +6,39 @@ namespace Fungus
public class StringVariable : Variable public class StringVariable : Variable
{ {
protected string stringValue; protected string stringVal;
public string Value public string Value
{ {
get { return (scope == VariableScope.Local) ? stringValue : GlobalVariables.GetString(key); } get { return (scope == VariableScope.Local) ? stringVal : GlobalVariables.GetString(key); }
set { if (scope == VariableScope.Local) { stringValue = value; } else { GlobalVariables.SetString(key, value); } } set { if (scope == VariableScope.Local) { stringVal = value; } else { GlobalVariables.SetString(key, value); } }
} }
} }
[System.Serializable] [System.Serializable]
public class StringData public struct StringData
{ {
[SerializeField] [SerializeField]
protected StringVariable stringReference; public StringVariable stringRef;
[SerializeField] [SerializeField]
protected string stringValue; public string stringVal;
public string Value public string Value
{ {
get { return (stringReference == null) ? stringValue : stringReference.Value; } get { return (stringRef == null) ? stringVal : stringRef.Value; }
set { if (stringReference == null) { stringValue = value; } else { stringReference.Value = value; } } set { if (stringRef == null) { stringVal = value; } else { stringRef.Value = value; } }
} }
public virtual string GetDescription() public string GetDescription()
{ {
if (stringReference == null) if (stringRef == null)
{ {
return stringValue; return stringVal;
} }
else else
{ {
return stringReference.key; return stringRef.key;
} }
} }
} }

Loading…
Cancel
Save