Skip to content

Commit 17aa4fe

Browse files
authored
Merge pull request #412 from niklas2902/godot4-meson
Method _save of ResourceFormatSaver didn't work
2 parents 9609216 + c3b1f73 commit 17aa4fe

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/godot/_lang_resource_format_saver.pxi

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from libc.stdint cimport intptr_t
12
# godot_extension: class(parent="ResourceFormatSaver")
23
@cython.final
34
cdef class PythonResourceFormatSaver:
@@ -59,17 +60,15 @@ cdef class PythonResourceFormatSaver:
5960
# `resource` is an instance of `Resource`
6061

6162
# Convert the path to a Python string
62-
cdef object py_path = gdapi.gd_string_to_pystr(&path)
63+
cdef object py_path = gdapi.gd_string_to_pystr(&path).replace("res://", "")
6364

64-
spy_log("CALLED PythonResourceFormatSaver::_save(resource=<resource>, path={py_path!r}, flags={flags})")
65-
66-
# For now, just write a simple placeholder file
67-
# TODO: Once PythonScript._get_source_code() is properly implemented,
68-
# we can call it directly here to get the actual source code
65+
spy_log(f"CALLED PythonResourceFormatSaver::_save(resource=<resource>, path={py_path!r}, flags={flags})")
6966

67+
script = _load_class("ScriptExtension")._from_ptr(<uintptr_t>resource)
68+
source_code = script.get_source_code()
7069
try:
7170
with open(py_path, 'w', encoding='utf-8') as f:
72-
f.write("# Python script saved from Godot\n")
71+
f.write(str(source_code))
7372
return Error.OK
7473
except:
7574
return Error.ERR_FILE_CANT_OPEN

0 commit comments

Comments
 (0)