public void draw(Condition c)
        {
            condition = c as VarCondition;

            EditorGUILayout.BeginHorizontal();

            if (Available)
            {
                var vars  = Controller.Instance.VarFlagSummary.getVars();
                var index = Mathf.Max(0, Array.IndexOf(vars, c.getId()));
                condition.setId(vars[EditorGUILayout.Popup(index >= 0 ? index : 0, vars)]);
            }
            else
            {
                using (new GUILayout.HorizontalScope(GUILayout.Height(15)))
                {
                    EditorGUILayout.HelpBox(TC.get("Condition.Var.Warning"), MessageType.Error);
                }
            }

            if (GUILayout.Button("New", collapseStyle, GUILayout.Width(35), GUILayout.Height(15)))
            {
                Controller.Instance.ShowInputDialog(TC.get("Vars.AddVar"), TC.get("Vars.AddVarMessage"), DEFAULT_VAR_ID, condition, this);
            }

            if (Available)
            {
                condition.setState(indexToState[EditorGUILayout.Popup(stateToIndex[condition.getState()], valueStrings)]);
                condition.setValue(int.Parse(EditorGUILayout.TextField(condition.getValue().ToString())));
            }

            EditorGUILayout.EndHorizontal();
        }
Beispiel #2
0
        public void SerializeSingleVarConditionTest()
        {
            var serializedVarCondition = JsonUtility.ToJson(varCondition);

            Debug.Log(serializedVarCondition);
            var restoredVarCondition = JsonUtility.FromJson <VarCondition>(serializedVarCondition);

            Assert.NotNull(restoredVarCondition);
            Assert.AreEqual(varCondition.GetType(), restoredVarCondition.GetType());
            Assert.AreEqual(varCondition.getType(), restoredVarCondition.getType());
            Assert.AreEqual(varCondition.getState(), restoredVarCondition.getState());
            Assert.AreEqual(varCondition.getValue(), restoredVarCondition.getValue());
        }
        public static bool check(Condition condition)
        {
            bool ret = true;

            switch (condition.getType())
            {
            case Condition.FLAG_CONDITION:
                ret = Game.Instance.GameState.CheckFlag(condition.getId()) == condition.getState();
                break;

            case Condition.GLOBAL_STATE_CONDITION:
                ret = Game.Instance.GameState.CheckGlobalState(condition.getId()) == condition.getState();
                break;

            case Condition.NO_STATE: break;

            case Condition.VAR_CONDITION:
                VarCondition c   = (VarCondition)condition;
                int          val = Game.Instance.GameState.GetVariable(condition.getId());

                switch (c.getState())
                {
                case VarCondition.VAR_EQUALS:
                    ret = val == c.getValue();
                    break;

                case VarCondition.VAR_GREATER_THAN:
                    ret = val > c.getValue();
                    break;

                case VarCondition.VAR_GREATER_EQUALS_THAN:
                    ret = val >= c.getValue();
                    break;

                case VarCondition.VAR_LESS_THAN:
                    ret = val < c.getValue();
                    break;

                case VarCondition.VAR_LESS_EQUALS_THAN:
                    ret = val <= c.getValue();
                    break;

                case VarCondition.VAR_NOT_EQUALS:
                    ret = val != c.getValue();
                    break;
                }
                break;
            }

            return(ret);
        }
Beispiel #4
0
        public void draw(Condition c)
        {
            condition = c as VarCondition;

            EditorGUILayout.BeginHorizontal();

            if (Available)
            {
                var vars  = Controller.Instance.VarFlagSummary.getVars();
                var index = Mathf.Max(0, Array.IndexOf(vars, c.getId()));
                condition.setId(vars[EditorGUILayout.Popup(index >= 0 ? index : 0, vars)]);
                condition.setState(indexToState[EditorGUILayout.Popup(stateToIndex[condition.getState()], valueStrings)]);
                condition.setValue(int.Parse(EditorGUILayout.TextField(condition.getValue().ToString())));
            }
            else
            {
                EditorGUILayout.HelpBox(TC.get("Condition.Var.Warning"), MessageType.Error);
            }

            EditorGUILayout.EndHorizontal();
        }
Beispiel #5
0
        private static XmlElement createConditionElement(XmlDocument doc, Condition condition)
        {
            XmlElement conditionElement = null;

            if (condition.getType() == Condition.FLAG_CONDITION)
            {
                // Create the tag
                if (condition.getState() == FlagCondition.FLAG_ACTIVE)
                {
                    conditionElement = doc.CreateElement("active");
                }
                else if (condition.getState() == FlagCondition.FLAG_INACTIVE)
                {
                    conditionElement = doc.CreateElement("inactive");
                }

                // Set the target flag and append it
                conditionElement.SetAttribute("flag", condition.getId());
            }
            else if (condition.getType() == Condition.VAR_CONDITION)
            {
                VarCondition varCondition = (VarCondition)condition;
                // Create the tag
                if (varCondition.getState() == VarCondition.VAR_EQUALS)
                {
                    conditionElement = doc.CreateElement("equals");
                }
                else if (varCondition.getState() == VarCondition.VAR_NOT_EQUALS)
                {
                    conditionElement = doc.CreateElement("not-equals");
                }
                else if (condition.getState() == VarCondition.VAR_GREATER_EQUALS_THAN)
                {
                    conditionElement = doc.CreateElement("greater-equals-than");
                }
                else if (condition.getState() == VarCondition.VAR_GREATER_THAN)
                {
                    conditionElement = doc.CreateElement("greater-than");
                }
                else if (condition.getState() == VarCondition.VAR_LESS_EQUALS_THAN)
                {
                    conditionElement = doc.CreateElement("less-equals-than");
                }
                else if (condition.getState() == VarCondition.VAR_LESS_THAN)
                {
                    conditionElement = doc.CreateElement("less-than");
                }

                // Set the target flag and append it
                conditionElement.SetAttribute("var", varCondition.getId());
                conditionElement.SetAttribute("value", varCondition.getValue().ToString());
            }
            else if (condition.getType() == Condition.GLOBAL_STATE_CONDITION)
            {
                GlobalStateCondition globalStateCondition = (GlobalStateCondition)condition;
                // Create the tag
                conditionElement = doc.CreateElement("global-state-ref");

                // Set the target flag and append it
                conditionElement.SetAttribute("id", globalStateCondition.getId());

                conditionElement.SetAttribute("value",
                                              globalStateCondition.getState() == GlobalStateCondition.GS_SATISFIED ? "true" : "false");
            }

            return(conditionElement);
        }