Beispiel #1
0
    public static void Export(Package package)
    {
        List <object[]> coms = new List <object[]>();

        foreach (ResourceComponent component in package.ComponentList)
        {
            if (component.isIngore)
            {
                continue;
            }

            coms.Add(new object[] { component.classNameExtend });
        }


        TemplateSystem template = new TemplateSystem(File.ReadAllText(TsPathTemplate.Binder));

        template.AddVariable("namespace", package.nameSpace);
        template.AddVariable("className", package.classNameBinder);
        template.AddVariable("coms", coms.ToArray());
        string content = template.Parse();
        string path    = string.Format(TsPathOut.Binder, package.codeFolderName, package.classNameBinder);

        PathHelper.CheckPath(path);
        File.WriteAllText(path, content);
    }
Beispiel #2
0
        public void ExportConfigReaderStruct()
        {
            List <object[]> dicts  = new List <object[]>();
            List <object[]> fields = new List <object[]>();

            for (int i = 0; i < dataStruct.fields.Count; i++)
            {
                DataField dataField = dataStruct.fields[i];

                if (dataField.fieldNameIsEnable)
                {
                    object[] lines = new object[] { dataField.field, GetParseTxt(dataField) };
                    fields.Add(lines);
                }
                else
                {
                    object[] lines = new object[] { dataField.field, GetParseTxt(dataField) };
                    dicts.Add(lines);
                }
            }


            TemplateSystem template = new TemplateSystem(File.ReadAllText(TemplatingFiles.Client.ConfigReaderStructTemplate));

            template.AddVariable("classNameConfig", classNameConfig);
            template.AddVariable("classNameConfigReaderStruct", classNameConfigReaderStruct);
            template.AddVariable("tableName", tableName);
            template.AddVariable("fields", fields.ToArray());
            template.AddVariable("dicts", dicts.ToArray());
            string content = template.Parse();
            string path    = string.Format(OutPaths.Client.ConfigReaderStructTemplate, classNameConfigReaderStruct);

            PathHelper.CheckPath(path);
            File.WriteAllText(path, content);
        }
        public void SaveCode()
        {
            List <object[]> fields = new List <object[]>();


            // 0 KeyField
            // 1 KeyValue
            // 2 ID
            // 3 ModuleName
            // 4 Name
            for (int i = 0; i < dataList.Count; i++)
            {
                Dictionary <string, string> rowData = dataList[i];

                object[] lines = new object[5];
                lines[0] = rowData[option.keyField].Replace("-", "_").Replace(" ", "");
                lines[1] = rowData[option.keyField];
                lines[2] = rowData[option.idField];
                lines[3] = string.IsNullOrEmpty(option.txtModuleField) ? string.Empty : rowData[option.txtModuleField];
                lines[4] = rowData[option.txtNameField];

                fields.Add(lines);
            }


            TemplateSystem template = new TemplateSystem(File.ReadAllText(option.tplPath));

            template.AddVariable("className", option.codeClassname);
            template.AddVariable("fields", fields.ToArray());
            string content = template.Parse();
            string path    = option.codePath;

            PathHelper.CheckPath(path);
            File.WriteAllText(path, content);
        }
        /// <summary>
        /// Generates the network manager that will allow the instantiation of these new network objects
        /// </summary>
        /// <returns>The string to save to a file</returns>
        public string SourceCodeNetworkManager()
        {
            TextAsset      asset    = Resources.Load <TextAsset>(EDITOR_RESOURCES_DIR + "/NetworkManagerTemplate");
            TemplateSystem template = new TemplateSystem(asset.text);

            List <object> networkObjects = new List <object>();

            for (int i = 0; i < _editorButtons.Count; ++i)
            {
                if (!_editorButtons[i].IsNetworkObject || _editorButtons[i].BaseType == ForgeBaseClassType.NetworkBehavior)
                {
                    continue;
                }

                string name = _editorButtons[i].StrippedSearchName;
                if (networkObjects.Contains(name))
                {
                    continue;
                }

                networkObjects.Add(name);
            }

            template.AddVariable("networkObjects", networkObjects.ToArray());
            return(template.Parse());
        }
