adapted script for Godot 4.1

This commit is contained in:
Jaap Marsman 2023-09-10 10:19:26 +08:00
parent aab6be4dea
commit 93631b95e5
2 changed files with 9 additions and 5 deletions

View File

@ -3,17 +3,17 @@ extends Node
signal read_completed
signal load_completed(image)
var js_callback = JavaScript.create_callback(self, "load_handler");
var js_callback = JavaScriptBridge.create_callback(self, "load_handler");
var js_interface;
func _ready():
if OS.get_name() == "HTML5" and OS.has_feature('JavaScript'):
_define_js()
js_interface = JavaScript.get_interface("_HTML5FileExchange");
js_interface = JavaScriptBridge.get_interface("_HTML5FileExchange");
func _define_js()->void:
#Define JS script
JavaScript.eval("""
JavaScriptBridge.eval("""
var _HTML5FileExchange = {};
_HTML5FileExchange.upload = function(gd_callback) {
canceled = true;
@ -51,7 +51,7 @@ func load_image():
yield(self, "read_completed")
var imageType = js_interface.fileType;
var imageData = JavaScript.eval("_HTML5FileExchange.result", true) # interface doesn't work as expected for some reason
var imageData = JavaScriptBridge.eval("_HTML5FileExchange.result", true) # interface doesn't work as expected for some reason
var image = Image.new()
var image_error
@ -77,4 +77,4 @@ func save_image(image:Image, fileName:String = "export.png")->void:
image.clear_mipmaps()
var buffer = image.save_png_to_buffer()
JavaScript.download_buffer(buffer, fileName)
JavaScriptBridge.download_buffer(buffer, fileName)

4
makefile Normal file
View File

@ -0,0 +1,4 @@
git:
git add -A
git commit -m "$m"
git push