#!/bin/bash # Author: Weiney # E-mail: admin@weiney.com # CreationTime: 2022/10/17 20:09 anynowtime="date +'%Y-%m-%d %H:%M:%S'" NOW="echo [\`$anynowtime\`][PID:$$]" ##### 可在脚本开始运行时调用,打印当时的时间戳及PID。 function job_start { echo "$(eval $NOW) job_start" } ##### 可在脚本执行成功的逻辑分支处调用,打印当时的时间戳及PID。 function job_success { MSG="$*" echo "$(eval $NOW) job_success:[$MSG]" exit 0 } ##### 可在脚本执行失败的逻辑分支处调用,打印当时的时间戳及PID。 function job_fail { MSG="$*" echo "$(eval $NOW) job_fail:[$MSG]" exit 1 } job_start # 全局变量 RUNTIME="" RUNTIME_MAC="osx.10.12-x64" RUNTIME_UBUNTU="ubuntu.18.04-x64" DIR_CURRENT=$(pwd) DIR_PROTOCOL="./protocol/" DIR_EXCEL_EXPORT="./ExcelExport/" DIR_SVR_COMM="${DIR_CURRENT}/../pandora_svr_proj/ServerComm/" DIR_CLI_HOTFIX_PROTOCOL="${DIR_CURRENT}/../pandora_cli_proj/pandora/Assets/Scripts/AIMachine/HotFixLogic/protocol" # 生成protobuf到指定的路径 function gen_proto_file() { cd "${DIR_PROTOCOL}" || job_fail "跳转路径失败" mkdir -p "${DIR_SVR_COMM}/protocol" || job_fail "创建路径失败" if [[ "${RUNTIME}" == "${RUNTIME_UBUNTU}" ]]; then chmod +x "./ubuntu.16.04-x64/protocsstruct" || job_fail "修改执行权限失败" ./ubuntu.16.04-x64/protocsstruct ./GameCs.proto ./GameSs.proto --csharp_out="${DIR_SVR_COMM}/protocol" || job_fail "生成Proto失败" ./ubuntu.16.04-x64/protocsstruct ./GameCs.proto ./GameSs.proto --genclasscfg=./GenClassConfig --namespace=ProtoCSClass --csharp_out="${DIR_CLI_HOTFIX_PROTOCOL}" || job_fail "生成Proto失败" fi if [[ "${RUNTIME}" == "${RUNTIME_MAC}" ]]; then chmod +x "./osx.10.12-x64/protocsstruct" || job_fail "修改执行权限失败" ./osx.10.12-x64/protocsstruct ./GameCs.proto ./GameSs.proto --csharp_out="${DIR_SVR_COMM}/protocol" || job_fail "生成Proto失败" ./osx.10.12-x64/protocsstruct ./GameCs.proto ./GameSs.proto --genclasscfg=./GenClassConfig --namespace=ProtoCSClass --csharp_out="${DIR_CLI_HOTFIX_PROTOCOL}" || job_fail "生成Proto失败" fi # 执行文件清理 find "${DIR_SVR_COMM}/protocol" -name "*_class.cs" -exec rm -rf {} \; || job_fail "删除文件失败" find "${DIR_CLI_HOTFIX_PROTOCOL}" -name "*_struct.cs" -exec rm -rf {} \; || job_fail "删除文件失败" find "${DIR_CLI_HOTFIX_PROTOCOL}" -name "FixedRepeatedStruct.cs" -exec rm -rf {} \; || job_fail "删除文件失败" find "${DIR_CLI_HOTFIX_PROTOCOL}" -name "GameSs_enum.cs" -exec rm -rf {} \; || job_fail "删除文件失败" cd "${DIR_CURRENT}" || job_fail "跳转路径失败" echo "生成protobuf成功" } # 更新Proto function update_client_proto() { cd "${DIR_PROTOCOL}" || job_fail "跳转路径失败" python export_lua.py || job_fail "更新Proto失败" cd "${DIR_CURRENT}" || job_fail "跳转路径失败" echo "更新Proto成功" } # excel转lua function excel_to_lua() { cd "${DIR_EXCEL_EXPORT}" || job_fail "跳转路径失败" python excelTolua.py || job_fail "excel转lua失败" cd "${DIR_CURRENT}" || job_fail "跳转路径失败" echo "excel转lua成功" } # 导出语言表 function export_language_to_text() { cd "${DIR_EXCEL_EXPORT}" || job_fail "跳转路径失败" python ExportLanguageToText.py || job_fail "导出语言表失败" cd "${DIR_CURRENT}" || job_fail "跳转路径失败" echo "导出语言表成功" } # 表格导出 function excel_export() { cd "${DIR_EXCEL_EXPORT}/ExcelExport" || job_fail "跳转路径失败" dotnet restore || job_fail "dotnet restore 失败" mkdir -p "./tmp_$$" || job_fail "创建路径失败" dotnet build . --configuration "Debug" --runtime "${RUNTIME}" --output "./tmp_$$" --framework "net5.0" || job_fail "dotnet 构建excelexport失败" cd "./tmp_$$" || job_fail "跳转路径失败" chmod +x ExcelExport || job_fail "修改文件权限失败" ./ExcelExport || job_fail "表格导出失败" cd .. && rm -rf "tmp_$$" || job_fail "清理临时文件失败" cd "${DIR_CURRENT}" || job_fail "跳转路径失败" echo "表格导出成功" } function struct_to_class() { cd "${DIR_PROTOCOL}/StructToClass" || job_fail "跳转路径失败" dotnet restore || job_fail "dotnet restore 失败" mkdir -p "./tmp_$$" || job_fail "创建路径失败" dotnet build . --configuration "Debug" --runtime "${RUNTIME}" --output "./tmp_$$" || job_fail "dotnet 构建StructToClass失败" cd "./tmp_$$" || job_fail "跳转路径失败" chmod +x StructToClass || job_fail "修改文件权限失败" ./StructToClass || job_fail "StructToClass失败" cd .. && rm -rf "tmp_$$" || job_fail "清理临时文件失败" cd "${DIR_CURRENT}" || job_fail "跳转路径失败" echo "StructToClass成功" } # 拷贝目录文件 function copy_room_file() { if [[ -d "../pandora_svr_proj/cfg/sog/map" ]]; then cd "../pandora_svr_proj/cfg/sog/map" || job_fail "跳转路径失败" find ./ -name "*.room" -exec rm -rf {} \; || job_fail "删除文件失败" # 执行文件拷贝 find ../../../../pandora_cli_proj/pandora/Assets/RawResources/HexMapConfig/ -name "*.map" -exec cp {} . \; || job_fail "拷贝文件失败" # 批量重命名 find ./ -name "*.map" | awk -F "." '{print $2}' | xargs -I {} -t mv .{}.map .{}.room || job_fail "重命名失败" fi cd "${DIR_CURRENT}" || job_fail "跳转路径失败" echo "拷贝目录文件" } # 校验参数 function validate_parameter() { # 系统校验 system=$(uname -s) if [[ ${system} == "Linux" ]]; then RUNTIME=${RUNTIME_UBUNTU} elif [[ ${system} == "Darwin" ]]; then RUNTIME=${RUNTIME_MAC} else job_fail "不支持的系统类型" fi # 判断是否安装Python if [[ ! $(command -v python) ]]; then job_fail "Python为必要依赖" fi # 判断是否安装xlrd==1.2.0 if [[ $(pip list | grep xlrd | awk '{print $2}') != "1.2.0" ]]; then job_fail "未安装xlrd==1.2.0, 尝试使用命令 pip install xlrd==1.2.0 安装" fi # 判断是否安装dotnet if [[ ! $(command -v dotnet) ]]; then job_fail "dotnet 为必要依赖" fi # 判断是否安装指定版本sdk if [[ $(dotnet --list-sdks | grep -c "5.0.214") -lt 1 ]]; then job_fail "dotnet sdk=5.0.214 为必要依赖" fi # 校验运行路径 if [[ ! -d "${DIR_PROTOCOL}" || ! -d "${DIR_EXCEL_EXPORT}" || ! -d "${DIR_SVR_COMM}" ]]; then job_fail "运行路径不存在" fi } function main() { # 参数校验 validate_parameter # 生成protobuf到指定的路径 gen_proto_file # StructToClass struct_to_class # excel转lua excel_to_lua # 导出语言表 export_language_to_text # 表格导出 excel_export # 拷贝目录文件 copy_room_file } main job_success "导表成功"