Beispiel #5
0
        public MenuManager( ContentManager content, SpriteBatch spriteBatch, GraphicsDevice graphicsDevice )
        {
            // Start constructor.

            // Initializing the instance:
            Instance = this;

            _content = content;

            _graphicsDevice = graphicsDevice;

            _spriteBatch = spriteBatch;

            // Setting up the template manager:
            templateManager = new TemplateSystem();

            // Setting up the menu list:
            listCount = MenuDefines.defaultNumberOfMenus;
            menuList = new Menu[ listCount ];

            // Variable to hold a temp template index:
            tempTemplateIndex = 0;

            // Putting empty menus in the list:
            for (i = 0; i < listCount; i++)
            {
                menuList[i] = new Menu();
            }
        }
        /// <summary>
        /// Generates the code factory for all our custom network objects
        /// </summary>
        /// <returns>The string for the save file</returns>
        public string SourceCodeFactory()
        {
            TextAsset      asset    = Resources.Load <TextAsset>(EDITOR_RESOURCES_DIR + "/NetworkObjectFactoryTemplate");
            TemplateSystem template = new TemplateSystem(asset.text);

            List <object> networkObjects = new List <object>();

            for (int i = 0; i < _editorButtons.Count; ++i)
            {
                if (!_editorButtons[i].IsNetworkObject)
                {
                    continue;
                }

                string name = _editorButtons[i].StrippedSearchName + "NetworkObject";
                if (networkObjects.Contains(name))
                {
                    continue;
                }

                networkObjects.Add(name);
            }

            template.AddVariable("networkObjects", networkObjects.ToArray());
            return(template.Parse());
        }
Beispiel #7
0
    public static void Export(Package package)
    {
        List <object[]> coms = new List <object[]>();

        foreach (ResourceComponent component in package.sounds)
        {
            if (!component.exported)
            {
                continue;
            }

            coms.Add(new object[] { component.classNameExtend, component.name, component.id, Path.GetExtension(component.name) });
        }


        TemplateSystem template = new TemplateSystem(File.ReadAllText(TsPathTemplate.SoundKey));

        template.AddVariable("packageName", package.name);
        template.AddVariable("packageId", package.id);
        template.AddVariable("list", coms.ToArray());
        string content = template.Parse();
        string path    = TsPathOut.SoundKey;

        PathHelper.CheckPath(path);
        File.WriteAllText(path, content);
    }
Beispiel #8
0
        public void ExportConfig()
        {
            List <object[]> langs = new List <object[]>();


            for (int i = 0; i < dataStruct.fields.Count; i++)
            {
                DataField dataField = dataStruct.fields[i];

                if (dataField.field.StartsWith("zh_cn_"))
                {
                    object[] lines = new object[] { dataField.field.Replace("zh_cn_", ""), dataField.field };
                    langs.Add(lines);
                }
                else if (dataField.field.StartsWith("cn_"))
                {
                    object[] lines = new object[] { dataField.field.Replace("cn_", ""), dataField.field };
                    langs.Add(lines);
                }
            }


            TemplateSystem template = new TemplateSystem(File.ReadAllText(TemplatingFiles.Client.ConfigTemplate));

            template.AddVariable("classNameConfig", classNameConfig);
            template.AddVariable("classNameConfigStruct", classNameConfigStruct);
            template.AddVariable("langs", langs.ToArray());
            string content = template.Parse();
            string path    = string.Format(OutPaths.Client.ConfigTemplate, classNameConfig);


            PathHelper.CheckPath(path);
            File.WriteAllText(path, content);
        }
Beispiel #9
0
    private static string GenerateFunCode(ProtoMessageData data)
    {
        TemplateSystem template = new TemplateSystem(tplAction);

        template.AddVariable("cnname", data.cnname);
        template.AddVariable("funName", data.name);
        template.AddVariable("msgType", data.resFullName);
        string content = template.Parse();

        return(content);
    }
Beispiel #10
0
        public void ExportConfigReader()
        {
            TemplateSystem template = new TemplateSystem(File.ReadAllText(TemplatingFiles.Client.ConfigReaderTemplate));

            template.AddVariable("classNameConfigReader", classNameConfigReader);
            template.AddVariable("classNameConfigReaderStruct", classNameConfigReaderStruct);
            string content = template.Parse();
            string path    = string.Format(OutPaths.Client.ConfigReaderTemplate, classNameConfigReader);


            PathHelper.CheckPath(path);
            File.WriteAllText(path, content);
        }
Beispiel #11
0
    /// <summary>
    /// 导出扩展
    /// </summary>
    private void ExportExtend()
    {
        TemplateSystem template = new TemplateSystem(File.ReadAllText(TsPathTemplate.ComponentExtend));

        template.AddVariable("namespace", com.nameSpace);
        template.AddVariable("classNameFGUI", com.classNameFGUI);
        template.AddVariable("classNameStruct", com.classNameStruct);
        template.AddVariable("classNameExtend", com.classNameExtend);
        string content = template.Parse();
        string path    = string.Format(TsPathOut.ComponentExtend, com.package.codeFolderName, name);

        PathHelper.CheckPath(path);
        File.WriteAllText(path, content);
    }
    private static string CreateDynamicData(string path, bool isClass)
    {
        TextAsset textAsset = Resources.Load <TextAsset>(path);

        TemplateSystem template = new TemplateSystem(textAsset.text);

        if (isClass)
        {
            for (int i = 0; i < ItemCreatorWindow.items.Count; i++)
            {
                template.AddVariable(PrepareClassTemplate());
            }
        }

        return(template.ParseData(isClass));
    }
