Mob looting fix and dungeon closure.

This commit is contained in:
dingo
2026-01-25 18:04:47 -05:00
parent 85c95e9f6a
commit c1a97b219e
8 changed files with 157 additions and 65 deletions
+21 -14
View File
@@ -190,21 +190,23 @@ func _on_download_completed(result: int, response_code: int, _headers: PackedStr
# Store in memory cache (works for both web and desktop)
_texture_bytes[item.filePath] = body
_local_hashes[item.filePath] = item.fileHash
print("[UpdateManager] Stored in _texture_bytes: %s (%d bytes)" % [item.filePath, body.size()])
# For desktop, also save to disk for persistence
if not _is_web:
var cache_path = _get_cache_path(item.filePath)
var dir_path = cache_path.get_base_dir()
DirAccess.make_dir_recursive_absolute(dir_path)
var file = FileAccess.open(cache_path, FileAccess.WRITE)
if file:
file.store_buffer(body)
file.close()
else:
push_warning("[UpdateManager] Failed to save file to disk: %s" % cache_path)
_files_downloaded += 1
print("[UpdateManager] Emitting file_downloaded signal for: %s" % item.filePath)
file_downloaded.emit(item.filePath)
print("[UpdateManager] Downloaded: %s (%d bytes)" % [item.filePath, body.size()])
@@ -419,32 +421,36 @@ func _find_file_recursive(dir: DirAccess, current_path: String, filename: String
func load_texture(file_path: String) -> Texture2D:
# Check already-loaded texture cache
if _loaded_textures.has(file_path):
print("[UpdateManager] load_texture(%s) - Found in _loaded_textures cache" % file_path)
return _loaded_textures[file_path]
var buffer: PackedByteArray
# Try memory cache first (works for web and desktop)
if _texture_bytes.has(file_path):
print("[UpdateManager] load_texture(%s) - Found in _texture_bytes, creating texture..." % file_path)
buffer = _texture_bytes[file_path]
elif not _is_web:
# Desktop: try disk cache
var cache_path = _get_cache_path(file_path)
if not FileAccess.file_exists(cache_path):
push_warning("[UpdateManager] Texture not in cache: %s" % file_path)
print("[UpdateManager] load_texture(%s) - Not in disk cache" % file_path)
return null
var file = FileAccess.open(cache_path, FileAccess.READ)
if not file:
push_warning("[UpdateManager] Failed to open cached file: %s" % file_path)
print("[UpdateManager] load_texture(%s) - Failed to open cached file" % file_path)
return null
buffer = file.get_buffer(file.get_length())
file.close()
# Store in memory cache for faster subsequent access
_texture_bytes[file_path] = buffer
else:
push_warning("[UpdateManager] Texture not in memory cache (web): %s" % file_path)
# Texture not in cache - this is normal for optional textures on web
# The calling code should handle null gracefully
print("[UpdateManager] load_texture(%s) - Not in memory cache (web build)" % file_path)
return null
var image = Image.new()
@@ -453,11 +459,12 @@ func load_texture(file_path: String) -> Texture2D:
err = image.load_jpg_from_buffer(buffer)
if err != OK:
err = image.load_webp_from_buffer(buffer)
if err != OK:
push_error("[UpdateManager] Failed to load image: %s" % file_path)
push_error("[UpdateManager] Failed to load image from buffer: %s (buffer size: %d bytes)" % [file_path, buffer.size()])
return null
print("[UpdateManager] load_texture(%s) - Successfully created texture from buffer" % file_path)
var texture = ImageTexture.create_from_image(image)
_loaded_textures[file_path] = texture
return texture