/// <summary>
        /// Tries to add a <see cref="NPCChatConditionalCollectionItemBase"/> to the <see cref="ConditionalCollection"/>.
        /// </summary>
        /// <param name="item">The item to add.</param>
        /// <returns>True if the <paramref name="item"/> was successfully added; otherwise false.</returns>
        public bool TryAddToConditionalCollection(NPCChatConditionalCollectionItemBase item)
        {
            if (ConditionalCollection == null)
            {
                return(false);
            }

            return(ConditionalCollection.TryAddItem(item));
        }
示例#2
0
 public XmlConnectionDescription(
     ConnectionName name,
     XmlComponentPoint start,
     XmlComponentPoint end,
     ConditionalCollection <ConnectionEdge> edge)
 {
     Name  = name;
     Start = start;
     End   = end;
     Edge  = edge;
 }
示例#3
0
        private bool TryParseTextAlignment(XAttribute alignmentAttribute, out ConditionalCollection <TextAlignment> alignment)
        {
            string tAlignment = "TopLeft";

            if (alignmentAttribute != null)
            {
                tAlignment = alignmentAttribute.Value;
            }

            if (!tAlignment.StartsWith("$"))
            {
                if (!Enum.TryParse(tAlignment, out TextAlignment singleAlignment))
                {
                    logger.LogError(alignmentAttribute, $"Invalid value for text alignment: '{tAlignment}'");
                    alignment = null;
                    return(false);
                }

                alignment = new ConditionalCollection <TextAlignment>
                {
                    new Conditional <TextAlignment>(singleAlignment, ConditionTree.Empty),
                };
                return(true);
            }
            else
            {
                // Check variable exists
                var variableName = tAlignment.Substring(1);
                if (!definitionsSection.Definitions.TryGetValue(variableName, out var variableValues))
                {
                    logger.LogError(alignmentAttribute, $"Variable '{tAlignment}' does not exist");
                    alignment = null;
                    return(false);
                }

                // Check all possible values are valid
                alignment = new ConditionalCollection <TextAlignment>();
                foreach (var variableValue in variableValues)
                {
                    if (!Enum.TryParse(variableValue.Value, out TextAlignment parsedValue) || !Enum.IsDefined(typeof(TextAlignment), parsedValue))
                    {
                        logger.LogError(alignmentAttribute, $"Value '{variableValue.Value}' for ${variableName} is not a valid text alignment");
                        return(false);
                    }

                    alignment.Add(new Conditional <TextAlignment>(parsedValue, variableValue.Conditions));
                }

                return(true);
            }
        }
示例#4
0
        private bool ReadConnection(XElement connectionElement, out XmlConnectionDescription connection)
        {
            ConnectionEdge edge = ConnectionEdge.None;

            if (connectionElement.Attribute("edge") != null)
            {
                string edgeText = connectionElement.Attribute("edge").Value.ToLowerInvariant();
                if (edgeText == "start")
                {
                    edge = ConnectionEdge.Start;
                }
                else if (edgeText == "end")
                {
                    edge = ConnectionEdge.End;
                }
                else if (edgeText == "both")
                {
                    edge = ConnectionEdge.Both;
                }
            }
            string connectionName;

            if (connectionElement.Attribute("name") != null)
            {
                connectionName = connectionElement.Attribute("name").Value;
            }
            else
            {
                connectionName = $"#{unnamedConnectionId++}";
            }

            if (!componentPointParser.TryParse(connectionElement.Attribute("start"), out var start) ||
                !componentPointParser.TryParse(connectionElement.Attribute("end"), out var end))
            {
                connection = null;
                return(false);
            }

            var edgeConditional = new ConditionalCollection <ConnectionEdge>();

            edgeConditional.Add(new Conditional <ConnectionEdge>(edge, ConditionTree.Empty));

            connection = new XmlConnectionDescription(
                connectionName,
                start,
                end,
                edgeConditional);

            return(true);
        }