Beispiel #13
0
        public static void ExportConfigIncludes(List <ExportClientTS> list)
        {
            List <object[]> lines = new List <object[]>();

            foreach (ExportClientTS item in list)
            {
                lines.Add(new object[] { item.classNameConfig });
            }
            TemplateSystem template = new TemplateSystem(File.ReadAllText(TemplatingFiles.Client.ConfigIncludesTemplate));

            template.AddVariable("list", lines.ToArray());
            string content = template.Parse();
            string path    = OutPaths.Client.ConfigIncludesTemplate;


            PathHelper.CheckPath(path);
            File.WriteAllText(path, content);
        }
    private static string GenerateFunCode(ProtoMessageData data)
    {
        List <string>   note = new List <string>();
        List <string>   args = new List <string>();
        List <object[]> list = new List <object[]>();

        note.Add("/**");
        note.Add($"         * {data.cnname}");


        int index = 0;
        int count = data.req.fields.Count;

        foreach (var kvp in data.req.fields)
        {
            // 0 fieldName
            // 1 fieldType
            // 2 ,或者空
            // 3 注释

            FieldData field = kvp.Value;

            list.Add(new object[] { field.fieldName, field.tsType, index >= count - 1 ? string.Empty : ",", field.cnname });
            args.Add($"{field.fieldName}: {field.tsType}");
            note.Add($"		 * @param {field.fieldName}  {field.cnname}");
            index++;
        }

        note.Add("         */");


        TemplateSystem template = new TemplateSystem(tplAction);

        template.AddVariable("cnname", data.cnname);
        template.AddVariable("funName", data.name);
        template.AddVariable("fullClassName", data.reqFullName);
        template.AddVariable("args", String.Join(", ", args));
        template.AddVariable("note", String.Join("\n", note));

        template.AddVariable("list", list.ToArray());
        string content = template.Parse();

        return(content);
    }
    private static void ExportStruct(ProtoStructData data)
    {
        string path = string.Format(TsPathOut.OobHandler, data.funName);

        if (File.Exists(path))
        {
            return;
        }


        TemplateSystem template = new TemplateSystem(tplContent);

        template.AddVariable("funName", data.funName);
        template.AddVariable("fullClassName", data.fullClassName);
        string content = template.Parse();

        PathHelper.CheckPath(path);
        File.WriteAllText(path, content);
    }
    public static void Export(List <Package> packageList)
    {
        List <object[]> list = new List <object[]>();

        foreach (Package package in packageList)
        {
            list.Add(new object[] { package.codeFolderName, package.name });
        }


        TemplateSystem template = new TemplateSystem(File.ReadAllText(TsPathTemplate.GuiPackageNames));

        template.AddVariable("packlist", list.ToArray());
        string content = template.Parse();
        string path    = TsPathOut.GuiPackageNames;

        PathHelper.CheckPath(path);
        File.WriteAllText(path, content);
    }
