@@ -17,6 +17,23 @@ def GlobRecursive(path, pattern, **kwargs):
1717KEYWORDS = ['GPROPERTY' , 'GMETHOD' , 'GGROUP' , 'GSUBGROUP' , 'GBITFIELD' , 'GSIGNAL' , 'GRPC' , 'GVARARG' , 'GIGNORE' ]
1818INIT_LEVELS = ['GINIT_LEVEL_CORE' , 'GINIT_LEVEL_SERVERS' , 'GINIT_LEVEL_SCENE' , 'GINIT_LEVEL_EDITOR' ]
1919
20+ CPPSCRIPT_BODY = """#ifndef {0}
21+ #define {0}
22+ #include <cppscript_defs.h>
23+ #include "properties.gen.h"
24+ #endif // {0}
25+ """
26+
27+ RPC_CONFIG_BODY = """ {{
28+ Dictionary opts;
29+ opts["rpc_mode"] = MultiplayerAPI::{0};
30+ opts["transfer_mode"] = MultiplayerPeer::{1};
31+ opts["call_local"] = {2};
32+ opts["channel"] = {3};
33+ rpc_config("{4}", opts);
34+ }}
35+ """
36+
2037# Helpers
2138class CppScriptException (Exception ):
2239 pass
@@ -145,14 +162,15 @@ def generate_header_cmake(target, source, env):
145162
146163def generate_header (target , source , env , get_file ):
147164 index = Index .create ()
148- prop_file_name = os .path .join (env ['src' ], 'properties.gen.h' )
165+ prop_file_name = os .path .join (env ['src' ], 'properties.gen.h' )
149166 try :
150167 shutil .move (prop_file_name , prop_file_name + '.tmp' )
151168 except :
152169 pass
153170
154171 try :
155- cached_defs_all = load_defs_json (env ['defs_file' ])
172+ defs_file_path = os .path .join (env ['gen_dir' ], 'defs.json' )
173+ cached_defs_all = load_defs_json (defs_file_path )
156174 cached_defs = cached_defs_all .get ('files' , {})
157175 need_regen = False
158176
@@ -168,6 +186,12 @@ def generate_header(target, source, env, get_file):
168186
169187 new_defs_all = {'hash' : cached_defs_all .get ('hash' , None ), 'files' : new_defs_files }
170188
189+ # Create include header if not exists
190+ path = os .path .join (env ['src' ], env ['header_name' ])
191+ if not os .path .exists (path ):
192+ with open (path , 'w' ) as file :
193+ file .write (CPPSCRIPT_BODY .format (env ['header_name' ].replace (' ' , '_' ).replace ('.' , '_' ).upper ()))
194+
171195 if write_register_header (new_defs_all , env ) or need_regen :
172196 write_property_header (new_defs_all , env )
173197 try :
@@ -180,7 +204,7 @@ def generate_header(target, source, env, get_file):
180204 except :
181205 pass
182206
183- with open (env [ 'defs_file' ] , 'w' ) as file :
207+ with open (defs_file_path , 'w' ) as file :
184208 json .dump (new_defs_all , file , indent = 2 , default = lambda x : x if not isinstance (x , set ) else list (x ))
185209
186210 except CppScriptException as e :
@@ -245,17 +269,17 @@ def add_class(cursor, macros):
245269
246270
247271 for macro in macros :
248- classes .append ((cursor , get_macro_args (filecontent , macro )[1 ], macro . spelling [ 1 :] ))
272+ classes .append ((cursor , get_macro_args (filecontent , macro )[1 ], macro ))
249273
250274
251275 collapse_list (found_class , lambda x : x .kind == CursorKind .CLASS_DECL , add_class )
252276
253277 parsed_classes = {}
254- for cursor , base , type in classes :
278+ for cursor , base , gdclass_macro in classes :
255279 class_defs = {
256280 'class_name' : cursor .spelling ,
257281 'base' : base ,
258- 'type' : type ,
282+ 'type' : gdclass_macro . spelling [ 1 :] ,
259283 'init_level' : 'SCENE' ,
260284 'methods' : [],
261285 'properties' : [],
@@ -266,6 +290,9 @@ def add_class(cursor, macros):
266290 }
267291 child_cursors = []
268292 parse_class (cursor , child_cursors )
293+ # Exclude cursors added by GCLASS() macro
294+ child_cursors = [i for i in child_cursors if gdclass_macro .extent .start .offset != i .extent .start .offset ]
295+
269296 group , subgroup = '' , ''
270297 start , end = cursor .extent .start .offset , cursor .extent .end .offset
271298 class_macros = sorted ([m for m in keyword_macros if start < m .extent .start .offset < end ] + child_cursors , key = lambda x : x .extent .start .offset )
@@ -488,15 +515,13 @@ def write_header(file, defs, env):
488515 Hmethod += f'\t Method<&{ class_name } ::{ method ["name" ]} >::bind(D_METHOD("{ method ["bind_name" ]} "{ args } ){ defvals } );\n '
489516
490517 if 'rpc_config' in method .keys ():
491- header_rpc_config += f""" {{
492- Dictionary opts;
493- opts["rpc_mode"] = MultiplayerAPI::{ method ['rpc_config' ]['rpc_mode' ]} ;
494- opts["transfer_mode"] = MultiplayerPeer::{ method ['rpc_config' ]['transfer_mode' ]} ;
495- opts["call_local"] = { method ['rpc_config' ]['call_local' ]} ;
496- opts["channel"] = { method ['rpc_config' ]['channel' ]} ;
497- rpc_config("{ method ["name" ]} ", opts);
498- }}
499- """
518+ header_rpc_config += RPC_CONFIG_BODY .format (
519+ method ['rpc_config' ]['rpc_mode' ],
520+ method ['rpc_config' ]['transfer_mode' ],
521+ method ['rpc_config' ]['call_local' ],
522+ method ['rpc_config' ]['channel' ],
523+ method ["name" ]
524+ )
500525 else :
501526 args_list = '\n ' .join (f'\t \t ,MakePropertyInfo<{ type } >("{ name } ")' for type , name in method ['varargs' ])
502527
0 commit comments