Пример #1
0
        public bool IsSetupCorrectly()
        {
            bool returnValue = true;

            List <string> variableNames = new List <string>();

            //Make sure it doesn't match the class name
            if (ForgeNetworkingEditor.IsValidName(ButtonName))
            {
                variableNames.Add(ButtonName);
            }
            else
            {
                returnValue = false;
            }

            string checkedName = string.Empty;

            //Check the fields
            if (returnValue)
            {
                for (int i = 0; i < ClassVariables.Count; ++i)
                {
                    checkedName = ClassVariables[i].FieldName;
                    if (variableNames.Contains(checkedName))
                    {
                        returnValue = false;
                        break;
                    }

                    if (ForgeNetworkingEditor.IsValidName(checkedName))
                    {
                        variableNames.Add(checkedName);
                    }
                    else
                    {
                        Debug.LogError("Invalid Character Found");
                        returnValue = false;
                        break;
                    }
                }
            }

            //Check the rpcs
            if (returnValue)
            {
                for (int i = 0; i < RPCVariables.Count; ++i)
                {
                    checkedName = RPCVariables[i].FieldName;
                    if (variableNames.Contains(checkedName))
                    {
                        returnValue = false;
                        break;
                    }

                    if (ForgeNetworkingEditor.IsValidName(checkedName))
                    {
                        variableNames.Add(checkedName);
                    }
                    else
                    {
                        Debug.LogError("Invalid Character Found");
                        returnValue = false;
                        break;
                    }
                }
            }

            //Check the rewinds
            if (returnValue)
            {
                for (int i = 0; i < RewindVariables.Count; ++i)
                {
                    checkedName = RewindVariables[i].FieldName;
                    if (variableNames.Contains(checkedName))
                    {
                        returnValue = false;
                        break;
                    }

                    if (ForgeNetworkingEditor.IsValidName(checkedName))
                    {
                        variableNames.Add(checkedName);
                    }
                    else
                    {
                        Debug.LogError("Invalid Character Found");
                        returnValue = false;
                        break;
                    }
                }
            }

            return(returnValue);
        }
Пример #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);
        }