Add skybox system: admin management + client 3D application

- SkyboxDefinition entity (catalog schema) with static/animated support
- EF migration: catalog.skybox_definitions table
- content.get_skybox_config handler returns active skybox definition
- SkyboxManagerPage.razor: full CRUD admin UI with inline editing,
  activate/deactivate, and animated frame config
- NavMenu.razor: Skyboxes link under Content section
- game_screen.gd: fetches active skybox on ready; applies as
  PanoramaSkyMaterial on WorldEnvironment; animated skyboxes cycle
  frames via Timer; procedural sky kept as fallback when none active

Also fixes inverted camera pan (delta.x / -delta.y signs corrected).

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-03-21 08:55:45 -04:00
co-authored by Claude Happy
parent 7c0b0f1953
commit 5b66f459c0
11 changed files with 1173 additions and 6 deletions
+114 -5
View File
@@ -157,6 +157,12 @@ var _unit_bodies : Dictionary = {} # instanceId → StaticBody3D
var _anim_players : Dictionary = {} # instanceId → AnimationPlayer (null if none)
var _unit_def_ids : Dictionary = {} # instanceId → card definition ID string
# ── Skybox state ───────────────────────────────────────────────────────────────
var _skybox_sky : Sky = null # the Sky object created in _setup_environment
var _skybox_frames : Array = [] # Array[ImageTexture] for animated skybox frames
var _skybox_frame_idx : int = 0
var _skybox_timer : Timer = null
# ── Animation / facing state ───────────────────────────────────────────────────
var _local_is_p1 : bool = false # true when Auth.user_id == playerOneAccountId
var _prev_unit_hp : Dictionary = {} # instanceId → int, HP snapshot for damage detection
@@ -294,18 +300,121 @@ func _setup_spectator_ui() -> void:
func _setup_environment() -> void:
var env := Environment.new()
var sky := Sky.new()
_skybox_sky = Sky.new()
var proc := ProceduralSkyMaterial.new()
proc.sky_top_color = Color(0.08, 0.10, 0.20)
proc.sky_horizon_color = Color(0.28, 0.38, 0.55)
proc.ground_bottom_color = Color(0.373, 0.374, 0.484, 1.0)
proc.ground_horizon_color = Color(0.20, 0.28, 0.38)
sky.sky_material = proc
_skybox_sky.sky_material = proc
env.background_mode = Environment.BG_SKY
env.sky = sky
env.sky = _skybox_sky
env.ambient_light_source = Environment.AMBIENT_SOURCE_SKY
env.ambient_light_energy = 0.6
$WorldEnvironment.environment = env
_fetch_skybox()
func _fetch_skybox() -> void:
Network.request("content.get_skybox_config", {},
func(_type: String, resp: Variant) -> void:
var d := resp as Dictionary
var skybox := d.get("skybox", null)
if skybox == null:
return # no active skybox — keep procedural sky
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():
return
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 _load_static_skybox(url: String) -> void:
var http := HTTPRequest.new()
add_child(http)
http.request_completed.connect(
func(_result: int, code: int, _headers: PackedStringArray, data: PackedByteArray) -> void:
http.queue_free()
if code < 200 or code >= 300 or data.is_empty():
push_warning("[GameScreen] Failed to download skybox: HTTP %d" % code)
return
var img := Image.new()
var ext := url.get_extension().to_lower()
var err : int
if ext in ["jpg", "jpeg"]:
err = img.load_jpg_from_buffer(data)
elif ext == "webp":
err = img.load_webp_from_buffer(data)
else:
err = img.load_png_from_buffer(data)
if err != OK:
push_warning("[GameScreen] Failed to decode skybox image")
return
var tex := ImageTexture.create_from_image(img)
var mat := PanoramaSkyMaterial.new()
mat.panorama = tex
if is_instance_valid(_skybox_sky):
_skybox_sky.sky_material = mat)
http.request(url)
func _load_animated_skybox(base_url: String, frame_count: int, fps: float) -> void:
_skybox_frames.clear()
_skybox_frame_idx = 0
var loaded : int = 0
var frames_arr: Array = []
frames_arr.resize(frame_count)
for i in frame_count:
var url := "%s/%d.png" % [base_url, i]
var http := HTTPRequest.new()
var frame_idx := i
add_child(http)
http.request_completed.connect(
func(_result: int, code: int, _headers: PackedStringArray, data: PackedByteArray) -> void:
http.queue_free()
loaded += 1
if code >= 200 and code < 300 and not data.is_empty():
var img := Image.new()
if img.load_png_from_buffer(data) == OK:
frames_arr[frame_idx] = ImageTexture.create_from_image(img)
if loaded == frame_count:
_skybox_frames = frames_arr.filter(func(f: Variant) -> bool: return f != null)
if not _skybox_frames.is_empty():
_start_skybox_animation(fps))
http.request(url)
func _start_skybox_animation(fps: float) -> void:
_apply_skybox_frame(0)
if _skybox_frames.size() <= 1:
return
if _skybox_timer != null:
_skybox_timer.queue_free()
_skybox_timer = Timer.new()
_skybox_timer.wait_time = 1.0 / maxf(fps, 1.0)
_skybox_timer.autostart = true
_skybox_timer.timeout.connect(_on_skybox_frame_tick)
add_child(_skybox_timer)
func _apply_skybox_frame(idx: int) -> void:
if _skybox_frames.is_empty() or not is_instance_valid(_skybox_sky):
return
var tex : ImageTexture = _skybox_frames[idx % _skybox_frames.size()]
if tex == null:
return
var mat := _skybox_sky.sky_material
if not (mat is PanoramaSkyMaterial):
mat = PanoramaSkyMaterial.new()
_skybox_sky.sky_material = mat
(mat as PanoramaSkyMaterial).panorama = tex
func _on_skybox_frame_tick() -> void:
_skybox_frame_idx = (_skybox_frame_idx + 1) % _skybox_frames.size()
_apply_skybox_frame(_skybox_frame_idx)
# ── Camera ────────────────────────────────────────────────────────────────────
@@ -375,10 +484,10 @@ func _unhandled_input(event: InputEvent) -> void:
_apply_camera()
if _pan_active:
var ps := _cam_distance * 0.0015
var right := _camera_rig.global_basis.x * -delta.x * ps
var right := _camera_rig.global_basis.x * delta.x * ps
var fwd := Vector3(_camera_rig.global_basis.z.x, 0,
_camera_rig.global_basis.z.z).normalized()
_cam_pivot += right + fwd * delta.y * ps
_cam_pivot += right + fwd * -delta.y * ps
_cam_pivot.x = clampf(_cam_pivot.x, -6.0, 6.0)
_cam_pivot.z = clampf(_cam_pivot.z, -6.0, 6.0)
_apply_camera()