Beispiel #17
0
 protected void DrawDefaultInspector()
 {
     if (this.ScriptObject == null)
     {
         EditorGUILayout.BeginHorizontal();
         if (this.graph.baseNodeType.Equals(typeof(StateNode)) && this.GetType().Equals(typeof(StateNode)))
         {
             this.scriptName = EditorGUILayout.TextField("状态脚本名称", this.scriptName);
             if (GUILayout.Button("创建"))
             {
                 if (string.IsNullOrEmpty(this.scriptName))
                 {
                     return;
                 }
                 string    path  = EditorUtility.OpenFolderPanel("选择保存脚本路径", "", "");
                 TextAsset asset = Resources.Load <TextAsset>("ScriptsTemplate/ClientStateTemplate");
                 if (asset != null)
                 {
                     TemplateSystem template = new TemplateSystem(asset.text);
                     template.AddVariable("className", this.scriptName);
                     path = path + "/" + this.scriptName + ".cs";
                     using (StreamWriter sw = File.CreateText(path))
                     {
                         sw.Write(template.Parse());
                     }
                 }
                 AssetDatabase.Refresh();
                 //EditorTool.OpenScriptOfType(typeof(ClientStateBase), scriptName);
             }
             else if (this.graph.baseNodeType.Equals(typeof(UINode)))
             {
             }
         }
         EditorGUILayout.EndHorizontal();
     }
     else
     {
         if (this.graph.baseNodeType.Equals(typeof(StateNode)) && this.GetType().Equals(typeof(StateNode)))
         {
         }
     }
 }
    public static void Export(ProtoManager pm)
    {
        List <object[]> ooblist = new List <object[]>();

        List <ProtoStructData> oobValues = pm.structReader.structs.Values;

        foreach (var oob in oobValues)
        {
            ooblist.Add(new object[] { oob.funName });
        }


        TemplateSystem template = new TemplateSystem(File.ReadAllText(TsPathTemplate.ProtoOobHandler));

        template.AddVariable("ooblist", ooblist.ToArray());
        string content = template.Parse();
        string path    = string.Format(TsPathOut.ProtoOobHandler);

        PathHelper.CheckPath(path);
        File.WriteAllText(path, content);
    }
    public static void Export(ProtoManager pm)
    {
        List <object[]> apilist = new List <object[]>();

        List <ProtoModuleData> apiValues = pm.apiReader.modules.Values;

        foreach (var module in apiValues)
        {
            apilist.Add(new object[] { module.name, module.moduleSenderClassName });
        }


        TemplateSystem template = new TemplateSystem(File.ReadAllText(TsPathTemplate.ProtoSenderList));

        template.AddVariable("apilist", apilist.ToArray());
        string content = template.Parse();
        string path    = string.Format(TsPathOut.ProtoSenderList);

        PathHelper.CheckPath(path);
        File.WriteAllText(path, content);
    }
    public static void Export(ProtoManager pm)
    {
        List <object[]> enumlist = new List <object[]>();

        List <ProtoEnumData> enumValues = pm.enumReader.enums.Values;

        foreach (var item in enumValues)
        {
            enumlist.Add(new object[] { item.name, item.fullClassName });
        }


        TemplateSystem template = new TemplateSystem(File.ReadAllText(TsPathTemplate.ProtoInclude));

        template.AddVariable("enumlist", enumlist.ToArray());
        string content = template.Parse();
        string path    = string.Format(TsPathOut.ProtoInclude);

        PathHelper.CheckPath(path);
        File.WriteAllText(path, content);
    }
Beispiel #21
0
    public void Generate()
    {
        List <object[]> lines = new List <object[]>();

        foreach (var kvp in xlsxManager.tables)
        {
            TableReader table = kvp.Value;


            lines.Add(new object[] { table.tableName.FirstLower(), table.tableName });
        }

        TemplateSystem template = new TemplateSystem(File.ReadAllText(TemplatingFiles.Client.LangConfigLoaderList));

        template.AddVariable("tables", lines.ToArray());
        string content = template.Parse();
        string path    = OutPaths.Client.LangConfigLoaderList;


        PathHelper.CheckPath(path);
        File.WriteAllText(path, content);
    }
Beispiel #22
0
    public static void Export()
    {
        List <Package> pkgList = Read();

        List <object[]> list = new List <object[]>();

        foreach (Package pkg in pkgList)
        {
            list.Add(new object[] { pkg.ToConfigCode() });
        }



        TemplateSystem template = new TemplateSystem(File.ReadAllText(TsPathTemplate.GuiResPackageConfigReader));

        template.AddVariable("classname", Setting.Options.codeClass);
        template.AddVariable("list", list.ToArray());
        string content = template.Parse();
        string path    = TsPathOut.GuiResPackageConfigReader;

        PathHelper.CheckPath(path);
        File.WriteAllText(path, content);
    }
