mirror of
https://github.com/thegatesbrowser/thegates.git
synced 2025-08-23 17:17:31 -04:00
change RenderResult size, don't show gate thumbnail if pack cached
This commit is contained in:
parent
df01c521a7
commit
3bf2f5d761
8 changed files with 42 additions and 27 deletions
Binary file not shown.
|
@ -22,6 +22,11 @@ func _ready() -> void:
|
|||
FileTools.remove_recursive(DOWNLOAD_FOLDER)
|
||||
|
||||
|
||||
func is_cached(url: String) -> bool:
|
||||
var save_path = DOWNLOAD_FOLDER + "/" + url.md5_text() + "." + url.get_file().get_extension()
|
||||
return FileAccess.file_exists(save_path)
|
||||
|
||||
|
||||
func download(url: String, timeout: float = 0) -> String:
|
||||
var save_path = DOWNLOAD_FOLDER + "/" + url.md5_text() + "." + url.get_file().get_extension()
|
||||
|
||||
|
@ -31,7 +36,6 @@ func download(url: String, timeout: float = 0) -> String:
|
|||
DirAccess.make_dir_recursive_absolute(save_path.get_base_dir())
|
||||
|
||||
var result = await create_request(url, save_path, timeout)
|
||||
|
||||
if result == 200:
|
||||
return save_path
|
||||
else:
|
||||
|
@ -50,7 +54,6 @@ func download_shared_lib(url: String, gate_url: String) -> String:
|
|||
DirAccess.make_dir_recursive_absolute(dir)
|
||||
|
||||
var result = await create_request(url, save_path)
|
||||
|
||||
if result == 200:
|
||||
return dir
|
||||
else:
|
||||
|
@ -108,4 +111,5 @@ func stop_all() -> void:
|
|||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
FileDownloader.stop_all()
|
||||
FileTools.remove_recursive(DOWNLOAD_FOLDER)
|
||||
|
|
|
@ -21,7 +21,8 @@ func load_gate(config_url: String) -> void:
|
|||
|
||||
var image_path = await FileDownloader.download(c_gate.image_url)
|
||||
var gate = Gate.create(config_url, c_gate.title, c_gate.description, image_path, "", "")
|
||||
gate_events.gate_info_loaded_emit(gate)
|
||||
var is_cached = FileDownloader.is_cached(c_gate.resource_pack_url)
|
||||
gate_events.gate_info_loaded_emit(gate, is_cached)
|
||||
|
||||
gate.resource_pack = await FileDownloader.download(c_gate.resource_pack_url)
|
||||
if gate.resource_pack.is_empty(): return error(GateEvents.GateError.MISSING_PACK)
|
||||
|
|
|
@ -4,7 +4,7 @@ class_name GateEvents
|
|||
signal search(query: String)
|
||||
signal open_gate(url: String)
|
||||
signal gate_config_loaded(url: String, config: ConfigGate)
|
||||
signal gate_info_loaded(gate: Gate)
|
||||
signal gate_info_loaded(gate: Gate, is_cached: bool)
|
||||
signal gate_loaded(gate: Gate)
|
||||
signal gate_entered
|
||||
signal exit_gate
|
||||
|
@ -42,9 +42,9 @@ func gate_config_loaded_emit(url: String, config: ConfigGate) -> void:
|
|||
gate_config_loaded.emit(url, config)
|
||||
|
||||
|
||||
func gate_info_loaded_emit(gate: Gate) -> void:
|
||||
func gate_info_loaded_emit(gate: Gate, is_cached: bool) -> void:
|
||||
current_gate = gate
|
||||
gate_info_loaded.emit(gate)
|
||||
gate_info_loaded.emit(gate, is_cached)
|
||||
|
||||
|
||||
func gate_loaded_emit(gate: Gate) -> void:
|
||||
|
|
|
@ -14,29 +14,35 @@ var texture_rid: RID
|
|||
|
||||
|
||||
func _ready() -> void:
|
||||
gate_events.gate_entered.connect(create_external_texture)
|
||||
gate_events.gate_info_loaded.connect(initialize)
|
||||
gate_events.gate_entered.connect(create_external_texture)
|
||||
command_events.send_filehandle.connect(send_filehandle)
|
||||
|
||||
# Change size
|
||||
var image = resize_and_convert(splash_screen.get_image(), Image.FORMAT_RGB8)
|
||||
self.texture = ImageTexture.create_from_image(image)
|
||||
|
||||
func initialize(gate: Gate) -> void:
|
||||
|
||||
func initialize(gate: Gate, is_cached: bool) -> void:
|
||||
rd = RenderingServer.get_rendering_device()
|
||||
|
||||
var image: Image
|
||||
var tex = FileTools.load_external_tex(gate.image)
|
||||
if tex != null:
|
||||
image = tex.get_image()
|
||||
image.resize(width, height)
|
||||
image.convert(Image.FORMAT_RGB8)
|
||||
image.clear_mipmaps()
|
||||
else:
|
||||
image = Image.create(width, height, false, Image.FORMAT_RGB8)
|
||||
if not is_cached: # Show thumbnail image
|
||||
self.texture = create_gate_image(gate)
|
||||
|
||||
self.texture = ImageTexture.create_from_image(image)
|
||||
texture_rid = RenderingServer.texture_get_rd_texture(self.texture.get_rid())
|
||||
if not texture_rid.is_valid(): Debug.logerr("Cannot create ImageTexture")
|
||||
|
||||
|
||||
func create_gate_image(gate: Gate) -> ImageTexture:
|
||||
var tex = FileTools.load_external_tex(gate.image)
|
||||
|
||||
var image: Image
|
||||
if tex != null: image = resize_and_convert(tex.get_image(), Image.FORMAT_RGB8)
|
||||
else: image = Image.create(width, height, false, Image.FORMAT_RGB8)
|
||||
|
||||
return ImageTexture.create_from_image(image)
|
||||
|
||||
|
||||
func create_external_texture() -> void:
|
||||
var t_format: RDTextureFormat = RDTextureFormat.new()
|
||||
t_format.format = RenderingDevice.DATA_FORMAT_R8G8B8A8_UNORM
|
||||
|
@ -47,11 +53,6 @@ func create_external_texture() -> void:
|
|||
t_format.depth = 1
|
||||
var t_view: RDTextureView = RDTextureView.new()
|
||||
|
||||
var image = splash_screen.get_image()
|
||||
image.resize(width, height)
|
||||
image.convert(Image.FORMAT_RGBA8)
|
||||
image.clear_mipmaps()
|
||||
|
||||
# For some reason when switching scene something is not freed
|
||||
# So need to wait to free that up
|
||||
await get_tree().process_frame
|
||||
|
@ -59,11 +60,19 @@ func create_external_texture() -> void:
|
|||
await get_tree().process_frame
|
||||
|
||||
ext_texure = ExternalTexture.new()
|
||||
var image = resize_and_convert(splash_screen.get_image(), Image.FORMAT_RGBA8)
|
||||
var err = ext_texure.create(t_format, t_view, [image.get_data()])
|
||||
if err: Debug.logerr("Cannot create external texture"); return
|
||||
if err: Debug.logerr("Cannot create external texture")
|
||||
else: Debug.logclr("External texture created", Color.AQUAMARINE)
|
||||
|
||||
|
||||
func resize_and_convert(image: Image, format: Image.Format) -> Image:
|
||||
image.resize(width, height)
|
||||
image.convert(format)
|
||||
image.clear_mipmaps()
|
||||
return image
|
||||
|
||||
|
||||
func send_filehandle(filehandle_path: String) -> void:
|
||||
Debug.logr("Sending filehandle...")
|
||||
var sent = false
|
||||
|
@ -76,4 +85,5 @@ func send_filehandle(filehandle_path: String) -> void:
|
|||
func _process(_delta: float) -> void:
|
||||
if ext_texure == null or not ext_texure.get_rid().is_valid(): return
|
||||
if not texture_rid.is_valid(): return
|
||||
|
||||
ext_texure.copy_to(texture_rid)
|
||||
|
|
|
@ -38,7 +38,7 @@ func hide_buttons() -> void:
|
|||
unstar.visible = false
|
||||
|
||||
|
||||
func update_info(_gate: Gate) -> void:
|
||||
func update_info(_gate: Gate, _is_cached: bool) -> void:
|
||||
gate = _gate
|
||||
if bookmarks.gates.has(gate.url):
|
||||
bookmarks.update(gate)
|
||||
|
|
|
@ -14,7 +14,7 @@ func _ready() -> void:
|
|||
gate_events.gate_error.connect(on_gate_error)
|
||||
|
||||
|
||||
func display_info(_gate: Gate) -> void:
|
||||
func display_info(_gate: Gate, _is_cached: bool) -> void:
|
||||
gate = _gate
|
||||
title.text = "Unnamed" if gate.title.is_empty() else gate.title
|
||||
description.text = "No description" if gate.description.is_empty() else gate.description
|
||||
|
|
|
@ -4,7 +4,7 @@ extends Label
|
|||
|
||||
|
||||
func _ready() -> void:
|
||||
gate_events.gate_info_loaded.connect(func(_gate): on_gate_info_loaded())
|
||||
gate_events.gate_info_loaded.connect(func(_gate, _is_cached): on_gate_info_loaded())
|
||||
gate_events.gate_entered.connect(on_gate_entered)
|
||||
gate_events.gate_error.connect(on_gate_error)
|
||||
set_text("Connecting...")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue