Пример #1
0
        /// <summary>
        /// 生成.
        /// </summary>
        /// <returns>成功したらtrueを返す</returns>
        public bool Generate()
        {
            // ファイル名をテーブル名として扱う。
            string TableName = Path.GetFileNameWithoutExtension(FilePath);

            var Dir = Path.GetDirectoryName(FilePath);

            if (!Directory.Exists(Dir))
            {
                Directory.CreateDirectory(Dir);
            }

            var Writer = File.CreateText(FilePath);

            Writer.WriteLine("DROP TABLE IF EXISTS `" + TableName + "`;");
            Writer.WriteLine("CREATE TABLE `" + TableName + "` (");
            if (Master.IsMultipleSheet)
            {
                Writer.WriteLine(" `SheetIndex` INT UNSIGNED,");
            }
            var Columns = Master.GetColumns(0);

            for (int i = 0; i < Columns.Count; i++)
            {
                Column Col  = Columns[i];
                string Line = " `" + Col.Name + "` ";
                Line += GetSQLTypeName(Col.DataType);
                if (i < Columns.Count - 1)
                {
                    Line += ",";
                }
                Writer.WriteLine(Line);
            }
            Writer.WriteLine(") DEFAULT CHARSET=utf8;");

            Writer.WriteLine("LOCK TABLES `" + TableName + "` WRITE;");

            WriteInsert(Writer, TableName);

            Writer.WriteLine("UNLOCK TABLES;");

            Writer.Close();
            return(true);
        }
