private void CopyVariable(GVar newVar, GVar oldVar) { if (newVar == null || oldVar == null) { ACDebug.LogWarning("Cannot copy variable since it cannot be found!"); return; } if (oldLocation == VariableLocation.Global) { oldVar.Download(); } if (newVar.type == VariableType.Integer || newVar.type == VariableType.Boolean || newVar.type == VariableType.PopUp) { int oldValue = oldVar.val; if (oldVar.type == VariableType.Float) { oldValue = (int)oldVar.floatVal; } else if (oldVar.type == VariableType.String) { float oldValueAsFloat = 0f; float.TryParse(oldVar.textVal, out oldValueAsFloat); oldValue = (int)oldValueAsFloat; } newVar.SetValue(oldValue, SetVarMethod.SetValue); } else if (newVar.type == VariableType.Float) { float oldValue = oldVar.floatVal; if (oldVar.type == VariableType.Integer || oldVar.type == VariableType.Boolean || oldVar.type == VariableType.PopUp) { oldValue = (float)oldVar.val; } else if (oldVar.type == VariableType.String) { float.TryParse(oldVar.textVal, out oldValue); } newVar.SetFloatValue(oldValue, AC.SetVarMethod.SetValue); } else if (newVar.type == VariableType.String) { string oldValue = oldVar.GetValue(); newVar.SetStringValue(oldValue); } }
/** * <summary>Sets the value of a global String variable.</summary> * <param name = "_id">The ID number of the variable</param> * <param name = "_value">The new string value of the variable</param> * <param name = "synchronise">If True, then the variable's value will be synchronised with any external link it may have.</param> */ public static void SetStringValue(int _id, string _value, bool synchronise = true) { GVar var = GetVariable(_id); if (var != null) { var.SetStringValue(_value); if (synchronise) { var.Upload(VariableLocation.Global); } } }
private void UnloadVariablesData(string data, LocalVariables localVariables) { if (data == null) { return; } if (data.Length > 0) { string[] varsArray = data.Split(SaveSystem.pipe[0]); foreach (string chunk in varsArray) { string[] chunkData = chunk.Split(SaveSystem.colon[0]); int _id = 0; int.TryParse(chunkData[0], out _id); GVar var = LocalVariables.GetVariable(_id, localVariables); if (var.type == VariableType.String) { string _text = chunkData[1]; var.SetStringValue(_text); } else if (var.type == VariableType.Float) { float _value = 0f; float.TryParse(chunkData[1], out _value); var.SetFloatValue(_value, SetVarMethod.SetValue); } else { int _value = 0; int.TryParse(chunkData[1], out _value); var.SetValue(_value, SetVarMethod.SetValue); } } } }
private void SetVariable(GVar newVar, VariableLocation _newLocation, GVar oldVar) { if (newVar == null || oldVar == null) { ACDebug.LogWarning("Cannot copy variable since it cannot be found!"); return; } if (oldLocation == VariableLocation.Global) { oldVar.Download(); } if (newVar.type == VariableType.Integer || newVar.type == VariableType.Boolean || newVar.type == VariableType.PopUp) { int oldValue = oldVar.val; newVar.SetValue(oldValue, SetVarMethod.SetValue); } else if (newVar.type == VariableType.Float) { float oldValue = oldVar.floatVal; newVar.SetFloatValue(oldValue, AC.SetVarMethod.SetValue); } else if (newVar.type == VariableType.String) { string oldValue = oldVar.textVal; newVar.SetStringValue(oldValue); } if (_newLocation == VariableLocation.Global) { newVar.Upload(); } KickStarter.actionListManager.VariableChanged(); }
private void UnloadVariablesData(string data, LocalVariables localVariables) { if (data == null) { return; } if (data.Length > 0) { string[] varsArray = data.Split(SaveSystem.pipe[0]); foreach (string chunk in varsArray) { string[] chunkData = chunk.Split(SaveSystem.colon[0]); int _id = 0; int.TryParse(chunkData[0], out _id); GVar _var = LocalVariables.GetVariable(_id, localVariables); if (_var != null) { if (_var.type == VariableType.String) { string _text = chunkData[1]; _var.SetStringValue(_text); } else if (_var.type == VariableType.Float) { float _value = 0f; float.TryParse(chunkData[1], out _value); _var.SetFloatValue(_value, SetVarMethod.SetValue); } else if (_var.type == VariableType.Vector3) { string _text = chunkData[1]; _text = AdvGame.PrepareStringForLoading(_text); Vector3 _value = Vector3.zero; string[] valuesArray = _text.Split(","[0]); if (valuesArray != null && valuesArray.Length == 3) { float xValue = 0f; float.TryParse(valuesArray[0], out xValue); float yValue = 0f; float.TryParse(valuesArray[1], out yValue); float zValue = 0f; float.TryParse(valuesArray[2], out zValue); _value = new Vector3(xValue, yValue, zValue); } _var.SetVector3Value(_value); } else { int _value = 0; int.TryParse(chunkData[1], out _value); _var.SetValue(_value, SetVarMethod.SetValue); } } } } }
private void SetVariable(GVar var, VariableLocation location, bool doSkip) { if (var == null) { return; } if (location == VariableLocation.Global) { var.Download (); } if (var.type == VariableType.Integer) { int _value = 0; if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere) { if (setVarMethod == SetVarMethod.Formula) { _value = (int) AdvGame.CalculateFormula (AdvGame.ConvertTokens (formula)); } else { _value = intValue; } } else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter) { if (animator && parameterName != "") { _value = animator.GetInteger (parameterName); setVarMethod = SetVarMethod.SetValue; } } if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip) { var.RestoreBackupValue (); } var.SetValue (_value, setVarMethod); if (doSkip) { var.BackupValue (); } } if (var.type == VariableType.Float) { float _value = 0; if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere) { if (setVarMethod == SetVarMethod.Formula) { _value = (float) AdvGame.CalculateFormula (AdvGame.ConvertTokens (formula)); } else { _value = floatValue; } } else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter) { if (animator && parameterName != "") { _value = animator.GetFloat (parameterName); setVarMethod = SetVarMethod.SetValue; } } if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip) { var.RestoreBackupValue (); } var.SetFloatValue (_value, setVarMethod); if (doSkip) { var.BackupValue (); } } else if (var.type == VariableType.Boolean) { int _value = 0; if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere) { _value = (int) boolValue; } else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter) { if (animator && parameterName != "") { if (animator.GetBool (parameterName)) { _value = 1; } } } var.SetValue (_value, SetVarMethod.SetValue); } else if (var.type == VariableType.PopUp) { var.SetValue (intValue); } else if (var.type == VariableType.String) { string _value = ""; if (setVarMethodString == SetVarMethodString.EnteredHere) { _value = AdvGame.ConvertTokens (stringValue); } else if (setVarMethodString == SetVarMethodString.SetAsMenuElementText) { MenuElement menuElement = PlayerMenus.GetElementWithName (menuName, elementName); if (menuElement != null) { if (menuElement is MenuInput) { MenuInput menuInput = (MenuInput) menuElement; _value = menuInput.GetContents (); if ((Options.GetLanguageName () == "Arabic" || Options.GetLanguageName () == "Hebrew") && _value.Length > 0) { // Invert char[] charArray = _value.ToCharArray (); _value = ""; for (int i = charArray.Length-1; i >= 0; i --) { _value += charArray[i]; } } } else { PlayerMenus.GetMenuWithName (menuName).Recalculate (); menuElement.PreDisplay (slotNumber, Options.GetLanguage (), false); _value = menuElement.GetLabel (slotNumber, Options.GetLanguage ()); } } else { Debug.LogWarning ("Could not find MenuInput '" + elementName + "' in Menu '" + menuName + "'"); } } var.SetStringValue (_value); } if (location == VariableLocation.Global) { var.Upload (); } KickStarter.actionListManager.VariableChanged (); }
private void SetVariable(GVar var, VariableLocation location, bool doSkip) { if (var == null) { return; } if (location == VariableLocation.Global) { var.Download(); } if (var.type == VariableType.Integer) { int _value = 0; if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere) { if (setVarMethod == SetVarMethod.Formula) { _value = (int)AdvGame.CalculateFormula(AdvGame.ConvertTokens(formula)); } else { _value = intValue; } } else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter) { if (animator && parameterName != "") { _value = animator.GetInteger(parameterName); setVarMethod = SetVarMethod.SetValue; } } if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip) { var.RestoreBackupValue(); } var.SetValue(_value, setVarMethod); if (doSkip) { var.BackupValue(); } } if (var.type == VariableType.Float) { float _value = 0; if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere) { if (setVarMethod == SetVarMethod.Formula) { _value = (float)AdvGame.CalculateFormula(AdvGame.ConvertTokens(formula)); } else { _value = floatValue; } } else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter) { if (animator && parameterName != "") { _value = animator.GetFloat(parameterName); setVarMethod = SetVarMethod.SetValue; } } if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip) { var.RestoreBackupValue(); } var.SetFloatValue(_value, setVarMethod); if (doSkip) { var.BackupValue(); } } else if (var.type == VariableType.Boolean) { int _value = 0; if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere) { _value = (int)boolValue; } else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter) { if (animator && parameterName != "") { if (animator.GetBool(parameterName)) { _value = 1; } } } var.SetValue(_value, SetVarMethod.SetValue); } else if (var.type == VariableType.PopUp) { // var.SetValue (intValue); int _value = 0; if (setVarMethod == SetVarMethod.Formula) { _value = (int)AdvGame.CalculateFormula(AdvGame.ConvertTokens(formula)); } else if (setVarMethod == SetVarMethod.SetAsRandom) { if (var.popUps != null) { _value = var.popUps.Length; } } else { _value = intValue; } if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip) { var.RestoreBackupValue(); } var.SetValue(_value, setVarMethod); if (doSkip) { var.BackupValue(); } } else if (var.type == VariableType.String) { string _value = ""; if (setVarMethodString == SetVarMethodString.EnteredHere) { _value = AdvGame.ConvertTokens(stringValue); } else if (setVarMethodString == SetVarMethodString.SetAsMenuElementText) { MenuElement menuElement = PlayerMenus.GetElementWithName(menuName, elementName); if (menuElement != null) { if (menuElement is MenuInput) { MenuInput menuInput = (MenuInput)menuElement; _value = menuInput.GetContents(); if ((Options.GetLanguageName() == "Arabic" || Options.GetLanguageName() == "Hebrew") && _value.Length > 0) { // Invert char[] charArray = _value.ToCharArray(); _value = ""; for (int i = charArray.Length - 1; i >= 0; i--) { _value += charArray[i]; } } } else { PlayerMenus.GetMenuWithName(menuName).Recalculate(); menuElement.PreDisplay(slotNumber, Options.GetLanguage(), false); _value = menuElement.GetLabel(slotNumber, Options.GetLanguage()); } } else { ACDebug.LogWarning("Could not find MenuInput '" + elementName + "' in Menu '" + menuName + "'"); } } var.SetStringValue(_value); } if (location == VariableLocation.Global) { var.Upload(); } KickStarter.actionListManager.VariableChanged(); }
private void SetVariable(GVar newVar, VariableLocation _newLocation, GVar oldVar) { if (newVar == null || oldVar == null) { ACDebug.LogWarning ("Cannot copy variable since it cannot be found!"); return; } if (oldLocation == VariableLocation.Global) { oldVar.Download (); } if (newVar.type == VariableType.Integer || newVar.type == VariableType.Boolean) { int oldValue = oldVar.val; newVar.SetValue (oldValue, SetVarMethod.SetValue); } else if (newVar.type == VariableType.Float) { float oldValue = oldVar.floatVal; newVar.SetFloatValue (oldValue, AC.SetVarMethod.SetValue); } else if (newVar.type == VariableType.String) { string oldValue = oldVar.textVal; newVar.SetStringValue (oldValue); } if (_newLocation == VariableLocation.Global) { newVar.Upload (); } KickStarter.actionListManager.VariableChanged (); }
protected void SetVariable(GVar var, VariableLocation location, bool doSkip) { if (var == null) { return; } switch (var.type) { case VariableType.Integer: { int _value = 0; if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere) { if (setVarMethod == SetVarMethod.Formula) { _value = (int)AdvGame.CalculateFormula(AdvGame.ConvertTokens(formula, Options.GetLanguage(), localVariables)); } else { _value = intValue; } } else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter) { if (animator && !string.IsNullOrEmpty(parameterName)) { _value = animator.GetInteger(parameterName); setVarMethod = SetVarMethod.SetValue; } } if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip) { var.RestoreBackupValue(); } var.SetValue(_value, setVarMethod); if (doSkip) { var.BackupValue(); } break; } case VariableType.Float: { float _value = 0; if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere) { if (setVarMethod == SetVarMethod.Formula) { _value = (float)AdvGame.CalculateFormula(AdvGame.ConvertTokens(formula, Options.GetLanguage(), localVariables)); } else { _value = floatValue; } } else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter) { if (animator && !string.IsNullOrEmpty(parameterName)) { _value = animator.GetFloat(parameterName); setVarMethod = SetVarMethod.SetValue; } } if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip) { var.RestoreBackupValue(); } var.SetFloatValue(_value, setVarMethod); if (doSkip) { var.BackupValue(); } break; } case VariableType.Boolean: { int _value = 0; if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere) { _value = (int)boolValue; } else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter) { if (animator && !string.IsNullOrEmpty(parameterName)) { if (animator.GetBool(parameterName)) { _value = 1; } } } var.SetValue(_value, SetVarMethod.SetValue); break; } case VariableType.Vector3: { Vector3 newValue = vector3Value; if (setVarMethodVector == SetVarMethodVector.IncreaseByValue) { newValue += var.vector3Val; } var.SetVector3Value(newValue); break; } case VariableType.PopUp: { int _value = 0; if (setVarMethod == SetVarMethod.Formula) { _value = (int)AdvGame.CalculateFormula(AdvGame.ConvertTokens(formula, Options.GetLanguage(), localVariables)); } else if (setVarMethod == SetVarMethod.SetAsRandom) { _value = var.GetNumPopUpValues(); } else { _value = Mathf.Clamp(intValue, 0, var.GetNumPopUpValues() - 1); } if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip) { var.RestoreBackupValue(); } var.SetValue(_value, setVarMethod); if (doSkip) { var.BackupValue(); } break; } case VariableType.String: { string _value = string.Empty; if (setVarMethodString == SetVarMethodString.EnteredHere) { _value = AdvGame.ConvertTokens(stringValue, Options.GetLanguage(), localVariables); } else if (setVarMethodString == SetVarMethodString.SetAsMenuElementText) { MenuElement menuElement = PlayerMenus.GetElementWithName(menuName, elementName); if (menuElement != null) { if (menuElement is MenuInput) { MenuInput menuInput = (MenuInput)menuElement; _value = menuInput.GetContents(); if (KickStarter.runtimeLanguages.LanguageReadsRightToLeft(Options.GetLanguage()) && _value.Length > 0) { // Invert char[] charArray = _value.ToCharArray(); _value = ""; for (int i = charArray.Length - 1; i >= 0; i--) { _value += charArray[i]; } } } else { PlayerMenus.GetMenuWithName(menuName).Recalculate(); menuElement.PreDisplay(slotNumber, Options.GetLanguage(), false); _value = menuElement.GetLabel(slotNumber, Options.GetLanguage()); } } else { LogWarning("Could not find MenuInput '" + elementName + "' in Menu '" + menuName + "'"); } } var.SetStringValue(_value, lineID); break; } default: break; } var.Upload(location, runtimeVariables); KickStarter.actionListManager.VariableChanged(); }