@@ -276,11 +276,16 @@ func _build() -> bool :
276276 get_editor_interface ().save_scene ()
277277 return true
278278
279+ func build_script (p_s :Script ):
280+ if not p_s or p_s == get_script ():
281+ return
282+ build_from_path (p_s .resource_path )
283+
279284func _on_script_close (p_s :Script ):
280285 if not p_s or p_s == get_script ():
281286 return
282287 var path = p_s .resource_path
283- build_from_path .call_deferred (path )
288+ build_from_path .call_deferred (path , true )
284289
285290class Line extends Resource :
286291 var start :int
@@ -305,7 +310,7 @@ class LineArray extends Resource:
305310 return true
306311 return false
307312
308- func build_from_path (path ):
313+ func build_from_path (path , use_old_save_method = false ):
309314 var file :FileAccess
310315 var s_c :String
311316 var tscn_match := build_in_tscn_script_regex .search (path )
@@ -322,15 +327,16 @@ func build_from_path(path):
322327 var file_input_text = file .get_as_text ()
323328 file .close ()
324329 var code_edit : CodeEdit
325- var candidates = find_code_edits ()
326- for c in candidates :
327- if c .text == s_c :
328- code_edit = c
329- break
330- if not code_edit :
331- print ("Error could not find demanded code edit node." )
332- print ("Building script from path \" " + path + "\" failed." )
333- return
330+ if not use_old_save_method :
331+ var candidates = find_code_edits ()
332+ for c in candidates :
333+ if c .text == s_c :
334+ code_edit = c
335+ break
336+ if not code_edit :
337+ printerr ("Error: could not find corresponding CodeEdit node." )
338+ printerr (" Will try to build \" " + path + "\" script using FileAccess." )
339+ use_old_save_method = true
334340 var to_readd := {}
335341 var strings_locations : LineArray = LineArray .new ()
336342 var strings_regex = RegEx .create_from_string ("" +
@@ -367,19 +373,17 @@ func build_from_path(path):
367373 for key in to_readd_keys :
368374 s_c += str (key ) + "-'" + to_readd [key ] + "'"
369375
370- # if tscn_match :
371- # file = FileAccess.open(tscn_match.get_string(1), FileAccess.WRITE)
372- # file.store_string(tscn_regex.sub(file_input_text,"$1"+s_c+'"'))
373- # else:
374- # file = FileAccess.open(path, FileAccess.WRITE)
375- # file.store_string(s_c)
376- # file.close()
377- code_edit .text = s_c
378-
379- func build_script (p_s :Script ):
380- if not p_s or p_s == get_script ():
376+ if not use_old_save_method :
377+ code_edit .text = s_c
381378 return
382- build_from_path (p_s .resource_path )
379+
380+ if tscn_match :
381+ file = FileAccess .open (tscn_match .get_string (1 ), FileAccess .WRITE )
382+ file .store_string (tscn_regex .sub (file_input_text ,"$1" + s_c + '"' ))
383+ else :
384+ file = FileAccess .open (path , FileAccess .WRITE )
385+ file .store_string (s_c )
386+ file .close ()
383387
384388func show_error (p_script :Script ,p_message :String ):
385389 var ES = get_editor_interface ().get_editor_settings ()
0 commit comments