Пример #2
0
        /// <summary>
        /// タグの変換.
        /// </summary>
        /// <param name="Source">変換前のソース</param>
        /// <returns>変換後のソース</returns>
        private string ReplaceTags(string Source)
        {
            var ColumnList = Master.GetColumns(0);

            // 取得関数宣言.
            string GetItemFunctionDecrare = "const $ITEM_STRUCT_NAME$ *GetItem($KEY_TYPE$ Key, s32 SheetIndex = 0) const;";

            if (Master.IsAutoKey)
            {
                if (ColumnList.Count <= 2)
                {
                    GetItemFunctionDecrare = "";
                }
                else
                {
                    GetItemFunctionDecrare = "std::vector<const $ITEM_STRUCT_NAME$ *> CollectItems($KEY_TYPE$ Key, s32 SheetIndex = 0) const;";
                }
            }
            Source = Source.Replace("$GET_ITEN_FUNCTION_DECRARE$", GetItemFunctionDecrare);

            // キー取得関数.
            string KeyFunctionFileName = TemplatePath + "GetKeyFunction.txt";

            if (Master.IsAutoKey)
            {
                KeyFunctionFileName = TemplatePath + "CollectItemFunction.txt";
            }
            string KeyFunction = "";

            if (!Master.IsAutoKey || (Master.IsAutoKey && ColumnList.Count > 2))
            {
                using (StreamReader Reader = new StreamReader(KeyFunctionFileName, Encoding.GetEncoding("shift-jis")))
                {
                    KeyFunction = Reader.ReadToEnd();
                }
            }
            Source = Source.Replace("$GET_KEY_FUNCTION$", KeyFunction);

            // インクルードガード
            string IncludeGuard = "__" + Master.Name.ToUpper() + "MASTER_H__";

            Source = Source.Replace("$INCLUDE_GUARD$", IncludeGuard);

            // ヘッダファイル名.
            string HeaderFileName = Master.Name + "Master.h";

            Source = Source.Replace("$HEADER_FILE_NAME$", HeaderFileName);

            // クラス名.
            string ClassName = GenerateClassName();

            Source = Source.Replace("$CLASS_NAME$", ClassName);

            // アイテム構造体名.
            string ItemStructName = Master.Name + "Item";

            Source = Source.Replace("$ITEM_STRUCT_NAME$", ItemStructName);

            // キーの型名.
            string KeyType = Util.ToTypeNameString(ColumnList[0].DataType);

            if (Master.IsAutoKey && ColumnList.Count > 2)
            {
                KeyType = Util.ToTypeNameString(ColumnList[1].DataType);
            }
            Source = Source.Replace("$KEY_TYPE$", KeyType);

            // キーの名前
            string KeyName = ColumnList[0].Name;

            if (Master.IsAutoKey)
            {
                KeyName = ColumnList[1].Name;
            }
            Source = Source.Replace("$KEY_NAME$", KeyName);

            // Enum
            string EnumList = "";

            foreach (var Enum in Master.EnumList)
            {
                EnumList += "\tenum\n\t{";
                foreach (var Data in Enum.EnumList)
                {
                    EnumList += "\n\t\t" + Data.Key + " = " + Data.Value + ",";
                }
                EnumList += "\n\t};\n";
            }
            Source = Source.Replace("$ENUMS$", EnumList);

            // アイテムリスト
            string ItemList = "";

            foreach (Column Col in ColumnList)
            {
                string Item = "\t" + Util.ToTypeNameString(Col.DataType);
                Item     += " " + Col.Name + ";";
                ItemList += Item + "\n";
            }
            Source = Source.Replace("$ITEM_LIST$", ItemList);

            // マスタ名.
            Source = Source.Replace("$MASTER_NAME$", Master.Name);

            // アイテムバインド
            string ItemBind = "";

            if (Master.IsMultipleSheet)
            {
                ItemBind += "\tQuery.BindResultInt(&Sheet);\n";
            }
            foreach (Column Col in ColumnList)
            {
                ItemBind += "\t";
                switch (Col.DataType)
                {
                case Type.Float:

                    ItemBind += "Query.BindResultFloat(&BindItem." + Col.Name + ");";
                    break;

                case Type.String:

                    ItemBind += "Query.BindResultString(" + Col.Name + "Bind);";
                    break;

                case Type.s32:
                case Type.u32:

                    ItemBind += "Query.BindResultInt(&BindItem." + Col.Name + ");";
                    break;

                case Type.s16:
                case Type.u16:

                    ItemBind += "Query.BIndResultShort(&BindItem." + Col.Name + ");";
                    break;

                case Type.s8:
                case Type.u8:

                    ItemBind += "Query.BindResultChar(&BindItem." + Col.Name + ");";
                    break;
                }
                ItemBind += "\n";
            }
            Source = Source.Replace("$ITEM_BIND$", ItemBind);

            // 文字列バインド
            string StringBind = "";

            foreach (Column Col in ColumnList)
            {
                if (Col.DataType != Type.String)
                {
                    continue;
                }
                StringBind += "\t";
                if (Col.DataType == Type.String)
                {
                    StringBind += "char ";
                }
                else
                {
                    StringBind += "wchar_t ";
                }
                StringBind += Col.Name + "Bind[128];";
            }
            Source = Source.Replace("$STRING_BIND$", StringBind);

            // アイテムフェッチ
            string ItemFetch = "";

            foreach (Column Col in ColumnList)
            {
                ItemFetch += "\t\t";
                if (Col.DataType == Type.String)
                {
                    // stringの場合は別領域に格納されたものを放り込む。
                    ItemFetch += "Item." + Col.Name + " = " + Col.Name + "Bind;";
                }
                else
                {
                    ItemFetch += "Item." + Col.Name + " = BindItem." + Col.Name + ";";
                }
                ItemFetch += "\n";
            }
            Source = Source.Replace("$ITEM_FETCH$", ItemFetch);

            // マップへの追加.
            string AppendToMap = "Items[Sheet][Item." + ColumnList[0].Name + "] = Item;\n";

            Source = Source.Replace("$APPEND_TO_MAP$", AppendToMap);

            return(Source);
        }
