using System.Collections; using System.Linq; using System.Collections.Generic; using UnityEngine; using Sirenix.OdinInspector; using KairoEngine.Core; namespace KairoEngine.Core.GameActions { [System.Serializable, HideReferenceObjectPicker] public class CompareStringsGameActionCondition : GameActionCondition { public override string name { get { if(equals) return $"{variable} == \"{stringValue}\""; else return $"{variable} != \"{stringValue}\""; } } public override GameActionsController controller { get => _controller; set { _controller = value; typeName = "CompareStringsGameActionCondition"; className = this.GetType().AssemblyQualifiedName; GetCompatibleVariablenames(); } } public override string GetTypeName() => "CompareStringsGameActionCondition"; public override string GetActionName() => "Compare Strings"; [IconFoldoutGroup("@name","Assets/Plugins/KairoEngine/Core/Editor/Icons/CompareStringsGameActionConditionIcon.png")] public string stringValue = ""; [ValueDropdown("possibleVariables", IsUniqueList = false)] [IconFoldoutGroup("@name")] public string variable; [IconFoldoutGroup("@name")] public bool equals = true; private IEnumerable possibleVariables = new ValueDropdownList(); public override bool Evaluate() { if(equals) return GetVariable(variable) == stringValue; else return GetVariable(variable) != stringValue; } private void GetCompatibleVariablenames() { if(_controller == null) return; if(_controller.context == null) return; possibleVariables = _controller.context.variables .Where(x => x.GetTypeName() == "GameActionContextString") .Select(x => new ValueDropdownItem(x.name, x.name)); } public static CompareStringsGameActionCondition JSONToCompareStringsGameActionCondition(string data) { return JsonUtility.FromJson(data); } private CompareStringsGameActionCondition Duplicate() { CompareStringsGameActionCondition condition = new CompareStringsGameActionCondition(); condition.controller = controller; condition.stringValue = stringValue; condition.equals = equals; condition.variable = variable; return condition; } private string GetVariable(string title) { for (int i = 0; i < controller.context.variables.Count; i++) { if(controller.context.variables[i].name == title) { return controller.context.variables[i].GetValue(""); } } return ""; } } }