├── .gitignore ├── Config ├── Test.xlsx ├── Test1.xlsx ├── Test2.xlsx └── __CommonEnum.xlsx ├── README.md ├── Tool ├── BinWrite.py ├── ColorHelper.py ├── ColorHelper_Mac.py ├── ColorHelper_Win.py ├── CommonType.py ├── ConfigExcelData.py ├── ConfigExcelRow.py ├── ConfigExcelSheel.py ├── ConfigExcelWork.py ├── Content.py ├── Derictory.py ├── EnumData.py ├── EnumUtils.py ├── ExcelCell.py ├── ExcelRow.py ├── ExcelSheel.py ├── ExcelUtils.py ├── ExcelWork.py ├── __Path.yaml ├── exportbin.py └── template │ ├── c++ │ ├── Template0.cpp │ ├── Template0.h │ ├── Template1.cpp │ ├── Template1.h │ ├── Template2.cpp │ ├── Template2.h │ └── common │ │ ├── BinData.cpp │ │ ├── BinData.h │ │ ├── DataBase.cpp │ │ └── DataBase.h │ ├── csharp │ ├── Template0.cs │ ├── Template1.cs │ ├── Template2.cs │ └── common │ │ ├── BinData.cs │ │ ├── ConfigDebugEx.cs │ │ └── DataBase.cs │ ├── java │ ├── Template0.java │ ├── Template1.java │ ├── Template2.java │ └── common │ │ ├── BinData.java │ │ └── DataBase.java │ └── lua │ └── common │ └── CommonLua.lua └── exceltool.sh /.gitignore: -------------------------------------------------------------------------------- 1 | /Tool/__pycache__ 2 | /ToolExcel/Library 3 | /ToolExcel/Temp 4 | -------------------------------------------------------------------------------- /Config/Test.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangpeng136139/Excel2Code/d49dbbd1c4a721863003dda7e2ddd320d142015d/Config/Test.xlsx -------------------------------------------------------------------------------- /Config/Test1.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangpeng136139/Excel2Code/d49dbbd1c4a721863003dda7e2ddd320d142015d/Config/Test1.xlsx -------------------------------------------------------------------------------- /Config/Test2.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangpeng136139/Excel2Code/d49dbbd1c4a721863003dda7e2ddd320d142015d/Config/Test2.xlsx -------------------------------------------------------------------------------- /Config/__CommonEnum.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangpeng136139/Excel2Code/d49dbbd1c4a721863003dda7e2ddd320d142015d/Config/__CommonEnum.xlsx -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Excel2Code 2 | Excel To Code 3 | 4 | ### Environment 5 | python-3.10.4 6 | 7 | pip install xlrd==1.2.0 8 | 9 | pip install pyyaml 10 | 11 | ### Excel 12 | The first line in Excel is the variable name 13 | 14 | The second line in Excel is a comment 15 | 16 | The third line in Excel is the variable type 17 | 18 | ### __Path.yaml 19 | basic configuration 20 | 21 | Path: 22 | ``` 23 | # CS = 0, 24 | # CPP = 1, 25 | # JAVA = 2, 26 | # LUA = 3, 27 | 28 | CodePath: ../Data/Code 29 | 30 | XlsxPath: ../Config 31 | 32 | BinPath: ../Data/Bin 33 | 34 | CodeType: 1 35 | 36 | JavaPackageName: TableConfig 37 | ``` 38 | 39 | 40 | ### Example 41 | csharp: 42 | ``` 43 | DataBase.SetDataPath("E:/Bin/"); 44 | Test.Load(); 45 | Test1.Load(); 46 | Test2.Load(); 47 | ``` 48 | java 49 | ``` 50 | DataBase.SetDataPath("E:/Bin/"); 51 | Test.Load(); 52 | Test1.Load(); 53 | Test2.Load(); 54 | ``` 55 | 56 | C++ 57 | ``` 58 | DataBase::SetDataPath("E:/project/ExportExcel/Data/Bin/"); 59 | Test::Load(); 60 | Test1::Load(); 61 | Test2::Load(); 62 | ``` 63 | ### Run 64 | 65 | Use exceltool.sh 66 | 67 | 68 | ### support languange: 69 | C++ 70 | 71 | CSharp 72 | 73 | Java 74 | 75 | Lua 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /Tool/BinWrite.py: -------------------------------------------------------------------------------- 1 | import os 2 | from typing import List 3 | import struct 4 | # x pad byte no value 5 | # c char string of length 1 1 6 | # b signed char integer 1 (3) 7 | # B unsigned char integer 1 (3) 8 | # ? _Bool bool 1 (1) 9 | # h short integer 2 (3) 10 | # H unsigned short integer 2 (3) 11 | # i int integer 4 (3) 12 | # I unsigned int integer 4 (3) 13 | # l long integer 4 (3) 14 | # L unsigned long integer 4 (3) 15 | # q long long integer 8 (2), (3) 16 | # Q unsigned long long integer 8 (2), (3) 17 | # f float float 4 (4) 18 | # d double float 8 (4) 19 | # s char[] string 1 20 | # p char[] string 21 | # P void * integer (5), (3) 22 | class BinWrite: 23 | m_path: str 24 | m_listContent: List = [] 25 | 26 | def __init__(self, path) -> None: 27 | self.m_path = path 28 | 29 | def StartWrite(self): 30 | return 31 | 32 | def WriteBin(self, value) -> None: 33 | self.m_listContent.append(value) 34 | 35 | def WriteList(self, value: List) -> None: 36 | self.m_listContent.extend(value) 37 | 38 | def WriteInt(self, value: int) -> None: 39 | binValue = struct.pack("i", value) 40 | self.WriteBin(binValue) 41 | 42 | def EndWrite(self): 43 | with open(self.m_path, 'wb') as wb: 44 | for value in self.m_listContent: 45 | wb.write(value) 46 | print("write end:"+self.m_path) 47 | 48 | -------------------------------------------------------------------------------- /Tool/ColorHelper.py: -------------------------------------------------------------------------------- 1 | def get_platform(): 2 | import platform 3 | sys_platform = platform.platform().lower() 4 | if "windows" in sys_platform: 5 | return "windows"; 6 | elif "macos" in sys_platform: 7 | return "macos"; 8 | elif "linux" in sys_platform: 9 | return "linux"; 10 | else: 11 | print("other systemC") 12 | 13 | if get_platform() == "windows": 14 | import ColorHelper_Win 15 | else: 16 | import ColorHelper_Mac 17 | 18 | #green 19 | def printGreen(mess): 20 | if get_platform() == "windows": 21 | ColorHelper_Win.printGreen(mess); 22 | else: 23 | ColorHelper_Mac.printGreen(mess); 24 | 25 | #red 26 | def printRed(mess): 27 | if get_platform() == "windows": 28 | ColorHelper_Win.printRed(mess); 29 | else: 30 | ColorHelper_Mac.printRed(mess); 31 | 32 | 33 | #yellow 34 | def printYellow(mess): 35 | if get_platform() == "windows": 36 | ColorHelper_Win.printYellow(mess); 37 | else: 38 | ColorHelper_Mac.printYellow(mess); 39 | 40 | 41 | -------------------------------------------------------------------------------- /Tool/ColorHelper_Mac.py: -------------------------------------------------------------------------------- 1 | class bcolors: 2 | HEADER = '\033[95m' 3 | OKBLUE = '\033[94m' 4 | OKGREEN = '\033[92m' 5 | WARNING = '\033[93m' 6 | FAIL = '\033[91m' 7 | ENDC = '\033[0m' 8 | BOLD = '\033[1m' 9 | UNDERLINE = '\033[4m' 10 | 11 | #green 12 | def printGreen(mess): 13 | print("\033[32m" + mess + '\n') 14 | 15 | #red 16 | def printRed(mess): 17 | print("\033[31m" + mess + '\n') 18 | 19 | #yellow 20 | def printYellow(mess): 21 | print("\033[33m" + mess + '\n') 22 | 23 | -------------------------------------------------------------------------------- /Tool/ColorHelper_Win.py: -------------------------------------------------------------------------------- 1 | import ctypes,sys 2 | 3 | STD_INPUT_HANDLE = -10 4 | STD_OUTPUT_HANDLE = -11 5 | STD_ERROR_HANDLE = -12 6 | 7 | #字体颜色定义 text colors 8 | FOREGROUND_BLUE = 0x09 # blue. 9 | FOREGROUND_GREEN = 0x0a # green. 10 | FOREGROUND_RED = 0x0c # red. 11 | FOREGROUND_YELLOW = 0x0e # yellow. 12 | 13 | # 背景颜色定义 background colors 14 | BACKGROUND_YELLOW = 0xe0 # yellow. 15 | 16 | # get handle 17 | std_out_handle = ctypes.windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE) 18 | 19 | def set_cmd_text_color(color, handle=std_out_handle): 20 | Bool = ctypes.windll.kernel32.SetConsoleTextAttribute(handle, color) 21 | return Bool 22 | 23 | #reset white 24 | def resetColor(): 25 | set_cmd_text_color(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE) 26 | 27 | #green 28 | def printGreen(mess): 29 | set_cmd_text_color(FOREGROUND_GREEN) 30 | sys.stdout.write(mess + '\n') 31 | resetColor() 32 | 33 | #red 34 | def printRed(mess): 35 | set_cmd_text_color(FOREGROUND_RED) 36 | sys.stdout.write(mess + '\n') 37 | resetColor() 38 | 39 | #yellow 40 | def printYellow(mess): 41 | set_cmd_text_color(FOREGROUND_YELLOW) 42 | sys.stdout.write(mess + '\n') 43 | resetColor() 44 | 45 | #white bkground and black text 46 | def printYellowRed(mess): 47 | set_cmd_text_color(BACKGROUND_YELLOW | FOREGROUND_RED) 48 | sys.stdout.write(mess + '\n') 49 | resetColor() -------------------------------------------------------------------------------- /Tool/CommonType.py: -------------------------------------------------------------------------------- 1 | from enum import Enum 2 | class VariableType(Enum): 3 | INT16 = 0 4 | INT32 = 1 5 | INT64 = 2 6 | UINT16 = 3 7 | UINT32 = 4 8 | UINT64 = 5 9 | STRING = 6 10 | FLOAT = 7 11 | DOUBLE = 8 12 | BOOL = 9 13 | ENUM = 10 14 | 15 | class CodeType(Enum): 16 | CS = 0 17 | CPP = 1 18 | JAVA = 2 19 | LUA = 3 20 | 21 | 22 | def GetStrToType(codeStr:str): 23 | codeStr = codeStr.lower(); 24 | if codeStr == "int16" or codeStr == "short": 25 | return VariableType.INT16; 26 | 27 | if codeStr == "int32" or codeStr == "int": 28 | return VariableType.INT32; 29 | 30 | if codeStr == "int64" or codeStr == "long": 31 | return VariableType.INT64; 32 | 33 | 34 | if codeStr == "uint16" or codeStr == "unsigned int16": 35 | return VariableType.UINT16; 36 | 37 | 38 | if codeStr == "uint32" or codeStr == "unsigned int": 39 | return VariableType.UINT32; 40 | 41 | 42 | if codeStr == "uint64" or codeStr == "unsigned long": 43 | return VariableType.UINT64; 44 | 45 | if codeStr == "string": 46 | return VariableType.STRING; 47 | 48 | if codeStr == "float": 49 | return VariableType.FLOAT; 50 | 51 | if codeStr == "double": 52 | return VariableType.DOUBLE; 53 | 54 | if codeStr == "bool": 55 | return VariableType.DOUBLE; 56 | 57 | if codeStr.find("enum.") > -1: 58 | return VariableType.ENUM; 59 | 60 | 61 | 62 | def GetTypeToRead(etype:VariableType,codeType:CodeType,enumName:str): 63 | if etype == VariableType.INT16: 64 | if codeType == CodeType.CS: 65 | return "bin.ReadInt16();"; 66 | elif codeType == CodeType.CPP: 67 | return "bin->ReadInt16();"; 68 | elif codeType == CodeType.JAVA: 69 | return "bin.ReadInt16();"; 70 | 71 | 72 | if etype == VariableType.INT32: 73 | if codeType == CodeType.CS: 74 | return "bin.ReadInt32();"; 75 | elif codeType == CodeType.CPP: 76 | return "bin->ReadInt32();"; 77 | elif codeType == CodeType.JAVA: 78 | return "bin.ReadInt32();"; 79 | 80 | 81 | if etype == VariableType.INT64: 82 | if codeType == CodeType.CS: 83 | return "bin.ReadInt64();"; 84 | elif codeType == CodeType.CPP: 85 | return "bin->ReadInt64();"; 86 | elif codeType == CodeType.JAVA: 87 | return "bin.ReadInt64();"; 88 | 89 | if etype == VariableType.UINT16: 90 | if codeType == CodeType.CS: 91 | return "bin.ReadUInt16();"; 92 | elif codeType == CodeType.CPP: 93 | return "bin->ReadUInt16();"; 94 | elif codeType == CodeType.JAVA: 95 | return "bin.ReadUInt16();"; 96 | 97 | if etype == VariableType.UINT32: 98 | if codeType == CodeType.CS: 99 | return "bin.ReadString();"; 100 | elif codeType == CodeType.CPP: 101 | return "bin->ReadString();"; 102 | elif codeType == CodeType.JAVA: 103 | return "bin.ReadString();"; 104 | 105 | 106 | 107 | if etype == VariableType.UINT64: 108 | if codeType == CodeType.CS: 109 | return "bin.ReadUInt64();"; 110 | elif codeType == CodeType.CPP: 111 | return "bin->ReadUInt64();"; 112 | elif codeType == CodeType.JAVA: 113 | return "bin.ReadUInt64();"; 114 | 115 | if etype == VariableType.STRING: 116 | if codeType == CodeType.CS: 117 | return "bin.ReadString();"; 118 | elif codeType == CodeType.CPP: 119 | return "bin->ReadString();"; 120 | elif codeType == CodeType.JAVA: 121 | return "bin.ReadString();"; 122 | 123 | 124 | if etype == VariableType.FLOAT: 125 | if codeType == CodeType.CS: 126 | return "bin.ReadFloat();"; 127 | elif codeType == CodeType.CPP: 128 | return "bin->ReadFloat();"; 129 | elif codeType == CodeType.JAVA: 130 | return "bin.ReadFloat();"; 131 | 132 | if etype == VariableType.DOUBLE: 133 | if codeType == CodeType.CS: 134 | return "bin.ReadDouble();"; 135 | elif codeType == CodeType.CPP: 136 | return "bin->ReadDouble();"; 137 | elif codeType == CodeType.JAVA: 138 | return "bin.ReadDouble();"; 139 | 140 | 141 | if etype == VariableType.BOOL: 142 | if codeType == CodeType.CS: 143 | return "bin.ReadBoolean();"; 144 | elif codeType == CodeType.CPP: 145 | return "bin->ReadBoolean();"; 146 | elif codeType == CodeType.JAVA: 147 | return "bin.ReadBoolean();"; 148 | 149 | 150 | if etype == VariableType.ENUM: 151 | if codeType == CodeType.CS: 152 | return "("+enumName + ")bin.ReadInt32();"; 153 | elif codeType == CodeType.CPP: 154 | return "("+enumName + ")bin->ReadInt32();"; 155 | elif codeType == CodeType.JAVA: 156 | return enumName + ".fromInt(bin.ReadInt32());"; 157 | return "GetTypeToRead error"; 158 | 159 | 160 | def GetTypeToStr(etype:VariableType,codeType:CodeType): 161 | if etype == VariableType.INT16: 162 | if codeType == CodeType.CS: 163 | return "Int16"; 164 | elif codeType == CodeType.CPP: 165 | return "short"; 166 | elif codeType == CodeType.JAVA: 167 | return "Short"; 168 | 169 | if etype == VariableType.INT32: 170 | if codeType == CodeType.CS: 171 | return "Int32"; 172 | elif codeType == CodeType.CPP: 173 | return "int"; 174 | elif codeType == CodeType.JAVA: 175 | return "Integer"; 176 | 177 | if etype == VariableType.INT64: 178 | if codeType == CodeType.CS: 179 | return "Int64"; 180 | elif codeType == CodeType.CPP: 181 | return "long"; 182 | elif codeType == CodeType.JAVA: 183 | return "Long"; 184 | 185 | if etype == VariableType.UINT16: 186 | if codeType == CodeType.CS: 187 | return "UInt16"; 188 | elif codeType == CodeType.CPP: 189 | return "unsigned short"; 190 | elif codeType == CodeType.JAVA: 191 | return "Short"; 192 | 193 | if etype == VariableType.UINT32: 194 | if codeType == CodeType.CS: 195 | return "UInt32"; 196 | elif codeType == CodeType.CPP: 197 | return "unsigned int"; 198 | elif codeType == CodeType.JAVA: 199 | return "Integer"; 200 | 201 | if etype == VariableType.UINT64: 202 | if codeType == CodeType.CS: 203 | return "UInt64"; 204 | elif codeType == CodeType.CPP: 205 | return "unsigned long"; 206 | elif codeType == CodeType.JAVA: 207 | return "Long"; 208 | 209 | if etype == VariableType.STRING: 210 | if codeType == CodeType.CS: 211 | return "string"; 212 | elif codeType == CodeType.CPP: 213 | return "std::string"; 214 | elif codeType == CodeType.JAVA: 215 | return "String"; 216 | 217 | if etype == VariableType.FLOAT: 218 | if codeType == CodeType.CS: 219 | return "float"; 220 | elif codeType == CodeType.CPP: 221 | return "float"; 222 | elif codeType == CodeType.JAVA: 223 | return "Float"; 224 | 225 | if etype == VariableType.DOUBLE: 226 | if codeType == CodeType.CS: 227 | return "double"; 228 | elif codeType == CodeType.CPP: 229 | return "double"; 230 | elif codeType == CodeType.JAVA: 231 | return "Double"; 232 | 233 | 234 | if etype == VariableType.BOOL: 235 | if codeType == CodeType.CS: 236 | return "bool"; 237 | elif codeType == CodeType.CPP: 238 | return "bool"; 239 | elif codeType == CodeType.JAVA: 240 | return "Boolean"; 241 | 242 | if etype == VariableType.ENUM: 243 | return "enum"; 244 | 245 | return "GetTypeToStr error"; -------------------------------------------------------------------------------- /Tool/ConfigExcelData.py: -------------------------------------------------------------------------------- 1 | # Type symbol Type number Python value 2 | # XL_CELL_EMPTY 0 empty string '' 3 | # XL_CELL_TEXT 1 a Unicode string 4 | # XL_CELL_NUMBER 2 float 5 | # XL_CELL_DATE 3 float 6 | # XL_CELL_BOOLEAN 4 int; 1 means TRUE, 0 means FALSE 7 | # XL_CELL_ERROR 5 int representing internal Excel codes; for a text representation, refer to the supplied dictionary error_text_from_code 8 | # XL_CELL_BLANK 6 empty string ''. Note: this type will appear only when open_workbook(..., formatting_info=True) is used. 9 | 10 | 11 | # x pad byte no value 12 | # c char string of length 1 1 13 | # b signed char integer 1 (3) 14 | # B unsigned char integer 1 (3) 15 | # ? _Bool bool 1 (1) 16 | # h short integer 2 (3) 17 | # H unsigned short integer 2 (3) 18 | # i int integer 4 (3) 19 | # I unsigned int integer 4 (3) 20 | # l long integer 4 (3) 21 | # L unsigned long integer 4 (3) 22 | # q long long integer 8 (2), (3) 23 | # Q unsigned long long integer 8 (2), (3) 24 | # f float float 4 (4) 25 | # d double float 8 (4) 26 | # s char[] string 1 27 | # p char[] string 28 | # P void * integer (5), (3) 29 | from re import search 30 | import struct 31 | import EnumUtils 32 | import ColorHelper 33 | import CommonType 34 | from CommonType import VariableType; 35 | from CommonType import CodeType; 36 | 37 | 38 | class ConfigExcelData: 39 | def __init__(self, value, valueName, type, mark, isTitle) -> None: 40 | self.m_enum = ""; 41 | self.m_value = value 42 | self.m_typeStr = type; 43 | self.m_typeStr = self.m_typeStr.replace(" ",""); 44 | self.m_valueType = CommonType.GetStrToType(self.m_typeStr); 45 | self.m_mark = mark 46 | mainIndex = valueName.find("(FirstKey)") 47 | secondIndex = valueName.find("(SecondKey)") 48 | self.m_bMainKey = False; 49 | self.m_bSecondKey = False; 50 | if mainIndex > -1: 51 | self.m_bMainKey = True 52 | valueName = valueName.replace("(FirstKey)", "") 53 | if secondIndex > -1: 54 | self.m_bSecondKey = True 55 | valueName = valueName.replace("(SecondKey)", "") 56 | self.m_valueName = valueName; 57 | if not isTitle: 58 | self.TypeToValue() 59 | 60 | if self.m_typeStr.find("enum") > -1: 61 | self.m_enum = (self.m_typeStr.split('.')[1]) 62 | 63 | 64 | def GetValueName(self): 65 | return self.m_valueName 66 | 67 | 68 | def StrToInt(self, strValue: str): 69 | if len(strValue) < 1: 70 | return 0 71 | index = strValue.find(".") 72 | if index > -1: 73 | strValue = strValue[0:index] 74 | 75 | if len(strValue) < 1: 76 | return 0 77 | 78 | return int(strValue) 79 | 80 | def GetVariableTypeEnum(self): 81 | return self.m_valueType; 82 | 83 | def TypeIsInt(self): 84 | return VariableType.INT16 == self.m_valueType or VariableType.INT32 == self.m_valueType or VariableType.INT64 == self.m_valueType or VariableType.UINT16 == self.m_valueType or VariableType.UINT32 == self.m_valueType or VariableType.UINT64 == self.m_valueType; 85 | 86 | def TypeIsFloat(self): 87 | return VariableType.FLOAT == self.m_valueType or VariableType.DOUBLE == self.m_valueType; 88 | 89 | 90 | 91 | def TypeToValue(self): 92 | value = str(self.m_value); 93 | if self.TypeIsInt() == True: 94 | value = self.StrToInt(value) 95 | elif VariableType.BOOL == self.m_valueType: 96 | if len(value) < 1: 97 | value = False 98 | else: 99 | value = bool(value) 100 | elif self.TypeIsFloat() == True: 101 | if len(value) < 1: 102 | value = 0 103 | else: 104 | value = float(value) 105 | elif VariableType.ENUM == self.m_valueType: 106 | list = value.split(".") 107 | if len(list) < 2: 108 | ColorHelper.printRed("value is error:" + value) 109 | exit() 110 | value = EnumUtils.GetIndex(list[0], list[1]) 111 | value = int(value) 112 | self.m_value = value 113 | 114 | def GetMark(self) -> str: 115 | return self.m_mark; 116 | 117 | def IsMainKey(self): 118 | return self.m_bMainKey 119 | 120 | def IsSecondKey(self): 121 | return self.m_bSecondKey 122 | 123 | def GetBytes(self): 124 | value = self.m_value 125 | binValue = "" 126 | if self.m_valueType == VariableType.INT16: 127 | binValue = struct.pack("h", value) 128 | if self.m_valueType == VariableType.INT32: 129 | binValue = struct.pack("i", value) 130 | elif self.m_valueType == VariableType.INT64: 131 | binValue = struct.pack("l", value) 132 | elif self.m_valueType == VariableType.UINT16: 133 | binValue = struct.pack("H", value) 134 | elif self.m_valueType == VariableType.UINT32: 135 | binValue = struct.pack("I", value) 136 | elif self.m_valueType == VariableType.UINT64: 137 | binValue = struct.pack("L", value) 138 | elif self.m_valueType == VariableType.BOOL: 139 | binValue = struct.pack("?", value) 140 | elif self.m_valueType == VariableType.FLOAT: 141 | binValue = struct.pack("f", value) 142 | elif self.m_valueType == VariableType.DOUBLE: 143 | binValue = struct.pack("d", value) 144 | elif self.m_valueType == VariableType.ENUM: 145 | binValue = struct.pack("i", value) 146 | elif self.m_valueType == VariableType.STRING: 147 | value = value.encode("utf-8") 148 | binValue = struct.pack("i%ds" % len(value), len(value), value) 149 | else: 150 | value = value.encode("utf-8") 151 | binValue = struct.pack("i%ds" % len(value), len(value), value) 152 | return binValue 153 | 154 | 155 | def GetValue(self): 156 | return self.m_value 157 | 158 | 159 | def IsEnum(self) -> bool: 160 | if self.m_typeStr.find("enum") > -1: 161 | return True 162 | return False 163 | 164 | def GetVariableType(self,codeType:CodeType): 165 | if codeType == CodeType.CS: 166 | if self.IsEnum(): 167 | return self.m_enum; 168 | return CommonType.GetTypeToStr(self.m_valueType,codeType); 169 | elif codeType == CodeType.CPP: 170 | if self.IsEnum(): 171 | return self.m_enum; 172 | return CommonType.GetTypeToStr(self.m_valueType,codeType); 173 | elif codeType == CodeType.JAVA: 174 | if self.IsEnum(): 175 | return self.m_enum; 176 | return CommonType.GetTypeToStr(self.m_valueType,codeType); 177 | 178 | 179 | def GetClassVariable(self,codeType:CodeType): 180 | if codeType == CodeType.CS: 181 | if self.IsEnum(): 182 | return "private "+self.m_enum+" m_" + self.m_valueName + ";" 183 | return "private "+CommonType.GetTypeToStr(self.m_valueType,codeType)+" m_" + self.m_valueName + ";" 184 | elif codeType == CodeType.JAVA: 185 | if self.IsEnum(): 186 | return "private "+self.m_enum+" m_" + self.m_valueName + ";" 187 | return "private "+CommonType.GetTypeToStr(self.m_valueType,codeType)+" m_" + self.m_valueName + ";" 188 | elif codeType == CodeType.CPP: 189 | if self.IsEnum(): 190 | return self.m_enum+" m_" + self.m_valueName + ";" 191 | return CommonType.GetTypeToStr(self.m_valueType,codeType)+" m_" + self.m_valueName + ";" 192 | 193 | def GetGetVariableRead(self,codeType:CodeType): 194 | if codeType == CodeType.CS: 195 | if self.IsEnum(): 196 | return "public "+self.m_enum+" " + self.m_valueName + " => " + " m_" + self.m_valueName + ";" 197 | return "public "+CommonType.GetTypeToStr(self.m_valueType,codeType)+" " + self.m_valueName + " => " + " m_" + self.m_valueName + ";" 198 | elif codeType == CodeType.JAVA: 199 | if self.IsEnum(): 200 | return self.m_enum +" Get" + self.m_valueName + "(){ return m_" + self.m_valueName + ";};" 201 | return CommonType.GetTypeToStr(self.m_valueType,codeType)+" Get" + self.m_valueName + "(){ return m_" + self.m_valueName + ";};" 202 | elif codeType == CodeType.CPP: 203 | if self.IsEnum(): 204 | return self.m_enum +" Get" + self.m_valueName + "(){ return m_" + self.m_valueName + ";};" 205 | return CommonType.GetTypeToStr(self.m_valueType,codeType)+" Get" + self.m_valueName + "(){ return m_" + self.m_valueName + ";};" 206 | 207 | def GetTypeToRead(self,codeType:CodeType): 208 | readContent = CommonType.GetTypeToRead(self.m_valueType,codeType,self.m_enum); 209 | return " m_" + self.m_valueName + " = " + readContent; 210 | -------------------------------------------------------------------------------- /Tool/ConfigExcelRow.py: -------------------------------------------------------------------------------- 1 | from typing import List, Tuple 2 | import xlrd 3 | 4 | from ConfigExcelData import ConfigExcelData 5 | from CommonType import VariableType; 6 | from CommonType import CodeType; 7 | 8 | class ConfigExcelRowTitle: 9 | def __init__(self, row, type,mark) -> None: 10 | self.__datalist = [] 11 | colCount = len(row) 12 | for i in range(colCount): 13 | cell = row[i] 14 | item = ConfigExcelData("", cell, type.GetValue(i), mark.GetValue(i), True) 15 | self.__datalist.append(item) 16 | 17 | def GetValue(self, index): 18 | return self.__datalist[index].GetValue() 19 | 20 | def GetValueName(self, index): 21 | return self.__datalist[index].GetValueName() 22 | 23 | def GetVariableType(self,codeType:CodeType): 24 | return self.__datalist[index].GetVariableType(codeType); 25 | 26 | def GetValueNameList(self): 27 | csList = [] 28 | for item in self.__datalist: 29 | csList.append(item.GetValueName()); 30 | return csList 31 | 32 | def GetClassVariable(self,codeType:CodeType): 33 | csList = [] 34 | for item in self.__datalist: 35 | csList.append(item.GetClassVariable(codeType)) 36 | return csList 37 | 38 | 39 | def GetGetVariableRead(self,codeType:CodeType): 40 | csList = [] 41 | for item in self.__datalist: 42 | csList.append(item.GetGetVariableRead(codeType)) 43 | return csList 44 | 45 | def GetMarkList(self) -> List: 46 | csList = [] 47 | for item in self.__datalist: 48 | csList.append(item.GetMark()) 49 | return csList 50 | 51 | def GetTypeToRead(self,codeType:CodeType) -> List: 52 | csList = [] 53 | for item in self.__datalist: 54 | csList.append(item.GetTypeToRead(codeType)); 55 | return csList 56 | 57 | def GetCount(self) -> int: 58 | return len(self.__datalist) 59 | 60 | def GetMainKey(self) -> List: 61 | mainKeyList: List = [] 62 | for item in self.__datalist: 63 | if item.IsMainKey() == True: 64 | mainKeyList.append(item) 65 | 66 | for item in self.__datalist: 67 | if item.IsSecondKey() == True: 68 | mainKeyList.append(item) 69 | 70 | return mainKeyList 71 | 72 | 73 | class ConfigExcelRowType: 74 | def __init__(self, row) -> None: 75 | self.__datalist = [] 76 | for cell in row: 77 | item = ConfigExcelData(cell, "", "", "", False) 78 | self.__datalist.append(item) 79 | 80 | def GetValue(self, index): 81 | return self.__datalist[index].GetValue() 82 | 83 | 84 | class ConfigExcelRowMark: 85 | def __init__(self, row) -> None: 86 | self.__datalist: List = [] 87 | for cell in row: 88 | item = ConfigExcelData(cell, "", "", "", False) 89 | self.__datalist.append(item) 90 | 91 | def GetValue(self, index): 92 | return self.__datalist[index].GetValue() 93 | 94 | def GetCount(self) -> int: 95 | return len(self.__datalist) 96 | 97 | 98 | class ConfigExcelRow: 99 | def __init__(self, row, title, type, mark) -> None: 100 | self.__datalist = [] 101 | colCount = len(row) 102 | for i in range(0, colCount): 103 | if i < colCount: 104 | cell = row[i] 105 | else: 106 | cell = "" 107 | 108 | titleValue = title.GetValueName(i) 109 | 110 | typeValue = type.GetValue(i).lower() 111 | markValue = mark.GetValue(i) 112 | item = ConfigExcelData(cell, titleValue, typeValue, markValue, False) 113 | self.__datalist.append(item) 114 | 115 | def GetCellBinList(self) -> list: 116 | cellList = [] 117 | for cell in self.__datalist: 118 | cellList.append(cell.GetBytes()) 119 | return cellList 120 | 121 | def GetVariableTypeEnum(self,index): 122 | return self.__datalist[index].GetVariableTypeEnum() 123 | 124 | def GetValue(self, index) -> list: 125 | return self.__datalist[index].GetValue() 126 | 127 | def GetCellBin(self, index) -> list: 128 | return self.__datalist[index].GetBytes() 129 | 130 | 131 | class DataExcelRow: 132 | def __init__(self, firstRow, curRow) -> None: 133 | self.__datalist = [] 134 | for i in range(0, len(firstRow)): 135 | value = firstRow[i] 136 | if value.find("#") > -1: 137 | continue 138 | self.__datalist.append(curRow[i]) 139 | 140 | def __len__(self): 141 | return len(self.__datalist) 142 | 143 | def __getitem__(self, key): 144 | return self.__datalist[key] 145 | -------------------------------------------------------------------------------- /Tool/ConfigExcelSheel.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | from ConfigExcelRow import ConfigExcelRow, ConfigExcelRowTitle, ConfigExcelRowType, ConfigExcelRowMark, DataExcelRow 3 | import xlrd 4 | from CommonType import VariableType; 5 | from CommonType import CodeType; 6 | 7 | 8 | # 第一行变量名 加#代表不写入,第一列一定是ID 9 | #(Main)代表为主键,(Second)代表为第二主键,如果没有标注,以第一列ID为主键,暂时只支持主键 10 | # 第二行是注释,或者备注,不写入 11 | # 第三行是类型,int string bool enum等,大小写无所谓 12 | # 第四行是具体数据的开始 13 | class ConfigExcelSheel: 14 | def __init__(self, sheet) -> None: 15 | self.__name = sheet.name 16 | 17 | firstRow = sheet.row_values(0) 18 | cullRow = DataExcelRow(firstRow, firstRow) 19 | self.__listrow = []; 20 | self.__rowMark = ConfigExcelRowMark(DataExcelRow(firstRow, sheet.row_values(1))) 21 | self.__rowType = ConfigExcelRowType(DataExcelRow(firstRow, sheet.row_values(2))) 22 | self.__rowTitle = ConfigExcelRowTitle(DataExcelRow(firstRow, sheet.row_values(0)), self.__rowType,self.__rowMark); 23 | 24 | self.__rowcount = sheet.nrows 25 | self.__colcount = len(cullRow) 26 | for i in range(3, self.__rowcount): 27 | row = sheet.row_values(i) 28 | item = ConfigExcelRow(DataExcelRow(firstRow, row), self.__rowTitle, self.__rowType, self.__rowMark) 29 | self.__listrow.append(item) 30 | 31 | 32 | def GetName(self) -> str: 33 | return self.__name 34 | 35 | def GetRowCount(self) -> int: 36 | return self.__rowcount 37 | 38 | def GetVariableType(self,codeType:CodeType): 39 | return self.__rowTitle.GetVariableType(codeType); 40 | 41 | def GetGetVariableRead(self,codeType:CodeType) -> List: 42 | return self.__rowTitle.GetGetVariableRead(codeType); 43 | 44 | def GetMarkList(self) -> List: 45 | return self.__rowTitle.GetMarkList() 46 | 47 | 48 | def GetClassVariable(self,codeType:CodeType) -> List: 49 | return self.__rowTitle.GetClassVariable(codeType) 50 | 51 | def GetTypeToRead(self,codeType:CodeType) -> List: 52 | return self.__rowTitle.GetTypeToRead(codeType) 53 | 54 | 55 | 56 | def GetMainKey(self) -> List: 57 | return self.__rowTitle.GetMainKey() 58 | 59 | 60 | def GetValueDic(self)->dict: 61 | valueDic = {}; 62 | list = self.__listrow 63 | for index in range(len(list)): 64 | row = list[index] 65 | for colIndex in range(self.__colcount): 66 | name = self.__rowTitle.GetValueName(colIndex); 67 | if False == (name in valueDic.keys()): 68 | valueDic[name] = []; 69 | valueDic[name].append(row.GetValue(colIndex)) 70 | return valueDic; 71 | 72 | #Lua 需要特殊处理 73 | def GetValueLuaDic(self)->dict: 74 | valueDic = {}; 75 | list = self.__listrow 76 | for index in range(len(list)): 77 | row = list[index] 78 | for colIndex in range(self.__colcount): 79 | name = self.__rowTitle.GetValueName(colIndex); 80 | if False == (name in valueDic.keys()): 81 | valueDic[name] = []; 82 | valueType = row.GetVariableTypeEnum(colIndex) 83 | if valueType == VariableType.STRING: 84 | valueDic[name].append("\""+row.GetValue(colIndex)+"\""); 85 | else: 86 | valueDic[name].append(row.GetValue(colIndex)) 87 | return valueDic; 88 | 89 | 90 | def GetBinList(self) -> List: 91 | binList: List = [] 92 | list = self.__listrow 93 | for index in range(len(list)): 94 | row = list[index] 95 | for colIndex in range(self.__colcount): 96 | binList.append(row.GetCellBin(colIndex)) 97 | return binList 98 | 99 | -------------------------------------------------------------------------------- /Tool/ConfigExcelWork.py: -------------------------------------------------------------------------------- 1 | from typing import Dict 2 | from typing import List 3 | from ConfigExcelData import ConfigExcelData 4 | from ConfigExcelSheel import ConfigExcelSheel 5 | from Content import Content 6 | from BinWrite import BinWrite 7 | import xlrd 8 | import ExcelUtils 9 | import os 10 | import Derictory 11 | import ColorHelper; 12 | import sys; 13 | from CommonType import VariableType; 14 | from CommonType import CodeType; 15 | 16 | 17 | class ConfigExcelWork: 18 | def __init__(self, path: str) -> None: 19 | self.__sheetList = []; 20 | self.__sheetDic: Dict = {} 21 | self.__workName = ""; 22 | workBook = ExcelUtils.GetXLSX(path) 23 | if workBook is None: 24 | print("path is error:" + path) 25 | return 26 | self.__workName = os.path.basename(path).split('.')[0] 27 | workSheets = workBook.sheets() 28 | if workSheets is None: 29 | print("sheets is none:" + path) 30 | for sheet in workSheets: 31 | excelSheet = ConfigExcelSheel(sheet) 32 | self.__sheetList.append(excelSheet) 33 | self.__sheetDic[excelSheet.GetName()] = excelSheet 34 | 35 | def ExportBin(self, binPath: str): 36 | try: 37 | binPath = os.path.join(binPath, self.__workName + ".bin") 38 | binPath = binPath.replace("\\", "/"); 39 | rowCount = self.GetRowCount() 40 | dataCount = self.GetDataCount() 41 | binWrite = BinWrite(binPath) 42 | binWrite.WriteInt(dataCount) 43 | for sheet in self.__sheetList: 44 | binlist = sheet.GetBinList() 45 | binWrite.WriteList(binlist) 46 | binWrite.EndWrite() 47 | except: 48 | ColorHelper.printRed(binPath + " is error"); 49 | sys.exit(); 50 | 51 | def GetDataCount(self) -> int: 52 | rowCount = self.GetRowCount() 53 | dataCount = rowCount - 3 54 | return dataCount 55 | 56 | def GetRowCount(self) -> int: 57 | count = 0 58 | for sheet in self.__sheetList: 59 | count = count + sheet.GetRowCount() 60 | return count 61 | 62 | def GetKeyList(self) -> List: 63 | return self.__sheetList[0].GetMainKey() 64 | 65 | def GetValueNameList(self) -> List: 66 | return self.__sheetList[0].GetValueNameList(); 67 | 68 | def GetValueDic(self)->dict: 69 | return self.__sheetList[0].GetValueDic(); 70 | 71 | def GetValueLuaDic(self)->dict: 72 | return self.__sheetList[0].GetValueLuaDic(); 73 | 74 | def GetGetVariableRead(self,codeType:CodeType) -> List: 75 | return self.__sheetList[0].GetGetVariableRead(codeType); 76 | 77 | def GetMarkList(self) -> List: 78 | return self.__sheetList[0].GetMarkList() 79 | 80 | def GetVariableType(self,codeType:CodeType): 81 | return self.__sheetList[0].GetVariableType(codeType); 82 | 83 | def GetClassVariable(self,codeType:CodeType) -> List: 84 | return self.__sheetList[0].GetClassVariable(codeType) 85 | 86 | def GetTypeToRead(self,codeType:CodeType) -> List: 87 | return self.__sheetList[0].GetTypeToRead(codeType) 88 | 89 | def GetMarkList(self) -> List: 90 | return self.__sheetList[0].GetMarkList() 91 | 92 | 93 | 94 | 95 | def ExportCS(self, path: str,templatePath:str): 96 | path = os.path.join(path, self.__workName + ".cs") 97 | path = path.replace("\\","/"); 98 | workName = self.__workName 99 | listKey = self.GetKeyList() 100 | 101 | MainData:ConfigExcelData = None; 102 | SecondData:ConfigExcelData = None 103 | listKeyCount = len(listKey) 104 | if listKeyCount > 0: 105 | MainData = listKey[0] 106 | 107 | if listKeyCount > 1: 108 | SecondData = listKey[1] 109 | 110 | try: 111 | templatePath = os.path.join(templatePath,"Template"+str(listKeyCount) + ".cs"); 112 | templatePath = templatePath.replace("\\","/"); 113 | f = open(templatePath,'r',encoding='utf-8') 114 | cscontent = f.read(); 115 | except: 116 | ColorHelper.printRed(path +" is error"); 117 | sys.exit(); 118 | 119 | valueList = self.GetClassVariable(CodeType.CS); 120 | valueGetList = self.GetGetVariableRead(CodeType.CS); 121 | markList = self.GetMarkList(); 122 | valueContent = ""; 123 | for i in range(len(valueList)): 124 | value = valueList[i] 125 | valueGet = valueGetList[i] 126 | valueMark = markList[i]; 127 | valueContent = valueContent + "\t\t//" + valueMark + "\n"; 128 | valueContent = valueContent + "\t\t" + value + "\n"; 129 | valueContent = valueContent + "\t\t" + valueGet + "\n"; 130 | 131 | cscontent = cscontent.replace("TemplateClass",workName); 132 | if MainData != None: 133 | cscontent = cscontent.replace("FirstKeyType",MainData.GetVariableType(CodeType.CS)); 134 | cscontent = cscontent.replace("FirstKey",MainData.GetValueName()); 135 | 136 | if SecondData != None: 137 | cscontent = cscontent.replace("SecondKeyType",SecondData.GetVariableType(CodeType.CS)); 138 | cscontent = cscontent.replace("SecondKey",SecondData.GetValueName()); 139 | 140 | cscontent = cscontent.replace("ValueContent",valueContent); 141 | 142 | 143 | 144 | valueContent = ""; 145 | valueReadList = self.GetTypeToRead(CodeType.CS); 146 | for value in valueReadList: 147 | valueContent = valueContent + "\t\t\t"+ value + "\n"; 148 | 149 | cscontent = cscontent.replace("ReadValueLoadContent",valueContent); 150 | with open(path, "w") as f: 151 | f.write(cscontent) 152 | 153 | 154 | 155 | 156 | 157 | def ExportJava(self, path: str,templatePath:str,javaPackage:str): 158 | path = os.path.join(path, self.__workName + ".java") 159 | path = path.replace("\\","/"); 160 | workName = self.__workName 161 | listKey = self.GetKeyList() 162 | 163 | MainData:ConfigExcelData = None; 164 | SecondData:ConfigExcelData = None 165 | listKeyCount = len(listKey) 166 | if listKeyCount > 0: 167 | MainData = listKey[0] 168 | 169 | if listKeyCount > 1: 170 | SecondData = listKey[1] 171 | 172 | try: 173 | templatePath = os.path.join(templatePath,"Template"+str(listKeyCount) + ".java"); 174 | templatePath = templatePath.replace("\\","/"); 175 | f = open(templatePath,'r',encoding='utf-8') 176 | cscontent = f.read(); 177 | except: 178 | ColorHelper.printRed(path +" is error"); 179 | sys.exit(); 180 | 181 | valueList = self.GetClassVariable(CodeType.JAVA); 182 | valueGetList = self.GetGetVariableRead(CodeType.JAVA); 183 | markList = self.GetMarkList(); 184 | valueContent = ""; 185 | for i in range(len(valueList)): 186 | value = valueList[i] 187 | valueGet = valueGetList[i] 188 | valueMark = markList[i]; 189 | valueContent = valueContent + "\t//" + valueMark + "\n"; 190 | valueContent = valueContent + "\t" + value + "\n"; 191 | valueContent = valueContent + "\t" + valueGet + "\n"; 192 | 193 | cscontent = cscontent.replace("TemplateClass",workName); 194 | if MainData != None: 195 | cscontent = cscontent.replace("FirstKeyType",MainData.GetVariableType(CodeType.JAVA)); 196 | cscontent = cscontent.replace("FirstKey",MainData.GetValueName()); 197 | 198 | if SecondData != None: 199 | cscontent = cscontent.replace("SecondKeyType",SecondData.GetVariableType(CodeType.JAVA)); 200 | cscontent = cscontent.replace("SecondKey",SecondData.GetValueName()); 201 | 202 | cscontent = cscontent.replace("ValueContent",valueContent); 203 | 204 | 205 | 206 | valueContent = ""; 207 | valueReadList = self.GetTypeToRead(CodeType.JAVA); 208 | for value in valueReadList: 209 | valueContent = valueContent + "\t\t"+ value + "\n"; 210 | 211 | cscontent = cscontent.replace("ReadValueLoadContent",valueContent); 212 | cscontent = cscontent.replace("package TableConfig;","package "+javaPackage + ";"); 213 | with open(path, "w") as f: 214 | f.write(cscontent) 215 | 216 | 217 | 218 | 219 | def ExportCpp(self, path: str,templatePath:str): 220 | 221 | pathh = os.path.join(path, self.__workName + ".h") 222 | pathh = pathh.replace("\\","/"); 223 | 224 | pathcpp = os.path.join(path, self.__workName + ".cpp") 225 | pathcpp = pathcpp.replace("\\","/"); 226 | workName = self.__workName 227 | listKey = self.GetKeyList() 228 | 229 | MainData:ConfigExcelData = None; 230 | SecondData:ConfigExcelData = None 231 | listKeyCount = len(listKey) 232 | if listKeyCount > 0: 233 | MainData = listKey[0] 234 | 235 | if listKeyCount > 1: 236 | SecondData = listKey[1] 237 | 238 | try: 239 | templateCppPath = os.path.join(templatePath,"Template"+str(listKeyCount) + ".cpp"); 240 | templateCppPath = templateCppPath.replace("\\","/"); 241 | fCpp = open(templateCppPath,'r',encoding='utf-8') 242 | cppcontent = fCpp.read(); 243 | 244 | templatehPath = os.path.join(templatePath,"Template"+str(listKeyCount) + ".h"); 245 | templatehPath = templatehPath.replace("\\","/"); 246 | fh = open(templatehPath,'r',encoding='utf-8') 247 | hcontent = fh.read(); 248 | except Exception as e: 249 | ColorHelper.printRed(pathcpp +" is error"); 250 | sys.exit(); 251 | 252 | valueList = self.GetClassVariable(CodeType.CPP); 253 | valueGetList = self.GetGetVariableRead(CodeType.CPP); 254 | markList = self.GetMarkList(); 255 | valueContent = ""; 256 | valueGetContent = ""; 257 | for i in range(len(valueList)): 258 | value = valueList[i] 259 | valueGet = valueGetList[i] 260 | valueMark = markList[i]; 261 | valueContent = valueContent + "\t//" + valueMark + "\n"; 262 | valueContent = valueContent + "\t" + value + "\n"; 263 | valueGetContent = valueGetContent + "\t" + valueGet + "\n"; 264 | 265 | hcontent = hcontent.replace("ValueContentFunction",valueGetContent); 266 | hcontent = hcontent.replace("ValueContent",valueContent); 267 | hcontent = hcontent.replace("TemplateClass",workName); 268 | 269 | cppcontent = cppcontent.replace("TemplateClass",workName); 270 | if MainData != None: 271 | hcontent = hcontent.replace("FirstKeyType",MainData.GetVariableType(CodeType.CPP)); 272 | hcontent = hcontent.replace("FirstKey",MainData.GetValueName()); 273 | cppcontent = cppcontent.replace("FirstKeyType",MainData.GetVariableType(CodeType.CPP)); 274 | cppcontent = cppcontent.replace("FirstKey",MainData.GetValueName()); 275 | 276 | if SecondData != None: 277 | hcontent = hcontent.replace("SecondKeyType",SecondData.GetVariableType(CodeType.CPP)); 278 | hcontent = hcontent.replace("SecondKey",SecondData.GetValueName()); 279 | cppcontent = cppcontent.replace("SecondKeyType",SecondData.GetVariableType(CodeType.CPP)); 280 | cppcontent = cppcontent.replace("SecondKey",SecondData.GetValueName()); 281 | 282 | 283 | 284 | 285 | 286 | valueContent = ""; 287 | valueReadList = self.GetTypeToRead(CodeType.CPP); 288 | for value in valueReadList: 289 | valueContent = valueContent + "\t" + value + "\n"; 290 | 291 | cppcontent = cppcontent.replace("ReadValueLoadContent",valueContent); 292 | with open(pathcpp, "w") as f: 293 | f.write(cppcontent) 294 | 295 | with open(pathh, "w") as f: 296 | f.write(hcontent) 297 | 298 | 299 | 300 | def ExportLua(self, path: str,templatePath:str): 301 | path = os.path.join(path, self.__workName + ".lua") 302 | path = path.replace("\\","/"); 303 | valueDic = self.GetValueLuaDic(); 304 | listDic = {}; 305 | for k,v in valueDic.items(): 306 | name = k; 307 | list = v; 308 | for i in range(0,len(list)): 309 | value = (name ,list[0]); 310 | if False == (i in listDic.keys()): 311 | listDic[i] = []; 312 | listDic[i].append(value); 313 | 314 | 315 | content = Content(); 316 | content.WriteLine("require(\"CommonLua\")"); 317 | content.WriteLine("local " + self.__workName + "=readOnly") 318 | content.StartBlock(); 319 | for k,v in listDic.items(): 320 | content.WriteLine("["+str(k)+"]="); 321 | content.StartBlock(); 322 | listRow = v; 323 | for i in range(0,len(listRow)): 324 | value = listRow[i]; 325 | content.WriteLine(str(value[0]) +"="+ str(value[1]) + ","); 326 | content.EndBlock(); 327 | content.WriteLine(","); 328 | content.EndBlock(); 329 | content.WriteFile(path); -------------------------------------------------------------------------------- /Tool/Content.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | import Derictory 3 | import os 4 | 5 | 6 | class Content: 7 | listContent: List 8 | tableStr: str 9 | 10 | def __init__(self): 11 | self.tableStr = "" 12 | self.listContent = [] 13 | 14 | def StartBlock(self) -> None: 15 | contentStr = self.tableStr + "{" 16 | self.listContent.append(contentStr) 17 | self.tableStr += "\t" 18 | 19 | def EndBlock(self) -> None: 20 | self.EndBlockAppendStr("") 21 | 22 | def EndBlockAppendStr(self, endStr: str) -> None: 23 | if len(self.tableStr) != 0: 24 | self.tableStr = self.tableStr[::-1].replace('\t', '', 1)[::-1] 25 | contentStr = self.tableStr + "}" 26 | if len(endStr) > 0: 27 | contentStr = contentStr + endStr 28 | self.listContent.append(contentStr) 29 | 30 | def AddSpace(self) -> None: 31 | self.listContent.append("\n") 32 | 33 | def WriteLine(self, str: str) -> None: 34 | content = self.tableStr + str 35 | self.listContent.append(content) 36 | 37 | def ClearContent(self) -> None: 38 | self.tableStr = "" 39 | self.listContent = {} 40 | 41 | def WriteFile(self, path: str) -> None: 42 | Derictory.CreateDir(os.path.dirname(path)) 43 | with open(path, "w") as f: 44 | content: str = "" 45 | for item in self.listContent: 46 | content = content + item + "\n" 47 | f.write(content) 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Tool/Derictory.py: -------------------------------------------------------------------------------- 1 | import os 2 | from typing import List 3 | import shutil; 4 | import fileinput; 5 | 6 | def DeleteDirFile(path): 7 | folder = ExistsDir(path) 8 | if not folder: 9 | return 10 | ls = os.listdir(path) 11 | for i in ls: 12 | c_path = os.path.join(path, i) 13 | if os.path.isdir(c_path): 14 | DeleteDirFile(c_path) 15 | else: 16 | os.remove(c_path) 17 | 18 | 19 | def CreateDir(path: str) -> None: 20 | folder = ExistsDir(path) 21 | if not folder: 22 | os.makedirs(path) 23 | 24 | 25 | def DeleteDir(path: str) -> None: 26 | os.path.defpath(path) 27 | 28 | 29 | def ExistsDir(path: str) -> bool: 30 | exists = os.path.exists(path) 31 | return exists 32 | 33 | 34 | def ExistsFile(path: str) -> bool: 35 | exists = os.path.exists(path) 36 | return exists 37 | 38 | def CopyDirToDes(from_file,to_file): 39 | if not os.path.exists(to_file): # 如不存在目标目录则创建 40 | os.makedirs(to_file) 41 | files = os.listdir(from_file) # 获取文件夹中文件和目录列表 42 | for f in files: 43 | if os.path.isdir(from_file + '/' + f): # 判断是否是文件夹 44 | CopyDirToDes(from_file + '/' + f, to_file + '/' + f) # 递归调用本函数 45 | else: 46 | shutil.copy(from_file + '/' + f, to_file + '/' + f) # 拷贝文件 47 | 48 | def replace_text_in_directory(directory, old_text, new_text,ext): 49 | for root, dirs, files in os.walk(directory): 50 | for file in files: 51 | file_path = os.path.join(root, file) 52 | file_path = file_path.replace("\\","/"); 53 | if file_path.find(ext) < 0: 54 | continue; 55 | f = open(file_path,'r',encoding='utf-8') 56 | content = f.read(); 57 | content = content.replace(old_text,new_text); 58 | with open(file_path, "w",encoding='utf-8') as f: 59 | f.write(content) 60 | 61 | 62 | def GetDirFileList(path) -> List: 63 | list_name = [] 64 | GetDirFile(path, list_name) 65 | return list_name 66 | 67 | 68 | def GetDirFile(path, list_name: List) -> None: #传入存储的list 69 | for file in os.listdir(path): 70 | file_path = os.path.join(path, file) 71 | if os.path.isdir(file_path): 72 | GetDirFile(file_path, list_name) 73 | else: 74 | file_path = file_path.replace("\\","/") 75 | list_name.append(file_path) -------------------------------------------------------------------------------- /Tool/EnumData.py: -------------------------------------------------------------------------------- 1 | class EnumData: 2 | # 枚举 3 | __value: str = "" 4 | # 所属枚举 5 | __enum: str = "" 6 | # int值 7 | __index: int = 0 8 | # 注释 9 | __des: str = "" 10 | def __init__(self, value, enum, index, des) -> None: 11 | self.__value = value 12 | self.__enum = enum 13 | self.__des = des 14 | if type(index) != int: 15 | self.__index = int(index) 16 | 17 | def GetValue(self) -> str: 18 | return self.__value 19 | 20 | def GetValueStr(self) -> str: 21 | return str(self.__value) 22 | 23 | def GetEnum(self) -> str: 24 | return self.__enum 25 | 26 | def GetInt(self) -> int: 27 | return int(self.__index) 28 | 29 | def GetIntStr(self) -> int: 30 | return str(int(self.__index)) 31 | 32 | def GetDes(self) -> int: 33 | return str(self.__des) 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Tool/EnumUtils.py: -------------------------------------------------------------------------------- 1 | from Content import Content 2 | from Derictory import ExistsFile 3 | from EnumData import EnumData 4 | from ExcelWork import ExcelWork 5 | 6 | 7 | __enumDic = {} 8 | 9 | 10 | def AddEnum(enum: str, value: str, index: int, des: str) -> bool: 11 | if len(enum) < 1 or len(value) < 1: 12 | return False 13 | item = EnumData(value, enum, index, des) 14 | dicList = [] 15 | if enum in __enumDic: 16 | dicList = __enumDic[enum] 17 | dicList.append(item) 18 | __enumDic[enum] = dicList 19 | return True 20 | 21 | 22 | def GetIndex(enum: str, value: str) -> int: 23 | dicList = [] 24 | if enum in __enumDic: 25 | dicList = __enumDic[enum] 26 | for item in dicList: 27 | if item.GetValue() == value: 28 | return item.GetInt() 29 | return -1 30 | 31 | 32 | def ClearEnum() -> None: 33 | enumDic = {} 34 | 35 | def Init(path: str): 36 | if ExistsFile(path): 37 | InitByWork(ExcelWork(path)) 38 | 39 | def InitByWork(work: ExcelWork) -> None: 40 | ClearEnum() 41 | listRow = work.GetAllSheetRowList() 42 | if listRow == None or len(listRow) < 1: 43 | return 44 | 45 | for row in listRow: 46 | try: 47 | AddEnum(row.GetValue(1), row.GetValue(0), row.GetValue(2), row.GetValue(3)) 48 | except: 49 | ColorHelper.printRed("__CommonEnum.xlsx "+ row.GetValue(1) +" is error"); 50 | sys.exit(); 51 | 52 | 53 | def ExportCpp(path): 54 | cspath = path + "/CommonEnum.h" 55 | content = Content() 56 | for k, v in __enumDic.items(): 57 | content.WriteLine("enum class "+k) 58 | content.StartBlock() 59 | for item in v: 60 | content.WriteLine("//" + item.GetDes()) 61 | content.WriteLine(item.GetValueStr() + " = " + item.GetIntStr() + " ,") 62 | content.EndBlock() 63 | content.WriteLine("\n"); 64 | content.WriteLine(";"); 65 | content.WriteFile(cspath) 66 | 67 | def ExportCS(path): 68 | for k, v in __enumDic.items(): 69 | cspath = path + "/" + k + ".cs" 70 | content = Content() 71 | content.WriteLine("namespace TableConfig") 72 | content.StartBlock() 73 | content.WriteLine("public enum "+k) 74 | content.StartBlock() 75 | for item in v: 76 | content.WriteLine("//" + item.GetDes()) 77 | content.WriteLine(item.GetValueStr() + " = " + item.GetIntStr() + " ,") 78 | 79 | content.EndBlock() 80 | content.EndBlock() 81 | content.WriteFile(cspath) 82 | 83 | 84 | def ExportJava(path,javaPackage): 85 | for k, v in __enumDic.items(): 86 | cspath = path + "/" + k + ".java" 87 | content = Content() 88 | content.WriteLine("package "+javaPackage+";"); 89 | content.WriteLine("public enum "+k) 90 | content.StartBlock() 91 | for item in v: 92 | content.WriteLine("//" + item.GetDes()) 93 | content.WriteLine(item.GetValueStr() + "(" + item.GetIntStr() + "),") 94 | content.WriteLine(";"); 95 | 96 | content.WriteLine(k + "(int v)"); 97 | content.StartBlock(); 98 | content.WriteLine("this."+k+"=v;"); 99 | content.EndBlock(); 100 | 101 | content.WriteLine("public int Get"+k+"()"); 102 | content.StartBlock(); 103 | content.WriteLine("return "+k+";"); 104 | content.EndBlock(); 105 | 106 | content.WriteLine("private final int "+k+";"); 107 | 108 | 109 | content.WriteLine("public static "+k+" fromInt(int v)"); 110 | content.StartBlock(); 111 | content.WriteLine("switch (v)"); 112 | content.StartBlock(); 113 | for item in v: 114 | content.WriteLine("case "+ item.GetIntStr() + ":"); 115 | content.WriteLine("return " + item.GetValueStr() + ";"); 116 | content.EndBlock(); 117 | content.WriteLine("return null; "); 118 | content.EndBlock(); 119 | 120 | 121 | content.EndBlock() 122 | content.WriteFile(cspath) 123 | 124 | -------------------------------------------------------------------------------- /Tool/ExcelCell.py: -------------------------------------------------------------------------------- 1 | class ExcelCell: 2 | # 内容 3 | m_value: str 4 | 5 | def __init__(self, value) -> None: 6 | self.m_value = value 7 | 8 | def GetValue(self): 9 | return self.m_value 10 | 11 | def GetValueStr(self): 12 | return str(self.m_value) 13 | -------------------------------------------------------------------------------- /Tool/ExcelRow.py: -------------------------------------------------------------------------------- 1 | from ExcelCell import ExcelCell 2 | 3 | 4 | class ExcelRow: 5 | def __init__(self, row, colCount) -> None: 6 | self.__datalist = [] 7 | rowCount = len(row) 8 | for i in range(0, colCount): 9 | if i < rowCount: 10 | cell = row[i] 11 | else: 12 | cell = "" 13 | item = ExcelCell(cell) 14 | self.__datalist.append(item) 15 | 16 | def GetValue(self, index: int) -> str: 17 | return self.__datalist[index].GetValue() 18 | 19 | def GetValueStr(self, index: int) -> str: 20 | return self.__datalist[index].GetValueStr() -------------------------------------------------------------------------------- /Tool/ExcelSheel.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | import xlrd 3 | 4 | from ExcelRow import ExcelRow 5 | 6 | 7 | class ExcelSheel: 8 | __listrow: List = [] 9 | __name: str = "" 10 | __rowCount: int = 0 11 | __colcount: int = 0 12 | 13 | def __init__(self, sheet) -> None: 14 | self.__name = sheet.name 15 | self.__rowcount = sheet.nrows 16 | self.__colcount = sheet.ncols 17 | for i in range(0, self.__rowcount): 18 | row = sheet.row_values(i) 19 | item = ExcelRow(row, self.__colcount) 20 | self.__listrow.append(item) 21 | 22 | def GetName(self) -> str: 23 | return self.__name 24 | 25 | def GetColCount(self) -> int: 26 | return self.__colcount 27 | 28 | def GetRowCount(self) -> int: 29 | return self.__rowcount 30 | 31 | def GetRowList(self) -> List: 32 | return self.__listrow 33 | 34 | def GetRowListByStart(self, start) -> List: 35 | return self.__listrow[start:] 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Tool/ExcelUtils.py: -------------------------------------------------------------------------------- 1 | import xlrd 2 | import os.path 3 | 4 | 5 | def GetXLSX(path: str): 6 | if os.path.exists(path) == False: 7 | return None 8 | workBook = xlrd.open_workbook(path) 9 | return workBook -------------------------------------------------------------------------------- /Tool/ExcelWork.py: -------------------------------------------------------------------------------- 1 | from typing import Dict 2 | from typing import List 3 | import xlrd 4 | from ExcelSheel import ExcelSheel 5 | import ExcelUtils 6 | import os 7 | import Derictory 8 | 9 | 10 | class ExcelWork: 11 | __sheetList: List = [] 12 | __sheetDic: Dict = {} 13 | __workName: str = "" 14 | 15 | def __init__(self, path: str) -> None: 16 | workBook = ExcelUtils.GetXLSX(path) 17 | if workBook is None: 18 | print("path is error:" + path) 19 | return 20 | self.__workName = os.path.basename(path).split('.')[0] 21 | workSheets = workBook.sheets() 22 | if workSheets is None: 23 | print("sheets is none:" + path) 24 | for sheet in workSheets: 25 | excelSheet = ExcelSheel(sheet) 26 | self.__sheetList.append(excelSheet) 27 | self.__sheetDic[excelSheet.GetName()] = excelSheet 28 | 29 | 30 | def GetAllSheetRowList(self) -> List: 31 | sheetRowList = [] 32 | for sheet in self.__sheetList: 33 | sheetRowList.extend(sheet.GetRowListByStart(1)) 34 | return sheetRowList 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Tool/__Path.yaml: -------------------------------------------------------------------------------- 1 | # CS = 0, 2 | # CPP = 1, 3 | # JAVA = 2, 4 | # LUA = 3, 5 | Path: 6 | CodePath: ../Data/Code 7 | XlsxPath: ../Config 8 | BinPath: ../Data/Bin 9 | CodeType: 1 10 | JavaPackageName: TableConfig -------------------------------------------------------------------------------- /Tool/exportbin.py: -------------------------------------------------------------------------------- 1 | import Derictory 2 | from ConfigExcelWork import ConfigExcelWork 3 | import os 4 | import sys 5 | import EnumUtils 6 | import ColorHelper 7 | import sys; 8 | import yaml; 9 | from CommonType import VariableType; 10 | from CommonType import CodeType; 11 | 12 | def main(): 13 | os.chdir(os.sys.path[0]); 14 | print("curl path: " + os.getcwd()) 15 | try: 16 | yamlPath = os.path.join(os.getcwd(),"__Path.yaml"); 17 | yamlPath = yamlPath.replace("\\","/"); 18 | f = open(yamlPath,'r',encoding='utf-8') 19 | yamlContent = yaml.load(f,Loader=yaml.FullLoader) 20 | configPath = yamlContent["Path"]["XlsxPath"]; 21 | BinPath = yamlContent["Path"]["BinPath"]; 22 | CodePath = yamlContent["Path"]["CodePath"]; 23 | CodeContentInt = int(yamlContent["Path"]["CodeType"]); 24 | JavaPackage = yamlContent["Path"]["JavaPackageName"]; 25 | except BaseException as e: 26 | ColorHelper.printRed(yamlPath + " is error" + str(e)); 27 | sys.exit(); 28 | 29 | CodeContentType = CodeType(CodeContentInt); 30 | templatePath = ""; 31 | if CodeContentType == CodeType.CPP: 32 | templatePath =os.path.join(os.getcwd(),"template","c++"); 33 | templatePath = templatePath.replace("\\","/"); 34 | elif CodeContentType == CodeType.CS: 35 | templatePath =os.path.join(os.getcwd(),"template","csharp"); 36 | templatePath = templatePath.replace("\\","/"); 37 | elif CodeContentType == CodeType.JAVA: 38 | templatePath =os.path.join(os.getcwd(),"template","java"); 39 | templatePath = templatePath.replace("\\","/"); 40 | elif CodeContentType == CodeType.LUA: 41 | templatePath =os.path.join(os.getcwd(),"template","lua"); 42 | templatePath = templatePath.replace("\\","/"); 43 | 44 | print("curl path: " + os.getcwd()) 45 | print("xlxs path: " + CodePath) 46 | print("code path: " + configPath) 47 | print("bin path: " + BinPath) 48 | print("template path" + templatePath) 49 | 50 | Derictory.CreateDir(BinPath) 51 | Derictory.CreateDir(CodePath) 52 | Derictory.DeleteDirFile(BinPath) 53 | Derictory.DeleteDirFile(CodePath) 54 | 55 | CodeContentType = CodeType.LUA; 56 | #拷贝公共代码到对应目录 57 | Derictory.CopyDirToDes(templatePath + "/common", CodePath); 58 | if CodeContentType == CodeType.JAVA: 59 | Derictory.replace_text_in_directory(CodePath,"package TableConfig;","package " + JavaPackage + ";",".java"); 60 | 61 | try: 62 | EnumPath = os.path.join(configPath, "__CommonEnum.xlsx"); 63 | EnumPath = EnumPath.replace("\\", "/") 64 | EnumUtils.Init(EnumPath) 65 | if CodeContentType == CodeType.CPP: 66 | EnumUtils.ExportCpp(CodePath); 67 | elif CodeContentType == CodeType.CS: 68 | EnumUtils.ExportCS(CodePath); 69 | elif CodeContentType == CodeType.JAVA: 70 | EnumUtils.ExportJava(CodePath,JavaPackage); 71 | except: 72 | ColorHelper.printRed("__CommonEnum.xlsx is error"); 73 | sys.exit(); 74 | 75 | filelist = Derictory.GetDirFileList(configPath) 76 | for i in range(0,len(filelist)): 77 | workpath = filelist[i] 78 | print("file path:"+workpath) 79 | enumFind = workpath.find("__CommonEnum"); 80 | if enumFind > -1 or workpath.find(".xlsx") < 0: 81 | continue 82 | item = ConfigExcelWork(workpath) 83 | if CodeContentType != CodeType.LUA: 84 | item.ExportBin(BinPath) 85 | 86 | if CodeContentType == CodeType.CS: 87 | item.ExportCS(CodePath,templatePath); 88 | elif CodeContentType == CodeType.CPP: 89 | item.ExportCpp(CodePath,templatePath); 90 | elif CodeContentType == CodeType.JAVA: 91 | item.ExportJava(CodePath,templatePath,JavaPackage); 92 | elif CodeContentType == CodeType.LUA: 93 | item.ExportLua(CodePath,templatePath); 94 | 95 | print("success"); 96 | 97 | main() -------------------------------------------------------------------------------- /Tool/template/c++/Template0.cpp: -------------------------------------------------------------------------------- 1 | #include "TemplateClass.h" 2 | 3 | std::vector* TemplateClass::m_Datas; 4 | 5 | int TemplateClass::GetCount() 6 | { 7 | if(m_Datas == NULL) 8 | { 9 | return 0; 10 | } 11 | return m_Datas->size(); 12 | } 13 | 14 | std::vector* TemplateClass::GetDatas() 15 | { 16 | return m_Datas; 17 | } 18 | 19 | 20 | 21 | void TemplateClass::Load(BinData *bin) 22 | { 23 | ReadValueLoadContent 24 | } 25 | 26 | 27 | 28 | void TemplateClass::Load() 29 | { 30 | BinData* bin = OpenBin("TemplateClass.bin"); 31 | if (bin != NULL && bin->IsOpen()) 32 | { 33 | try 34 | { 35 | int count = bin->ReadInt32(); 36 | m_Datas = new std::vector(count); 37 | for (int i = 0; i < count; ++i) 38 | { 39 | TemplateClass * data = new TemplateClass(); 40 | data->Load(bin); 41 | m_Datas->push_back(data); 42 | } 43 | } 44 | catch (const std::exception& e) 45 | { 46 | 47 | } 48 | bin->Close(); 49 | delete bin; 50 | bin = NULL; 51 | } 52 | } 53 | 54 | void TemplateClass::Reload() 55 | { 56 | Unload(); 57 | TemplateClass::Load(); 58 | } 59 | 60 | void TemplateClass::Unload() 61 | { 62 | if (m_Datas == NULL) 63 | { 64 | return; 65 | } 66 | 67 | for (std::vector::iterator it = m_Datas->begin(); it != m_Datas->end(); it++) { 68 | delete *it; 69 | } 70 | 71 | m_Datas->clear(); 72 | delete m_Datas; 73 | m_Datas = NULL; 74 | } 75 | 76 | 77 | -------------------------------------------------------------------------------- /Tool/template/c++/Template0.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "DataBase.h" 4 | #include "BinData.h" 5 | 6 | 7 | class TemplateClass :DataBase 8 | { 9 | public: 10 | static std::vector* GetDatas(); 11 | static int GetCount(); 12 | static void Load(); 13 | static void Reload(); 14 | static void Unload(); 15 | public: 16 | ValueContentFunction 17 | private: 18 | void Load(BinData *bin); 19 | private: 20 | static std::vector* m_Datas; 21 | private: 22 | ValueContent 23 | }; 24 | 25 | -------------------------------------------------------------------------------- /Tool/template/c++/Template1.cpp: -------------------------------------------------------------------------------- 1 | #include "TemplateClass.h" 2 | 3 | std::vector* TemplateClass::m_Datas = NULL; 4 | std::map* TemplateClass::m_DatasDic = NULL; 5 | 6 | int TemplateClass::GetCount() 7 | { 8 | if(m_Datas == NULL) 9 | { 10 | return NULL; 11 | } 12 | return m_Datas->size(); 13 | } 14 | 15 | std::vector* TemplateClass::GetDatas() 16 | { 17 | return m_Datas; 18 | } 19 | 20 | TemplateClass* TemplateClass::Get(FirstKeyType FirstKey) 21 | { 22 | if(m_DatasDic == NULL) 23 | { 24 | return NULL; 25 | } 26 | auto it = m_DatasDic->find(FirstKey); 27 | if (it != m_DatasDic->end()) { 28 | // 键存在于map中 29 | return it->second; // 访问键对应的值 30 | } 31 | else { 32 | return NULL; 33 | } 34 | } 35 | 36 | void TemplateClass::Load(BinData* bin) 37 | { 38 | ReadValueLoadContent 39 | } 40 | 41 | 42 | 43 | void TemplateClass::Load() 44 | { 45 | BinData* bin = OpenBin("TemplateClass.bin"); 46 | if (bin != NULL && bin->IsOpen()) 47 | { 48 | try 49 | { 50 | int count = bin->ReadInt32(); 51 | m_Datas = new std::vector(count); 52 | m_DatasDic = new std::map(); 53 | for (int i = 0; i < count; ++i) 54 | { 55 | TemplateClass * data = new TemplateClass(); 56 | data->Load(bin); 57 | m_Datas->push_back(data); 58 | if(Get(data->GetFirstKey()) == NULL) 59 | { 60 | m_DatasDic->insert(std::make_pair(data->GetFirstKey(), data)); 61 | } 62 | } 63 | } 64 | catch (const std::exception& e) 65 | { 66 | 67 | } 68 | bin->Close(); 69 | delete bin; 70 | bin = NULL; 71 | } 72 | } 73 | 74 | void TemplateClass::Reload() 75 | { 76 | Unload(); 77 | TemplateClass::Load(); 78 | } 79 | 80 | void TemplateClass::Unload() 81 | { 82 | if (m_Datas == NULL) 83 | { 84 | return; 85 | } 86 | 87 | for (std::vector::iterator it = m_Datas->begin(); it != m_Datas->end(); it++) { 88 | delete *it; 89 | } 90 | 91 | m_Datas->clear(); 92 | m_DatasDic->clear(); 93 | delete m_Datas; 94 | delete m_DatasDic; 95 | m_Datas = NULL; 96 | m_DatasDic = NULL; 97 | } 98 | 99 | 100 | -------------------------------------------------------------------------------- /Tool/template/c++/Template1.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "DataBase.h" 4 | #include "BinData.h" 5 | #include 6 | 7 | 8 | class TemplateClass :DataBase 9 | { 10 | public: 11 | static int GetCount(); 12 | static TemplateClass* Get(FirstKeyType FirstKey); 13 | static std::vector* GetDatas(); 14 | static void Load(); 15 | static void Reload(); 16 | static void Unload(); 17 | public: 18 | ValueContentFunction 19 | private: 20 | void Load(BinData* bin); 21 | private: 22 | static std::vector* m_Datas; 23 | static std::map* m_DatasDic; 24 | private: 25 | ValueContent 26 | }; 27 | -------------------------------------------------------------------------------- /Tool/template/c++/Template2.cpp: -------------------------------------------------------------------------------- 1 | #include "TemplateClass.h" 2 | 3 | std::vector* TemplateClass::m_Datas = NULL; 4 | std::map*>* TemplateClass::m_DatasDic = NULL; 5 | std::map, TemplateClass*>* TemplateClass::m_DatasDicDic = NULL; 6 | 7 | int TemplateClass::GetCount() 8 | { 9 | if(m_Datas == NULL) 10 | { 11 | return 0; 12 | } 13 | return m_Datas->size(); 14 | } 15 | 16 | std::vector* TemplateClass::GetDatas() 17 | { 18 | return m_Datas; 19 | } 20 | 21 | std::vector* TemplateClass::Get(FirstKeyType FirstKey) 22 | { 23 | if(m_DatasDic == NULL) 24 | { 25 | return NULL; 26 | } 27 | 28 | auto it = m_DatasDic->find(FirstKey); 29 | if (it != m_DatasDic->end()) { 30 | // 键存在于map中 31 | return it->second; // 访问键对应的值 32 | } 33 | else { 34 | return NULL; 35 | } 36 | } 37 | 38 | TemplateClass* TemplateClass::Get(FirstKeyType FirstKey,SecondKeyType SecondKey) 39 | { 40 | if(m_DatasDicDic == NULL) 41 | { 42 | return NULL; 43 | } 44 | 45 | std::pair> keyPair; 46 | keyPair.first = FirstKey; 47 | keyPair.second = SecondKey; 48 | auto it = m_DatasDicDic->find(keyPair); 49 | if (it != m_DatasDicDic->end()) { 50 | // 键存在于map中 51 | return it->second; // 访问键对应的值 52 | } 53 | else { 54 | return NULL; 55 | } 56 | } 57 | 58 | void TemplateClass::Load(BinData* bin) 59 | { 60 | ReadValueLoadContent 61 | } 62 | 63 | 64 | 65 | void TemplateClass::Load() 66 | { 67 | BinData* bin = OpenBin("TemplateClass.bin"); 68 | if (bin != NULL && bin->IsOpen()) 69 | { 70 | try 71 | { 72 | int count = bin->ReadInt32(); 73 | m_Datas = new std::vector(); 74 | m_DatasDic = new std::map*>(); 75 | m_DatasDicDic = new std::map>, Test2*>(); 76 | for (int i = 0; i < count; ++i) 77 | { 78 | TemplateClass * data = new TemplateClass(); 79 | data->Load(bin); 80 | m_Datas->push_back(data); 81 | auto it = m_DatasDic->find(data->GetFirstKey()); 82 | if (it == m_DatasDic->end()) { 83 | std::vector *pVec = new std::vector(); 84 | m_DatasDic->insert(std::make_pair(data->GetFirstKey(), pVec)); 85 | pVec->push_back(data); 86 | } 87 | else 88 | { 89 | it->second->push_back(data); 90 | } 91 | 92 | std::pair> keyPair; 93 | keyPair.first = data->GetFirstKey(); 94 | keyPair.second = data->GetSecondKey(); 95 | auto itDic = m_DatasDicDic->find(keyPair); 96 | if (itDic == m_DatasDicDic->end()) { 97 | m_DatasDicDic->insert(std::make_pair(keyPair, data)); 98 | } 99 | 100 | 101 | } 102 | } 103 | catch (const std::exception& e) 104 | { 105 | 106 | } 107 | bin->Close(); 108 | delete bin; 109 | bin = NULL; 110 | } 111 | } 112 | 113 | void TemplateClass::Reload() 114 | { 115 | Unload(); 116 | TemplateClass::Load(); 117 | } 118 | 119 | void TemplateClass::Unload() 120 | { 121 | for (std::vector::iterator it = m_Datas->begin(); it != m_Datas->end(); it++) { 122 | delete *it; 123 | } 124 | 125 | 126 | m_DatasDicDic->clear(); 127 | m_Datas->clear(); 128 | m_DatasDic->clear(); 129 | delete m_Datas; 130 | delete m_DatasDic; 131 | delete m_DatasDicDic; 132 | m_Datas = NULL; 133 | m_DatasDic = NULL; 134 | m_DatasDicDic = NULL; 135 | } 136 | 137 | 138 | -------------------------------------------------------------------------------- /Tool/template/c++/Template2.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "DataBase.h" 4 | #include "BinData.h" 5 | #include 6 | 7 | 8 | class TemplateClass :DataBase 9 | { 10 | public: 11 | static int GetCount(); 12 | static std::vector* Get(FirstKeyType FirstKey); 13 | static std::vector* GetDatas(); 14 | static TemplateClass* Get(FirstKeyType FirstKey,SecondKeyType SecondKey); 15 | static void Load(); 16 | static void Reload(); 17 | static void Unload(); 18 | public: 19 | ValueContentFunction 20 | private: 21 | void Load(BinData* bin); 22 | private: 23 | static std::vector* m_Datas; 24 | static std::map*>* m_DatasDic; 25 | static std::map, TemplateClass*>* m_DatasDicDic; 26 | private: 27 | ValueContent 28 | }; 29 | -------------------------------------------------------------------------------- /Tool/template/c++/common/BinData.cpp: -------------------------------------------------------------------------------- 1 | #include "BinData.h" 2 | #include 3 | 4 | BinData::BinData(std::string path) 5 | { 6 | Open(path); 7 | } 8 | 9 | std::string BinData::ReadString() 10 | { 11 | int length = ReadInt32(); 12 | std::string str; 13 | str.reserve(length); 14 | m_fin.read((char*)str.c_str(), length); 15 | return std::string(); 16 | } 17 | 18 | unsigned long BinData::ReadUInt64() 19 | { 20 | unsigned long s; 21 | m_fin.read((char*)&s, sizeof(s)); 22 | return s; 23 | } 24 | 25 | 26 | bool BinData::IsOpen() 27 | { 28 | return m_fin.is_open(); 29 | } 30 | 31 | float BinData::ReadFloat() 32 | { 33 | float s; 34 | m_fin.read((char*)&s, sizeof(s)); 35 | return s; 36 | } 37 | 38 | double BinData::ReadDouble() 39 | { 40 | double s; 41 | m_fin.read((char*)&s, sizeof(s)); 42 | return s; 43 | } 44 | 45 | bool BinData::ReadBoolean() 46 | { 47 | bool s = false; 48 | m_fin.read((char*)&s, sizeof(s)); 49 | return s; 50 | } 51 | 52 | char BinData::Readsbyte() 53 | { 54 | char s; 55 | m_fin.read((char*)&s, sizeof(s)); 56 | return s; 57 | } 58 | 59 | std::string BinData::ReadCommonString() 60 | { 61 | int index = ReadInt32(); 62 | return commonString[index]; 63 | } 64 | 65 | 66 | 67 | void BinData::Close() 68 | { 69 | delete[] commonString; 70 | commonString = NULL; 71 | 72 | m_fin.close(); 73 | } 74 | 75 | void BinData::Open(std::string path) 76 | { 77 | m_fin.open(path,std::ios::in);//默认是ios::trunc 78 | if (!m_fin) 79 | { 80 | return; 81 | } 82 | } 83 | 84 | void BinData::ReadStringArray() 85 | { 86 | int len = ReadInt32(); 87 | commonString = new std::string[len]; 88 | for (int i = 0; i < len; ++i) 89 | { 90 | commonString[i] = ReadString(); 91 | } 92 | } 93 | 94 | 95 | int BinData::ReadInt32() 96 | { 97 | int s = 0; 98 | m_fin.read((char*)&s, sizeof(s)); 99 | return s; 100 | } 101 | 102 | long BinData::ReadInt64() 103 | { 104 | long s = 0; 105 | m_fin.read((char*)&s, sizeof(s)); 106 | return s; 107 | } 108 | 109 | short BinData::ReadInt16() 110 | { 111 | short s = 0; 112 | m_fin.read((char*)&s, sizeof(s)); 113 | return s; 114 | } 115 | 116 | 117 | unsigned short BinData::ReadUInt16() 118 | { 119 | unsigned short s = 0; 120 | m_fin.read((char*)&s, sizeof(s)); 121 | return s; 122 | } 123 | 124 | unsigned int BinData::ReadUInt32() 125 | { 126 | unsigned int s = 0; 127 | m_fin.read((char*)&s, sizeof(s)); 128 | return s; 129 | } 130 | 131 | 132 | -------------------------------------------------------------------------------- /Tool/template/c++/common/BinData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | class BinData 6 | { 7 | public: 8 | BinData(std::string path); 9 | void ReadStringArray(); 10 | int ReadInt32(); 11 | long ReadInt64(); 12 | short ReadInt16(); 13 | unsigned short ReadUInt16(); 14 | unsigned int ReadUInt32(); 15 | unsigned long ReadUInt64(); 16 | float ReadFloat(); 17 | double ReadDouble(); 18 | bool ReadBoolean(); 19 | char Readsbyte(); 20 | std::string ReadCommonString(); 21 | std::string ReadString(); 22 | void Close(); 23 | bool IsOpen(); 24 | private: 25 | void Open(std::string path); 26 | private: 27 | std::string* commonString; 28 | std::ifstream m_fin; 29 | }; -------------------------------------------------------------------------------- /Tool/template/c++/common/DataBase.cpp: -------------------------------------------------------------------------------- 1 | #include "DataBase.h" 2 | 3 | std::string DataBase::m_defaultPath = ""; 4 | 5 | void DataBase::SetDataPath(std::string path) 6 | { 7 | m_defaultPath = path; 8 | } 9 | 10 | std::string DataBase::GetDataPath() 11 | { 12 | return m_defaultPath; 13 | } 14 | 15 | BinData* DataBase::OpenBin(std::string fileName) 16 | { 17 | int count = m_defaultPath.length() + 1 + fileName.length(); 18 | char* cstr1 = new char[count]; 19 | strcpy_s(cstr1, m_defaultPath.length()+1,m_defaultPath.c_str()); 20 | strcat_s(cstr1, count,fileName.c_str()); 21 | std::string fullPath = cstr1; 22 | delete[] cstr1; 23 | BinData* bin = new BinData(fullPath); 24 | return bin; 25 | } -------------------------------------------------------------------------------- /Tool/template/c++/common/DataBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include ; 3 | #include ; 4 | #include "BinData.h"; 5 | #include "CommonEnum.h" 6 | 7 | class DataBase 8 | { 9 | public: 10 | static void SetDataPath(std::string path); 11 | static std::string GetDataPath(); 12 | static BinData* OpenBin(std::string fullPath); 13 | private: 14 | static std::string m_defaultPath; 15 | }; 16 | 17 | -------------------------------------------------------------------------------- /Tool/template/csharp/Template0.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | using System; 4 | using TableConfig; 5 | namespace TableConfig 6 | { 7 | public class TemplateClass :DataBase 8 | { 9 | #region value 10 | ValueContent 11 | #endregion 12 | #region load and get funtion 13 | private static TemplateClass[] m_Datas = null; 14 | public static TemplateClass[] Datas 15 | { 16 | get 17 | { 18 | Load(); 19 | return m_Datas; 20 | } 21 | } 22 | 23 | 24 | public static int Count 25 | { 26 | get 27 | { 28 | Load(); 29 | if(Datas == null) 30 | { 31 | return 0; 32 | } 33 | return Datas.Length; 34 | } 35 | } 36 | 37 | private void Load(BinData bin) 38 | { 39 | ReadValueLoadContent 40 | } 41 | 42 | 43 | public static void Load() 44 | { 45 | BinData bin = OpenData("TemplateClass.bin"); 46 | if (bin != null) 47 | { 48 | try 49 | { 50 | var count = bin.ReadInt32(); 51 | m_Datas = new TemplateClass[count]; 52 | for (int i = 0; i < count; ++i) 53 | { 54 | TemplateClass data = new TemplateClass(); 55 | data.Load(bin); 56 | m_Datas[i] = data; 57 | } 58 | } 59 | catch(Exception e) 60 | { 61 | ConfigDebugEx.LogException(e); 62 | } 63 | } 64 | } 65 | 66 | public static void Reload() 67 | { 68 | Unload(); 69 | Load(); 70 | } 71 | 72 | 73 | public static void Unload() 74 | { 75 | bool bGC = false; 76 | if(m_Datas != null) 77 | { 78 | m_Datas = null; 79 | bGC = true; 80 | } 81 | if(bGC) 82 | { 83 | System.GC.Collect(); 84 | } 85 | } 86 | #endregion 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /Tool/template/csharp/Template1.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | using System; 4 | using TableConfig; 5 | namespace TableConfig 6 | { 7 | public class TemplateClass:DataBase 8 | { 9 | #region value 10 | ValueContent 11 | #endregion 12 | #region load and get funtion 13 | private static TemplateClass[] m_Datas = null; 14 | public static TemplateClass[] Datas 15 | { 16 | get 17 | { 18 | Load(); 19 | return m_Datas; 20 | } 21 | } 22 | 23 | 24 | public static int Count 25 | { 26 | get 27 | { 28 | Load(); 29 | if(Datas == null) 30 | { 31 | return 0; 32 | } 33 | return Datas.Length; 34 | } 35 | } 36 | 37 | private static Dictionary m_DicDatas = null; 38 | public static Dictionary DicDatas 39 | { 40 | get 41 | { 42 | Load(); 43 | return m_DicDatas; 44 | } 45 | } 46 | 47 | 48 | 49 | private void Load(BinData bin) 50 | { 51 | ReadValueLoadContent 52 | } 53 | 54 | public static void Load() 55 | { 56 | BinData bin = OpenData("TemplateClass.bin") ; 57 | if (bin != null) 58 | { 59 | try 60 | { 61 | var count = bin.ReadInt32(); 62 | m_Datas = new TemplateClass[count]; 63 | m_DicDatas = new Dictionary(count); 64 | for (int i = 0; i < count; ++i) 65 | { 66 | TemplateClass data = new TemplateClass(); 67 | data.Load(bin); 68 | m_Datas[i] = data; 69 | m_DicDatas.Add(data.FirstKey, data); 70 | } 71 | } 72 | catch(Exception e) 73 | { 74 | ConfigDebugEx.LogException(e); 75 | } 76 | } 77 | } 78 | 79 | 80 | 81 | public static TemplateClass Get(FirstKeyType FirstKey) 82 | { 83 | Get(FirstKey,out var data); 84 | return data; 85 | } 86 | 87 | public static bool Get(FirstKeyType FirstKey,out TemplateClass data) 88 | { 89 | Load(); 90 | bool b = m_DicDatas.TryGetValue(FirstKey, out data); 91 | return b; 92 | } 93 | 94 | public static void Reload() 95 | { 96 | Unload(); 97 | Load(); 98 | } 99 | 100 | public static void Unload() 101 | { 102 | bool bGC = false; 103 | if(m_Datas != null) 104 | { 105 | m_Datas = null; 106 | m_DicDatas = null; 107 | bGC = true; 108 | } 109 | if(bGC) 110 | { 111 | System.GC.Collect(); 112 | } 113 | } 114 | #endregion 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /Tool/template/csharp/Template2.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | using System; 4 | using TableConfig; 5 | namespace TableConfig 6 | { 7 | public class TemplateClass:DataBase 8 | { 9 | #region value 10 | ValueContent 11 | #endregion 12 | #region load and get funtion 13 | private static TemplateClass[] m_Datas = null; 14 | public static TemplateClass[] Datas 15 | { 16 | get 17 | { 18 | #if UNITY_ART || WINFORM 19 | Load(); 20 | #endif 21 | return m_Datas; 22 | } 23 | } 24 | 25 | 26 | private static Dictionary> m_DicDicDatas = null; 27 | public static Dictionary> DicDicDatas 28 | { 29 | get 30 | { 31 | Load(); 32 | return m_DicDicDatas; 33 | } 34 | } 35 | private static Dictionary> m_DicListDatas = null; 36 | public static Dictionary> DicListDatas 37 | { 38 | get 39 | { 40 | Load(); 41 | return m_DicListDatas; 42 | } 43 | } 44 | 45 | 46 | public static int Count 47 | { 48 | get 49 | { 50 | Load(); 51 | if(Datas == null) 52 | { 53 | return 0; 54 | } 55 | return Datas.Length; 56 | } 57 | } 58 | 59 | 60 | 61 | private void Load(BinData bin) 62 | { 63 | ReadValueLoadContent 64 | } 65 | 66 | public static void Load() 67 | { 68 | BinData bin = OpenData("TemplateClass.bin") ; 69 | if (bin != null) 70 | { 71 | try 72 | { 73 | var count = bin.ReadInt32(); 74 | m_Datas = new TemplateClass[count]; 75 | m_DicDicDatas = new Dictionary>(); 76 | m_DicListDatas = new Dictionary>(); 77 | for (int i = 0; i < count; ++i) 78 | { 79 | TemplateClass data = new TemplateClass(); 80 | data.Load(bin); 81 | m_Datas[i] = data; 82 | if(false == m_DicDicDatas.TryGetValue(data.FirstKey,out var dicData)) 83 | { 84 | dicData = new Dictionary(); 85 | m_DicDicDatas.Add(data.FirstKey, dicData); 86 | } 87 | if(false == m_DicListDatas.TryGetValue(data.FirstKey,out var dataList)) 88 | { 89 | dataList = new List(); 90 | m_DicListDatas.Add(data.FirstKey, dataList); 91 | } 92 | dicData.Add(data.SecondKey, data); 93 | dataList.Add(data); 94 | } 95 | } 96 | catch(Exception e) 97 | { 98 | ConfigDebugEx.LogException(e); 99 | } 100 | } 101 | } 102 | 103 | public static TemplateClass Get(FirstKeyType FirstKey,SecondKeyType SecondKey) 104 | { 105 | Get(FirstKey,SecondKey,out var data); 106 | return data; 107 | } 108 | 109 | public static bool Get(FirstKeyType FirstKey, SecondKeyType SecondKey , out TemplateClass data) 110 | { 111 | Load(); 112 | bool b = false; 113 | data = null; 114 | if(m_DicDicDatas.TryGetValue(FirstKey, out var dicData)) 115 | { 116 | if(dicData.TryGetValue(SecondKey,out data)) 117 | { 118 | b = true; 119 | } 120 | } 121 | return b; 122 | } 123 | public static List Get(FirstKeyType FirstKey) 124 | { 125 | Get(FirstKey,out var data); 126 | return data; 127 | } 128 | public static bool Get(FirstKeyType FirstKey,out List data) 129 | { 130 | Load(); 131 | bool b = m_DicListDatas.TryGetValue(FirstKey, out data); 132 | return b; 133 | } 134 | 135 | public static void Reload() 136 | { 137 | Unload(); 138 | Load(); 139 | } 140 | 141 | 142 | public static void Unload() 143 | { 144 | bool bGC = false; 145 | if(m_Datas != null) 146 | { 147 | m_Datas = null; 148 | m_DicDicDatas = null; 149 | m_DicListDatas = null; 150 | bGC = true; 151 | } 152 | if(bGC) 153 | { 154 | System.GC.Collect(); 155 | } 156 | } 157 | #endregion 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /Tool/template/csharp/common/BinData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Text; 5 | 6 | namespace TableConfig 7 | { 8 | public unsafe class BinData 9 | { 10 | 11 | static readonly UTF8Encoding encoding = new UTF8Encoding(); 12 | private byte[] m_buffer; 13 | private string[] commonstring = null; 14 | private int position; 15 | public BinData(byte[] bytes) 16 | { 17 | this.m_buffer = bytes; 18 | } 19 | 20 | public unsafe int ReadInt32() 21 | { 22 | var v = (int) this.m_buffer[position] | (int) this.m_buffer[position+1] << 8 | (int) this.m_buffer[position+2] << 16 | (int) this.m_buffer[position+3] << 24; 23 | position += 4; 24 | return v; 25 | } 26 | 27 | public unsafe void ReadStringArray() 28 | { 29 | int count = 0; 30 | count = ReadInt32(); 31 | commonstring = new string[count]; 32 | string str = string.Empty; 33 | for (int i = 0; i < count; ++i) 34 | { 35 | commonstring[i] = ReadString(); 36 | } 37 | } 38 | 39 | 40 | public unsafe Int64 ReadInt64() 41 | { 42 | var v = (long) (uint) ((int) this.m_buffer[position+4] | (int) this.m_buffer[position+5] << 8 | (int) this.m_buffer[position+6] << 16 | (int) this.m_buffer[position+7] << 24) << 32 | (long) (uint) ((int) this.m_buffer[position+0] | (int) this.m_buffer[position+1] << 8 | (int) this.m_buffer[position+2] << 16 | (int) this.m_buffer[position+3] << 24); 43 | position += 8; 44 | return v; 45 | } 46 | 47 | public unsafe Int16 ReadInt16() 48 | { 49 | var v = (short) ((int) this.m_buffer[position] | (int) this.m_buffer[position+1] << 8); 50 | position += 2; 51 | return v; 52 | } 53 | 54 | public unsafe UInt16 ReadUInt16() 55 | { 56 | var v = (ushort) ((uint) this.m_buffer[position] | (uint) this.m_buffer[position+1] << 8); 57 | position += 2; 58 | return v; 59 | } 60 | public unsafe UInt32 ReadUInt32() 61 | { 62 | var v = (uint) ((int) this.m_buffer[position] | (int) this.m_buffer[position+1] << 8 | (int) this.m_buffer[position+2] << 16 | (int) this.m_buffer[position+3] << 24); 63 | position += 4; 64 | return v; 65 | } 66 | public unsafe UInt64 ReadUInt64() 67 | { 68 | var v = (ulong)((int) this.m_buffer[position+4] | (int) this.m_buffer[position+5] << 8 | (int) this.m_buffer[position+6] << 16 | (int) this.m_buffer[position+7] << 24) << 32 | (ulong) (uint) ((int) this.m_buffer[position] | (int) this.m_buffer[position+1] << 8 | (int) this.m_buffer[position+2] << 16 | (int) this.m_buffer[position+3] << 24); 69 | position += 8; 70 | return v; 71 | } 72 | public unsafe float ReadFloat() 73 | { 74 | float a = 0; 75 | byte i; 76 | void* pf; 77 | pf = &a; 78 | float v; 79 | fixed (byte* start = m_buffer) 80 | { 81 | byte* px = start + position; 82 | for (i = 0; i < 4; i++) 83 | { 84 | *((byte*)pf + i) = *(px + i); 85 | } 86 | v = a; 87 | } 88 | position += 4; 89 | return v; 90 | } 91 | 92 | public unsafe double ReadDouble() 93 | { 94 | double a = 0; 95 | byte i; 96 | void* pf; 97 | pf = &a; 98 | double v; 99 | fixed (byte* start = m_buffer) 100 | { 101 | byte* px = start + position; 102 | for (i = 0; i < 8; i++) 103 | { 104 | *((byte*)pf + i) = *(px + i); 105 | } 106 | v = a; 107 | } 108 | position += 8; 109 | return v; 110 | } 111 | public bool ReadBoolean() 112 | { 113 | var v = this.m_buffer[position] > (byte) 0; 114 | position += 1; 115 | return v; 116 | } 117 | 118 | public sbyte Readsbyte() 119 | { 120 | var v = (sbyte)this.m_buffer[position]; 121 | position += 1; 122 | return v; 123 | } 124 | public string ReadCommonString() 125 | { 126 | var len = ReadInt32(); 127 | if(len < 0) 128 | { 129 | return string.Empty; 130 | } 131 | var v = commonstring[len]; 132 | return v; 133 | } 134 | 135 | 136 | public string ReadString() 137 | { 138 | var len = ReadInt32(); 139 | if(len < 0) 140 | { 141 | return string.Empty; 142 | } 143 | string v = encoding.GetString(m_buffer,position , (int)len); 144 | position += len; 145 | return v; 146 | 147 | } 148 | 149 | public void Close() 150 | { 151 | m_buffer = null; 152 | commonstring = null; 153 | position = 0; 154 | } 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /Tool/template/csharp/common/ConfigDebugEx.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Text; 5 | 6 | namespace TableConfig 7 | { 8 | public unsafe class ConfigDebugEx 9 | { 10 | public static void LogException(Exception ex) 11 | { 12 | Console.WriteLine($"[{DateTime.Now.ToString("yy:MM:dd HH-mm-ss-ffff")}]{ex.ToString()}"); 13 | } 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Tool/template/csharp/common/DataBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | namespace TableConfig 5 | { 6 | public class DataBase 7 | { 8 | private static string DefaultFolder = ""; 9 | public static void SetDataPath(string path) 10 | { 11 | DefaultFolder = path; 12 | } 13 | 14 | public static BinData OpenData(string fileName) 15 | { 16 | var filePath = System.IO.Path.Combine(DefaultFolder ,fileName); 17 | filePath = filePath.Replace("\\","/"); 18 | return OpenBin(filePath);V 19 | } 20 | 21 | public static BinData OpenBin(string fullPath) 22 | { 23 | BinData bin = null; 24 | try 25 | { 26 | var bytes = File.ReadAllBytes(fullPath); 27 | bin = new BinData(bytes); 28 | return bin; 29 | } 30 | catch (Exception e) 31 | { 32 | 33 | } 34 | return bin; 35 | } 36 | 37 | public virtual void Load(BinData pStream) { } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Tool/template/java/Template0.java: -------------------------------------------------------------------------------- 1 | package TableConfig; 2 | 3 | 4 | public class TemplateClass extends DataBase 5 | { 6 | //region value 7 | ValueContent 8 | //endregion 9 | //region load and get funtion 10 | private static TemplateClass[] m_Datas = null; 11 | public static TemplateClass[] GetDatas() 12 | { 13 | return m_Datas; 14 | } 15 | 16 | 17 | public static int GetCount() 18 | { 19 | if(m_Datas == null) 20 | { 21 | return 0; 22 | } 23 | return m_Datas.length; 24 | } 25 | 26 | private void Load(BinData bin) 27 | { 28 | ReadValueLoadContent 29 | } 30 | 31 | 32 | public static void Load() 33 | { 34 | BinData bin = OpenData("TemplateClass.bin"); 35 | if (bin != null) 36 | { 37 | try 38 | { 39 | int count = bin.ReadInt32(); 40 | m_Datas = new TemplateClass[count]; 41 | for (int i = 0; i < count; ++i) 42 | { 43 | TemplateClass data = new TemplateClass(); 44 | data.Load(bin); 45 | m_Datas[i] = data; 46 | } 47 | } 48 | catch(Exception e) 49 | { 50 | 51 | } 52 | } 53 | } 54 | 55 | public static void Reload() 56 | { 57 | Unload(); 58 | Load(); 59 | } 60 | 61 | 62 | public static void Unload() 63 | { 64 | boolean bGC = false; 65 | if(m_Datas != null) 66 | { 67 | m_Datas = null; 68 | bGC = true; 69 | } 70 | if(bGC) 71 | { 72 | System.gc(); 73 | } 74 | } 75 | //endregion 76 | } -------------------------------------------------------------------------------- /Tool/template/java/Template1.java: -------------------------------------------------------------------------------- 1 | package TableConfig; 2 | import java.util.HashMap; 3 | import java.util.Map; 4 | import java.util.List; 5 | import java.util.ArrayList; 6 | 7 | public class TemplateClass extends DataBase 8 | { 9 | //region value 10 | ValueContent 11 | //endregion 12 | //region load and get funtion 13 | private static TemplateClass[] m_Datas = null; 14 | public static TemplateClass[] GetDatas() 15 | { 16 | return m_Datas; 17 | } 18 | 19 | 20 | public static int GetCount() 21 | { 22 | if(m_Datas == null) 23 | { 24 | return 0; 25 | } 26 | return m_Datas.length; 27 | } 28 | 29 | 30 | private static Map m_DicDatas = null; 31 | public static Map GetDicDatas() 32 | { 33 | return m_DicDatas; 34 | } 35 | 36 | 37 | 38 | private void Load(BinData bin) 39 | { 40 | ReadValueLoadContent 41 | } 42 | 43 | public static void Load() 44 | { 45 | BinData bin = OpenData("TemplateClass.bin") ; 46 | if (bin != null) 47 | { 48 | try 49 | { 50 | int count = bin.ReadInt32(); 51 | m_Datas = new TemplateClass[count]; 52 | m_DicDatas = new HashMap<>(); 53 | for (int i = 0; i < count; ++i) 54 | { 55 | TemplateClass data = new TemplateClass(); 56 | data.Load(bin); 57 | m_Datas[i] = data; 58 | m_DicDatas.put(data.GetFirstKey(), data); 59 | } 60 | } 61 | catch(Exception e) 62 | { 63 | 64 | } 65 | } 66 | } 67 | 68 | 69 | 70 | public static TemplateClass Get(FirstKeyType FirstKey) 71 | { 72 | TemplateClass data = m_DicDatas.get(FirstKey); 73 | return data; 74 | } 75 | 76 | 77 | 78 | public static void Reload() 79 | { 80 | Unload(); 81 | Load(); 82 | } 83 | 84 | public static void Unload() 85 | { 86 | boolean bGC = false; 87 | if(m_Datas != null) 88 | { 89 | m_Datas = null; 90 | bGC = true; 91 | } 92 | if(bGC) 93 | { 94 | System.gc(); 95 | } 96 | } 97 | //endregion 98 | } 99 | -------------------------------------------------------------------------------- /Tool/template/java/Template2.java: -------------------------------------------------------------------------------- 1 | package TableConfig; 2 | import java.util.HashMap; 3 | import java.util.Map; 4 | import java.util.List; 5 | import java.util.ArrayList; 6 | import javafx.util.Pair; 7 | 8 | public class TemplateClass extends DataBase 9 | { 10 | //region value 11 | ValueContent 12 | //endregion 13 | //region load and get funtion 14 | private static TemplateClass[] m_Datas = null; 15 | public static TemplateClass[] GetDatas() 16 | { 17 | return m_Datas; 18 | } 19 | 20 | 21 | public static int GetCount() 22 | { 23 | if(m_Datas == null) 24 | { 25 | return 0; 26 | } 27 | return m_Datas.length; 28 | } 29 | 30 | 31 | private static Map, TemplateClass> m_DicDicDatas = null; 32 | public static Map, TemplateClass> GetDicDicDatas() 33 | { 34 | return m_DicDicDatas; 35 | } 36 | 37 | private static Map> m_DicListDatas = null; 38 | public static Map> GetDicListDatas() 39 | { 40 | return m_DicListDatas; 41 | } 42 | 43 | 44 | 45 | private void Load(BinData bin) 46 | { 47 | ReadValueLoadContent 48 | } 49 | 50 | public static void Load() 51 | { 52 | BinData bin = OpenData("TemplateClass.bin") ; 53 | if (bin != null) 54 | { 55 | try 56 | { 57 | int count = bin.ReadInt32(); 58 | m_Datas = new TemplateClass[count]; 59 | m_DicDicDatas = new HashMap<>(); 60 | m_DicListDatas = new HashMap<>(); 61 | for (int i = 0; i < count; ++i) 62 | { 63 | TemplateClass data = new TemplateClass(); 64 | data.Load(bin); 65 | m_Datas[i] = data; 66 | Pair mainKey = new Pair<>(data.GetFirstKey(),data.GetSecondKey()); 67 | if(null == m_DicDicDatas.get(mainKey)) 68 | { 69 | m_DicDicDatas.put(mainKey, data); 70 | } 71 | 72 | List dataList = m_DicListDatas.get(data.GetFirstKey()); 73 | if(dataList == null) 74 | { 75 | dataList = new ArrayList(); 76 | m_DicListDatas.put(data.GetFirstKey(), dataList); 77 | } 78 | dataList.add(data); 79 | } 80 | } 81 | catch(Exception e) 82 | { 83 | 84 | } 85 | } 86 | } 87 | 88 | public static TemplateClass Get(FirstKeyType FirstKey,SecondKeyType SecondKey) 89 | { 90 | Pair mainKey = new Pair<>(FirstKey,SecondKey); 91 | return m_DicDicDatas.get(mainKey); 92 | } 93 | 94 | 95 | public static List Get(FirstKeyType FirstKey) 96 | { 97 | return m_DicListDatas.get(FirstKey); 98 | } 99 | 100 | public static void Reload() 101 | { 102 | Unload(); 103 | Load(); 104 | } 105 | 106 | 107 | public static void Unload() 108 | { 109 | boolean bGC = false; 110 | if(m_Datas != null) 111 | { 112 | m_Datas = null; 113 | bGC = true; 114 | } 115 | if(bGC) 116 | { 117 | System.gc(); 118 | } 119 | } 120 | //endregion 121 | } -------------------------------------------------------------------------------- /Tool/template/java/common/BinData.java: -------------------------------------------------------------------------------- 1 | package TableConfig; 2 | 3 | import java.io.*; 4 | 5 | public class BinData 6 | { 7 | private String[] commonstring = null; 8 | private FileInputStream fileInputStream = null; 9 | public BinData(String path) 10 | { 11 | try { 12 | fileInputStream = new FileInputStream(path); 13 | // 执行文件操作 14 | } catch (FileNotFoundException e) { 15 | e.printStackTrace(); 16 | } 17 | 18 | } 19 | 20 | public int ReadInt32() 21 | { 22 | try { 23 | int ch1 = fileInputStream.read(); 24 | int ch2 = fileInputStream.read(); 25 | int ch3 = fileInputStream.read(); 26 | int ch4 = fileInputStream.read(); 27 | if ((ch1 | ch2 | ch3 | ch4) < 0) 28 | throw new EOFException(); 29 | return ((ch1) + (ch2 << 8) + (ch3 << 16) + (ch4 << 24)); 30 | // 执行文件操作 31 | } catch (Exception e) { 32 | e.printStackTrace(); 33 | } 34 | 35 | return 0; 36 | } 37 | 38 | public void ReadStringArray() 39 | { 40 | int count = 0; 41 | count = ReadInt32(); 42 | commonstring = new String[count]; 43 | for (int i = 0; i < count; ++i) 44 | { 45 | commonstring[i] = ReadString(); 46 | } 47 | } 48 | 49 | 50 | public long ReadInt64() 51 | { 52 | try { 53 | 54 | int ch1 = fileInputStream.read(); 55 | int ch2 = fileInputStream.read(); 56 | int ch3 = fileInputStream.read(); 57 | int ch4 = fileInputStream.read(); 58 | int ch5 = fileInputStream.read(); 59 | int ch6 = fileInputStream.read(); 60 | int ch7 = fileInputStream.read(); 61 | int ch8 = fileInputStream.read(); 62 | return (((long)ch8 << 56) + 63 | ((long)(ch7 & 255) << 48) + 64 | ((long)(ch6 & 255) << 40) + 65 | ((long)(ch5 & 255) << 32) + 66 | ((long)(ch4 & 255) << 24) + 67 | ((ch3 & 255) << 16) + 68 | ((ch2 & 255) << 8) + 69 | ((ch1 & 255) << 0)); 70 | // 执行文件操作 71 | } catch (Exception e) { 72 | e.printStackTrace(); 73 | } 74 | return 0; 75 | } 76 | 77 | public short ReadInt16() 78 | { 79 | try { 80 | int ch1 = fileInputStream.read(); 81 | int ch2 = fileInputStream.read(); 82 | if ((ch1 | ch2) < 0) 83 | throw new EOFException(); 84 | return (short)((ch1) + (ch2 << 8)); 85 | // 执行文件操作 86 | } catch (Exception e) { 87 | e.printStackTrace(); 88 | } 89 | return 0; 90 | } 91 | 92 | public short ReadUInt16() 93 | { 94 | return ReadInt16(); 95 | } 96 | public int ReadUInt32() 97 | { 98 | return ReadInt32(); 99 | } 100 | public long ReadUInt64() 101 | { 102 | return ReadInt64(); 103 | } 104 | public float ReadFloat() 105 | { 106 | return Float.intBitsToFloat(ReadInt32()); 107 | } 108 | 109 | public double ReadDouble() 110 | { 111 | return Double.longBitsToDouble(ReadInt64()); 112 | } 113 | 114 | public boolean ReadBoolean() 115 | { 116 | try { 117 | int ch = fileInputStream.read(); 118 | if (ch < 0) 119 | throw new EOFException(); 120 | return (ch != 0); 121 | // 执行文件操作 122 | } catch (Exception e) { 123 | e.printStackTrace(); 124 | } 125 | return false; 126 | } 127 | 128 | public int Readsbyte() 129 | { 130 | try { 131 | return fileInputStream.read(); 132 | // 执行文件操作 133 | } catch (Exception e) { 134 | e.printStackTrace(); 135 | } 136 | return 0; 137 | } 138 | 139 | public String ReadCommonString() 140 | { 141 | int id = ReadInt32(); 142 | if(id < 0) 143 | { 144 | return ""; 145 | } 146 | return commonstring[id]; 147 | } 148 | 149 | 150 | public String ReadString() 151 | { 152 | int len = ReadInt32(); 153 | if(len < 0) 154 | { 155 | return ""; 156 | } 157 | 158 | try { 159 | byte[] bytes = new byte[len]; 160 | if (len < 0) 161 | throw new IndexOutOfBoundsException(); 162 | int n = 0; 163 | while (n < len) { 164 | int count = fileInputStream.read(bytes, n, len - n); 165 | if (count < 0) 166 | throw new EOFException(); 167 | n += count; 168 | } 169 | String v = new String(bytes, "UTF-8"); 170 | return v; 171 | // 执行文件操作 172 | } catch (Exception e) { 173 | e.printStackTrace(); 174 | } 175 | return ""; 176 | } 177 | 178 | public void Close() 179 | { 180 | try 181 | { 182 | fileInputStream.close(); 183 | commonstring = null; 184 | } 185 | catch (Exception e) { 186 | e.printStackTrace(); 187 | } 188 | } 189 | } -------------------------------------------------------------------------------- /Tool/template/java/common/DataBase.java: -------------------------------------------------------------------------------- 1 | package TableConfig; 2 | 3 | public class DataBase 4 | { 5 | private static String DefaultFolder = ""; 6 | public static void SetDataPath(String path) 7 | { 8 | DefaultFolder = path; 9 | } 10 | 11 | public static BinData OpenData(String fileName) 12 | { 13 | StringBuilder stringBuilder = new StringBuilder(); 14 | stringBuilder.append(DefaultFolder); 15 | stringBuilder.append(fileName); 16 | String fullPath = stringBuilder.toString(); 17 | return OpenBin(fullPath); 18 | } 19 | 20 | public static BinData OpenBin(String fullPath) 21 | { 22 | BinData bin = null; 23 | try 24 | { 25 | bin = new BinData(fullPath); 26 | return bin; 27 | } 28 | catch (Exception e) 29 | { 30 | 31 | } 32 | return bin; 33 | } 34 | } -------------------------------------------------------------------------------- /Tool/template/lua/common/CommonLua.lua: -------------------------------------------------------------------------------- 1 | function readOnly (t) 2 | local proxy = {} 3 | local mt = {-- create metatable 4 | __index = t, 5 | __newindex = function (t,k,v) 6 | error("attempt to update a read-only table", 2) 7 | end 8 | } 9 | setmetatable(proxy, mt) 10 | return proxy 11 | end -------------------------------------------------------------------------------- /exceltool.sh: -------------------------------------------------------------------------------- 1 | python Tool/exportbin.py 2 | sleep 5 # 暂停5秒 --------------------------------------------------------------------------------