Пример #3
0
        /// <summary>
        /// 生成.
        /// </summary>
        /// <returns>成功したらtrueを返す</returns>
        public bool Generate()
        {
            try
            {
                string     FilePath    = Config.TemporaryDirectoryPath + "\\" + MasterName + ".bin";
                FileStream WriteStream = new FileStream(FilePath, FileMode.Create);
                using (BinaryWriter BinWriter = new BinaryWriter(WriteStream))
                {
                    // シート数.
                    {
                        byte[] Bytes = BitConverter.GetBytes(Master.SheetCount);
                        if (BitConverter.IsLittleEndian)
                        {
                            Bytes = Bytes.Reverse().ToArray();
                            BinWriter.Write(Bytes);
                        }
                    }
                    for (int Sheet = 0; Sheet < Master.SheetCount; Sheet++)
                    {
                        var Columns = Master.GetColumns(Sheet);
                        // カラム数.
                        {
                            byte[] Bytes = BitConverter.GetBytes(Columns[0].DataList.Count);
                            if (BitConverter.IsLittleEndian)
                            {
                                Bytes = Bytes.Reverse().ToArray();
                                BinWriter.Write(Bytes);
                            }
                        }
                        for (int i = 0; i < Columns[0].DataList.Count; i++)
                        {
                            for (int j = 0; j < Columns.Count; j++)
                            {
                                byte[] Bytes = null;
                                double Data  = 0.0;
                                if (Columns[j].DataType != Type.String)
                                {
                                    int EnumValue = 0;
                                    if (Master.TryFindEnumValue(Columns[j].DataList[i].ToString(), out EnumValue))
                                    {
                                        Data = EnumValue;
                                    }
                                    else
                                    {
                                        Data = (double)Columns[j].DataList[i];
                                    }
                                }
                                switch (Columns[j].DataType)
                                {
                                case Type.s8:

                                    // @HACK:負数ブチ込んだ時に問題起きる気がする・・・
                                    Bytes    = new byte[1];
                                    Bytes[0] = (byte)Data;
                                    break;

                                case Type.u8:

                                    Bytes    = new byte[1];
                                    Bytes[0] = (byte)Data;
                                    break;

                                case Type.s16:

                                    Bytes = BitConverter.GetBytes((short)Data);
                                    break;

                                case Type.u16:

                                    Bytes = BitConverter.GetBytes((ushort)Data);
                                    break;

                                case Type.s32:

                                    Bytes = BitConverter.GetBytes((int)Data);
                                    break;

                                case Type.u32:

                                    Bytes = BitConverter.GetBytes((uint)Data);
                                    break;

                                case Type.Float:

                                    Bytes = BitConverter.GetBytes((float)Data);
                                    break;

                                case Type.String:

                                    string Str       = (string)Columns[j].DataList[i];
                                    int    StrSize   = Encoding.UTF8.GetByteCount(Str);
                                    byte[] SizeBytes = BitConverter.GetBytes(StrSize);
                                    if (BitConverter.IsLittleEndian)
                                    {
                                        SizeBytes = SizeBytes.Reverse().ToArray();
                                    }
                                    BinWriter.Write(SizeBytes);
                                    Bytes = Encoding.UTF8.GetBytes(Str).Reverse().ToArray();
                                    break;
                                }
                                if (BitConverter.IsLittleEndian)
                                {
                                    Bytes = Bytes.Reverse().ToArray();
                                }

                                BinWriter.Write(Bytes);
                            }
                        }
                    }
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Пример #4
0
        /// <summary>
        /// タグの変換.
        /// </summary>
        /// <param name="Source">変換前のソース</param>
        /// <returns>変換後のソース</returns>
        private string ReplaceTags(string Source)
        {
            // インクルードガード
            string IncludeGuard = "__" + Master.Name.ToUpper() + "MASTER_H__";

            Source = Source.Replace("$INCLUDE_GUARD$", IncludeGuard);

            // 取得関数定義.
            string GetItemFunctionDecrare = "const $ITEM_STRUCT_NAME$ *Get($KEY_TYPE$ Key, int32 SheetIndex = 0) const;";

            if (Master.IsAutoKey)
            {
                GetItemFunctionDecrare = "TArray<const $ITEM_STRUCT_NAME$ *> CollectItems($SECONDARY_KEY_TYPE$ Key, int SheetIndex = 0) const;";
            }
            Source = Source.Replace("$GET_ITEM_FUNCTION_DECRARE$", GetItemFunctionDecrare);

            // 取得関数.
            string KeyFunctionFileName = TemplatePath + "GetKeyFunction.txt";

            if (Master.IsAutoKey)
            {
                KeyFunctionFileName = TemplatePath + "CollectItemFunction.txt";
            }
            using (StreamReader Reader = new StreamReader(KeyFunctionFileName, Encoding.GetEncoding("shift-jis")))
            {
                string KeyFunction = Reader.ReadToEnd();
                Source = Source.Replace("$GET_ITEM_FUNCTION$", KeyFunction);
            }

            // ヘッダファイル名.
            string HeaderFileName = Master.Name + "Master.h";

            Source = Source.Replace("$HEADER_FILE_NAME$", HeaderFileName);

            // バイナリファイル名.
            string BinaryFileName = Master.Name + ".bin";

            Source = Source.Replace("$BINARY_FILE_NAME$", BinaryFileName);

            // クラス名.
            string ClassName = GenerateClassName();

            Source = Source.Replace("$CLASS_NAME$", ClassName);

            // アイテム構造体名.
            string ItemStructName = Master.Name + "Item";

            Source = Source.Replace("$ITEM_STRUCT_NAME$", ItemStructName);

            var ColumnList = Master.GetColumns(0);

            // キーの型名.
            string KeyType = Util.ToTypeNameString(ColumnList[0].DataType);

            Source = Source.Replace("$KEY_TYPE$", KeyType);

            // キーの名前
            string KeyName = ColumnList[0].Name;

            Source = Source.Replace("$KEY_NAME$", KeyName);

            // セカンダリキーの型名.
            string SecondaryKeyType = Util.ToTypeNameString(ColumnList[1].DataType);

            Source = Source.Replace("$SECONDARY_KEY_TYPE$", SecondaryKeyType);

            // セカンダリキーの名前.
            string SecondaryKeyName = ColumnList[1].Name;

            Source = Source.Replace("$SECONDARY_KEY_NAME$", SecondaryKeyName);

            // Enum
            string EnumList = "";

            foreach (var Enum in Master.EnumList)
            {
                EnumList += "\tenum\n\t{";
                foreach (var Data in Enum.EnumList)
                {
                    EnumList += "\n\t\t" + Data.Key + " = " + Data.Value + ",";
                }
                EnumList += "\n\t};\n";
            }
            Source = Source.Replace("$ENUMS$", EnumList);

            // アイテムリスト
            string ItemList = "";

            foreach (Column Col in ColumnList)
            {
                string TypeName = Util.ToTypeNameString(Col.DataType);
                if (Col.DataType == Type.String)
                {
                    TypeName = "FString";
                }
                string Item = "\t" + TypeName;
                Item     += " " + Col.Name + ";";
                ItemList += Item + "\n";
            }
            Source = Source.Replace("$ITEM_LIST$", ItemList);

            // シリアライズ
            string ItemSerialize = "";

            foreach (Column Col in ColumnList)
            {
                ItemSerialize += "\t\t";
                if (Col.DataType == Type.String)
                {
                    ItemSerialize += "std::string Str" + Col.Name + ";\n\t\t";
                    ItemSerialize += "if(!pStream->Serialize(&Str" + Col.Name + ")) { return false; }\n\t\t";
                    ItemSerialize += Col.Name + " = UTF8_TO_TCHAR(Str" + Col.Name + ".c_str());";
                }
                else
                {
                    ItemSerialize += "if(!pStream->Serialize(&" + Col.Name + ")) { return false; }";
                }
                ItemSerialize += "\n";
            }
            Source = Source.Replace("$ITEM_SERIALIZE$", ItemSerialize);

            return(Source);
        }