diff --git a/scenes/auth/Registration.psd b/scenes/auth/Registration.psd new file mode 100644 index 0000000..79c13ee Binary files /dev/null and b/scenes/auth/Registration.psd differ diff --git a/scripts/autoload/update_manager.gd b/scripts/autoload/update_manager.gd index e6353e5..93fc9a4 100644 --- a/scripts/autoload/update_manager.gd +++ b/scripts/autoload/update_manager.gd @@ -4,7 +4,8 @@ extends Node ## Downloads and caches files from CDN, enabling hot-updates without client redeploy ## Files are stored at: {CDN_BASE_URL}/{cdnPath} ## -## For .tscn scenes: textures are also downloaded and paths are rewritten to use cache +## For web builds: textures are kept in memory only (no disk cache) +## For desktop builds: textures are cached to disk signal update_check_started signal update_progress(downloaded: int, total: int, current_file: String) @@ -30,13 +31,32 @@ var _loaded_scenes: Dictionary = {} # filePath -> PackedScene var _loaded_textures: Dictionary = {} # filePath -> Texture2D var _loaded_scripts: Dictionary = {} # filePath -> GDScript +# Web builds: store raw bytes in memory since disk access is unreliable +var _texture_bytes: Dictionary = {} # filePath -> PackedByteArray +var _is_web: bool = false + func _ready(): - # Ensure cache directory exists - DirAccess.make_dir_recursive_absolute(LOCAL_CACHE_DIR) - _load_local_manifest() + print("[UpdateManager] _ready called!") + print("[UpdateManager] OS.get_name(): %s" % OS.get_name()) + print("[UpdateManager] OS.has_feature('web'): %s" % OS.has_feature("web")) + + # Detect web platform + _is_web = OS.has_feature("web") + + if _is_web: + print("[UpdateManager] Running on WEB - using memory-only cache") + else: + print("[UpdateManager] Running on DESKTOP - using disk cache") + # Ensure cache directory exists (desktop only) + DirAccess.make_dir_recursive_absolute(LOCAL_CACHE_DIR) + _load_local_manifest() + + print("[UpdateManager] _ready complete!") ## Request manifest from server and check for updates func check_for_updates(): + print("[UpdateManager] check_for_updates() called") + if _is_updating: push_warning("[UpdateManager] Already checking for updates") return @@ -44,6 +64,7 @@ func check_for_updates(): update_check_started.emit() if Network and Network.is_socket_connected(): + print("[UpdateManager] Sending ASSET_MANIFEST_REQUEST") Network.send_message(OpCodes.ASSET_MANIFEST_REQUEST, {}) else: push_error("[UpdateManager] Network not connected, cannot check for updates") @@ -51,8 +72,11 @@ func check_for_updates(): ## Called by GameState when manifest response is received func on_manifest_received(data: Dictionary): + print("[UpdateManager] on_manifest_received() called") cdn_base_url = data.get("cdnBaseUrl", cdn_base_url) + print("[UpdateManager] CDN base URL: %s" % cdn_base_url) var assets = data.get("assets", []) + print("[UpdateManager] Received %d assets in manifest" % assets.size()) _manifest.clear() for asset in assets: @@ -156,29 +180,33 @@ func _on_download_completed(result: int, response_code: int, _headers: PackedStr _download_next() return - # Save file to cache - var cache_path = _get_cache_path(item.filePath) + # Verify hash + var actual_hash = _compute_md5(body) + if actual_hash != item.fileHash: + push_error("[UpdateManager] Hash mismatch for %s: expected %s, got %s" % [item.filePath, item.fileHash, actual_hash]) + _download_next() + return - # Ensure subdirectory exists - var dir_path = cache_path.get_base_dir() - DirAccess.make_dir_recursive_absolute(dir_path) + # Store in memory cache (works for both web and desktop) + _texture_bytes[item.filePath] = body + _local_hashes[item.filePath] = item.fileHash - var file = FileAccess.open(cache_path, FileAccess.WRITE) - if file: - file.store_buffer(body) - file.close() + # 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) - # Verify hash - var actual_hash = _compute_md5(body) - if actual_hash == item.fileHash: - _local_hashes[item.filePath] = item.fileHash - _files_downloaded += 1 - file_downloaded.emit(item.filePath) - print("[UpdateManager] Downloaded: %s" % item.filePath) + var file = FileAccess.open(cache_path, FileAccess.WRITE) + if file: + file.store_buffer(body) + file.close() else: - push_error("[UpdateManager] Hash mismatch for %s: expected %s, got %s" % [item.filePath, item.fileHash, actual_hash]) - else: - push_error("[UpdateManager] Failed to save file: %s" % cache_path) + push_warning("[UpdateManager] Failed to save file to disk: %s" % cache_path) + + _files_downloaded += 1 + file_downloaded.emit(item.filePath) + print("[UpdateManager] Downloaded: %s (%d bytes)" % [item.filePath, body.size()]) _download_next() @@ -389,23 +417,36 @@ func _find_file_recursive(dir: DirAccess, current_path: String, filename: String ## Load a texture from cache (for items, UI, etc.) func load_texture(file_path: String) -> Texture2D: - # Check memory cache + # Check already-loaded texture cache if _loaded_textures.has(file_path): return _loaded_textures[file_path] - # Check 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) - return null + var buffer: PackedByteArray - var file = FileAccess.open(cache_path, FileAccess.READ) - if not file: + # Try memory cache first (works for web and desktop) + if _texture_bytes.has(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) + return null + + var file = FileAccess.open(cache_path, FileAccess.READ) + if not file: + push_warning("[UpdateManager] Failed to open cached file: %s" % 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) return null - var buffer = file.get_buffer(file.get_length()) - file.close() - var image = Image.new() var err = image.load_png_from_buffer(buffer) if err != OK: @@ -421,10 +462,18 @@ func load_texture(file_path: String) -> Texture2D: _loaded_textures[file_path] = texture return texture -## Check if a file is in the cache +## Check if a file is in the cache (memory or disk) func has_file(file_path: String) -> bool: - var cache_path = _get_cache_path(file_path) - return FileAccess.file_exists(cache_path) + # Check memory cache first (works for both web and desktop) + if _texture_bytes.has(file_path): + return true + + # For desktop, also check disk cache + if not _is_web: + var cache_path = _get_cache_path(file_path) + return FileAccess.file_exists(cache_path) + + return false ## Get the local cache path for a file func get_cache_path(file_path: String) -> String: diff --git a/scripts/dungeon/mob_visual.gd b/scripts/dungeon/mob_visual.gd index fa66d5c..010858a 100644 --- a/scripts/dungeon/mob_visual.gd +++ b/scripts/dungeon/mob_visual.gd @@ -18,6 +18,8 @@ var _current_state: String = "idle" var _facing_direction: String = "down" # down, up, left, right, front, back func _ready(): + print("[MobVisual] _ready called!") + # Try to find child nodes (they may not exist in all mob scenes) fallback_sprite = get_node_or_null("Sprite2D") name_label = get_node_or_null("NameLabel") @@ -50,6 +52,9 @@ func _ready(): # Connect to UpdateManager for async texture loading if UpdateManager: UpdateManager.file_downloaded.connect(_on_file_downloaded) + print("[MobVisual] Connected to UpdateManager") + else: + print("[MobVisual] WARNING: UpdateManager is null!") func update_data(data: Dictionary): mob_data = data diff --git a/scripts/ui/hud.gd b/scripts/ui/hud.gd index 22bba64..ca10e09 100644 --- a/scripts/ui/hud.gd +++ b/scripts/ui/hud.gd @@ -179,6 +179,11 @@ func _update_hotbar(): if i >= hotbar_slots.size(): break var slot = hotbar_slots[i] + + # Clear existing children (sprites, labels) + for child in slot.get_children(): + child.queue_free() + var hotbar_entry = GameState.hotbar[i] if hotbar_entry and hotbar_entry is Dictionary and hotbar_entry.has("inventory_slot"): @@ -186,7 +191,47 @@ func _update_hotbar(): if inv_slot < GameState.inventory.size(): var item = GameState.inventory[inv_slot] if item and item.get("type") == "Consumable": - slot.text = _get_item_emoji(item) + slot.text = "" + + # Try to load sprite from CDN + var sprite_path = item.get("spritePath", item.get("SpritePath", "")) + var has_sprite = false + + if sprite_path and not sprite_path.is_empty() and UpdateManager: + var texture = UpdateManager.load_texture(sprite_path) + if texture: + var sprite = TextureRect.new() + sprite.texture = texture + sprite.expand_mode = TextureRect.EXPAND_FIT_WIDTH_PROPORTIONAL + sprite.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED + sprite.custom_minimum_size = Vector2(28, 28) + sprite.position = Vector2(6, 6) # Center in slot + + # Apply tint if specified + var tint = item.get("tintColor", item.get("TintColor", "")) + if tint and not tint.is_empty(): + sprite.modulate = Color.from_string(tint, Color.WHITE) + + slot.add_child(sprite) + has_sprite = true + + # Fall back to emoji if no sprite + if not has_sprite: + slot.text = _get_item_emoji(item) + + # Add stack count label + var quantity = item.get("quantity", item.get("Quantity", 1)) + if quantity > 1: + var count_label = Label.new() + count_label.text = str(quantity) + count_label.add_theme_font_size_override("font_size", 9) + count_label.add_theme_color_override("font_color", Color.WHITE) + count_label.add_theme_color_override("font_shadow_color", Color.BLACK) + count_label.add_theme_constant_override("shadow_offset_x", 1) + count_label.add_theme_constant_override("shadow_offset_y", 1) + count_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT + count_label.position = Vector2(slot.custom_minimum_size.x - 18, slot.custom_minimum_size.y - 14) + slot.add_child(count_label) continue slot.text = str(i + 1) diff --git a/scripts/ui/inventory_ui.gd b/scripts/ui/inventory_ui.gd index b06cc49..0b95765 100644 --- a/scripts/ui/inventory_ui.gd +++ b/scripts/ui/inventory_ui.gd @@ -156,14 +156,62 @@ func _refresh_inventory(): _update_slot(equipment_slots[slot_name], item, EQUIPMENT_ICONS.get(slot_name, "?")) func _update_slot(slot: Button, item, default_text: String = ""): + # Clear any existing children (sprites, labels) + for child in slot.get_children(): + child.queue_free() + if item == null or (item is Dictionary and item.is_empty()): slot.text = default_text slot.set_meta("item", null) slot.add_theme_stylebox_override("normal", _create_slot_style(Color(0.15, 0.15, 0.2))) else: - slot.text = _get_item_emoji(item) + slot.text = "" # Clear text, we'll use sprite instead slot.set_meta("item", item) + # Try to load sprite from CDN + var sprite_path = item.get("spritePath", item.get("SpritePath", "")) + var has_sprite = false + + if sprite_path and not sprite_path.is_empty() and UpdateManager: + var texture = UpdateManager.load_texture(sprite_path) + if texture: + var sprite = TextureRect.new() + sprite.texture = texture + sprite.expand_mode = TextureRect.EXPAND_FIT_WIDTH_PROPORTIONAL + sprite.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED + sprite.custom_minimum_size = Vector2(32, 32) + sprite.anchors_preset = Control.PRESET_CENTER + sprite.position = Vector2(8, 8) # Center in 48x48 slot + + # Apply tint if specified + var tint = item.get("tintColor", item.get("TintColor", "")) + if tint and not tint.is_empty(): + sprite.modulate = Color.from_string(tint, Color.WHITE) + + slot.add_child(sprite) + has_sprite = true + + # Fall back to emoji if no sprite + if not has_sprite: + slot.text = _get_item_emoji(item) + + # Add stack count label if quantity > 1 + var quantity = item.get("quantity", item.get("Quantity", 1)) + if quantity > 1: + var count_label = Label.new() + count_label.text = str(quantity) + count_label.add_theme_font_size_override("font_size", 10) + count_label.add_theme_color_override("font_color", Color.WHITE) + count_label.add_theme_color_override("font_shadow_color", Color.BLACK) + count_label.add_theme_constant_override("shadow_offset_x", 1) + count_label.add_theme_constant_override("shadow_offset_y", 1) + count_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT + count_label.vertical_alignment = VERTICAL_ALIGNMENT_BOTTOM + count_label.anchors_preset = Control.PRESET_BOTTOM_RIGHT + count_label.position = Vector2(slot.custom_minimum_size.x - 20, slot.custom_minimum_size.y - 16) + slot.add_child(count_label) + + # Style based on rarity var rarity = item.get("rarity", item.get("Rarity", "Common")) var style = _create_slot_style(Color(0.15, 0.15, 0.2)) style.border_color = RARITY_COLORS.get(rarity, Color.GRAY) @@ -261,8 +309,13 @@ func _show_tooltip(item: Dictionary, slot: Button): var rarity = item.get("rarity", item.get("Rarity", "Common")) var item_name = item.get("name", item.get("Name", "Unknown")) var item_type = item.get("type", item.get("Type", "")) + var quantity = item.get("quantity", item.get("Quantity", 1)) - name_label.text = item_name + # Show quantity in name if > 1 + if quantity > 1: + name_label.text = "%s (x%d)" % [item_name, quantity] + else: + name_label.text = item_name name_label.modulate = RARITY_COLORS.get(rarity, Color.WHITE) if type_label: diff --git a/scripts/ui/main.gd b/scripts/ui/main.gd index ff508cb..ea5fa90 100644 --- a/scripts/ui/main.gd +++ b/scripts/ui/main.gd @@ -29,9 +29,11 @@ func _show_screen(state: String): if auth_screen: _set_screen_visible(auth_screen, state == "AUTH") print("[Main] AuthScreen visible: ", state == "AUTH") - if not Network.is_socket_connected(): + if state == "AUTH" and not Network.is_socket_connected(): + print("[Main] Connecting to server...") Network.connect_to_server() await Network.connected + print("[Main] Connected! Calling check_for_updates...") UpdateManager.check_for_updates() if hub_screen: _set_screen_visible(hub_screen, state == "HUB")