Beispiel #23
0
        public static void ExportConfigManagerList(List <ExportClientTS> list)
        {
            List <object[]> lines = new List <object[]>();

            foreach (ExportClientTS item in list)
            {
                if (item.isExtend)
                {
                    continue;
                }

                lines.Add(new object[] { item.fieldName, item.classNameConfigReader });
            }
            TemplateSystem template = new TemplateSystem(File.ReadAllText(TemplatingFiles.Client.ConfigManagerListTemplate));

            template.AddVariable("tables", lines.ToArray());
            string content = template.Parse();
            string path    = OutPaths.Client.ConfigManagerListTemplate;


            PathHelper.CheckPath(path);
            File.WriteAllText(path, content);
        }
    public static void Export(List <Package> packageList)
    {
        List <object[]> list = new List <object[]>();

        foreach (Package package in packageList)
        {
            if (!package.genCode)
            {
                continue;
            }

            list.Add(new object[] { $"{package.nameSpace}.{package.classNameBinder}.bindAll()" });
        }


        TemplateSystem template = new TemplateSystem(File.ReadAllText(TsPathTemplate.GuiBinderList));

        template.AddVariable("packlist", list.ToArray());
        string content = template.Parse();
        string path    = TsPathOut.GuiBinderList;

        PathHelper.CheckPath(path);
        File.WriteAllText(path, content);
    }
    public static void Export(ProtoManager pm)
    {
        List <object[]> apilist = new List <object[]>();
        List <object[]> ooblist = new List <object[]>();

        List <ProtoModuleData> apiValues = pm.apiReader.modules.Values;

        foreach (var module in apiValues)
        {
            List <ProtoMessageData> msgValues = module.msgs.Values;
            foreach (var msg in msgValues)
            {
                apilist.Add(new object[] { module.name, msg.name });
            }
        }


        List <ProtoStructData> oobValues = pm.structReader.structs.Values;

        foreach (var oob in oobValues)
        {
            ooblist.Add(new object[] { oob.name });
        }



        TemplateSystem template = new TemplateSystem(File.ReadAllText(TsPathTemplate.ProtoEventKey));

        template.AddVariable("apilist", apilist.ToArray());
        template.AddVariable("ooblist", ooblist.ToArray());
        string content = template.Parse();
        string path    = string.Format(TsPathOut.ProtoEventKey);

        PathHelper.CheckPath(path);
        File.WriteAllText(path, content);
    }
