diff --git a/Client/origin-client/autoloads/ContentCache.gd b/Client/origin-client/autoloads/ContentCache.gd index 939e3fe..2036462 100644 --- a/Client/origin-client/autoloads/ContentCache.gd +++ b/Client/origin-client/autoloads/ContentCache.gd @@ -21,6 +21,7 @@ const CACHE_DIR := "user://content" const CACHE_PATH := "user://content/defs.json" const TILE_MODELS_PATH := "user://content/tile_models.json" const TILE_BOTTOMS_PATH := "user://content/tile_bottoms.json" +const SKYBOXES_PATH := "user://content/skyboxes.json" const PAGE_SIZE := 200 const REFRESH_INTERVAL_SECS := 300.0 # re-sync every 5 minutes during live play @@ -42,12 +43,16 @@ var _tile_textures: Dictionary = {} ## Array of CDN URL strings for tile bottom (stalagmite) models. var _tile_bottom_urls: Array = [] +## Array of Dictionary (SkyboxDefinitionDto) for all active skyboxes. +var _skyboxes: Array = [] + # ── Lifecycle ───────────────────────────────────────────────────────────────── func _ready() -> void: _load_from_disk() _load_tile_models_from_disk() _load_tile_bottoms_from_disk() + _load_skyboxes_from_disk() # ── Public API ──────────────────────────────────────────────────────────────── @@ -91,6 +96,7 @@ func start_sync() -> void: _fetch_page(_sync_version) fetch_tile_models() fetch_tile_bottoms() + fetch_skyboxes() ## Return the GLB animation track name for a card action. @@ -141,6 +147,87 @@ func fetch_tile_bottoms() -> void: ) +## Fetch active skybox definitions from the server and update the local cache. +func fetch_skyboxes() -> void: + Network.request( + "content.get_skybox_config", + {}, + func(_type: String, p: Variant): _on_skyboxes(p), + func(code: String, msg: String): + push_warning("ContentCache: skyboxes fetch failed — %s %s" % [code, msg]) + ) + + +## Returns a random active skybox Dictionary, or {} if none are cached. +func get_random_skybox() -> Dictionary: + if _skyboxes.is_empty(): + return {} + return _skyboxes[randi() % _skyboxes.size()] as Dictionary + + +## Returns the best URL to use as a flat 2D background from this skybox dict. +## For Cubemap: returns the +Z (Front) face URL. +## For Panoramic/AnimatedPanorama: returns the cdnPath. +func get_skybox_bg_url(skybox: Dictionary) -> String: + var sky_type := str(skybox.get("type", "Panoramic")) + if sky_type == "Cubemap": + return str(skybox.get("cubePzUrl", "")) + return str(skybox.get("cdnPath", "")) + + +## Downloads an image from url and calls callback(Texture2D). +## Adds a temporary HTTPRequest child; frees itself on completion. +func load_texture_async(url: String, callback: Callable) -> void: + var http := HTTPRequest.new() + add_child(http) + http.request_completed.connect(func(result: int, code: int, _hdrs: PackedStringArray, body: PackedByteArray): + http.queue_free() + if result != HTTPRequest.RESULT_SUCCESS or code != 200: + callback.call(null) + return + var img := Image.new() + var ext := url.split("?")[0].get_extension().to_lower() + var err: Error + if ext in ["jpg", "jpeg"]: + err = img.load_jpg_from_buffer(body) + elif ext == "webp": + err = img.load_webp_from_buffer(body) + else: + err = img.load_png_from_buffer(body) + if err != OK: + callback.call(null) + return + callback.call(ImageTexture.create_from_image(img))) + http.request(url) + + +## Hides the first direct-child ColorRect of `parent` and injects a full-rect +## TextureRect (from a random active skybox) as the new first child. +## Call from _ready() in any 2D scene that has a solid-color background. +func apply_scene_background(parent: Control) -> void: + var skybox := get_random_skybox() + if skybox.is_empty(): + return + var url := get_skybox_bg_url(skybox) + if url.is_empty(): + return + load_texture_async(url, func(tex: Texture2D): + if not is_instance_valid(parent) or tex == null: + return + for child in parent.get_children(): + if child is ColorRect: + child.visible = false + break + var tr := TextureRect.new() + tr.texture = tex + tr.expand_mode = TextureRect.EXPAND_IGNORE_SIZE + tr.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_COVERED + tr.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) + tr.mouse_filter = Control.MOUSE_FILTER_IGNORE + parent.add_child(tr) + parent.move_child(tr, 0)) + + ## Fetch tile model bindings from the server and update the local cache. ## Emits tile_models_ready when done (even on error, using cached data). func fetch_tile_models() -> void: @@ -226,6 +313,15 @@ func _on_tile_bottoms(payload: Variant) -> void: _tile_bottom_urls.append(u as String) _save_tile_bottoms_to_disk() + +func _on_skyboxes(payload: Variant) -> void: + var p := payload as Dictionary + _skyboxes.clear() + for item in p.get("skyboxes", []): + if typeof(item) == TYPE_DICTIONARY: + _skyboxes.append(item as Dictionary) + _save_skyboxes_to_disk() + # ── Persistence ─────────────────────────────────────────────────────────────── func _load_from_disk() -> void: @@ -298,3 +394,24 @@ func _save_tile_bottoms_to_disk() -> void: return file.store_string(JSON.stringify(_tile_bottom_urls)) file.close() + + +func _load_skyboxes_from_disk() -> void: + if not FileAccess.file_exists(SKYBOXES_PATH): + return + var file := FileAccess.open(SKYBOXES_PATH, FileAccess.READ) + if not file: + return + var parsed: Variant = JSON.parse_string(file.get_as_text()) + file.close() + if typeof(parsed) == TYPE_ARRAY: + _skyboxes = parsed as Array + + +func _save_skyboxes_to_disk() -> void: + DirAccess.make_dir_recursive_absolute(CACHE_DIR) + var file := FileAccess.open(SKYBOXES_PATH, FileAccess.WRITE) + if not file: + return + file.store_string(JSON.stringify(_skyboxes)) + file.close() diff --git a/Client/origin-client/scenes/account/account_screen.gd b/Client/origin-client/scenes/account/account_screen.gd index a27202f..97ded96 100644 --- a/Client/origin-client/scenes/account/account_screen.gd +++ b/Client/origin-client/scenes/account/account_screen.gd @@ -14,6 +14,7 @@ const NOTIF_ROW = preload("res://scenes/account/components/NotificationRow.tscn" # ── Lifecycle ───────────────────────────────────────────────────────────────── func _ready() -> void: + ContentCache.apply_scene_background(self) back_btn.pressed.connect(_on_back) _load_profile() _load_notifications() @@ -207,7 +208,7 @@ func _show_notification_dialog(notification: Dictionary, focus_reply: bool) -> v func _extract_bug_report_payload(notification: Dictionary) -> Dictionary: - var payload_raw := notification.get("payloadJson", null) + var payload_raw : String = notification.get("payloadJson", null) if payload_raw == null: return {} @@ -215,7 +216,7 @@ func _extract_bug_report_payload(notification: Dictionary) -> Dictionary: if payload_text.is_empty(): return {} - var parsed := JSON.parse_string(payload_text) + var parsed : Variant = JSON.parse_string(payload_text) if typeof(parsed) == TYPE_DICTIONARY: return parsed as Dictionary return {} diff --git a/Client/origin-client/scenes/bazaar/bazaar_screen.gd b/Client/origin-client/scenes/bazaar/bazaar_screen.gd index 63e0da9..7473af6 100644 --- a/Client/origin-client/scenes/bazaar/bazaar_screen.gd +++ b/Client/origin-client/scenes/bazaar/bazaar_screen.gd @@ -65,6 +65,7 @@ var _type_filter : String = "" # ── Lifecycle ───────────────────────────────────────────────────────────────── func _ready() -> void: + ContentCache.apply_scene_background(self) back_btn.pressed.connect(_on_back) boosters_tab_btn.pressed.connect(func(): _switch_tab(Tab.BOOSTERS)) decks_tab_btn.pressed.connect(func(): _switch_tab(Tab.DECKS)) diff --git a/Client/origin-client/scenes/collection/collection_screen.gd b/Client/origin-client/scenes/collection/collection_screen.gd index f85cb2d..d54f37e 100644 --- a/Client/origin-client/scenes/collection/collection_screen.gd +++ b/Client/origin-client/scenes/collection/collection_screen.gd @@ -22,6 +22,7 @@ var _card_popup: Control = null # ── Lifecycle ───────────────────────────────────────────────────────────────── func _ready() -> void: + ContentCache.apply_scene_background(self) back_btn.pressed.connect(_on_back) cards_tab_btn.pressed.connect(func(): _show_tab(0)) decks_tab_btn.pressed.connect(func(): _show_tab(1)) diff --git a/Client/origin-client/scenes/free_play/free_play_screen.gd b/Client/origin-client/scenes/free_play/free_play_screen.gd index 50b8989..00338af 100644 --- a/Client/origin-client/scenes/free_play/free_play_screen.gd +++ b/Client/origin-client/scenes/free_play/free_play_screen.gd @@ -36,6 +36,7 @@ var _deck_btn_group : ButtonGroup = null # ── Lifecycle ───────────────────────────────────────────────────────────────── func _ready() -> void: + ContentCache.apply_scene_background(self) Chat.set_bubble_visible(true) _setup_ui() _load_decks() # load decks first; lobbies load after decks arrive diff --git a/Client/origin-client/scenes/free_play/lobby_room_screen.gd b/Client/origin-client/scenes/free_play/lobby_room_screen.gd index ac8249b..deb7ca2 100644 --- a/Client/origin-client/scenes/free_play/lobby_room_screen.gd +++ b/Client/origin-client/scenes/free_play/lobby_room_screen.gd @@ -49,6 +49,7 @@ var _current_rules : Dictionary = {} # ── Lifecycle ───────────────────────────────────────────────────────────────── func _ready() -> void: + ContentCache.apply_scene_background(self) _setup_ui() _connect_signals() _refresh_display() @@ -139,7 +140,7 @@ func _refresh_display() -> void: lobby_title_label.text = "LOBBY: %s" % lobby_name # Host slot - host_name_label.text = "Host: %s" % str(lobby.get("hostDisplayName", Auth.user_id)) + host_name_label.text = "Host: %s" % str(lobby.get("hostDisplayName", Auth.display_name)) host_deck_label.text = "Deck: (selected)" # Guest slot diff --git a/Client/origin-client/scenes/game/game_screen.gd b/Client/origin-client/scenes/game/game_screen.gd index 1139828..06113db 100644 --- a/Client/origin-client/scenes/game/game_screen.gd +++ b/Client/origin-client/scenes/game/game_screen.gd @@ -340,7 +340,7 @@ func _setup_environment() -> void: _setup_live_skybox(env) "cdn": _setup_procedural_sky(env) - _fetch_skybox() + _apply_skybox_from_cache() _: # "off" or any unknown value _setup_procedural_sky(env) @@ -410,7 +410,7 @@ func _on_skybox_setting_changed() -> void: _setup_live_skybox(env) "cdn": _setup_procedural_sky() - _fetch_skybox() + _apply_skybox_from_cache() _: _setup_procedural_sky() @@ -517,30 +517,79 @@ func _clear_stars() -> void: # ── CDN skybox helpers ───────────────────────────────────────────────────────── -func _fetch_skybox() -> void: - Network.request("content.get_skybox_config", {}, - func(_type: String, resp: Variant) -> void: - var d := resp as Dictionary - # Use a Variant to safely detect null before treating as Dictionary. - var skybox_raw : Variant = d.get("skybox", null) - if skybox_raw == null or not skybox_raw is Dictionary: - print("[GameScreen] No active skybox configured — keeping procedural sky.") - return - var skybox := skybox_raw as Dictionary - var cdn_path : String = str(skybox.get("cdnPath", "")) - var is_animated : bool = bool(skybox.get("isAnimated", false)) - var frame_count : int = int(skybox.get("frameCount", 1)) - var fps : float = float(skybox.get("fps", 24.0)) - if cdn_path.is_empty(): - push_warning("[GameScreen] Skybox has empty cdnPath — skipping.") - return - print("[GameScreen] Loading CDN skybox: animated=%s url=%s" % [is_animated, cdn_path]) - if is_animated: - _load_animated_skybox(cdn_path, frame_count, fps) - else: - _load_static_skybox(cdn_path), - func(code: String, msg: String) -> void: - push_warning("[GameScreen] Skybox fetch failed — %s: %s" % [code, msg])) +func _apply_skybox_from_cache() -> void: + var skybox := ContentCache.get_random_skybox() + if skybox.is_empty(): + print("[GameScreen] No active skybox — keeping procedural sky.") + return + var sky_type := str(skybox.get("type", "Panoramic")) + print("[GameScreen] Applying skybox type=%s" % sky_type) + if sky_type == "Cubemap": + _load_cubemap_skybox(skybox) + elif bool(skybox.get("isAnimated", false)) or sky_type == "AnimatedPanorama": + _load_animated_skybox( + str(skybox.get("cdnPath", "")), + int(skybox.get("frameCount", 1)), + float(skybox.get("fps", 24.0))) + else: + _load_static_skybox(str(skybox.get("cdnPath", ""))) + +func _load_cubemap_skybox(skybox: Dictionary) -> void: + # Face order for Godot 4 Cubemap.create_from_images(): + # index 0=+X(Right) 1=-X(Left) 2=+Y(Top) 3=-Y(Bottom) 4=+Z(Front) 5=-Z(Back) + var urls := [ + str(skybox.get("cubePxUrl", "")), + str(skybox.get("cubeNxUrl", "")), + str(skybox.get("cubePyUrl", "")), + str(skybox.get("cubeNyUrl", "")), + str(skybox.get("cubePzUrl", "")), + str(skybox.get("cubeNzUrl", "")), + ] + var images: Array = [] + images.resize(6) + var pending := 6 + for i in 6: + var idx := i + var url := urls[idx] + if url.is_empty(): + images[idx] = null + pending -= 1 + if pending == 0: + _apply_cubemap_images(images) + continue + ContentCache.load_texture_async(url, func(tex: Texture2D): + images[idx] = tex.get_image() if tex != null else null + pending -= 1 + if pending == 0: + _apply_cubemap_images.call_deferred(images)) + +func _apply_cubemap_images(images: Array) -> void: + for i in 6: + if images[i] == null: + var img := Image.create(1, 1, false, Image.FORMAT_RGB8) + img.fill(Color.BLACK) + images[i] = img + else: + (images[i] as Image).convert(Image.FORMAT_RGB8) + var cubemap := Cubemap.new() + cubemap.create_from_images(images) + _apply_cubemap_material(cubemap) + +func _apply_cubemap_material(cubemap: Cubemap) -> void: + var shader := Shader.new() + shader.code = """ +shader_type sky; +uniform samplerCube environment : filter_linear, repeat_disable; +void sky() { COLOR = texture(environment, EYEDIR).rgb; } +""" + var mat := ShaderMaterial.new() + mat.shader = shader + mat.set_shader_parameter("environment", cubemap) + var sky := Sky.new() + sky.sky_material = mat + $WorldEnvironment.environment.sky = sky + $WorldEnvironment.environment.background_mode = Environment.BG_SKY + print("[GameScreen] Cubemap sky applied.") func _load_static_skybox(url: String) -> void: var http := HTTPRequest.new() diff --git a/Client/origin-client/scenes/init/init_screen.gd b/Client/origin-client/scenes/init/init_screen.gd index 2e4e110..eeb4cb7 100644 --- a/Client/origin-client/scenes/init/init_screen.gd +++ b/Client/origin-client/scenes/init/init_screen.gd @@ -33,6 +33,7 @@ var _pulse_tween : Tween = null # ── Lifecycle ───────────────────────────────────────────────────────────────── func _ready() -> void: + ContentCache.apply_scene_background(self) update_panel.visible = false retry_btn.visible = false progress_bar.value = 0.0 diff --git a/Client/origin-client/scenes/leaderboard/leaderboard_screen.gd b/Client/origin-client/scenes/leaderboard/leaderboard_screen.gd index 6e77695..a60c1c5 100644 --- a/Client/origin-client/scenes/leaderboard/leaderboard_screen.gd +++ b/Client/origin-client/scenes/leaderboard/leaderboard_screen.gd @@ -19,6 +19,7 @@ var _page_count : int = 1 # ── Lifecycle ───────────────────────────────────────────────────────────────── func _ready() -> void: + ContentCache.apply_scene_background(self) back_btn.pressed.connect(_on_back) prev_btn.pressed.connect(func(): _go_page(_page - 1)) next_btn.pressed.connect(func(): _go_page(_page + 1)) diff --git a/Client/origin-client/scenes/login/login_screen.gd b/Client/origin-client/scenes/login/login_screen.gd index cca396b..47e7227 100644 --- a/Client/origin-client/scenes/login/login_screen.gd +++ b/Client/origin-client/scenes/login/login_screen.gd @@ -42,6 +42,7 @@ var _pending_pass := "" # ── Lifecycle ───────────────────────────────────────────────────────────────── func _ready() -> void: + ContentCache.apply_scene_background(self) # If already authenticated (e.g. scene reloaded), skip straight to main. # Use call_deferred so the scene tree is not modified while _ready() is running. if not Auth.user_id.is_empty(): diff --git a/Client/origin-client/scenes/main/main_screen.gd b/Client/origin-client/scenes/main/main_screen.gd index e9a1604..8b53836 100644 --- a/Client/origin-client/scenes/main/main_screen.gd +++ b/Client/origin-client/scenes/main/main_screen.gd @@ -20,6 +20,7 @@ extends Control # ── Lifecycle ───────────────────────────────────────────────────────────────── func _ready() -> void: + ContentCache.apply_scene_background(self) welcome_label.text = "Welcome, %s!" % Auth.display_name Chat.set_bubble_visible(true) diff --git a/Client/origin-client/scenes/matchmaking/matchmaking_screen.gd b/Client/origin-client/scenes/matchmaking/matchmaking_screen.gd index 334948d..3e15c8c 100644 --- a/Client/origin-client/scenes/matchmaking/matchmaking_screen.gd +++ b/Client/origin-client/scenes/matchmaking/matchmaking_screen.gd @@ -25,6 +25,7 @@ var _searching : bool = false # ── Lifecycle ───────────────────────────────────────────────────────────────── func _ready() -> void: + ContentCache.apply_scene_background(self) cancel_btn.pressed.connect(_on_cancel) Game.match_found.connect(_on_match_found) _show_deck_panel() diff --git a/Client/origin-client/scenes/settings/settings_screen.gd b/Client/origin-client/scenes/settings/settings_screen.gd index 27d9a73..9ccd3b6 100644 --- a/Client/origin-client/scenes/settings/settings_screen.gd +++ b/Client/origin-client/scenes/settings/settings_screen.gd @@ -15,6 +15,7 @@ const _HI_LABELS: Array = ["Movement", "Attack", "Ability", "Terramorpha", "Sele # ── Lifecycle ───────────────────────────────────────────────────────────────── func _ready() -> void: + ContentCache.apply_scene_background(self) # Populate controls from current settings (no signal spam). music_slider.set_value_no_signal(Settings.music_volume) music_mute_btn.set_pressed_no_signal(Settings.music_muted) diff --git a/Client/origin-client/scenes/starter_deck/starter_deck_screen.gd b/Client/origin-client/scenes/starter_deck/starter_deck_screen.gd index 4b685a4..90edf0c 100644 --- a/Client/origin-client/scenes/starter_deck/starter_deck_screen.gd +++ b/Client/origin-client/scenes/starter_deck/starter_deck_screen.gd @@ -23,6 +23,7 @@ var _confirming: bool = false # ── Lifecycle ───────────────────────────────────────────────────────────────── func _ready() -> void: + ContentCache.apply_scene_background(self) confirm_btn.disabled = true confirm_btn.pressed.connect(_on_confirm_pressed) _fetch_decks() diff --git a/Server/src/SOR.Admin/Components/Pages/Content/SkyboxManagerPage.razor b/Server/src/SOR.Admin/Components/Pages/Content/SkyboxManagerPage.razor index 8fe31f2..674a4e1 100644 --- a/Server/src/SOR.Admin/Components/Pages/Content/SkyboxManagerPage.razor +++ b/Server/src/SOR.Admin/Components/Pages/Content/SkyboxManagerPage.razor @@ -12,7 +12,17 @@