Пример #1
0
        internal void AddChild(RSSInstance instance)
        {
            if (Children == null)
            {
                Children = new List <RSSInstance>();
            }

            Children.Add(instance);
        }
Пример #2
0
        private void ProcessCustomWidgetScope(string Line, Statment Stat, string[] details)
        {
            RSSInstance CustomInstance;

            if (!Parser.TryGetWidget(details[0], out CustomInstance))
            {
                throw new ParserException($"No custom widget named {details[0]}");
            }

            RSSInstance Instance = new RSSInstance(CustomInstance.ClassName, details[0], CustomInstance.Name);

            WidgetScope sc = (WidgetScope)Stat.Generate(Line, (Scopes.Count == 0 ? this : Scopes.Peek()));

            sc.Instance = Instance;

            Scopes.Push(sc);
        }
Пример #3
0
        internal bool TryGetWidget(string customWidgetName, out RSSInstance customInstance)
        {
            if (CustomWidgets == null)
            {
                customInstance = null;
                return(false);
            }

            foreach (var Inst in CustomWidgets)
            {
                if (Inst.Name == customWidgetName)
                {
                    customInstance = Inst;
                    return(true);
                }
            }

            customInstance = null;
            return(false);
        }
Пример #4
0
        private void AddToNeccessaryList(RSSInstance Instance)
        {
            if (Instance.IsCustomChild)
            {
                if (CustomWidgets == null)
                {
                    CustomWidgets = new List <RSSInstance>();
                }

                CustomWidgets.Add(Instance);
            }
            else
            {
                if (FinishedWidgets == null)
                {
                    FinishedWidgets = new List <RSSInstance>();
                }

                //Is defined within the top scpoe.
                FinishedWidgets.Add(Instance);
            }
        }
Пример #5
0
        internal void AddStatment(Statment Stat, string line)
        {
            if (Stat == null)
            {
                // Console.WriteLine($"Unkown statment '{line}'");
                return;
            }

            //Check for the mismatch of a type.
            if (Scopes.Count > 0)
            {
                if (Stat.ID != StatmentType.ScopeEnding && Stat.ID != StatmentType.Any)
                {
                    if (!Scopes.Peek().AcceptsStatmentType(Stat.ID))
                    {
                        throw new ParserException("Attempted to open an unaccepted scope");
                    }
                }
            }



            string[] details = Stat.GetDetails(line);

            switch (Stat.ID)
            {
            case StatmentType.Variable:
                ProcessVariable(Stat.GetDetails(line));
                break;

            case StatmentType.ScopeEnding:
                CloseScope();
                break;

            case StatmentType.PropertyAssignment:
                ProcessPropertyAssignment(details, Scopes.Peek());
                break;

            case StatmentType.CustomWidgetScopeOpening:
                ProcessCustomWidgetScope(line, Stat, details);
                //Check the custom class exsists.
                break;

            case StatmentType.StyleScopeOpening:
                ProcessStyleScope(line, details, Stat);
                break;

            case StatmentType.StyleIdOpening:
                ProcessStyleId(details, Stat);
                break;

            default:
                bool        isCustom = line.StartsWith("widget");
                RSSInstance Instance = new RSSInstance(details[0], details[1], isCustom);

                WidgetScope sc = (WidgetScope)Stat.Generate(line, (Scopes.Count == 0 ? this : Scopes.Peek()));

                sc.Instance = Instance;

                Scopes.Push(sc);
                break;
            }
        }
Пример #6
0
        internal static void Parse(Scope Sc, string varVal, string propName, string[] classes = null)
        {
            if (PropertyCallbacks == null)
            {
                AddCallbacks();
            }

            //Properties can be defined within a WidgetScope.

            if (Sc.ID == "Widget")
            {
                var WScope = Sc as WidgetScope;

                if (WScope != null)
                {
                    RSSInstance Instance = WScope.Instance;

                    RobloxProperty Prop;

                    if (!Instance.HasProperty(propName, out Prop))
                    {
                        throw new ParserException($"The Instance {Instance.Name} does not have the property {propName}");
                    }

                    //Check to make sure the value passed isn't a variable.

                    varVal = FetchVarVal(Sc, varVal);

                    //Check for a callback.

                    PropertyProcessCallback Callback;

                    bool isValidFunc = PropertyCallbacks.TryGetValue(Prop.ValueType, out Callback);

                    if (!isValidFunc)
                    {
                        /////ENUM CALLBACK
                        RobloxEnum Enum;
                        if (!RobloxEnum.Enums.TryGetValue(Prop.ValueType, out Enum))
                        {
                            throw new ParserException($"Failed to find the correct datatype for {Prop.Name} for Instance {Instance.Name}");
                        }

                        if (!Enum.HasEnumItem(varVal))
                        {
                            throw new ParserException($"The Enunm {Enum.Name} does not have the item {varVal}");
                        }

                        Instance.AddProperty(new RSSProperty(Prop.Name, Prop.ValueType, new string[] { RSS.RobloxJSONParser.Writer.JSONWriter.Quotify(varVal) }));
                    }
                    else
                    {
                        Instance.AddProperty(new RSSProperty(Prop.Name, Prop.ValueType, Callback(varVal, WScope)));
                    }
                }
            }
            else if (Sc.ID == "StyleId")
            {
                RobloxProperty Prop = null;
                foreach (var Name in classes)
                {
                    RobloxInstance Inst = RobloxParser.RobloxHierachy[Name];

                    if (!Inst.GetProperty(propName, out Prop))
                    {
                        throw new ParserException($"The ClassName {Name} in the style {((StyleScope)Sc.Parent).StyleName} does not have the property you are trying to set: {propName}");
                    }
                }

                PropertyProcessCallback Callback;

                bool isValidFunc = PropertyCallbacks.TryGetValue(Prop.ValueType, out Callback);

                if (isValidFunc)
                {
                    ((StyleIdScope)Sc).AddProperty(new RSSProperty(Prop.Name, Prop.ValueType, Callback(varVal, Sc)));
                }
            }
        }