Beispiel #26
0
        public void ExportDT()
        {
            List <object[]> fields = new List <object[]>();

            for (int i = 0; i < dataStruct.fields.Count; i++)
            {
                DataField dataField = dataStruct.fields[i];

                object[] lines = new object[] { dataField.field, dataField.GetTsTypeName() };
                fields.Add(lines);
            }



            TemplateSystem template = new TemplateSystem(File.ReadAllText(TemplatingFiles.Server.DTTemplate));

            template.AddVariable("classNameConfig", classNameConfig);
            template.AddVariable("fields", fields.ToArray());
            string content = template.Parse();
            string path    = string.Format(OutPaths.Server.DTTemplate, classNameConfig);

            PathHelper.CheckPath(path);
            File.WriteAllText(path, content);
        }
    private static void ExportModule(ProtoModuleData data)
    {
        List <object[]> funCodeList = new List <object[]>();

        List <ProtoMessageData> msgValues = data.msgs.Values;

        foreach (var msgData in msgValues)
        {
            string code = GenerateFunCode(msgData);
            msgData.req.code = code;
            funCodeList.Add(new object[] { code });
        }

        string path    = string.Format(TsPathOut.ApiSender, data.name);
        string content = "";

        if (!File.Exists(path))
        {
            TemplateSystem template = new TemplateSystem(tplContent);
            template.AddVariable("classNote", data.cnname);
            template.AddVariable("className", data.moduleSenderClassName);
            template.AddVariable("name", data.name);
            template.AddVariable("funCodeList", funCodeList.ToArray());
            content = template.Parse();
            PathHelper.CheckPath(path);
            File.WriteAllText(path, content);
        }
        else
        {
            List <string> addCodeList = new List <string>();
            string        code        = File.ReadAllText(path);

            foreach (var msgData in msgValues)
            {
                string pattern = $@"{msgData.name}\s*\([\s\S]*?\)\s*{{";
                Regex  regex   = new Regex(pattern);
                //Console.WriteLine();
                //Console.WriteLine();
                //Console.WriteLine(pattern);
                //Console.WriteLine(regex.IsMatch(code));
                if (!regex.IsMatch(code))
                {
                    addCodeList.Add(msgData.req.code);
                }

                //int i = 0;
                //MatchCollection mc = regex.Matches(code);
                //foreach (var v in mc)
                //{
                //    Console.WriteLine(i + "  " + v.ToString());
                //    i++;
                //}
            }

            if (addCodeList.Count > 0)
            {
                string pattern = @"}\s*}";
                Regex  regex   = new Regex(pattern, RegexOptions.RightToLeft);
                code = regex.Replace(code, String.Join("", addCodeList) + "\n\t}\n}", 1);

                File.WriteAllText(path, code);
            }
        }
    }
        /// <summary>
        /// Generate a network behavior from a class object and a button that contains key information about the class
        /// </summary>
        /// <param name="cObj">The class object</param>
        /// <param name="btn">The button containing key information</param>
        /// <returns>The generated string to save to a file</returns>
        public string SourceCodeNetworkBehavior(ForgeClassObject cObj, ForgeEditorButton btn)
        {
            string behaviorPath = string.Empty;

            if (btn.BaseType == ForgeBaseClassType.NetworkBehavior)
            {
                behaviorPath = EDITOR_RESOURCES_DIR + "/StandAloneNetworkBehaviorTemplate";
            }
            else
            {
                behaviorPath = EDITOR_RESOURCES_DIR + "/NetworkBehaviorTemplate";
            }

            TextAsset      asset    = Resources.Load <TextAsset>(behaviorPath);
            TemplateSystem template = new TemplateSystem(asset.text);

            template.AddVariable("className", btn.StrippedSearchName + "Behavior");
            template.AddVariable("networkObject", btn.StrippedSearchName + "NetworkObject");
            StringBuilder generatedJSON            = new StringBuilder();
            StringBuilder generatedHelperTypesJSON = new StringBuilder();

            string          caps      = "QWERTYUIOPASDFGHJKLZXCVBNM";
            List <object[]> rpcs      = new List <object[]>();
            List <object[]> constRpcs = new List <object[]>();

            for (int i = 0; i < btn.RPCVariables.Count; ++i)
            {
                StringBuilder innerTypes           = new StringBuilder();
                StringBuilder helperNames          = new StringBuilder();
                StringBuilder innerJSON            = new StringBuilder();
                StringBuilder innerHelperTypesJSON = new StringBuilder();
                for (int x = 0; x < btn.RPCVariables[i].ArgumentCount; ++x)
                {
                    Type t = ForgeClassFieldRPCValue.GetTypeFromAcceptable(btn.RPCVariables[i].FieldTypes[x].Type);

                    helperNames.AppendLine("\t\t/// " + _referenceVariables[t.Name] + " " + btn.RPCVariables[i].FieldTypes[x].HelperName);

                    string fieldHelper = btn.RPCVariables[i].FieldTypes[x].HelperName;
                    if (x + 1 < btn.RPCVariables[i].ArgumentCount)
                    {
                        innerTypes.Append(", typeof(" + _referenceVariables[t.Name] + ")");
                        innerJSON.Append("\"" + _referenceVariables[t.Name] + "\", ");
                        innerHelperTypesJSON.Append("\"" + fieldHelper + "\", ");
                    }
                    else
                    {
                        innerTypes.Append(", typeof(" + _referenceVariables[t.Name] + ")");
                        innerJSON.Append("\"" + _referenceVariables[t.Name] + "\"");
                        innerHelperTypesJSON.Append("\"" + fieldHelper + "\"");
                    }
                }

                object[] rpcData = new object[]
                {
                    btn.RPCVariables[i].FieldName,                                              // The function name
                    innerTypes.ToString(),                                                      // The list of types
                    helperNames.ToString().TrimEnd()
                };

                string constRpc = "";
                for (int j = 0; j < btn.RPCVariables[i].FieldName.Length; j++)
                {
                    if (constRpc.Length > 0 && caps.Contains(btn.RPCVariables[i].FieldName[j]))
                    {
                        constRpc += "_";
                    }

                    constRpc += btn.RPCVariables[i].FieldName[j].ToString().ToUpper();
                }
                constRpc = constRpc.Replace("R_P_C_", "");

                object[] constRpcData = new object[]
                {
                    constRpc,                                                                       // The function name
                    innerTypes.ToString(),                                                          // The list of types
                    helperNames.ToString().TrimEnd()
                };

                rpcs.Add(rpcData);
                constRpcs.Add(constRpcData);
                generatedJSON.Append("[");
                generatedJSON.Append(innerJSON.ToString());
                generatedJSON.Append("]");
                generatedHelperTypesJSON.Append("[");
                generatedHelperTypesJSON.Append(innerHelperTypesJSON.ToString());
                generatedHelperTypesJSON.Append("]");
            }

            template.AddVariable("generatedTypes", generatedJSON.ToString().Replace("\"", "\\\""));
            template.AddVariable("generatedHelperTypes", generatedHelperTypesJSON.ToString().Replace("\"", "\\\""));
            template.AddVariable("rpcs", rpcs.ToArray());
            template.AddVariable("constRpcs", constRpcs.ToArray());

            return(template.Parse());
        }
        /// <summary>
        /// Generate a source network object based on the class and button provided
        /// </summary>
        /// <param name="cObj">The class we a generating</param>
        /// <param name="btn">The button that holds key information to this class</param>
        /// <param name="identity">The network identity that we will assing this class</param>
        /// <returns>The generated string to save to a file</returns>
        public string SourceCodeNetworkObject(ForgeClassObject cObj, ForgeEditorButton btn, int identity)
        {
            TextAsset      asset    = Resources.Load <TextAsset>(EDITOR_RESOURCES_DIR + "/NetworkObjectTemplate");
            TemplateSystem template = new TemplateSystem(asset.text);

            template.AddVariable("className", btn.StrippedSearchName + "NetworkObject");
            template.AddVariable("identity", cObj == null ? identity : cObj.IdentityValue);
            template.AddVariable("bitwiseSize", Math.Ceiling(btn.ClassVariables.Count / 8.0));

            List <object[]> variables         = new List <object[]>();
            List <object[]> rewinds           = new List <object[]>();
            string          interpolateValues = string.Empty;

            string interpolateType = string.Empty;
            int    i = 0, j = 0;

            for (i = 0, j = 0; i < btn.ClassVariables.Count; ++i)
            {
                Type t = ForgeClassFieldValue.GetTypeFromAcceptable(btn.ClassVariables[i].FieldType);
                interpolateType = ForgeClassFieldValue.GetInterpolateFromAcceptable(btn.ClassVariables[i].FieldType);

                if (i != 0 && i % 8 == 0)
                {
                    j++;
                }

                object[] fieldData = new object[]
                {
                    _referenceVariables[t.Name],                                                // Data type
                    btn.ClassVariables[i].FieldName.Replace(" ", string.Empty),                 // Field name
                    btn.ClassVariables[i].Interpolate,                                          // Interpolated
                    interpolateType,                                                            // Interpolate type
                    btn.ClassVariables[i].InterpolateValue,                                     // Interpolate time
                    _referenceBitWise[i % 8],                                                   // Hexcode
                    j                                                                           // Dirty fields index
                };

                if (i + 1 < btn.ClassVariables.Count)
                {
                    interpolateValues += btn.ClassVariables[i].InterpolateValue.ToString() + ",";
                }
                else
                {
                    interpolateValues += btn.ClassVariables[i].InterpolateValue.ToString();
                }

                variables.Add(fieldData);
            }

            // TODO:  This should relate to the rewind variables
            for (i = 0; i < 0; i++)
            {
                object[] rewindData = new object[]
                {
                    "Vector3",                                  // The data type for this rewind
                    "Position",                                 // The name except with the first letter uppercase
                    5000                                        // The time in ms for this rewind to track
                };

                rewinds.Add(rewindData);
            }

            template.AddVariable("variables", variables.ToArray());
            template.AddVariable("rewinds", rewinds.ToArray());
            template.AddVariable("interpolateValues", interpolateValues.Replace("\"", "\\\""));
            return(template.Parse());
        }
