diff options
Diffstat (limited to 'platform/javascript/api')
| -rw-r--r-- | platform/javascript/api/api.cpp | 116 | ||||
| -rw-r--r-- | platform/javascript/api/api.h | 37 | ||||
| -rw-r--r-- | platform/javascript/api/javascript_singleton.h | 70 | ||||
| -rw-r--r-- | platform/javascript/api/javascript_tools_editor_plugin.cpp | 157 | ||||
| -rw-r--r-- | platform/javascript/api/javascript_tools_editor_plugin.h | 58 | 
5 files changed, 0 insertions, 438 deletions
diff --git a/platform/javascript/api/api.cpp b/platform/javascript/api/api.cpp deleted file mode 100644 index 46a0a816bf..0000000000 --- a/platform/javascript/api/api.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/*************************************************************************/ -/*  api.cpp                                                              */ -/*************************************************************************/ -/*                       This file is part of:                           */ -/*                           GODOT ENGINE                                */ -/*                      https://godotengine.org                          */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md).   */ -/*                                                                       */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the       */ -/* "Software"), to deal in the Software without restriction, including   */ -/* without limitation the rights to use, copy, modify, merge, publish,   */ -/* distribute, sublicense, and/or sell copies of the Software, and to    */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions:                                             */ -/*                                                                       */ -/* The above copyright notice and this permission notice shall be        */ -/* included in all copies or substantial portions of the Software.       */ -/*                                                                       */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ -/*************************************************************************/ - -#include "api.h" -#include "core/config/engine.h" -#include "javascript_singleton.h" -#include "javascript_tools_editor_plugin.h" - -static JavaScript *javascript_eval; - -void register_javascript_api() { -	JavaScriptToolsEditorPlugin::initialize(); -	GDREGISTER_ABSTRACT_CLASS(JavaScriptObject); -	GDREGISTER_ABSTRACT_CLASS(JavaScript); -	javascript_eval = memnew(JavaScript); -	Engine::get_singleton()->add_singleton(Engine::Singleton("JavaScript", javascript_eval)); -} - -void unregister_javascript_api() { -	memdelete(javascript_eval); -} - -JavaScript *JavaScript::singleton = nullptr; - -JavaScript *JavaScript::get_singleton() { -	return singleton; -} - -JavaScript::JavaScript() { -	ERR_FAIL_COND_MSG(singleton != nullptr, "JavaScript singleton already exist."); -	singleton = this; -} - -JavaScript::~JavaScript() {} - -void JavaScript::_bind_methods() { -	ClassDB::bind_method(D_METHOD("eval", "code", "use_global_execution_context"), &JavaScript::eval, DEFVAL(false)); -	ClassDB::bind_method(D_METHOD("get_interface", "interface"), &JavaScript::get_interface); -	ClassDB::bind_method(D_METHOD("create_callback", "callable"), &JavaScript::create_callback); -	{ -		MethodInfo mi; -		mi.name = "create_object"; -		mi.arguments.push_back(PropertyInfo(Variant::STRING, "object")); -		ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "create_object", &JavaScript::_create_object_bind, mi); -	} -	ClassDB::bind_method(D_METHOD("download_buffer", "buffer", "name", "mime"), &JavaScript::download_buffer, DEFVAL("application/octet-stream")); -	ClassDB::bind_method(D_METHOD("pwa_needs_update"), &JavaScript::pwa_needs_update); -	ClassDB::bind_method(D_METHOD("pwa_update"), &JavaScript::pwa_update); -	ADD_SIGNAL(MethodInfo("pwa_update_available")); -} - -#if !defined(JAVASCRIPT_ENABLED) || !defined(JAVASCRIPT_EVAL_ENABLED) -Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) { -	return Variant(); -} - -Ref<JavaScriptObject> JavaScript::get_interface(const String &p_interface) { -	return Ref<JavaScriptObject>(); -} - -Ref<JavaScriptObject> JavaScript::create_callback(const Callable &p_callable) { -	return Ref<JavaScriptObject>(); -} - -Variant JavaScript::_create_object_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { -	if (p_argcount < 1) { -		r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; -		r_error.argument = 0; -		return Ref<JavaScriptObject>(); -	} -	if (p_args[0]->get_type() != Variant::STRING) { -		r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; -		r_error.argument = 0; -		r_error.expected = Variant::STRING; -		return Ref<JavaScriptObject>(); -	} -	return Ref<JavaScriptObject>(); -} -#endif -#if !defined(JAVASCRIPT_ENABLED) -bool JavaScript::pwa_needs_update() const { -	return false; -} -Error JavaScript::pwa_update() { -	return ERR_UNAVAILABLE; -} -void JavaScript::download_buffer(Vector<uint8_t> p_arr, const String &p_name, const String &p_mime) { -} -#endif diff --git a/platform/javascript/api/api.h b/platform/javascript/api/api.h deleted file mode 100644 index 97e06c8577..0000000000 --- a/platform/javascript/api/api.h +++ /dev/null @@ -1,37 +0,0 @@ -/*************************************************************************/ -/*  api.h                                                                */ -/*************************************************************************/ -/*                       This file is part of:                           */ -/*                           GODOT ENGINE                                */ -/*                      https://godotengine.org                          */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md).   */ -/*                                                                       */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the       */ -/* "Software"), to deal in the Software without restriction, including   */ -/* without limitation the rights to use, copy, modify, merge, publish,   */ -/* distribute, sublicense, and/or sell copies of the Software, and to    */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions:                                             */ -/*                                                                       */ -/* The above copyright notice and this permission notice shall be        */ -/* included in all copies or substantial portions of the Software.       */ -/*                                                                       */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ -/*************************************************************************/ - -#ifndef JAVASCRIPT_API_H -#define JAVASCRIPT_API_H - -void register_javascript_api(); -void unregister_javascript_api(); - -#endif // JAVASCRIPT_API_H diff --git a/platform/javascript/api/javascript_singleton.h b/platform/javascript/api/javascript_singleton.h deleted file mode 100644 index e93b0a18a1..0000000000 --- a/platform/javascript/api/javascript_singleton.h +++ /dev/null @@ -1,70 +0,0 @@ -/*************************************************************************/ -/*  javascript_singleton.h                                               */ -/*************************************************************************/ -/*                       This file is part of:                           */ -/*                           GODOT ENGINE                                */ -/*                      https://godotengine.org                          */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md).   */ -/*                                                                       */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the       */ -/* "Software"), to deal in the Software without restriction, including   */ -/* without limitation the rights to use, copy, modify, merge, publish,   */ -/* distribute, sublicense, and/or sell copies of the Software, and to    */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions:                                             */ -/*                                                                       */ -/* The above copyright notice and this permission notice shall be        */ -/* included in all copies or substantial portions of the Software.       */ -/*                                                                       */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ -/*************************************************************************/ - -#ifndef JAVASCRIPT_SINGLETON_H -#define JAVASCRIPT_SINGLETON_H - -#include "core/object/class_db.h" -#include "core/object/ref_counted.h" - -class JavaScriptObject : public RefCounted { -private: -	GDCLASS(JavaScriptObject, RefCounted); - -protected: -	virtual bool _set(const StringName &p_name, const Variant &p_value) { return false; } -	virtual bool _get(const StringName &p_name, Variant &r_ret) const { return false; } -	virtual void _get_property_list(List<PropertyInfo> *p_list) const {} -}; - -class JavaScript : public Object { -private: -	GDCLASS(JavaScript, Object); - -	static JavaScript *singleton; - -protected: -	static void _bind_methods(); - -public: -	Variant eval(const String &p_code, bool p_use_global_exec_context = false); -	Ref<JavaScriptObject> get_interface(const String &p_interface); -	Ref<JavaScriptObject> create_callback(const Callable &p_callable); -	Variant _create_object_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error); -	void download_buffer(Vector<uint8_t> p_arr, const String &p_name, const String &p_mime = "application/octet-stream"); -	bool pwa_needs_update() const; -	Error pwa_update(); - -	static JavaScript *get_singleton(); -	JavaScript(); -	~JavaScript(); -}; - -#endif // JAVASCRIPT_SINGLETON_H diff --git a/platform/javascript/api/javascript_tools_editor_plugin.cpp b/platform/javascript/api/javascript_tools_editor_plugin.cpp deleted file mode 100644 index 1507f32375..0000000000 --- a/platform/javascript/api/javascript_tools_editor_plugin.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/*************************************************************************/ -/*  javascript_tools_editor_plugin.cpp                                   */ -/*************************************************************************/ -/*                       This file is part of:                           */ -/*                           GODOT ENGINE                                */ -/*                      https://godotengine.org                          */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md).   */ -/*                                                                       */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the       */ -/* "Software"), to deal in the Software without restriction, including   */ -/* without limitation the rights to use, copy, modify, merge, publish,   */ -/* distribute, sublicense, and/or sell copies of the Software, and to    */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions:                                             */ -/*                                                                       */ -/* The above copyright notice and this permission notice shall be        */ -/* included in all copies or substantial portions of the Software.       */ -/*                                                                       */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ -/*************************************************************************/ - -#if defined(TOOLS_ENABLED) && defined(JAVASCRIPT_ENABLED) -#include "javascript_tools_editor_plugin.h" - -#include "core/config/engine.h" -#include "core/config/project_settings.h" -#include "core/io/dir_access.h" -#include "core/io/file_access.h" -#include "core/os/time.h" -#include "editor/editor_node.h" - -#include <emscripten/emscripten.h> - -// JavaScript functions defined in library_godot_editor_tools.js -extern "C" { -extern void godot_js_os_download_buffer(const uint8_t *p_buf, int p_buf_size, const char *p_name, const char *p_mime); -} - -static void _javascript_editor_init_callback() { -	EditorNode::get_singleton()->add_editor_plugin(memnew(JavaScriptToolsEditorPlugin)); -} - -void JavaScriptToolsEditorPlugin::initialize() { -	EditorNode::add_init_callback(_javascript_editor_init_callback); -} - -JavaScriptToolsEditorPlugin::JavaScriptToolsEditorPlugin() { -	add_tool_menu_item("Download Project Source", callable_mp(this, &JavaScriptToolsEditorPlugin::_download_zip)); -} - -void JavaScriptToolsEditorPlugin::_download_zip(Variant p_v) { -	if (!Engine::get_singleton() || !Engine::get_singleton()->is_editor_hint()) { -		ERR_PRINT("Downloading the project as a ZIP archive is only available in Editor mode."); -		return; -	} -	String resource_path = ProjectSettings::get_singleton()->get_resource_path(); - -	Ref<FileAccess> io_fa; -	zlib_filefunc_def io = zipio_create_io(&io_fa); - -	// Name the downloaded ZIP file to contain the project name and download date for easier organization. -	// Replace characters not allowed (or risky) in Windows file names with safe characters. -	// In the project name, all invalid characters become an empty string so that a name -	// like "Platformer 2: Godette's Revenge" becomes "platformer_2-_godette-s_revenge". -	const String project_name = GLOBAL_GET("application/config/name"); -	const String project_name_safe = project_name.to_lower().replace(" ", "_"); -	const String datetime_safe = -			Time::get_singleton()->get_datetime_string_from_system(false, true).replace(" ", "_"); -	const String output_name = OS::get_singleton()->get_safe_dir_name(vformat("%s_%s.zip")); -	const String output_path = String("/tmp").plus_file(output_name); - -	zipFile zip = zipOpen2(output_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io); -	const String base_path = resource_path.substr(0, resource_path.rfind("/")) + "/"; -	_zip_recursive(resource_path, base_path, zip); -	zipClose(zip, nullptr); -	{ -		Ref<FileAccess> f = FileAccess::open(output_path, FileAccess::READ); -		ERR_FAIL_COND_MSG(f.is_null(), "Unable to create ZIP file."); -		Vector<uint8_t> buf; -		buf.resize(f->get_length()); -		f->get_buffer(buf.ptrw(), buf.size()); -		godot_js_os_download_buffer(buf.ptr(), buf.size(), output_name.utf8().get_data(), "application/zip"); -	} - -	// Remove the temporary file since it was sent to the user's native filesystem as a download. -	DirAccess::remove_file_or_error(output_path); -} - -void JavaScriptToolsEditorPlugin::_zip_file(String p_path, String p_base_path, zipFile p_zip) { -	Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ); -	if (f.is_null()) { -		WARN_PRINT("Unable to open file for zipping: " + p_path); -		return; -	} -	Vector<uint8_t> data; -	uint64_t len = f->get_length(); -	data.resize(len); -	f->get_buffer(data.ptrw(), len); - -	String path = p_path.replace_first(p_base_path, ""); -	zipOpenNewFileInZip(p_zip, -			path.utf8().get_data(), -			nullptr, -			nullptr, -			0, -			nullptr, -			0, -			nullptr, -			Z_DEFLATED, -			Z_DEFAULT_COMPRESSION); -	zipWriteInFileInZip(p_zip, data.ptr(), data.size()); -	zipCloseFileInZip(p_zip); -} - -void JavaScriptToolsEditorPlugin::_zip_recursive(String p_path, String p_base_path, zipFile p_zip) { -	Ref<DirAccess> dir = DirAccess::open(p_path); -	if (dir.is_null()) { -		WARN_PRINT("Unable to open directory for zipping: " + p_path); -		return; -	} -	dir->list_dir_begin(); -	String cur = dir->get_next(); -	String project_data_dir_name = ProjectSettings::get_singleton()->get_project_data_dir_name(); -	while (!cur.is_empty()) { -		String cs = p_path.plus_file(cur); -		if (cur == "." || cur == ".." || cur == project_data_dir_name) { -			// Skip -		} else if (dir->current_is_dir()) { -			String path = cs.replace_first(p_base_path, "") + "/"; -			zipOpenNewFileInZip(p_zip, -					path.utf8().get_data(), -					nullptr, -					nullptr, -					0, -					nullptr, -					0, -					nullptr, -					Z_DEFLATED, -					Z_DEFAULT_COMPRESSION); -			zipCloseFileInZip(p_zip); -			_zip_recursive(cs, p_base_path, p_zip); -		} else { -			_zip_file(cs, p_base_path, p_zip); -		} -		cur = dir->get_next(); -	} -} -#endif diff --git a/platform/javascript/api/javascript_tools_editor_plugin.h b/platform/javascript/api/javascript_tools_editor_plugin.h deleted file mode 100644 index cbf5f49497..0000000000 --- a/platform/javascript/api/javascript_tools_editor_plugin.h +++ /dev/null @@ -1,58 +0,0 @@ -/*************************************************************************/ -/*  javascript_tools_editor_plugin.h                                     */ -/*************************************************************************/ -/*                       This file is part of:                           */ -/*                           GODOT ENGINE                                */ -/*                      https://godotengine.org                          */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md).   */ -/*                                                                       */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the       */ -/* "Software"), to deal in the Software without restriction, including   */ -/* without limitation the rights to use, copy, modify, merge, publish,   */ -/* distribute, sublicense, and/or sell copies of the Software, and to    */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions:                                             */ -/*                                                                       */ -/* The above copyright notice and this permission notice shall be        */ -/* included in all copies or substantial portions of the Software.       */ -/*                                                                       */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ -/*************************************************************************/ - -#ifndef JAVASCRIPT_TOOLS_EDITOR_PLUGIN_H -#define JAVASCRIPT_TOOLS_EDITOR_PLUGIN_H - -#if defined(TOOLS_ENABLED) && defined(JAVASCRIPT_ENABLED) -#include "core/io/zip_io.h" -#include "editor/editor_plugin.h" - -class JavaScriptToolsEditorPlugin : public EditorPlugin { -	GDCLASS(JavaScriptToolsEditorPlugin, EditorPlugin); - -private: -	void _zip_file(String p_path, String p_base_path, zipFile p_zip); -	void _zip_recursive(String p_path, String p_base_path, zipFile p_zip); -	void _download_zip(Variant p_v); - -public: -	static void initialize(); - -	JavaScriptToolsEditorPlugin(); -}; -#else -class JavaScriptToolsEditorPlugin { -public: -	static void initialize() {} -}; -#endif - -#endif // JAVASCRIPT_TOOLS_EDITOR_PLUGIN_H  |