diff --git a/Client/src/interaction.cpp b/Client/src/interaction.cpp index be089a8..cef284e 100644 --- a/Client/src/interaction.cpp +++ b/Client/src/interaction.cpp @@ -394,7 +394,7 @@ QString Interaction::getRealAddress(int index){ void Interaction::updateTestScriptList(){ QProcess process; - process.start("./tools/scan_scripts"); + process.start("./tools/scan_tool scripts playname"); process.waitForFinished(-1); QString stdout = process.readAllStandardOutput(); _test_script_show_name_list = (stdout).split('\n'); @@ -403,7 +403,7 @@ void Interaction::updateTestScriptList(){ void Interaction::updateRefConfigList(){ QProcess process; - process.start("./tools/scan_ref_configs"); + process.start("./tools/scan_tool ref_configs"); process.waitForFinished(-1); QString stdout = process.readAllStandardOutput(); _ref_config_show_name_list = (stdout).split('\n'); diff --git a/Core/CMakeLists.txt b/Core/CMakeLists.txt index 7773d01..0f13743 100644 --- a/Core/CMakeLists.txt +++ b/Core/CMakeLists.txt @@ -116,13 +116,16 @@ list(APPEND PROJECT_SOURCE subdir_list(TACTIC_PACKS ${CMAKE_CURRENT_SOURCE_DIR}) # remove ignore directory from TACTIC_PACKS -list(REMOVE_ITEM TACTIC_PACKS +set(TACTIC_IGNORE_PACKS "src" ) +list(REMOVE_ITEM TACTIC_PACKS + ${TACTIC_IGNORE_PACKS} +) -message("Write tactic_packages.txt to ${CMAKE_SOURCE_DIR}/ZBin/tactic_packages.txt") -string (REPLACE ";" "\n" TACTIC_PACKS_OUTPUT "${TACTIC_PACKS}") -file(WRITE ${CMAKE_SOURCE_DIR}/ZBin/tactic_packages.txt "${TACTIC_PACKS_OUTPUT}") +message("Write tactic_ignore_packages.txt to ${CMAKE_SOURCE_DIR}/ZBin/tactic_ignore_packages.txt") +string (REPLACE ";" "\n" TACTIC_IGNORE_PACKS_OUTPUT "${TACTIC_IGNORE_PACKS}") +file(WRITE ${CMAKE_SOURCE_DIR}/ZBin/tactic_ignore_packages.txt "${TACTIC_IGNORE_PACKS_OUTPUT}") foreach(pack ${TACTIC_PACKS}) message(STATUS "rocos - tactics_package: '${pack}'") file(GLOB TACTIC_SOURCE diff --git a/ZBin/lua_scripts/Zeus.lua b/ZBin/lua_scripts/Zeus.lua index 47d19c7..1a61a93 100644 --- a/ZBin/lua_scripts/Zeus.lua +++ b/ZBin/lua_scripts/Zeus.lua @@ -42,10 +42,11 @@ end -- init skill from tactic packages local tactic_packages = {} -for line in io.lines("tactic_packages.txt") do +pfile = io.popen('./tools/scan_tool tactic_dir') +for line in pfile:lines() do table.insert(tactic_packages, line) end -print("Tactic Packages : ",table.concat(tactic_packages, ",")) +-- print("Tactic Packages : ",table.concat(tactic_packages, ",")) local scan_scripts = function(tactic_dir) local t = {} @@ -63,7 +64,7 @@ local path_exists = function(file) end for _, value in ipairs(tactic_packages) do - local tactic_dir = "../Core/"..value.."/skill/" + local tactic_dir = value .. "/skill/" if path_exists(tactic_dir) then local skill_files = scan_scripts(tactic_dir) -- print("Tactic Dir : ",tactic_dir) @@ -79,9 +80,9 @@ end -- load task.lua for each tactic package for _, value in ipairs(tactic_packages) do - local task_file = "../Core/" .. value .. "/task.lua" + local task_file = value .. "/task.lua" if path_exists(task_file) then - package.path = "../Core/" .. value .. "/?.lua;" .. package.path + package.path = value .. "/?.lua;" .. package.path package.loaded['task'] = nil print("Load Task File : ",task_file) require('task') @@ -96,7 +97,7 @@ end -- init play from tactic packages for _, value in ipairs(tactic_packages) do - local tactic_dir = "../Core/"..value.."/play/" + local tactic_dir = value .. "/play/" if path_exists(tactic_dir) then local play_files = scan_scripts(tactic_dir) -- print("Tactic Dir : ",tactic_dir) diff --git a/ZBin/lua_scripts/play/Test/TestSkill.lua b/ZBin/lua_scripts/play/Test/TestSkill.lua index b26719d..f1bc3b6 100644 --- a/ZBin/lua_scripts/play/Test/TestSkill.lua +++ b/ZBin/lua_scripts/play/Test/TestSkill.lua @@ -6,7 +6,7 @@ firstState = "t", ["t"] = { switch = function() end, - Leader = {MyTouch{}}, + Leader = task.touch(), match = "[L]" }, diff --git a/ZBin/tools/scan_ref_configs b/ZBin/tools/scan_ref_configs deleted file mode 100755 index 6b60a1b..0000000 --- a/ZBin/tools/scan_ref_configs +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python3 -import os, re - -# get all tactic package name from ../tactic_packages.txt -def get_tactic_packages(file_path): - tactic_packages = [] - with open(file_path, "r") as f: - for line in f: - tactic_packages.append(line.strip()) - return tactic_packages - -if __name__ == '__main__': - current_path = os.path.dirname(os.path.abspath(__file__)) - tactic_packages_name_file_path = os.path.join(current_path, "../tactic_packages.txt") - tactic_name_list = get_tactic_packages(tactic_packages_name_file_path) - tactic_path = os.path.join(current_path, "../../Core/") - for tactic_name in tactic_name_list: - ref_config_file = os.path.join(tactic_path, tactic_name, "PlayConfig.lua") - if not os.path.exists(ref_config_file): - continue - print(tactic_name) \ No newline at end of file diff --git a/ZBin/tools/scan_scripts b/ZBin/tools/scan_scripts deleted file mode 100755 index 0799f0d..0000000 --- a/ZBin/tools/scan_scripts +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env python3 -import os, re - -# get all tactic package name from ../tactic_packages.txt -def get_tactic_packages(file_path): - tactic_packages = [] - with open(file_path, "r") as f: - for line in f: - tactic_packages.append(line.strip()) - return tactic_packages - -# get all file name in current dir -def get_all_files(dir): - files = [] - for root, dirs, file in os.walk(dir): - for f in file: - rela_path = os.path.relpath(root, dir) - if rela_path != ".": - f = os.path.join(rela_path, f) - # files.append(os.path.abspath(os.path.join(root, f))) - files.append(f) - # sort - files.sort() - return files - -if __name__ == '__main__': - # get current file path - current_path = os.path.dirname(os.path.abspath(__file__)) - tactic_packages_name_file_path = os.path.join(current_path, "../tactic_packages.txt") - tactic_name_list = get_tactic_packages(tactic_packages_name_file_path) - tactic_path = os.path.join(current_path, "../../Core/") - for tactic_name in tactic_name_list: - tactic_dir = os.path.join(tactic_path, tactic_name, "play") - if not os.path.exists(tactic_dir): - # print("tactic package {} not exists".format(tactic_dir)) - continue - # get all file name in tactic package - files = get_all_files(tactic_dir) - # print("tactic package {} has {} files".format(tactic_name, len(files))) - for file in files: - # check if file is .lua file - if not file.endswith(".lua"): - continue - # get file content and get 'name = "TestName"' line using regex - file_path = os.path.join(tactic_dir, file) - with open(file_path, "r") as f: - content = f.read().split('\n') - for line in content: - line = line.replace(' ','') - if "name" in line and line.startswith("name=") and line.endswith(","): - # get name value in "" or '' - name = re.findall(r'name=(?:"|\')(.*?)(?:"|\')', line) - if len(name) == 0: - continue - print(name[0]) - break - - # print("{}\t{}".format(tactic_name,file)) - # print(file) \ No newline at end of file diff --git a/ZBin/tools/scan_tool b/ZBin/tools/scan_tool new file mode 100755 index 0000000..b7e921e --- /dev/null +++ b/ZBin/tools/scan_tool @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 +import os, re + +# get all tactic package name from pack_path and ignore package name from ignore_file_path +def get_tactic_packages(pack_path,ignore_file_path): + tactic_packages = [] + tactic_ignore_packages = [] + with open(ignore_file_path, "r") as f: + for line in f: + tactic_ignore_packages.append(line.strip()) + for pack in os.listdir(pack_path): + if pack in tactic_ignore_packages or not os.path.isdir(os.path.join(pack_path, pack)): + continue + tactic_packages.append(pack) + return tactic_packages + +# get all file name in current dir +def get_all_files(dir): + files = [] + for root, dirs, file in os.walk(dir): + for f in file: + rela_path = os.path.relpath(root, dir) + if rela_path != ".": + f = os.path.join(rela_path, f) + # files.append(os.path.abspath(os.path.join(root, f))) + files.append(f) + # sort + files.sort() + return files + +if __name__ == '__main__': + RELATIVE_PATH = "../../Core/" + # get current file path + current_path = os.path.dirname(os.path.abspath(__file__)) + tactic_ignore_packages_name_file_path = os.path.join(current_path, "../tactic_ignore_packages.txt") + tactic_name_list = get_tactic_packages(os.path.join(current_path, RELATIVE_PATH), tactic_ignore_packages_name_file_path) + tactic_path = os.path.normpath(os.path.join(current_path, RELATIVE_PATH)) + + import sys + if sys.argv[1] == 'tactic_dir': + for tactic_name in tactic_name_list: + print(os.path.join(tactic_path, tactic_name)) + if sys.argv[1] == "scripts": + for tactic_name in tactic_name_list: + tactic_dir = os.path.join(tactic_path, tactic_name, "play") + if not os.path.exists(tactic_dir): + # print("tactic package {} not exists".format(tactic_dir)) + continue + # get all file name in tactic package + files = get_all_files(tactic_dir) + # print("tactic package {} has {} files".format(tactic_name, len(files))) + for file in files: + # check if file is .lua file + if not file.endswith(".lua"): + continue + # get file content and get 'name = "TestName"' line using regex + file_path = os.path.join(tactic_dir, file) + with open(file_path, "r") as f: + content = f.read().split('\n') + for line in content: + line = line.replace(' ','') + if "name" in line and line.startswith("name=") and line.endswith(","): + # get name value in "" or '' + name = re.findall(r'name=(?:"|\')(.*?)(?:"|\')', line) + if len(name) == 0: + continue + if len(sys.argv) <= 2 or sys.argv[2] == "playname": + print(name[0]) + elif sys.argv[2] == "filename": + print(file_path) + break + + # print("{}\t{}".format(tactic_name,file)) + # print(file) + + if sys.argv[1] == "ref_configs": + for tactic_name in tactic_name_list: + ref_config_file = os.path.join(tactic_path, tactic_name, "PlayConfig.lua") + if not os.path.exists(ref_config_file): + continue + print(tactic_name) \ No newline at end of file