From 7ac04c81d136b29add4b4affde125def6110c54d Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 26 Aug 2022 17:38:00 +0200 Subject: [PATCH] Also moved editing itself to commands. --- game/addons/web_pages/classes/WebPage.gd | 12 +++++++++++- game/addons/web_pages/classes/WebPageEntry.gd | 7 ++++--- .../classes/post_entries/WebPageEntryImage.gd | 18 ++++++++++-------- .../classes/post_entries/WebPageEntryText.gd | 13 ++++++++----- .../post_entries/WebPageEntryTitleText.gd | 13 ++++++++----- 5 files changed, 41 insertions(+), 22 deletions(-) diff --git a/game/addons/web_pages/classes/WebPage.gd b/game/addons/web_pages/classes/WebPage.gd index 36a284b..f3358f7 100644 --- a/game/addons/web_pages/classes/WebPage.gd +++ b/game/addons/web_pages/classes/WebPage.gd @@ -154,7 +154,11 @@ func web_editor_handle_edit(request : WebServerRequest) -> bool: return true request.push_path() - entry.handle_edit(request) + + var e : WebPageEntry = entry.handle_edit(request) + + if e: + edit_entry_command(entry, e) return true @@ -494,6 +498,8 @@ func _notification(what): if !Engine.editor_hint: _pending_array_mutex.lock() + var changed : bool = _pending_commands.size() > 0 + for i in range(_pending_commands.size()): var e : WebPageEditCommand = _pending_commands[i] as WebPageEditCommand @@ -502,6 +508,10 @@ func _notification(what): _pending_commands.clear() _pending_array_mutex.unlock() + + if changed: + #todo save + on_entries_changed() func _on_entry_changed(): on_entries_changed() diff --git a/game/addons/web_pages/classes/WebPageEntry.gd b/game/addons/web_pages/classes/WebPageEntry.gd index 0ebc937..8ba9f0e 100644 --- a/game/addons/web_pages/classes/WebPageEntry.gd +++ b/game/addons/web_pages/classes/WebPageEntry.gd @@ -16,11 +16,12 @@ func render(request : WebServerRequest): func _render(request : WebServerRequest): pass -func handle_edit(request : WebServerRequest) -> void: - _handle_edit(request) +func handle_edit(request : WebServerRequest) -> WebPageEntry: + return _handle_edit(request) -func _handle_edit(request : WebServerRequest) -> void: +func _handle_edit(request : WebServerRequest) -> WebPageEntry: request.send_error(404) + return null func render_edit_bar(request : WebServerRequest) -> void: _render_edit_bar(request) diff --git a/game/addons/web_pages/classes/post_entries/WebPageEntryImage.gd b/game/addons/web_pages/classes/post_entries/WebPageEntryImage.gd index a76cdf4..4f8fda5 100644 --- a/game/addons/web_pages/classes/post_entries/WebPageEntryImage.gd +++ b/game/addons/web_pages/classes/post_entries/WebPageEntryImage.gd @@ -40,21 +40,23 @@ func _render(request : WebServerRequest): request.body += '>' -func _handle_edit(request : WebServerRequest) -> void: +func _handle_edit(request : WebServerRequest) -> WebPageEntry: if !request.can_edit(): #should be ERR_FAIL_COND - return + return null var b : HTMLBuilder = HTMLBuilder.new() if request.get_method() == HTTPServerEnums.HTTP_METHOD_POST: - image_url = request.get_parameter("image_url") - alt = request.get_parameter("image_alt") + var e : WebPageEntry = duplicate() + + e.image_url = request.get_parameter("image_url") + e.alt = request.get_parameter("image_alt") var imgssx : String = request.get_parameter("image_size_x") var imgssy : String = request.get_parameter("image_size_y") - image_size = Vector2i(imgssx.to_int(), imgssy.to_int()) + e.image_size = Vector2i(imgssx.to_int(), imgssy.to_int()) if request.get_file_count() > 0: var fd : PoolByteArray = request.get_file_data(0) @@ -66,12 +68,11 @@ func _handle_edit(request : WebServerRequest) -> void: f.store_buffer(fd) f.close() - image_path = "user://" + fn + e.image_path = "user://" + fn - #b.div().f().w("Save successful!").cdiv() - emit_changed() request.send_redirect(request.get_url_root_parent(2)) + return e b.div().f().a(request.get_url_root_parent(2)).f().w("<-- back").ca().cdiv() b.br() @@ -110,6 +111,7 @@ func _handle_edit(request : WebServerRequest) -> void: request.body += b.result request.compile_and_send_body() + return null func _get_editor() -> Control: var WebPageEntryImageEditor : PackedScene = ResourceLoader.load("res://addons/web_pages/editor/post_entries/WebPageEntryImageEditor.tscn", "PackedScene") diff --git a/game/addons/web_pages/classes/post_entries/WebPageEntryText.gd b/game/addons/web_pages/classes/post_entries/WebPageEntryText.gd index eaf01bd..88adb99 100644 --- a/game/addons/web_pages/classes/post_entries/WebPageEntryText.gd +++ b/game/addons/web_pages/classes/post_entries/WebPageEntryText.gd @@ -16,19 +16,21 @@ func set_text(t : String) -> void: func _render(request : WebServerRequest): request.body += compiled_text -func _handle_edit(request : WebServerRequest) -> void: +func _handle_edit(request : WebServerRequest) -> WebPageEntry: if !request.can_edit(): #should be ERR_FAIL_COND - return + return null var b : HTMLBuilder = HTMLBuilder.new() if request.get_method() == HTTPServerEnums.HTTP_METHOD_POST: - set_text(request.get_parameter("text")) + var e : WebPageEntry = duplicate() + + e.set_text(request.get_parameter("text")) - #b.div().f().w("Save successful!").cdiv() - emit_changed() request.send_redirect(request.get_url_root_parent(2)) + return e + b.div().f().a(request.get_url_root_parent(2)).f().w("<-- back").ca().cdiv() b.br() @@ -48,6 +50,7 @@ func _handle_edit(request : WebServerRequest) -> void: request.body += b.result request.compile_and_send_body() + return null func _get_editor() -> Control: var WebPageEntryTextEditor : PackedScene = ResourceLoader.load("res://addons/web_pages/editor/post_entries/WebPageEntryTextEditor.tscn", "PackedScene") diff --git a/game/addons/web_pages/classes/post_entries/WebPageEntryTitleText.gd b/game/addons/web_pages/classes/post_entries/WebPageEntryTitleText.gd index 083f617..dd2a397 100644 --- a/game/addons/web_pages/classes/post_entries/WebPageEntryTitleText.gd +++ b/game/addons/web_pages/classes/post_entries/WebPageEntryTitleText.gd @@ -11,20 +11,22 @@ func _render(request : WebServerRequest): func get_page_entry_class_name() -> String: return "WebPageEntryTitleText" -func _handle_edit(request : WebServerRequest) -> void: +func _handle_edit(request : WebServerRequest) -> WebPageEntry: if !request.can_edit(): #should be ERR_FAIL_COND - return + return null var b : HTMLBuilder = HTMLBuilder.new() if request.get_method() == HTTPServerEnums.HTTP_METHOD_POST: - text = request.get_parameter("text") + var e : WebPageEntry = duplicate() - #b.div().f().w("Save successful!").cdiv() - emit_changed() + e.text = request.get_parameter("text") + request.send_redirect(request.get_url_root_parent(2)) + return e + b.div().f().a(request.get_url_root_parent(2)).f().w("<-- back").ca().cdiv() b.br() @@ -40,6 +42,7 @@ func _handle_edit(request : WebServerRequest) -> void: request.body += b.result request.compile_and_send_body() + return null func _get_editor() -> Control: var WebPageEntryTitleTextEditor : PackedScene = ResourceLoader.load("res://addons/web_pages/editor/post_entries/WebPageEntryTitleTextEditor.tscn", "PackedScene")