Skip to content

Commit 0daeb0d

Browse files
committed
feat: 🚧 added optional @moddable requirement
1 parent 4b2f4b6 commit 0daeb0d

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

addons/mod_loader/_export_plugin/export_plugin.gd

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
extends EditorExportPlugin
22

3-
3+
const REQUIRE_EXPLICIT_ADDITION := false
44
const METHOD_PREFIX := "GodotModLoader"
55

66
func _get_name() -> String:
@@ -35,6 +35,10 @@ func _export_file(path: String, type: String, features: PackedStringArray) -> vo
3535
var method_first_line_start := get_index_at_method_start(method.name, source_code)
3636
if method_first_line_start == -1 or method.name in method_store:
3737
continue
38+
39+
if not is_func_moddable(method_first_line_start, source_code):
40+
continue
41+
3842
#print(method.flags)
3943
var type_string := get_return_type_string(method.return)
4044
var is_static := true if method.flags == METHOD_FLAG_STATIC + METHOD_FLAG_NORMAL else false
@@ -192,6 +196,31 @@ static func get_mod_loader_hook(
192196
"%SELF%": self_string,
193197
})
194198

199+
static func get_previous_line_to(text: String, index: int) -> String:
200+
if index <= 0 or index >= text.length():
201+
return ""
202+
203+
var start_index = index - 1
204+
# Find the end of the previous line
205+
while start_index > 0 and text[start_index] != "\n":
206+
start_index -= 1
207+
208+
if start_index == 0:
209+
return ""
210+
211+
start_index -= 1
212+
213+
# Find the start of the previous line
214+
var end_index = start_index
215+
while start_index > 0 and text[start_index - 1] != "\n":
216+
start_index -= 1
217+
218+
return text.substr(start_index, end_index - start_index + 1)
219+
220+
static func is_func_moddable(method_start_idx, text) -> bool:
221+
if not REQUIRE_EXPLICIT_ADDITION:
222+
return true
223+
return get_previous_line_to(text, method_start_idx).contains("@moddable")
195224

196225
static func get_index_at_method_start(method_name: String, text: String) -> int:
197226
# Regular expression to match the function definition with arbitrary whitespace

0 commit comments

Comments
 (0)