Esempio n. 1
0
        /// <summary>
        /// Validates Fields to ensure no conflicts on compilation
        /// </summary>
        public ValidationResult Validate(ForgeEditorButton btn)
        {
            ValidationResult result = new ValidationResult();
            Dictionary <string, ForgeEditorField> classVariables = btn.ClassVariables.ToDictionary(x => x.FieldName, y => y);

            foreach (var field in btn.ClassVariables)
            {
                string fieldName = field.FieldName;
                string duplicate = string.Empty;

                if (fieldName.EndsWith("Changed"))
                {
                    duplicate = fieldName.Substring(0, fieldName.LastIndexOf("Changed"));
                    if (classVariables.ContainsKey(duplicate))
                    {
                        result.ReportValidationError(String.Format("Field \"{0}\" conflicts with Changed event of {1}", fieldName, duplicate));
                    }
                }
                if (fieldName.EndsWith("Interpolation"))
                {
                    duplicate = fieldName.Substring(0, fieldName.LastIndexOf("Interpolation"));
                    if (classVariables.ContainsKey(duplicate))
                    {
                        result.ReportValidationError(String.Format("Field \"{0}\" conflicts with Interpolation field of {1}", fieldName, duplicate));
                    }
                }
            }
            return(result);
        }
Esempio n. 2
0
        public ValidationResult ValidateSetup()
        {
            ValidationResult result        = new ValidationResult();
            List <string>    variableNames = new List <string>();

            //Make sure the class name is valid, and that no fields/RPCs/Rewinds match the class name
            if (ForgeNetworkingEditor.IsValidName(ButtonName))
            {
                variableNames.Add(ButtonName);
            }
            else
            {
                result.ReportValidationError(String.Format("Class \"{0}\" has a non-valid name", ButtonName));
            }

            string checkedName = string.Empty;

            //Validate Fields
            for (int i = 0; i < ClassVariables.Count; ++i)
            {
                checkedName = ClassVariables[i].FieldName;
                if (variableNames.Contains(checkedName))
                {
                    result.ReportValidationError(String.Format("Duplicate element \"{0}\" found in \"{1}\"", checkedName, ButtonName));
                }

                switch (ClassVariables[i].FieldName)
                {
                case "IDENTITY":
                case "networkObject":
                case "fieldAltered":
                case "_dirtyFields":
                case "dirtyFields":
                    result.ReportValidationError(String.Format("Field \"{0}\" conflicts with a field name reserved for Forge Networking Remastered", checkedName));
                    break;
                }

                string duplicate = string.Empty;
                if (checkedName.EndsWith("Changed"))
                {
                    duplicate = checkedName.Substring(0, checkedName.LastIndexOf("Changed"));
                    if (variableNames.Contains(duplicate))
                    {
                        result.ReportValidationError(String.Format("Field \"{0}\" conflicts with Changed event of {1}", checkedName, duplicate));
                    }
                }

                if (checkedName.EndsWith("Interpolation"))
                {
                    duplicate = checkedName.Substring(0, checkedName.LastIndexOf("Interpolation"));
                    if (variableNames.Contains(duplicate))
                    {
                        result.ReportValidationError(String.Format("Field \"{0}\" conflicts with Interpolation field of {1}", checkedName, duplicate));
                    }
                }

                //Check if the field name is a valid identifier
                if (ForgeNetworkingEditor.IsValidName(checkedName))
                {
                    variableNames.Add(checkedName);
                }
                else
                {
                    result.ReportValidationError(String.Format("Invalid identifier for Field \"{0}\" in \"{1}\"", checkedName, ButtonName));
                }
            }

            //Validate RPCs
            for (int i = 0; i < RPCVariables.Count; ++i)
            {
                checkedName = RPCVariables[i].FieldName;
                if (variableNames.Contains(checkedName))
                {
                    result.ReportValidationError(String.Format("Duplicate element \"{0}\" found in \"{1}\"", checkedName, ButtonName));
                }

                //Check if RPC name is a valid identifier
                if (ForgeNetworkingEditor.IsValidName(checkedName))
                {
                    variableNames.Add(checkedName);
                }
                else
                {
                    result.ReportValidationError(String.Format("Invalid identifier for RPC \"{0}\" in \"{1}\"", checkedName, ButtonName));
                }

                switch (RPCVariables[i].FieldName.ToLower())
                {
                case "initialize":
                case "networkcreateobject":
                    result.ReportValidationError(String.Format("RPC \"{0}\" conflicts with a method name reserved for Forge Networking Remastered", checkedName));
                    break;
                }

                if (RPCVariables[i].FieldName.StartsWith("get_") ||
                    RPCVariables[i].FieldName.StartsWith("set_"))
                {
                    result.ReportValidationError(String.Format("RPC \"{0}\" cannot start with \"get_\" or \"set_\"", checkedName));
                    break;
                }
            }

            //Validate Rewinds
            for (int i = 0; i < RewindVariables.Count; ++i)
            {
                checkedName = RewindVariables[i].FieldName;
                if (variableNames.Contains(checkedName))
                {
                    result.ReportValidationError(String.Format("Duplicate element \"{0}\" found in \"{1}\"", checkedName, ButtonName));
                }
                //Check if Rewind name is a valid identifier
                if (ForgeNetworkingEditor.IsValidName(checkedName))
                {
                    variableNames.Add(checkedName);
                }
                else
                {
                    result.ReportValidationError(String.Format("Invalid identifier for Rewind \"{0}\" in \"{1}\"", checkedName, ButtonName));
                }
            }

            return(result);
        }