From 08864f0a2504b699329cd75c0b9c166cde10b49f Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 25 Feb 2024 16:23:36 +0100 Subject: [PATCH] Added an importer for HTMLTemplateData. --- modules/web/SCsub | 2 + .../resource_importer_html_template_data.cpp | 87 +++++++++++++++++++ .../resource_importer_html_template_data.h | 57 ++++++++++++ modules/web/register_types.cpp | 14 ++- 4 files changed, 157 insertions(+), 3 deletions(-) create mode 100644 modules/web/html/editor/resource_importer_html_template_data.cpp create mode 100644 modules/web/html/editor/resource_importer_html_template_data.h diff --git a/modules/web/SCsub b/modules/web/SCsub index 4f1cfc314..bf263b2e1 100644 --- a/modules/web/SCsub +++ b/modules/web/SCsub @@ -61,6 +61,8 @@ sources = [ ] if env["tools"]: + sources.append("html/editor/resource_importer_html_template_data.cpp") + sources.append("editor/web_node_editor.cpp") sources.append("editor/web_node_editor_plugin.cpp") sources.append("editor/web_node_editor_web_server.cpp") diff --git a/modules/web/html/editor/resource_importer_html_template_data.cpp b/modules/web/html/editor/resource_importer_html_template_data.cpp new file mode 100644 index 000000000..a16ae5636 --- /dev/null +++ b/modules/web/html/editor/resource_importer_html_template_data.cpp @@ -0,0 +1,87 @@ +/*************************************************************************/ +/* resource_importer_html_template_data.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* PANDEMONIUM ENGINE */ +/* https://github.com/Relintai/pandemonium_engine */ +/*************************************************************************/ +/* Copyright (c) 2022-present Péter Magyar. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 "resource_importer_html_template_data.h" + +#include "core/io/resource_saver.h" + +#include "../html_template_data.h" + +String ResourceImporterHTMLTemplateData::get_importer_name() const { + return "html_template_data"; +} + +String ResourceImporterHTMLTemplateData::get_visible_name() const { + return "HTMLTemplateData"; +} +void ResourceImporterHTMLTemplateData::get_recognized_extensions(List *p_extensions) const { + p_extensions->push_back("phtpl"); +} +String ResourceImporterHTMLTemplateData::get_save_extension() const { + return "res"; +} + +String ResourceImporterHTMLTemplateData::get_resource_type() const { + return "HTMLTemplateData"; +} + +bool ResourceImporterHTMLTemplateData::get_option_visibility(const String &p_option, const RBMap &p_options) const { + return true; +} + +int ResourceImporterHTMLTemplateData::get_preset_count() const { + return 0; +} +String ResourceImporterHTMLTemplateData::get_preset_name(int p_idx) const { + return String(); +} + +void ResourceImporterHTMLTemplateData::get_import_options(List *r_options, int p_preset) const { +} + +Error ResourceImporterHTMLTemplateData::import(const String &p_source_file, const String &p_save_path, const RBMap &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) { + Ref template_data; + template_data.instance(); + + Error err = template_data->load_from_file(p_source_file); + + if (err != OK) { + return err; + } + + return ResourceSaver::save(p_save_path + ".res", template_data); +} + +ResourceImporterHTMLTemplateData::ResourceImporterHTMLTemplateData() { +} + +ResourceImporterHTMLTemplateData::~ResourceImporterHTMLTemplateData() { +} diff --git a/modules/web/html/editor/resource_importer_html_template_data.h b/modules/web/html/editor/resource_importer_html_template_data.h new file mode 100644 index 000000000..948802c80 --- /dev/null +++ b/modules/web/html/editor/resource_importer_html_template_data.h @@ -0,0 +1,57 @@ +#ifndef RESOURCE_IMPORTER_HTML_TEMPLATE_DATA_H +#define RESOURCE_IMPORTER_HTML_TEMPLATE_DATA_H + +/*************************************************************************/ +/* resource_importer_html_template_data.h */ +/*************************************************************************/ +/* This file is part of: */ +/* PANDEMONIUM ENGINE */ +/* https://github.com/Relintai/pandemonium_engine */ +/*************************************************************************/ +/* Copyright (c) 2022-present Péter Magyar. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 "core/io/resource_importer.h" + +class ResourceImporterHTMLTemplateData : public ResourceImporter { + GDCLASS(ResourceImporterHTMLTemplateData, ResourceImporter); + +public: + virtual String get_importer_name() const; + virtual String get_visible_name() const; + virtual void get_recognized_extensions(List *p_extensions) const; + virtual String get_save_extension() const; + virtual String get_resource_type() const; + + virtual int get_preset_count() const; + virtual String get_preset_name(int p_idx) const; + + virtual void get_import_options(List *r_options, int p_preset = 0) const; + virtual bool get_option_visibility(const String &p_option, const RBMap &p_options) const; + virtual Error import(const String &p_source_file, const String &p_save_path, const RBMap &p_options, List *r_platform_variants, List *r_gen_files = nullptr, Variant *r_metadata = nullptr); + + ResourceImporterHTMLTemplateData(); + ~ResourceImporterHTMLTemplateData(); +}; +#endif // RESOURCE_IMPORTER_HTML_TEMPLATE_DATA_H diff --git a/modules/web/register_types.cpp b/modules/web/register_types.cpp index b011fc5a4..7802a3c84 100644 --- a/modules/web/register_types.cpp +++ b/modules/web/register_types.cpp @@ -39,10 +39,14 @@ #include "html/form_validator.h" #include "html/html_builder_bind.h" #include "html/html_parser.h" -#include "html/markdown_renderer.h" -#include "html/paginator.h" #include "html/html_template.h" #include "html/html_template_data.h" +#include "html/markdown_renderer.h" +#include "html/paginator.h" + +#if TOOLS_ENABLED +#include "html/editor/resource_importer_html_template_data.h" +#endif #include "http/csrf_token.h" #include "http/http_server_enums.h" @@ -87,7 +91,7 @@ void register_web_types(ModuleRegistrationLevel p_level) { if (p_level == MODULE_REGISTRATION_LEVEL_SCENE) { ClassDB::register_class<_HTMLBuilder>(); ClassDB::register_class<_HTMLTag>(); - + ClassDB::register_class(); ClassDB::register_class(); @@ -160,6 +164,10 @@ void register_web_types(ModuleRegistrationLevel p_level) { #if TOOLS_ENABLED if (p_level == MODULE_REGISTRATION_LEVEL_EDITOR) { EditorPlugins::add_by_type(); + + Ref html_template_data_importer; + html_template_data_importer.instance(); + ResourceFormatImporter::get_singleton()->add_importer(html_template_data_importer); } #endif }