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 10 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 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()
{
@ -49,7 +49,7 @@ namespace Fungus
if (variable.GetType() == typeof(BooleanVariable))
{
bool lhs = (variable as BooleanVariable).Value;
bool rhs = booleanValue.Value;
bool rhs = booleanData.Value;
switch (compareOperator)
{
@ -65,7 +65,7 @@ namespace Fungus
else if (variable.GetType() == typeof(IntegerVariable))
{
int lhs = (variable as IntegerVariable).Value;
int rhs = integerValue.Value;
int rhs = integerData.Value;
switch (compareOperator)
{
@ -92,7 +92,7 @@ namespace Fungus
else if (variable.GetType() == typeof(FloatVariable))
{
float lhs = (variable as FloatVariable).Value;
float rhs = floatValue.Value;
float rhs = floatData.Value;
switch (compareOperator)
{
@ -119,7 +119,7 @@ namespace Fungus
else if (variable.GetType() == typeof(StringVariable))
{
string lhs = (variable as StringVariable).Value;
string rhs = stringValue.Value;
string rhs = stringData.Value;
switch (compareOperator)
{
@ -199,19 +199,19 @@ namespace Fungus
if (variable.GetType() == typeof(BooleanVariable))
{
summary += booleanValue.GetDescription();
summary += booleanData.GetDescription();
}
else if (variable.GetType() == typeof(IntegerVariable))
{
summary += integerValue.GetDescription();
summary += integerData.GetDescription();
}
else if (variable.GetType() == typeof(FloatVariable))
{
summary += floatValue.GetDescription();
summary += floatData.GetDescription();
}
else if (variable.GetType() == typeof(StringVariable))
{
summary += stringValue.GetDescription();
summary += stringData.GetDescription();
}
return summary;

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

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

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save