11from .config import USERSET ,json ,SPRITE_INIT_CODE ,GAME_INIT_CODE ,HEAD ,Any ,Union ,Tuple ,digits ,repath ,init_path
22init_path ()
33from .mypath import log ,UnPackingScratch3File ,PathTool
4- from .spectype import FuncParser ,ID ,BlockBuffer ,NestParser ,VarListParser
4+ from .spectype import FuncParser ,ID ,BlockBuffer ,InputParser ,VarListParser
55
66class CodeParser :
77 def __init__ (self ,last :UnPackingScratch3File ):
@@ -15,18 +15,7 @@ def __init__(self,last:UnPackingScratch3File):
1515 self .t = PathTool (self .cdir )
1616 with open (self .t .join ((self .cdir ,"project.json" )),'r' ,encoding = 'utf-8' ) as f : #导入project.json
1717 self .pj = json .load (f )
18- self .semver = self .pj ['meta' ]['semver' ]
19- self .vmver = self .pj ['meta' ]['vm' ]
20- self .agent = self .pj ['meta' ]['agent' ]
21- self .platform_name = self .pj ['meta' ]['platform' ]['name' ]
22- self .platform_url = self .pj ['meta' ]['platform' ]['url' ]
23- log .debug ("=" * 40 )
24- log .debug (f"Project version: { self .semver } " )
25- log .debug (f"VM version: { self .vmver } " )
26- log .debug (f"Agent: { self .agent if self .agent else 'unknown' } " )
27- log .debug (f'Platform name: { self .platform_name } ' )
28- log .debug (f'Platform url: { self .platform_url } ' )
29- log .debug ("=" * 40 )
18+ self .baseinfo = {"semver" :self .pj ['meta' ]['semver' ],"vm" :self .pj ['meta' ]['vm' ],"agent" :self .pj ['meta' ]['agent' ],"platform_name" :self .pj ['meta' ]['platform' ]['name' ],"platform_url" :self .pj ['meta' ]['platform' ]['url' ]}
3019 self .last = last
3120 self .mod = {"internal" :{"typing" :["" ,["Any" ]],"math" :["" ,[]],"random" :["" ,[]],"sys" :["" ,[]],"threading" :["" ,["Thread" ,"Timer" ]]},"third-party" :{"pygame" :["pg" ,[]]}} #根据情况导入所需要的库
3221 self .var = {"public" :{},"private" :{}} #存储变量
@@ -134,7 +123,7 @@ def fstr(self,string:str|dict="",mode=0,args=()):
134123 mode=4: 游戏基础信息,string为代码,args不填
135124 mode=5: 列表、变量管理,string为代码,args不填
136125 mode=6: 嵌套类型管理,string为代码,args为每个的嵌套深度
137- mode=7: 两者运算类 ,args为(inputs开头参数名,运算符)
126+ mode=7: 含参类 ,args为(inputs开头参数名,运算符)
138127 '''
139128 args = list (str (i ) for i in args )
140129 match mode :
@@ -257,10 +246,9 @@ def write_result(self):
257246 self .code .append (f" def { funcname } (self):" )
258247 if funcinfo [1 ]: #有代码
259248 for line ,depth in funcinfo [1 ].items ():
260- if line .startswith ('id=' ):
261- code = self .buffer .buffer .get (line [3 :],[])
262- if code :
263- self .code .append (' ' * (depth + 2 )+ '' .join (code ))
249+ if line .startswith ('id=' ): #输入类型占位标识
250+ code = self .buffer .get (line [3 :])
251+ self .code .append (' ' * (depth + 2 )+ code )
264252 self .code .append (' ' * (depth + 2 )+ line )
265253 self .code .append ("" )
266254 else : #无代码
@@ -288,6 +276,7 @@ def write_result(self):
288276
289277 def code_tree (self ):
290278 return {
279+ "project_info" : self .baseinfo ,
291280 "import_modules" : self .mod ,
292281 "requirements" : self .requirements ,
293282 "variables" : self .var ,
0 commit comments