@@ -35,47 +35,100 @@ def getParams() -> list:
3535if param_verbose == "verbose" :
3636 verbose_enabled = True
3737
38- filein = "bkscr/多行.bkscr"
39- fileout = "compile_out/out.txt" # 备份 fileout = filein.replace(".bkscr",".txt")
38+ # filein = "bkscr/多行.bkscr"
39+ # filein = os.path.split(param_input_dir)[1] # 多好.bkscr
40+ # fileout = "",filein.replace(".bkscr",".txt")
41+ # fileout = "compile_out/out.txt" # 备份 fileout = filein.replace(".bkscr",".txt")
4042
4143ColorPrint .print_verbose_once ()
4244ColorPrint .print_compile_once ()
4345ColorPrint .print_verbose_hint ("输入文件夹 -> " + param_input_dir )
44- ColorPrint .print_verbose_hint ("输出文件 -> " + fileout )
46+ # ColorPrint.print_verbose_hint("输出文件 -> " + fileout)
47+
48+ def getAllBkscr (p_dir ) -> list :
49+ L = []
50+ for root , dirs , files in os .walk (p_dir ):
51+ #获得所有bkscr文件
52+ for file in files :
53+ if os .path .splitext (file )[1 ] == ".bkscr" :
54+ if file != "macro.bkscr" :
55+ L .append (os .path .join (root , file ))
56+ return L
57+
58+ # 先预处理一变所有文件的所有行的开头和结尾的空格 因为这个空格是非必要的,而且三种格式可能都存在首尾空格,所以去除空格并不会影响游戏代码
59+ def preCompile (eachFile : str ) -> list :
60+ result = [] # string []
61+ # 针对每个文件,读取每个文件的所有行
62+ each_lines :str = eachFile .readlines ()
63+ for lines in each_lines :
64+ result .append (预处理 .处理 ("单行宏" ,lines ,verbose_enabled ))
65+ ColorPrint .print_compile ("预处理结果" ,str (result ))
66+
67+ return result
68+ # 过程 getAllBkscr -> preCompile -> compile
69+ def compileProject (p_dir ,p_verbose ):
70+ all_FilePaths :list = getAllBkscr (p_dir )
71+
72+ for each_FilePath in all_FilePaths :
73+ with open (each_FilePath ,"r" ,encoding = "utf-8" ) as eachFile :
74+ # filein = os.path.split(param_input_dir)[1] # 多好.bkscr
75+ # fileout filein.replace(".bkscr",".txt")
76+ p = os .path .split (each_FilePath )
77+ output_name = "compile_out/" + p [1 ].replace (".bkscr" ,".txt" )
78+ FileOut = open (output_name ,"w" ,encoding = "utf-8" )
79+ # 这里的预处理结果是当前的一行
80+ 每一行的预处理结果 :list = preCompile (eachFile )
81+ # ColorPrint.print_compile("预处理结果",str(预处理结果))
82+ for index ,line in enumerate (每一行的预处理结果 ):
83+ currentScanLine = index + 1
84+ if line [0 ] == "@" :
85+ lineToken :list = sp .parse (line ,currentScanLine ,verbose_enabled )
86+ #print("缓冲区",buffer_line)
87+ for element in lineToken :
88+ # print(currentScanLine, buffer_array)
89+
90+ FileOut .write (element + "\n " )
91+ # result.append(buffer_line)
92+ if line [0 ] == "[" :
93+ lineToken :list = mp .parse (line ,currentScanLine ,verbose_enabled )
94+ for element in lineToken :
95+ # #print(currentScanLine, buffer_array)
96+ FileOut .write (element + "\n " )
97+ # #result.append(buffer_array)
4598
4699if param_input_dir != None :
47100 if Encoder .encodeProject (param_input_dir ,verbose_enabled ):
48- srcfile = open (filein ,"r" ,encoding = "utf-8" )
49- lines = srcfile .readlines ()
50- srcfile .close ()
51- # print("所有行")
52- # #print(lines)
101+ compileProject (param_input_dir ,verbose_enabled )
102+ # srcfile = open(filein,"r",encoding="utf-8")
103+ # lines = srcfile.readlines()
104+ # srcfile.close()
105+ # # print("所有行")
106+ # # #print(lines)
107+
108+ # out = open(fileout,"w",encoding="utf-8")
53109
54- out = open (fileout ,"w" ,encoding = "utf-8" )
55- # result = [] 以后可能要用到的变量 先暂时备份
56- # 先预处理一变所有文件的所有行的开头和结尾的空格 因为这个空格是非必要的,而且三种格式可能都存在首尾空格,所以去除空格并不会影响游戏代码
57- 预处理结果 = [] # string []
58- for line in lines :
59- 预处理结果 .append (预处理 .处理 ("单行宏" ,line ,verbose_enabled ))
60- ColorPrint .print_compile ("预处理结果" ,str (预处理结果 ))
110+ # 预处理结果 = [] # string []
111+ # for line in lines:
112+ # 预处理结果.append(预处理.处理("单行宏",line,verbose_enabled))
113+ # ColorPrint.print_compile("预处理结果",str(预处理结果))
61114
62- # 逐行扫描
63- for index ,line in enumerate (lines ):
64- currentScanLine = index + 1
65- # # 每一行的结果 如果遇到注释行,则会丢弃那一行
66- # buffer_array = []
67- if line [0 ] == "@" :
68- lineToken :list = sp .parse (line ,currentScanLine ,verbose_enabled )
69- #print("缓冲区",buffer_line)
70- for element in lineToken :
71- # print(currentScanLine, buffer_array)
72-
73- out .write (element + "\n " )
74- # result.append(buffer_line)
75- if line [0 ] == "[" :
76- lineToken :list = mp .parse (code = line , scanLine = currentScanLine , verbose = verbose_enabled )
77- for element in lineToken :
78- # #print(currentScanLine, buffer_array)
79- out .write (element + "\n " )
80- # #result.append(buffer_array)
81- out .close ()
115+ # # 逐行扫描
116+ # for index,line in enumerate(lines):
117+ # currentScanLine = index + 1
118+ # # # 每一行的结果 如果遇到注释行,则会丢弃那一行
119+ # # buffer_array = []
120+ # if line[0] == "@":
121+ # lineToken:list = sp.parse(line,currentScanLine,verbose_enabled)
122+ # #print("缓冲区",buffer_line)
123+ # for element in lineToken:
124+ # # print(currentScanLine, buffer_array)
125+
126+ # out.write(element + "\n")
127+ # # result.append(buffer_line)
128+ # if line[0] == "[":
129+ # lineToken:list = mp.parse(code=line, scanLine=currentScanLine, verbose=verbose_enabled)
130+ # for element in lineToken:
131+ # # #print(currentScanLine, buffer_array)
132+ # out.write(element + "\n")
133+ # # #result.append(buffer_array)
134+ # out.close()
0 commit comments