|
1 | 1 | extends EditorExportPlugin
|
2 | 2 |
|
3 |
| - |
| 3 | +const REQUIRE_EXPLICIT_ADDITION := false |
4 | 4 | const METHOD_PREFIX := "GodotModLoader"
|
5 | 5 |
|
6 | 6 | func _get_name() -> String:
|
@@ -35,6 +35,10 @@ func _export_file(path: String, type: String, features: PackedStringArray) -> vo
|
35 | 35 | var method_first_line_start := get_index_at_method_start(method.name, source_code)
|
36 | 36 | if method_first_line_start == -1 or method.name in method_store:
|
37 | 37 | continue
|
| 38 | + |
| 39 | + if not is_func_moddable(method_first_line_start, source_code): |
| 40 | + continue |
| 41 | + |
38 | 42 | #print(method.flags)
|
39 | 43 | var type_string := get_return_type_string(method.return)
|
40 | 44 | 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(
|
192 | 196 | "%SELF%": self_string,
|
193 | 197 | })
|
194 | 198 |
|
| 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") |
195 | 224 |
|
196 | 225 | static func get_index_at_method_start(method_name: String, text: String) -> int:
|
197 | 226 | # Regular expression to match the function definition with arbitrary whitespace
|
|
0 commit comments