Browser seems good to go!
This commit is contained in:
@@ -53,6 +53,8 @@ var attack_cooldown: float = 0.5 # Default attack cooldown in seconds
|
||||
var _last_move_sent_time_ms: int = 0
|
||||
var _last_move_vec: Vector2 = Vector2.ZERO
|
||||
var _last_aim_sent: float = 0.0
|
||||
var _prefetched_mob_paths: Dictionary = {}
|
||||
var _mob_prefetch_in_progress: bool = false
|
||||
|
||||
func _ready():
|
||||
# Add to group for HUD to access
|
||||
@@ -474,6 +476,7 @@ func _on_state_updated():
|
||||
if player_scene and players_container:
|
||||
_update_entities(players_container, GameState.players, player_scene)
|
||||
if mob_scene and mobs_container:
|
||||
await _prefetch_mob_textures_if_needed()
|
||||
_update_entities(mobs_container, GameState.mobs, mob_scene)
|
||||
if chest_scene and chests_container:
|
||||
_update_entities(chests_container, GameState.chests, chest_scene)
|
||||
@@ -484,6 +487,61 @@ func _on_state_updated():
|
||||
if loot_chest_scene and loot_chests_container:
|
||||
_update_loot_chests()
|
||||
|
||||
func _collect_mob_sprite_paths(mobs: Dictionary) -> Array:
|
||||
var paths: Array = []
|
||||
for id in mobs:
|
||||
var mob_data = mobs[id]
|
||||
var sprite_config = mob_data.get("spriteConfig", mob_data.get("SpriteConfig", null))
|
||||
if sprite_config == null or not (sprite_config is Dictionary):
|
||||
continue
|
||||
|
||||
# New format (sheets)
|
||||
if sprite_config.has("sheets"):
|
||||
var sheets = sprite_config.get("sheets", {})
|
||||
for sheet_key in sheets:
|
||||
var sheet_info = sheets[sheet_key]
|
||||
var path = sheet_info.get("path", "")
|
||||
if path != "" and not paths.has(path):
|
||||
paths.append(path)
|
||||
continue
|
||||
|
||||
# Legacy format (sprites)
|
||||
var sprites = sprite_config.get("sprites", {})
|
||||
for anim_name in sprites:
|
||||
var sprite_path = sprites[anim_name]
|
||||
if sprite_path != "" and not paths.has(sprite_path):
|
||||
paths.append(sprite_path)
|
||||
|
||||
return paths
|
||||
|
||||
func _prefetch_mob_textures_if_needed() -> void:
|
||||
if not UpdateManager or not UpdateManager._is_web:
|
||||
return
|
||||
if _mob_prefetch_in_progress:
|
||||
return
|
||||
|
||||
var paths = _collect_mob_sprite_paths(GameState.mobs)
|
||||
if paths.is_empty():
|
||||
return
|
||||
|
||||
var missing: Array = []
|
||||
for path in paths:
|
||||
if _prefetched_mob_paths.has(path):
|
||||
continue
|
||||
if UpdateManager.has_file(path):
|
||||
_prefetched_mob_paths[path] = true
|
||||
continue
|
||||
missing.append(path)
|
||||
|
||||
if missing.is_empty():
|
||||
return
|
||||
|
||||
_mob_prefetch_in_progress = true
|
||||
await UpdateManager.prefetch_files(missing)
|
||||
for path in missing:
|
||||
_prefetched_mob_paths[path] = true
|
||||
_mob_prefetch_in_progress = false
|
||||
|
||||
func _update_entities(container: Node2D, data: Dictionary, scene: PackedScene):
|
||||
if scene == null or container == null:
|
||||
return
|
||||
|
||||
@@ -104,7 +104,10 @@ func update_data(data: Dictionary):
|
||||
if sprite_config != null and sprite_config is Dictionary and not sprite_config.is_empty():
|
||||
if sprite_config != _sprite_config:
|
||||
_sprite_config = sprite_config
|
||||
_build_animated_sprite()
|
||||
if UpdateManager and UpdateManager.has_method("queue_build"):
|
||||
UpdateManager.queue_build(Callable(self, "_build_animated_sprite"))
|
||||
else:
|
||||
_build_animated_sprite()
|
||||
else:
|
||||
_setup_fallback(data)
|
||||
|
||||
@@ -350,14 +353,20 @@ func _on_file_downloaded(file_path: String):
|
||||
for sheet_key in sheets:
|
||||
var sheet_info = sheets[sheet_key]
|
||||
if sheet_info.get("path", "") == file_path:
|
||||
_build_animated_sprite()
|
||||
if UpdateManager and UpdateManager.has_method("queue_build"):
|
||||
UpdateManager.queue_build(Callable(self, "_build_animated_sprite"))
|
||||
else:
|
||||
_build_animated_sprite()
|
||||
return
|
||||
|
||||
# Check legacy format sprites
|
||||
var sprites = _sprite_config.get("sprites", {})
|
||||
for anim_name in sprites:
|
||||
if sprites[anim_name] == file_path:
|
||||
_build_animated_sprite()
|
||||
if UpdateManager and UpdateManager.has_method("queue_build"):
|
||||
UpdateManager.queue_build(Callable(self, "_build_animated_sprite"))
|
||||
else:
|
||||
_build_animated_sprite()
|
||||
return
|
||||
|
||||
func _setup_fallback(data: Dictionary):
|
||||
|
||||
Reference in New Issue
Block a user