Beispiel #30
0
    /// <summary>
    /// 导出结构
    /// </summary>
    private void ExportStruct()
    {
        List <object[]> fields            = new List <object[]>();
        List <object[]> setControllerList = new List <object[]>();
        List <object[]> setTransitionList = new List <object[]>();
        List <object[]> setDisplayList    = new List <object[]>();

        // fields
        foreach (Node node in com.controllerList)
        {
            if (node.isIngore)
            {
                continue;
            }

            object[] lines = new object[] { node.fieldName, node.type };
            fields.Add(lines);
        }

        foreach (Node node in com.transitionList)
        {
            if (node.isIngore)
            {
                continue;
            }

            object[] lines = new object[] { node.fieldName, node.type };
            fields.Add(lines);
        }

        foreach (Node node in com.displayList)
        {
            if (node.isIngore)
            {
                continue;
            }

            object[] lines = new object[] { node.fieldName, node.type };
            fields.Add(lines);
        }

        foreach (ComponentNode node in com.componentList)
        {
            if (node.isIngore)
            {
                continue;
            }

            object[] lines = new object[] { node.fieldName, node.GetType(com) };
            fields.Add(lines);
        }

        // setControllerList
        foreach (Node node in com.controllerList)
        {
            if (node.isIngore)
            {
                continue;
            }

            object[] lines = new object[] { node.fieldName, node.name };
            setControllerList.Add(lines);
        }

        // setTransitionList
        foreach (Node node in com.transitionList)
        {
            if (node.isIngore)
            {
                continue;
            }

            object[] lines = new object[] { node.fieldName, node.name };
            setTransitionList.Add(lines);
        }

        // setDisplayList
        foreach (Node node in com.displayList)
        {
            if (node.isIngore)
            {
                continue;
            }

            object[] lines = new object[] { node.fieldName, node.name, node.type };
            setDisplayList.Add(lines);
        }

        foreach (ComponentNode node in com.componentList)
        {
            if (node.isIngore)
            {
                continue;
            }

            object[] lines = new object[] { node.fieldName, node.name, node.GetType(com) };
            setDisplayList.Add(lines);
        }

        string        dependPackages    = "";
        List <string> dependPackageList = new List <string>();

        foreach (Package item in com.dependPackageList)
        {
            dependPackageList.Add($"\"{item.name}\"");
        }

        dependPackages = String.Join(",", dependPackageList.ToArray());


        TemplateSystem template = new TemplateSystem(File.ReadAllText(TsPathTemplate.ComponentStruct));

        template.AddVariable("namespace", com.nameSpace);
        template.AddVariable("classNameFGUI", com.classNameFGUI);
        template.AddVariable("classNameStruct", com.classNameStruct);
        template.AddVariable("classNameExtend", com.classNameExtend);
        template.AddVariable("packagename", com.packageName);
        template.AddVariable("dependPackages", dependPackages);
        template.AddVariable("comname", Path.GetFileNameWithoutExtension(com.name));
        template.AddVariable("URL", com.URL);
        template.AddVariable("fields", fields.ToArray());
        template.AddVariable("setControllerList", setControllerList.ToArray());
        template.AddVariable("setDisplayList", setDisplayList.ToArray());
        template.AddVariable("setTransitionList", setTransitionList.ToArray());
        string content = template.Parse();
        string path    = string.Format(TsPathOut.ComponentStruct, com.package.codeFolderName, name);

        PathHelper.CheckPath(path);
        File.WriteAllText(path, content);
    }
