Skip to content

Commit

Permalink
[all] use scan_tool for Core & Client
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-tz committed Feb 29, 2024
1 parent 89cc389 commit 8ee250e
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 93 deletions.
4 changes: 2 additions & 2 deletions Client/src/interaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand Down
11 changes: 7 additions & 4 deletions Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions ZBin/lua_scripts/Zeus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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)
Expand All @@ -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')
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ZBin/lua_scripts/play/Test/TestSkill.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ firstState = "t",
["t"] = {
switch = function()
end,
Leader = {MyTouch{}},
Leader = task.touch(),
match = "[L]"
},

Expand Down
21 changes: 0 additions & 21 deletions ZBin/tools/scan_ref_configs

This file was deleted.

59 changes: 0 additions & 59 deletions ZBin/tools/scan_scripts

This file was deleted.

81 changes: 81 additions & 0 deletions ZBin/tools/scan_tool
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 8ee250e

Please sign in to comment.