示例#5
0
        private bool TryReadDouble(XAttribute attr, out ConditionalCollection <double> result)
        {
            if (!attr.Value.StartsWith("$"))
            {
                if (double.TryParse(attr.Value, out var plainValue))
                {
                    result = new ConditionalCollection <double> {
                        new Conditional <double>(plainValue, ConditionTree.Empty)
                    };
                    return(true);
                }

                result = null;
                return(false);
            }

            // Check variable exists
            var variableName = attr.Value.Substring(1);

            if (!definitionsSection.Definitions.TryGetValue(variableName, out var variableValues))
            {
                logger.LogError(attr, $"Variable '{attr.Value}' does not exist");
                result = null;
                return(false);
            }

            // Check all possible values are valid
            result = new ConditionalCollection <double>();
            foreach (var variableValue in variableValues)
            {
                if (!double.TryParse(variableValue.Value, out var parsedValue))
                {
                    logger.LogError(attr, $"Value '{attr.Value}' for ${variableName} is not a valid number");
                    return(false);
                }

                result.Add(new Conditional <double>(parsedValue, variableValue.Conditions));
            }

            return(true);
        }
        public void ReadSection(XElement element, ComponentDescription description)
        {
            var definitions = new Dictionary <string, ConditionalCollection <string> >();

            foreach (var definitionNode in element.Elements(XmlLoader.ComponentNamespace + "def"))
            {
                if (!definitionNode.GetAttributeValue("name", logger, out var name))
                {
                    continue;
                }

                var values = new ConditionalCollection <string>();
                foreach (var valueWhen in definitionNode.Elements(XmlLoader.ComponentNamespace + "when"))
                {
                    valueWhen.GetAttribute("conditions", logger, out var conditionsAttribute);
                    valueWhen.GetAttributeValue("value", logger, out var whenValue);
                    conditionParser.Parse(conditionsAttribute, description, logger, out var conditions);

                    values.Add(new Conditional <string>(whenValue, conditions));
                }

                definitions.Add(name, values);
            }

            foreach (var constNode in element.Elements(XmlLoader.ComponentNamespace + "const"))
            {
                if (!constNode.GetAttributeValue("name", logger, out var name) ||
                    !constNode.GetAttributeValue("value", logger, out var value))
                {
                    continue;
                }

                var values = new ConditionalCollection <string>();
                values.Add(new Conditional <string>(value, ConditionTree.Empty));

                definitions.Add(name, values);
            }

            sectionRegistry.RegisterSection(new DefinitionsSection(definitions));
        }
        protected override bool TryParseOffset(string offset, OffsetAxis axis, FileRange range, out IXmlComponentPointOffset result)
        {
            if (!offset.Contains("$"))
            {
                // Does not contain a variable
                return(base.TryParseOffset(offset, axis, range, out result));
            }

            offset = offset.Replace("(", "").Replace(")", "");

            var variableIndex = offset.IndexOf("$");
            var variableName  = offset.Substring(variableIndex + 1);

            // Check variable exists
            if (!definitionsSection.Definitions.TryGetValue(variableName, out var variableValues))
            {
                logger.Log(LogLevel.Error, range, $"Variable '{variableName}' does not exist", null);
                result = null;
                return(false);
            }

            // Check all possible values are valid
            var parsedValues = new ConditionalCollection <double>();

            foreach (var variableValue in variableValues)
            {
                if (!double.TryParse(variableValue.Value, NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var parsedValue))
                {
                    logger.Log(LogLevel.Error, range, $"Value '{variableValue.Value}' for ${variableName} is not a valid decimal", null);
                    result = null;
                    return(false);
                }

                parsedValues.Add(new TypeDescription.Conditions.Conditional <double>(parsedValue, variableValue.Conditions));
            }

            result = new ComponentPointOffsetWithDefinition(offset.First() == '-', parsedValues, axis);
            return(true);
        }
        void EvaluationTypeComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ConditionalCollection == null || EvaluationTypeComboBox == null)
            {
                return;
            }

            var item = EvaluationTypeComboBox.SelectedItem;

            if (item == null)
            {
                return;
            }

            var t = (NPCChatConditionalEvaluationType)item;

            if (!EnumHelper <NPCChatConditionalEvaluationType> .IsDefined(t))
            {
                EvaluationTypeComboBox.SelectedItem = ConditionalCollection.EvaluationType;
                return;
            }

            ConditionalCollection.SetEvaluationType(t);
        }
示例#9
0
 public ComponentPointOffsetWithDefinition(bool negative, ConditionalCollection <double> values, OffsetAxis axis)
 {
     Negative = negative;
     Values   = values;
     Axis     = axis;
 }