Beispiel #31
0
        public void ExportConfigStruct()
        {
            List <object[]> dicts  = new List <object[]>();
            List <object[]> fields = new List <object[]>();


            for (int i = 0; i < dataStruct.fields.Count; i++)
            {
                DataField dataField = dataStruct.fields[i];

                if (dataField.fieldNameIsEnable)
                {
                    object[] lines = new object[] { dataField.field, dataField.GetTsTypeName() };
                    fields.Add(lines);
                }
                else
                {
                    object[] lines = new object[] { dataField.field, dataField.GetTsTypeName(), Regex.Replace(dataField.field, @"[^A-Za-z0-9_]", @"_") };
                    dicts.Add(lines);
                }
            }


            List <object[]> langs = new List <object[]>();


            for (int i = 0; i < dataStruct.fields.Count; i++)
            {
                DataField dataField = dataStruct.fields[i];

                if (dataField.field.StartsWith("zh_cn_"))
                {
                    object[] lines = new object[] { dataField.field.Replace("zh_cn_", ""), dataField.field, fieldName };
                    langs.Add(lines);
                }
                else if (dataField.field.StartsWith("cn_"))
                {
                    object[] lines = new object[] { dataField.field.Replace("cn_", ""), dataField.field, fieldName };
                    langs.Add(lines);
                }
            }



            string parse      = "";
            string parseArray = "";

            if (isExtend)
            {
                StringWriter sw = new StringWriter();
                sw.WriteLine($"  static parse(txt: string): {classNameConfig} ");
                sw.WriteLine("      {");

                sw.WriteLine($"          let csv = toStringArray(txt);");
                sw.WriteLine($"          let config = new {classNameConfig}();");


                for (int i = 0; i < dataStruct.fields.Count; i++)
                {
                    DataField dataField = dataStruct.fields[i];
                    sw.WriteLine($"          config.{dataField.field} = {GetParseCsvTxt(dataField, i)};");
                }

                sw.WriteLine("          return config;");
                sw.WriteLine("      }");

                parse = sw.ToString();



                // parseArray
                sw = new StringWriter();
                sw.WriteLine($"  static parseArray(txt: string): {classNameConfig}[] ");
                sw.WriteLine("      {");
                sw.WriteLine($"          let csv = toStringArray(txt, /[;]/);");
                sw.WriteLine($"          let list:{classNameConfig}[] = [];");
                sw.WriteLine($"          for(let i = 0; i < csv.length; i ++)");
                sw.WriteLine("          {");
                sw.WriteLine($"              list.push(      {classNameConfig}.parse(csv[i])          );");
                sw.WriteLine("           }");

                sw.WriteLine("          return list;");
                sw.WriteLine("      }");

                parseArray = sw.ToString();
            }



            TemplateSystem template = new TemplateSystem(File.ReadAllText(TemplatingFiles.Client.ConfigStructTemplates));

            template.AddVariable("classNameConfigStruct", classNameConfigStruct);
            template.AddVariable("fields", fields.ToArray());
            template.AddVariable("dicts", dicts.ToArray());
            template.AddVariable("langs", langs.ToArray());
            template.AddVariable("parse", parse);
            template.AddVariable("parseArray", parseArray);
            string content = template.Parse();
            string path    = string.Format(OutPaths.Client.ConfigStructTeamplate, classNameConfigStruct);

            PathHelper.CheckPath(path);
            File.WriteAllText(path, content);
        }