diff --git a/game/addons/web_pages/classes/WebPage.gd b/game/addons/web_pages/classes/WebPage.gd index bba902c..efddb4c 100644 --- a/game/addons/web_pages/classes/WebPage.gd +++ b/game/addons/web_pages/classes/WebPage.gd @@ -9,8 +9,6 @@ export(Array, Resource) var entries : Array signal entries_changed() -#TODO fix webperm assign - func _handle_request(request : WebServerRequest): if request.get_remaining_segment_count() > 0: if allow_web_interface_editing: @@ -264,6 +262,24 @@ func web_editor_handle_delete(request : WebServerRequest) -> bool: return true +func create_entry(cls_name : String) -> WebPageEntry: + return _create_entry(cls_name) + +func _create_entry(cls_name : String) -> WebPageEntry: + var entry : WebPageEntry = null + + if cls_name == "WebPageEntryTitleText": + entry = WebPageEntryTitleText.new() + elif cls_name == "WebPageEntryText": + entry = WebPageEntryText.new() + elif cls_name == "WebPageEntryImage": + entry = WebPageEntryImage.new() + + if !entry: + PLogger.log_error("PageEditor: Couldn't create entry for: " + cls_name) + + return entry + func get_next_id() -> int: var id : int = 0 for i in range(entries.size()): diff --git a/game/addons/web_pages/classes/WebPageEntry.gd b/game/addons/web_pages/classes/WebPageEntry.gd index 46e326b..0ebc937 100644 --- a/game/addons/web_pages/classes/WebPageEntry.gd +++ b/game/addons/web_pages/classes/WebPageEntry.gd @@ -48,5 +48,11 @@ func _render_edit_bar(request : WebServerRequest) -> void: request.body += hb.result +func get_editor() -> Control: + return _get_editor() + +func _get_editor() -> Control: + return null + func get_page_entry_class_name() -> String: return "WebPageEntry" diff --git a/game/addons/web_pages/classes/post_entries/WebPageEntryImage.gd b/game/addons/web_pages/classes/post_entries/WebPageEntryImage.gd index f72623f..0f7958f 100644 --- a/game/addons/web_pages/classes/post_entries/WebPageEntryImage.gd +++ b/game/addons/web_pages/classes/post_entries/WebPageEntryImage.gd @@ -40,6 +40,10 @@ func _render(request : WebServerRequest): request.body += '>' +func _get_editor() -> Control: + var WebPageEntryImageEditor : PackedScene = ResourceLoader.load("res://addons/web_pages/editor/post_entries/WebPageEntryImageEditor.tscn", "PackedScene") + return WebPageEntryImageEditor.instance() as Control + func get_page_entry_class_name() -> String: return "WebPageEntryImage" diff --git a/game/addons/web_pages/classes/post_entries/WebPageEntryText.gd b/game/addons/web_pages/classes/post_entries/WebPageEntryText.gd index 60ce952..73b71e8 100644 --- a/game/addons/web_pages/classes/post_entries/WebPageEntryText.gd +++ b/game/addons/web_pages/classes/post_entries/WebPageEntryText.gd @@ -16,5 +16,9 @@ func set_text(t : String) -> void: func _render(request : WebServerRequest): request.body += compiled_text +func _get_editor() -> Control: + var WebPageEntryTextEditor : PackedScene = ResourceLoader.load("res://addons/web_pages/editor/post_entries/WebPageEntryTextEditor.tscn", "PackedScene") + return WebPageEntryTextEditor.instance() as Control + func get_page_entry_class_name() -> String: return "WebPageEntryText" diff --git a/game/addons/web_pages/classes/post_entries/WebPageEntryTitleText.gd b/game/addons/web_pages/classes/post_entries/WebPageEntryTitleText.gd index fc17765..d25cc33 100644 --- a/game/addons/web_pages/classes/post_entries/WebPageEntryTitleText.gd +++ b/game/addons/web_pages/classes/post_entries/WebPageEntryTitleText.gd @@ -39,3 +39,7 @@ func _handle_edit(request : WebServerRequest) -> void: request.body += b.result request.compile_and_send_body() + +func _get_editor() -> Control: + var WebPageEntryTitleTextEditor : PackedScene = ResourceLoader.load("res://addons/web_pages/editor/post_entries/WebPageEntryTitleTextEditor.tscn", "PackedScene") + return WebPageEntryTitleTextEditor.instance() as Control diff --git a/game/addons/web_pages/editor/PageEditor.gd b/game/addons/web_pages/editor/PageEditor.gd index e3c8c05..bb37e39 100644 --- a/game/addons/web_pages/editor/PageEditor.gd +++ b/game/addons/web_pages/editor/PageEditor.gd @@ -173,18 +173,7 @@ func on_page_entries_changed() -> void: recreate() func _on_add_entry_class_selected(cls_name : String) -> void: - var entry : WebPageEntry = null - - if cls_name == "WebPageEntryTitleText": - entry = WebPageEntryTitleText.new() - elif cls_name == "WebPageEntryText": - entry = WebPageEntryText.new() - elif cls_name == "WebPageEntryImage": - entry = WebPageEntryImage.new() - - if !entry: - PLogger.log_error("PageEditor: Couldn't create entry for: " + cls_name) - return + var entry : WebPageEntry = _page.create_entry(cls_name) add_entry(entry, _entry_add_after) diff --git a/game/addons/web_pages/editor/WebPageEntryEditor.gd b/game/addons/web_pages/editor/WebPageEntryEditor.gd index 02649d0..8fa8111 100644 --- a/game/addons/web_pages/editor/WebPageEntryEditor.gd +++ b/game/addons/web_pages/editor/WebPageEntryEditor.gd @@ -8,10 +8,6 @@ var _main_container : Control = null var _editor : Control = null -var WebPageEntryTitleTextEditor : PackedScene = null -var WebPageEntryTextEditor : PackedScene = null -var WebPageEntryImageEditor : PackedScene = null - signal entry_add_requested_after(entry) signal entry_move_up_requested(entry) signal entry_move_down_requested(entry) @@ -20,16 +16,11 @@ signal entry_delete_requested(entry) func set_entry(entry : WebPageEntry, undo_redo : UndoRedo) -> void: _entry = entry + _editor = entry.get_editor() + var cls : String = entry.get_page_entry_class_name() _entry_type_label.text = cls - if cls == "WebPageEntryTitleText": - _editor = WebPageEntryTitleTextEditor.instance() - elif cls == "WebPageEntryText": - _editor = WebPageEntryTextEditor.instance() - elif cls == "WebPageEntryImage": - _editor = WebPageEntryImageEditor.instance() - if _editor: _editor.set_entry(entry, undo_redo) _main_container.add_child(_editor) @@ -45,13 +36,9 @@ func _on_down_button_pressed(): func _on_delete_button_pressed(): emit_signal("entry_delete_requested", _entry) - + func _notification(what): if what == NOTIFICATION_INSTANCED: - WebPageEntryTitleTextEditor = ResourceLoader.load("res://addons/web_pages/editor/post_entries/WebPageEntryTitleTextEditor.tscn", "PackedScene") - WebPageEntryTextEditor = ResourceLoader.load("res://addons/web_pages/editor/post_entries/WebPageEntryTextEditor.tscn", "PackedScene") - WebPageEntryImageEditor = ResourceLoader.load("res://addons/web_pages/editor/post_entries/WebPageEntryImageEditor.tscn", "PackedScene") - _entry_type_label = get_node("PC/VBC/TopBar/EntryTypeLabel") _main_container = get_node("PC/VBC/MainContainer")