Skip to content

Commit 1f622c0

Browse files
committed
Static Typing ReAdd
Readd interface static typing when script is loaded.
1 parent b6f6ec6 commit 1f622c0

File tree

16 files changed

+50
-6
lines changed

16 files changed

+50
-6
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ Used internally.
165165
- using interfaces in scripts build-in scene
166166
- support for external editor
167167
- do not remove interface static typing from strings
168-
- readd interface static typing when script is loaded
169168
- show line where error occured.
170169
- automatic conversion from interfaces to traits (traits need to be completed first)
171170
- move implementation erros from bottom 'Interfaces' tab to Script Editor main window (might not be possible)

a.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,5 @@ class SubR extends Resource:
4545
@export var b := Vector4.ONE
4646
@export_category("Test")
4747
@export var d := &"Test"
48+
49+
#

addons/gdscript-interfaces/BasicInterface.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ extends RefCounted
1717
## Constants are implemented in Interfaces them self,
1818
## so this will not have any effect on definition of Interfaces.
1919
const ___DUMMY___ = "DUMMY"
20+
21+
#

addons/gdscript-interfaces/bottom_panel_tab.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,5 @@ func _on_timer_timeout() -> void:
104104
_remove_at_index(i)
105105
i -= 1
106106
i += 1
107+
108+
#

addons/gdscript-interfaces/gdscript-interfaces.gd

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ func read_script(p_s:Script):
127127
if inst.has_method("free"):
128128
inst.free()
129129

130+
func find_code_edits(parent:Node=SE) -> Array[CodeEdit]:
131+
var _to_return : Array[CodeEdit] = []
132+
var _nodes = parent.find_children("*",&"CodeEdit",true,false)
133+
for n in _nodes:
134+
_to_return.append(n as CodeEdit)
135+
return _to_return
136+
130137
func _readd_static_typing(p_script:Script,p_info:String):
131138
if p_info == "":
132139
return
@@ -137,6 +144,13 @@ func _readd_static_typing(p_script:Script,p_info:String):
137144
if s.ends_with("-"):
138145
slices[i] = s.trim_suffix("-").to_int()
139146
var s_c = p_script.source_code
147+
var code_edit : CodeEdit
148+
if len(slices) > 1:
149+
var candidates = find_code_edits()
150+
for c in candidates:
151+
if c.text == s_c:
152+
code_edit = c
153+
break
140154
for i in range(1,len(slices),2):
141155
var pos = slices[i-1] as int
142156
var typing = slices[i] as String
@@ -150,8 +164,9 @@ func _readd_static_typing(p_script:Script,p_info:String):
150164
# for m in regex.search_all(p_script.source_code,pos,pos+len(typing)):
151165
# print(m.get_string(0))
152166
s_c = regex.sub(s_c,":"+typing,true,pos,pos+len(typing)+1)
153-
p_script.source_code = s_c.trim_suffix(p_info)
154-
p_script.changed.emit()
167+
if code_edit:
168+
print("Readed static typing in '",p_script.resource_path,"' successfully.")
169+
code_edit.text = s_c.trim_suffix("\n#"+p_info)
155170
# print(p_script.source_code)
156171

157172
func _read_internal_interface(inst:BasicInterface,interface_global_name:StringName):
@@ -279,7 +294,10 @@ func build_from_path(path):
279294
to_readd[m.get_start()] = m.get_string(1) + i_name
280295
s_c = regex.sub(s_c," $1"+empty+"$2",true)
281296
file = FileAccess.open(path, FileAccess.WRITE)
282-
s_c += "\n#"
297+
if s_c.ends_with("\n#\n"):
298+
s_c = s_c.trim_suffix("\n")
299+
elif not s_c.ends_with("\n#"):
300+
s_c += "\n#"
283301
var to_readd_keys = to_readd.keys()
284302
to_readd_keys.sort()
285303
for key in to_readd_keys:

addons/gdscript-interfaces/global.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,5 @@ static func as_interface(who:Object,interface:StringName=&"") -> Object:
9696

9797
static func say(what:String) -> void:
9898
print_rich("Global is not able to say "+what+" himself.")
99+
100+
#

addons/gdscript-interfaces/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="Interfaces"
44
description=""
55
author="Rito12 "
6-
version="1.0.7"
6+
version="1.0.8"
77
script="gdscript-interfaces.gd"

i2.interface.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ func _on_go_pressed() -> void:
1313

1414
func get_id() -> int:
1515
return 0
16+
17+
#

inter.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ func foo():
1717

1818
func bar(i:int):
1919
pass
20+
21+
#

inter3.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ signal id_changed
44

55
func get_id(of:Object):
66
pass
7+
8+
#

0 commit comments

Comments
 (0)