Beispiel #1
0
        // test
        public static void Test()
        {
            ScriptGenTool tool = new ScriptGenTool();
            ScriptGenInfo info = new ScriptGenInfo();
            info.className = "DiyCharConfig";
            info.elements = new List<ScriptGenElementInfo>();

            ScriptGenElementInfo id = new ScriptGenElementInfo();
            id.index = 0;
            id.classTypeName = "int";
            id.desc = "模型id";
            id.memberName = "id";
            id.rangeMax = int.MaxValue.ToString();
            id.rangeMin = int.MinValue.ToString();
            id.isList = false;
            info.elements.Add(id);

            ScriptGenElementInfo positionId = new ScriptGenElementInfo();
            positionId.index = 2;
            positionId.classTypeName = "int";
            positionId.desc = "position id";
            positionId.memberName = "positionId";
            positionId.rangeMax = int.MaxValue.ToString();
            positionId.rangeMin = int.MinValue.ToString();
            positionId.isList = false;
            info.elements.Add(positionId);

            ScriptGenElementInfo vertexid = new ScriptGenElementInfo();
            vertexid.index = 3;
            vertexid.classTypeName = "int";
            vertexid.desc = "vertex id";
            vertexid.memberName = "vertexid";
            vertexid.rangeMax = int.MaxValue.ToString();
            vertexid.rangeMin = int.MinValue.ToString();
            vertexid.isList = false;
            info.elements.Add(vertexid);

            ScriptGenElementInfo radius = new ScriptGenElementInfo();
            radius.index = 3;
            radius.classTypeName = "int";
            radius.desc = "radius ";
            radius.memberName = "radius";
            radius.rangeMax = int.MaxValue.ToString();
            radius.rangeMin = int.MinValue.ToString();
            radius.isList = false;
            info.elements.Add(radius);

            ScriptGenElementInfo min = new ScriptGenElementInfo();
            min.index = 3;
            min.classTypeName = "int";
            min.desc = "min ";
            min.memberName = "min";
            min.rangeMax = int.MaxValue.ToString();
            min.rangeMin = int.MinValue.ToString();
            min.isList = false;
            info.elements.Add(min);

            ScriptGenElementInfo max = new ScriptGenElementInfo();
            max.index = 3;
            max.classTypeName = "int";
            max.desc = "max ";
            max.memberName = "max";
            max.rangeMax = int.MaxValue.ToString();
            max.rangeMin = int.MinValue.ToString();
            max.isList = false;
            info.elements.Add(max);

            ScriptGenElementInfo dirx = new ScriptGenElementInfo();
            dirx.index = 3;
            dirx.classTypeName = "int";
            dirx.desc = "dirx ";
            dirx.memberName = "dirx";
            dirx.rangeMax = int.MaxValue.ToString();
            dirx.rangeMin = int.MinValue.ToString();
            dirx.isList = false;
            info.elements.Add(dirx);

            ScriptGenElementInfo diry = new ScriptGenElementInfo();
            diry.index = 3;
            diry.classTypeName = "int";
            diry.desc = "diry ";
            diry.memberName = "diry";
            diry.rangeMax = int.MaxValue.ToString();
            diry.rangeMin = int.MinValue.ToString();
            diry.isList = false;
            info.elements.Add(diry);

            ScriptGenElementInfo dirz = new ScriptGenElementInfo();
            dirz.index = 3;
            dirz.classTypeName = "int";
            dirz.desc = "dirz ";
            dirz.memberName = "dirz";
            dirz.rangeMax = int.MaxValue.ToString();
            dirz.rangeMin = int.MinValue.ToString();
            dirz.isList = false;
            info.elements.Add(dirz);

            tool.GenScript(info);
        }
Beispiel #2
0
        public static void GenAllScript()
        {
            // load config
            ScriptGenTool tool = new ScriptGenTool();

            string configPath = ScriptGenConstant.resourcePath + "ConfigXml.xml";
            string configContent = File.ReadAllText(configPath);

            var config = XmlConfigBase.DeSerialize<GenScriptXmlConfig>(configContent);

            if (null == config)
            {
                return;
            }

            for (int i = 0; i < config.classConfigList.Count; ++i)
            {
                var elemConfig = config.classConfigList[i];
                ScriptGenInfo info = new ScriptGenInfo();
                info.className = elemConfig.className;
                info.elements = new List<ScriptGenElementInfo>(elemConfig.lineConfigList.Count);
                int lineIndex = -1;
                foreach (var line in elemConfig.lineConfigList)
                {
                    ++lineIndex;
                    if (string.IsNullOrEmpty(line.classTypeName))
                    {
                        // skip this line
                        continue;
                    }
                    ScriptGenElementInfo infoLine = new ScriptGenElementInfo();
                    //infoLine.index = line.index-1;
                    infoLine.index = lineIndex;
                    infoLine.classTypeName = line.classTypeName;
                    infoLine.desc = line.desc;
                    if (string.IsNullOrEmpty(infoLine.desc))
                    {
                        infoLine.desc = line.memberName;
                    }
                    infoLine.isList = line.isList;
                    infoLine.memberName = line.memberName;
                    infoLine.rangeMax = line.rangeMax;
                    infoLine.rangeMin = line.rangeMin;
                    infoLine.isNullable = line.isNullable;
                    if (infoLine.classTypeName.EndsWith("string"))
                    {
                        infoLine.rangeMax = "string.Empty";
                        infoLine.rangeMin = "string.Empty";
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(infoLine.rangeMax))
                        {
                            infoLine.rangeMax = infoLine.classTypeName + ".MaxValue";
                        }
                        if (string.IsNullOrEmpty(infoLine.rangeMin))
                        {
                            infoLine.rangeMin = infoLine.classTypeName + ".MinValue";
                        }
                    }
                    info.elements.Add(infoLine);
                }
                // gen script
                tool.GenScript(info);
            }
        }