public override bool VisitFirstMemberAccess([NotNull] sphereScript99Parser.FirstMemberAccessContext context)
        {
            var name = new FirstMemberAccessNameVisitor().Visit(context);

            if (name.Equals("setlocation", StringComparison.OrdinalIgnoreCase))
            {
                var arguments = new FinalChainedMemberAccessArgumentsVisitor().Visit(context);
                if (arguments != null && arguments.Length > 0)
                {
                    parentTranspiler.AppendArguments(arguments);
                    builder.AppendLine();
                    return(true);
                }
            }

            return(base.VisitFirstMemberAccess(context));
        }
Example #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);
        }