Exemplo n.º 1
0
        private void TranspileVarNamesPropertyList(sphereScript99Parser.PropertyListContext context)
        {
            if (context.NEWLINE() != null)
            {
                dataBuilder.Append(context.NEWLINE().GetText());
            }

            if (context.propertyAssignment() == null)
            {
                return;
            }

            foreach (var assignment in context.propertyAssignment())
            {
                var name  = assignment.propertyName().GetText();
                var value = assignment.propertyValue()?.GetText();

                if (SharpStriper.TryStrip(value, out string strippedValue))
                {
                    dataVisitor.AppendPropertyAssignment(assignment, strippedValue);
                }
                else
                {
                    dataVisitor.AppendPropertyAssignment(assignment);
                }
            }

            dataBuilder.EnsureNewline();
        }
Exemplo n.º 2
0
        public override bool VisitPropertyList([NotNull] sphereScript99Parser.PropertyListContext context)
        {
            if (context.NEWLINE() != null)
            {
                builder.Append(context.NEWLINE().GetText());
            }

            if (context.propertyAssignment() == null)
            {
                return(true);
            }

            uint?flagValue = null;
            uint?attrValue = null;

            foreach (var assignment in context.propertyAssignment())
            {
                var name  = assignment.propertyName().GetText();
                var value = assignment.propertyValue()?.GetText();

                if (invalidPropertyValues.TryGetValue(name, out IReadOnlyCollection <string> invalidValues) && invalidValues.Contains(value))
                {
                    continue;
                }
                if (specificFlagValues.TryGetValue(name, out uint specificFlagValue))
                {
                    if (!value.Equals("0", StringComparison.OrdinalIgnoreCase))
                    {
                        flagValue = flagValue.HasValue ? flagValue.Value | specificFlagValue : specificFlagValue;
                    }
                }
                else if (specificAttrValues.TryGetValue(name, out uint specificAttrValue))
                {
                    if (!value.Equals("0", StringComparison.OrdinalIgnoreCase))
                    {
                        attrValue = attrValue.HasValue ? attrValue.Value | specificAttrValue : specificAttrValue;
                    }
                }
                else if (name.Equals("MORE1", StringComparison.OrdinalIgnoreCase) || name.Equals("MORE2", StringComparison.OrdinalIgnoreCase))
                {
                    parentVisitor.AppendPropertyAssignment(assignment, value.Trim('"'));
                }
                else if (SharpStriper.TryStrip(value, out string strippedValue))
                {
                    parentVisitor.AppendPropertyAssignment(assignment, strippedValue);
                }
                else if (!forbiddenProperties.Contains(name))
                {
                    parentVisitor.AppendPropertyAssignment(assignment);
                }
            }

            builder.EnsureNewline();

            if (flagValue.HasValue)
            {
                builder.AppendLine($"FLAGS=0{flagValue.Value:X8}");
            }
            if (attrValue.HasValue)
            {
                builder.AppendLine($"ATTR=0{attrValue.Value:X8}");
            }

            return(true);
        }