Feature: tile height variation + stalagmite bottoms + live content refresh
## Tile height variation (fix) Tile tops now visibly vary (0.8–1.0) from a fixed bottom at world Y=0. Previously the top was fixed and the variation was only visible underneath. Heights are seeded by tile coordinate so they're deterministic per board. Unit y_offsets and highlight positions update to match per-tile height. ## Stalagmite tile bottoms Server: new TileBottomModel entity + migration (catalog.tile_bottom_models), content.tile_bottoms handler returns all active CDN URLs. Admin: "Tile Bottom Models" section in the Tile Model Manager page — add/toggle active/delete entries with CDN picker. Client: ContentCache fetches + disk-caches the URL pool; _try_load_tile_model picks a random URL and attaches it flipped below the tile model as a stalagmite using the existing _fit_model_to_tile scale logic. ## Live content refresh ContentCache schedules start_sync() every 5 minutes after sync_complete so card definitions, tile models, and bottom models are refreshed in the background without restarting the client. 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:
@@ -20,7 +20,9 @@ extends Node
|
|||||||
const CACHE_DIR := "user://content"
|
const CACHE_DIR := "user://content"
|
||||||
const CACHE_PATH := "user://content/defs.json"
|
const CACHE_PATH := "user://content/defs.json"
|
||||||
const TILE_MODELS_PATH := "user://content/tile_models.json"
|
const TILE_MODELS_PATH := "user://content/tile_models.json"
|
||||||
|
const TILE_BOTTOMS_PATH := "user://content/tile_bottoms.json"
|
||||||
const PAGE_SIZE := 200
|
const PAGE_SIZE := 200
|
||||||
|
const REFRESH_INTERVAL_SECS := 300.0 # re-sync every 5 minutes during live play
|
||||||
|
|
||||||
signal sync_progress(fetched_total: int) ## Running count of total definitions in memory.
|
signal sync_progress(fetched_total: int) ## Running count of total definitions in memory.
|
||||||
signal sync_complete(total: int) ## Emitted once sync finishes.
|
signal sync_complete(total: int) ## Emitted once sync finishes.
|
||||||
@@ -34,11 +36,15 @@ var _is_syncing: bool = false
|
|||||||
## "Affinity_Shape" (e.g. "Forest_Square") → CDN model URL string
|
## "Affinity_Shape" (e.g. "Forest_Square") → CDN model URL string
|
||||||
var _tile_models: Dictionary = {}
|
var _tile_models: Dictionary = {}
|
||||||
|
|
||||||
|
## Array of CDN URL strings for tile bottom (stalagmite) models.
|
||||||
|
var _tile_bottom_urls: Array = []
|
||||||
|
|
||||||
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
_load_from_disk()
|
_load_from_disk()
|
||||||
_load_tile_models_from_disk()
|
_load_tile_models_from_disk()
|
||||||
|
_load_tile_bottoms_from_disk()
|
||||||
|
|
||||||
# ── Public API ────────────────────────────────────────────────────────────────
|
# ── Public API ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
@@ -74,13 +80,14 @@ func is_syncing() -> bool:
|
|||||||
|
|
||||||
## Start (or resume) the incremental sync.
|
## Start (or resume) the incremental sync.
|
||||||
## Emits sync_progress during, sync_complete or sync_failed when done.
|
## Emits sync_progress during, sync_complete or sync_failed when done.
|
||||||
## Also triggers a fresh fetch of tile model bindings.
|
## Also triggers a fresh fetch of tile model bindings and bottom models.
|
||||||
func start_sync() -> void:
|
func start_sync() -> void:
|
||||||
if _is_syncing:
|
if _is_syncing:
|
||||||
return
|
return
|
||||||
_is_syncing = true
|
_is_syncing = true
|
||||||
_fetch_page(_sync_version)
|
_fetch_page(_sync_version)
|
||||||
fetch_tile_models()
|
fetch_tile_models()
|
||||||
|
fetch_tile_bottoms()
|
||||||
|
|
||||||
|
|
||||||
## Return the GLB animation track name for a card action.
|
## Return the GLB animation track name for a card action.
|
||||||
@@ -108,6 +115,24 @@ func get_tile_model_url(affinity: String, shape: String) -> String:
|
|||||||
return _tile_models.get(affinity + "_" + shape, "")
|
return _tile_models.get(affinity + "_" + shape, "")
|
||||||
|
|
||||||
|
|
||||||
|
## Returns a random active tile bottom (stalagmite) CDN URL, or "" if none configured.
|
||||||
|
func get_random_tile_bottom_url() -> String:
|
||||||
|
if _tile_bottom_urls.is_empty():
|
||||||
|
return ""
|
||||||
|
return _tile_bottom_urls[randi() % _tile_bottom_urls.size()] as String
|
||||||
|
|
||||||
|
|
||||||
|
## Fetch tile bottom model URLs from the server and update the local cache.
|
||||||
|
func fetch_tile_bottoms() -> void:
|
||||||
|
Network.request(
|
||||||
|
"content.tile_bottoms",
|
||||||
|
{},
|
||||||
|
func(_type: String, p: Variant): _on_tile_bottoms(p),
|
||||||
|
func(code: String, msg: String):
|
||||||
|
push_warning("ContentCache: tile_bottoms fetch failed — %s %s" % [code, msg])
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
## Fetch tile model bindings from the server and update the local cache.
|
## Fetch tile model bindings from the server and update the local cache.
|
||||||
## Emits tile_models_ready when done (even on error, using cached data).
|
## Emits tile_models_ready when done (even on error, using cached data).
|
||||||
func fetch_tile_models() -> void:
|
func fetch_tile_models() -> void:
|
||||||
@@ -151,6 +176,10 @@ func _on_page(payload: Variant) -> void:
|
|||||||
_is_syncing = false
|
_is_syncing = false
|
||||||
_save_to_disk()
|
_save_to_disk()
|
||||||
sync_complete.emit(_defs.size())
|
sync_complete.emit(_defs.size())
|
||||||
|
# Schedule next background refresh so live content patches are picked up
|
||||||
|
# without restarting the client.
|
||||||
|
get_tree().create_timer(REFRESH_INTERVAL_SECS).timeout.connect(
|
||||||
|
func() -> void: start_sync(), CONNECT_ONE_SHOT)
|
||||||
|
|
||||||
|
|
||||||
func _on_error(code: String, msg: String) -> void:
|
func _on_error(code: String, msg: String) -> void:
|
||||||
@@ -174,6 +203,16 @@ func _on_tile_models(payload: Variant) -> void:
|
|||||||
_save_tile_models_to_disk()
|
_save_tile_models_to_disk()
|
||||||
tile_models_ready.emit()
|
tile_models_ready.emit()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_tile_bottoms(payload: Variant) -> void:
|
||||||
|
var p := payload as Dictionary
|
||||||
|
var urls : Array = p.get("urls", [])
|
||||||
|
_tile_bottom_urls.clear()
|
||||||
|
for u in urls:
|
||||||
|
if typeof(u) == TYPE_STRING and not (u as String).is_empty():
|
||||||
|
_tile_bottom_urls.append(u as String)
|
||||||
|
_save_tile_bottoms_to_disk()
|
||||||
|
|
||||||
# ── Persistence ───────────────────────────────────────────────────────────────
|
# ── Persistence ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
func _load_from_disk() -> void:
|
func _load_from_disk() -> void:
|
||||||
@@ -225,3 +264,24 @@ func _save_tile_models_to_disk() -> void:
|
|||||||
return
|
return
|
||||||
file.store_string(JSON.stringify(_tile_models))
|
file.store_string(JSON.stringify(_tile_models))
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
|
|
||||||
|
func _load_tile_bottoms_from_disk() -> void:
|
||||||
|
if not FileAccess.file_exists(TILE_BOTTOMS_PATH):
|
||||||
|
return
|
||||||
|
var file := FileAccess.open(TILE_BOTTOMS_PATH, FileAccess.READ)
|
||||||
|
if not file:
|
||||||
|
return
|
||||||
|
var parsed: Variant = JSON.parse_string(file.get_as_text())
|
||||||
|
file.close()
|
||||||
|
if typeof(parsed) == TYPE_ARRAY:
|
||||||
|
_tile_bottom_urls = parsed as Array
|
||||||
|
|
||||||
|
|
||||||
|
func _save_tile_bottoms_to_disk() -> void:
|
||||||
|
DirAccess.make_dir_recursive_absolute(CACHE_DIR)
|
||||||
|
var file := FileAccess.open(TILE_BOTTOMS_PATH, FileAccess.WRITE)
|
||||||
|
if not file:
|
||||||
|
return
|
||||||
|
file.store_string(JSON.stringify(_tile_bottom_urls))
|
||||||
|
file.close()
|
||||||
|
|||||||
@@ -160,6 +160,7 @@ var _prev_unit_hp : Dictionary = {} # instanceId → int, HP snapshot for damag
|
|||||||
var _prev_unit_pos: Dictionary = {} # instanceId → Vector2i, position snapshot for move detection
|
var _prev_unit_pos: Dictionary = {} # instanceId → Vector2i, position snapshot for move detection
|
||||||
var _move_anims : Dictionary = {} # instanceId → Tween (active movement tweens)
|
var _move_anims : Dictionary = {} # instanceId → Tween (active movement tweens)
|
||||||
var _last_attack_target_iid : String = "" # target of the most recent send_attack() call
|
var _last_attack_target_iid : String = "" # target of the most recent send_attack() call
|
||||||
|
var _tile_heights : Dictionary = {} # "x,y" → float, world Y of tile top surface
|
||||||
|
|
||||||
# Delayed rebuild: when animations need time to play we don't destroy unit nodes immediately.
|
# Delayed rebuild: when animations need time to play we don't destroy unit nodes immediately.
|
||||||
var _pending_rebuild : Dictionary = {} # latest state waiting for the delayed rebuild
|
var _pending_rebuild : Dictionary = {} # latest state waiting for the delayed rebuild
|
||||||
@@ -438,6 +439,7 @@ func _build_board(board: Dictionary) -> void:
|
|||||||
_tile_bodies.clear()
|
_tile_bodies.clear()
|
||||||
_unit_meshes.clear()
|
_unit_meshes.clear()
|
||||||
_unit_bodies.clear()
|
_unit_bodies.clear()
|
||||||
|
_tile_heights.clear()
|
||||||
for tile: Dictionary in board.get("tiles", []):
|
for tile: Dictionary in board.get("tiles", []):
|
||||||
var coord : Dictionary = tile.get("coord", {})
|
var coord : Dictionary = tile.get("coord", {})
|
||||||
_add_tile(coord.get("x", 0), coord.get("y", 0),
|
_add_tile(coord.get("x", 0), coord.get("y", 0),
|
||||||
@@ -447,25 +449,30 @@ func _build_board(board: Dictionary) -> void:
|
|||||||
func _add_tile(x: int, y: int, affinity: String) -> void:
|
func _add_tile(x: int, y: int, affinity: String) -> void:
|
||||||
var wp := _coord_to_world(x, y)
|
var wp := _coord_to_world(x, y)
|
||||||
|
|
||||||
|
# Deterministic random height per tile (seeded by coord) so the same board
|
||||||
|
# always produces the same heights. Bottom is fixed at world Y=0; the TOP
|
||||||
|
# varies between 0.8 and 1.0, giving each tile a distinct elevation visible
|
||||||
|
# from the camera angle.
|
||||||
|
var rng := RandomNumberGenerator.new()
|
||||||
|
rng.seed = hash("%d_%d" % [x, y])
|
||||||
|
var h : float = rng.randf_range(0.8, 1.0)
|
||||||
|
_tile_heights["%d,%d" % [x, y]] = h
|
||||||
|
|
||||||
var body := StaticBody3D.new()
|
var body := StaticBody3D.new()
|
||||||
body.position = wp + Vector3(0, 0.25, 0)
|
body.position = wp + Vector3(0, h * 0.5, 0) # centre at half-height so bottom = Y 0
|
||||||
body.set_meta("tile_coord", Vector2i(x, y))
|
body.set_meta("tile_coord", Vector2i(x, y))
|
||||||
|
body.set_meta("tile_height", h) # used by bottom-model loader
|
||||||
|
|
||||||
var shape := CollisionShape3D.new()
|
var shape := CollisionShape3D.new()
|
||||||
var box := BoxShape3D.new()
|
var box := BoxShape3D.new()
|
||||||
box.size = Vector3(0.98, 0.5, 0.98)
|
box.size = Vector3(0.98, h, 0.98)
|
||||||
shape.shape = box
|
shape.shape = box
|
||||||
body.add_child(shape)
|
body.add_child(shape)
|
||||||
|
|
||||||
# Placeholder: affinity-coloured flat box, swapped out if a 3D model loads.
|
# Placeholder: affinity-coloured flat box, swapped out if a 3D model loads.
|
||||||
# Visual height varies per tile (0.8–1.0) for organic terrain feel.
|
|
||||||
# The mesh is shifted downward so the TOP surface always stays at Y=0.5 in
|
|
||||||
# world space — collision shape, unit positions, and highlights are unaffected.
|
|
||||||
var vis_h : float = randf_range(0.8, 1.0)
|
|
||||||
var mi := MeshInstance3D.new()
|
var mi := MeshInstance3D.new()
|
||||||
var bm := BoxMesh.new()
|
var bm := BoxMesh.new()
|
||||||
bm.size = Vector3(0.98, vis_h, 0.98)
|
bm.size = Vector3(0.98, h, 0.98)
|
||||||
mi.position = Vector3(0, (0.5 - vis_h) * 0.5, 0) # shift down to keep top at body-local +0.25
|
|
||||||
mi.mesh = bm
|
mi.mesh = bm
|
||||||
var mat := StandardMaterial3D.new()
|
var mat := StandardMaterial3D.new()
|
||||||
mat.albedo_color = AFFINITY_COLORS.get(affinity, Color(0.2, 0.2, 0.2))
|
mat.albedo_color = AFFINITY_COLORS.get(affinity, Color(0.2, 0.2, 0.2))
|
||||||
@@ -481,6 +488,7 @@ func _add_tile(x: int, y: int, affinity: String) -> void:
|
|||||||
|
|
||||||
|
|
||||||
## Load (or replace) the 3D model on a tile body for the given affinity.
|
## Load (or replace) the 3D model on a tile body for the given affinity.
|
||||||
|
## Also attaches a random stalagmite bottom model below the tile when available.
|
||||||
## Safe to call any time affinity changes — replaces existing mesh if present.
|
## Safe to call any time affinity changes — replaces existing mesh if present.
|
||||||
func _try_load_tile_model(body: StaticBody3D, affinity: String) -> void:
|
func _try_load_tile_model(body: StaticBody3D, affinity: String) -> void:
|
||||||
var model_url := ContentCache.get_tile_model_url(affinity, "Square")
|
var model_url := ContentCache.get_tile_model_url(affinity, "Square")
|
||||||
@@ -506,6 +514,33 @@ func _try_load_tile_model(body: StaticBody3D, affinity: String) -> void:
|
|||||||
b.add_child(model_node)
|
b.add_child(model_node)
|
||||||
# Scale so the XZ footprint fits the 0.98-unit tile square.
|
# Scale so the XZ footprint fits the 0.98-unit tile square.
|
||||||
_fit_model_to_tile(model_node, 0.98)
|
_fit_model_to_tile(model_node, 0.98)
|
||||||
|
|
||||||
|
# Attach a random stalagmite bottom model below the tile (if any are configured).
|
||||||
|
var bottom_url := ContentCache.get_random_tile_bottom_url()
|
||||||
|
if not bottom_url.is_empty():
|
||||||
|
_try_load_tile_bottom(body_ref, bottom_url)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
## Loads a stalagmite bottom model and attaches it below the tile body.
|
||||||
|
func _try_load_tile_bottom(body_ref: Variant, url: String) -> void:
|
||||||
|
ModelCache.load_model(url, func(bottom_node: Node3D) -> void:
|
||||||
|
var b := body_ref.get_ref() as StaticBody3D
|
||||||
|
if not is_instance_valid(b):
|
||||||
|
if bottom_node != null:
|
||||||
|
bottom_node.queue_free()
|
||||||
|
return
|
||||||
|
if bottom_node == null:
|
||||||
|
return
|
||||||
|
# The body centre is at world Y = h/2. The bottom of the tile is at
|
||||||
|
# body-local Y = -h/2. Scale the stalagmite to fit the tile footprint,
|
||||||
|
# then flip it upside-down (scale Y = -1) so it hangs downward, and
|
||||||
|
# seat its origin at the tile-bottom local position.
|
||||||
|
var tile_h : float = float(b.get_meta("tile_height", 1.0))
|
||||||
|
_fit_model_to_tile(bottom_node, 0.98)
|
||||||
|
bottom_node.scale.y = -absf(bottom_node.scale.y) # flip to hang down
|
||||||
|
bottom_node.position.y = -tile_h * 0.5 # move to tile bottom
|
||||||
|
b.add_child(bottom_node)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -614,7 +649,10 @@ func _rebuild_units(state: Dictionary) -> void:
|
|||||||
func _add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false) -> void:
|
func _add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false) -> void:
|
||||||
var pd : Dictionary = unit.get("position", {})
|
var pd : Dictionary = unit.get("position", {})
|
||||||
if pd.is_empty(): return
|
if pd.is_empty(): return
|
||||||
var wp := _coord_to_world(pd.get("x", 0), pd.get("y", 0))
|
var px : int = pd.get("x", 0)
|
||||||
|
var py : int = pd.get("y", 0)
|
||||||
|
var wp := _coord_to_world(px, py)
|
||||||
|
var tile_h : float = _tile_heights.get("%d,%d" % [px, py], 1.0)
|
||||||
var card_type : String = unit.get("cardType", "Spirit")
|
var card_type : String = unit.get("cardType", "Spirit")
|
||||||
var iid : String = unit.get("instanceId", "")
|
var iid : String = unit.get("instanceId", "")
|
||||||
var exhausted : bool = unit.get("isExhausted", false)
|
var exhausted : bool = unit.get("isExhausted", false)
|
||||||
@@ -639,7 +677,7 @@ func _add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false)
|
|||||||
var cs := CylinderShape3D.new()
|
var cs := CylinderShape3D.new()
|
||||||
cs.radius = 0.22; cs.height = 0.8
|
cs.radius = 0.22; cs.height = 0.8
|
||||||
shape.shape = cs
|
shape.shape = cs
|
||||||
y_offset = 0.5 + 0.4
|
y_offset = tile_h + 0.4
|
||||||
"Ruin":
|
"Ruin":
|
||||||
var bm := BoxMesh.new()
|
var bm := BoxMesh.new()
|
||||||
bm.size = Vector3(0.25, 1.0, 0.25)
|
bm.size = Vector3(0.25, 1.0, 0.25)
|
||||||
@@ -648,7 +686,7 @@ func _add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false)
|
|||||||
var bs := BoxShape3D.new()
|
var bs := BoxShape3D.new()
|
||||||
bs.size = Vector3(0.25, 1.0, 0.25)
|
bs.size = Vector3(0.25, 1.0, 0.25)
|
||||||
shape.shape = bs
|
shape.shape = bs
|
||||||
y_offset = 0.5 + 0.5
|
y_offset = tile_h + 0.5
|
||||||
_:
|
_:
|
||||||
var sm := SphereMesh.new()
|
var sm := SphereMesh.new()
|
||||||
sm.radius = 0.28; sm.height = 0.28
|
sm.radius = 0.28; sm.height = 0.28
|
||||||
@@ -657,7 +695,7 @@ func _add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false)
|
|||||||
var ss := SphereShape3D.new()
|
var ss := SphereShape3D.new()
|
||||||
ss.radius = 0.28
|
ss.radius = 0.28
|
||||||
shape.shape = ss
|
shape.shape = ss
|
||||||
y_offset = 0.5 + 0.28
|
y_offset = tile_h + 0.28
|
||||||
|
|
||||||
mi.material_override = mat
|
mi.material_override = mat
|
||||||
if exhausted:
|
if exhausted:
|
||||||
@@ -1267,8 +1305,9 @@ func _add_highlight(x: int, y: int, color: Color) -> void:
|
|||||||
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
|
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
|
||||||
mat.albedo_color.a = 0.75
|
mat.albedo_color.a = 0.75
|
||||||
mi.material_override = mat
|
mi.material_override = mat
|
||||||
# Position clearly above the tile top (tile top = Y 0.50).
|
# Position just above the tile top (varies per-tile).
|
||||||
mi.position = _coord_to_world(x, y) + Vector3(0, 0.58, 0)
|
var _hi_tile_h : float = _tile_heights.get("%d,%d" % [x, y], 1.0)
|
||||||
|
mi.position = _coord_to_world(x, y) + Vector3(0, _hi_tile_h + 0.08, 0)
|
||||||
_hi_root.add_child(mi)
|
_hi_root.add_child(mi)
|
||||||
print("[Highlight] added (%d,%d) hi_root children=%d" % [x, y, _hi_root.get_child_count()])
|
print("[Highlight] added (%d,%d) hi_root children=%d" % [x, y, _hi_root.get_child_count()])
|
||||||
|
|
||||||
|
|||||||
@@ -75,6 +75,59 @@ else
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<!-- ── Tile Bottoms (stalagmite undersides) ── -->
|
||||||
|
<div class="card shadow-sm mb-4">
|
||||||
|
<div class="card-header fw-medium d-flex justify-content-between align-items-center">
|
||||||
|
<span>Tile Bottom Models <span class="text-muted small fw-normal">(stalagmites, randomly selected per tile)</span></span>
|
||||||
|
<button class="btn btn-sm btn-outline-primary" @onclick="OpenBottomPickerAsync">
|
||||||
|
<i class="bi bi-plus me-1"></i>Add
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="card-body p-0">
|
||||||
|
@if (_bottomModels.Count == 0)
|
||||||
|
{
|
||||||
|
<div class="text-muted text-center py-3 small">No bottom models yet — upload GLBs and add them here.</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<table class="table table-sm table-hover mb-0">
|
||||||
|
<thead class="table-light">
|
||||||
|
<tr>
|
||||||
|
<th>Model</th>
|
||||||
|
<th style="width:80px">Active</th>
|
||||||
|
<th style="width:100px"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (var bottom in _bottomModels)
|
||||||
|
{
|
||||||
|
var b = bottom;
|
||||||
|
<tr>
|
||||||
|
<td class="align-middle font-monospace small text-break">
|
||||||
|
@(b.CdnKey.Contains('/') ? b.CdnKey[(b.CdnKey.LastIndexOf('/') + 1)..] : b.CdnKey)
|
||||||
|
</td>
|
||||||
|
<td class="align-middle">
|
||||||
|
<input type="checkbox" class="form-check-input" checked="@b.IsActive"
|
||||||
|
@onchange="e => ToggleBottomActiveAsync(b, (bool)e.Value!)" />
|
||||||
|
</td>
|
||||||
|
<td class="align-middle text-end pe-2">
|
||||||
|
<button class="btn btn-sm btn-outline-info py-0 me-1"
|
||||||
|
@onclick="() => _previewUrl = b.PublicUrl" title="Preview">
|
||||||
|
<i class="bi bi-box"></i>
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-sm btn-outline-danger py-0"
|
||||||
|
@onclick="() => DeleteBottomAsync(b)" title="Delete">
|
||||||
|
<i class="bi bi-trash"></i>
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Assign / Picker Modal -->
|
<!-- Assign / Picker Modal -->
|
||||||
@if (_pickerOpen)
|
@if (_pickerOpen)
|
||||||
{
|
{
|
||||||
@@ -198,6 +251,63 @@ else
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<!-- Bottom Model Picker Modal -->
|
||||||
|
@if (_bottomPickerOpen)
|
||||||
|
{
|
||||||
|
<div class="modal d-block" tabindex="-1" style="background:rgba(0,0,0,0.55)">
|
||||||
|
<div class="modal-dialog modal-xl modal-dialog-scrollable">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">Add Tile Bottom Model</h5>
|
||||||
|
<button type="button" class="btn-close" @onclick="() => _bottomPickerOpen = false"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<input @bind="_bottomPickerSearch" @bind:event="oninput"
|
||||||
|
class="form-control form-control-sm font-monospace mb-3"
|
||||||
|
placeholder="Filter models…" />
|
||||||
|
@if (_pickerLoading)
|
||||||
|
{
|
||||||
|
<div class="text-muted text-center py-4">
|
||||||
|
<span class="spinner-border spinner-border-sm me-2"></span>Loading CDN models…
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<div class="row g-3">
|
||||||
|
@foreach (var model in BottomPickerFiltered())
|
||||||
|
{
|
||||||
|
var m = model;
|
||||||
|
var isSel = _bottomPickerSelected == m.Key;
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card h-100 @(isSel ? "border-primary" : "")"
|
||||||
|
style="cursor:pointer" @onclick="() => _bottomPickerSelected = m.Key">
|
||||||
|
<div class="card-body py-2 px-3">
|
||||||
|
<div class="font-monospace small text-break">@m.ShortName</div>
|
||||||
|
</div>
|
||||||
|
@if (isSel)
|
||||||
|
{
|
||||||
|
<div class="card-footer py-1 bg-primary text-white text-center small">✓ Selected</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button class="btn btn-secondary" @onclick="() => _bottomPickerOpen = false">Cancel</button>
|
||||||
|
<button class="btn btn-primary"
|
||||||
|
disabled="@(_bottomPickerSelected is null || _saving)"
|
||||||
|
@onclick="SaveBottomAsync">
|
||||||
|
@if (_saving) { <span class="spinner-border spinner-border-sm me-1"></span> }
|
||||||
|
Add
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
<script type="module" src="https://ajax.googleapis.com/ajax/libs/model-viewer/3.5.0/model-viewer.min.js"></script>
|
<script type="module" src="https://ajax.googleapis.com/ajax/libs/model-viewer/3.5.0/model-viewer.min.js"></script>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
@@ -236,6 +346,12 @@ else
|
|||||||
("Gateways", new[] { Affinity.GatewayLake, Affinity.GatewayHill, Affinity.GatewayForest, Affinity.GatewayField }),
|
("Gateways", new[] { Affinity.GatewayLake, Affinity.GatewayHill, Affinity.GatewayForest, Affinity.GatewayField }),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Tile bottom models
|
||||||
|
private List<TileBottomModel> _bottomModels = new();
|
||||||
|
private bool _bottomPickerOpen;
|
||||||
|
private string _bottomPickerSearch = "";
|
||||||
|
private string? _bottomPickerSelected;
|
||||||
|
|
||||||
// ── Lifecycle ─────────────────────────────────────────────────────────────
|
// ── Lifecycle ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync() => await LoadAsync();
|
protected override async Task OnInitializedAsync() => await LoadAsync();
|
||||||
@@ -245,6 +361,7 @@ else
|
|||||||
_loading = true;
|
_loading = true;
|
||||||
var all = await Db.TileModelBindings.ToListAsync();
|
var all = await Db.TileModelBindings.ToListAsync();
|
||||||
_bindings = all.ToDictionary(b => (b.Affinity, b.Shape));
|
_bindings = all.ToDictionary(b => (b.Affinity, b.Shape));
|
||||||
|
_bottomModels = await Db.TileBottomModels.OrderBy(m => m.CdnKey).ToListAsync();
|
||||||
_loading = false;
|
_loading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -378,6 +495,68 @@ else
|
|||||||
_isError = false;
|
_isError = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Tile Bottom Models ────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
private async Task OpenBottomPickerAsync()
|
||||||
|
{
|
||||||
|
_bottomPickerSelected = null;
|
||||||
|
_bottomPickerSearch = "";
|
||||||
|
_bottomPickerOpen = true;
|
||||||
|
_pickerLoading = true;
|
||||||
|
await LoadPickerModelsAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<ModelItem> BottomPickerFiltered()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(_bottomPickerSearch))
|
||||||
|
return _pickerModels;
|
||||||
|
return _pickerModels.Where(m =>
|
||||||
|
m.Key.Contains(_bottomPickerSearch, StringComparison.OrdinalIgnoreCase));
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SaveBottomAsync()
|
||||||
|
{
|
||||||
|
if (_bottomPickerSelected is null) return;
|
||||||
|
_saving = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var options = CdnOptionsAccessor.Value;
|
||||||
|
var publicUrl = BuildPublicUrl(options, _bottomPickerSelected);
|
||||||
|
var model = new TileBottomModel
|
||||||
|
{
|
||||||
|
CdnKey = _bottomPickerSelected,
|
||||||
|
PublicUrl = publicUrl,
|
||||||
|
IsActive = true,
|
||||||
|
UpdatedAt = DateTimeOffset.UtcNow,
|
||||||
|
};
|
||||||
|
Db.TileBottomModels.Add(model);
|
||||||
|
await Db.SaveChangesAsync();
|
||||||
|
_bottomModels.Add(model);
|
||||||
|
_bottomModels = _bottomModels.OrderBy(m => m.CdnKey).ToList();
|
||||||
|
_bottomPickerOpen = false;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_message = $"Save failed: {ex.Message}";
|
||||||
|
_isError = true;
|
||||||
|
}
|
||||||
|
finally { _saving = false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ToggleBottomActiveAsync(TileBottomModel model, bool active)
|
||||||
|
{
|
||||||
|
model.IsActive = active;
|
||||||
|
model.UpdatedAt = DateTimeOffset.UtcNow;
|
||||||
|
await Db.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task DeleteBottomAsync(TileBottomModel model)
|
||||||
|
{
|
||||||
|
Db.TileBottomModels.Remove(model);
|
||||||
|
await Db.SaveChangesAsync();
|
||||||
|
_bottomModels.Remove(model);
|
||||||
|
}
|
||||||
|
|
||||||
// ── Helpers ───────────────────────────────────────────────────────────────
|
// ── Helpers ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
private RenderFragment ModelCell(TileModelBinding? binding, Affinity affinity, TileShape shape) => __builder =>
|
private RenderFragment ModelCell(TileModelBinding? binding, Affinity affinity, TileShape shape) => __builder =>
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ public sealed record GetCardDefinitionRequest(Guid Id);
|
|||||||
/// <summary>Fetch all tile model bindings (affinity × shape → CDN URL).</summary>
|
/// <summary>Fetch all tile model bindings (affinity × shape → CDN URL).</summary>
|
||||||
public sealed record GetTileModelsRequest;
|
public sealed record GetTileModelsRequest;
|
||||||
|
|
||||||
|
/// <summary>Fetch all active tile bottom (stalagmite) model URLs.</summary>
|
||||||
|
public sealed record GetTileBottomsRequest;
|
||||||
|
|
||||||
// ── Response / DTO types (server → client) ────────────────────────────────────
|
// ── Response / DTO types (server → client) ────────────────────────────────────
|
||||||
|
|
||||||
public sealed record SyncCardDefinitionsResponse(
|
public sealed record SyncCardDefinitionsResponse(
|
||||||
@@ -32,6 +35,8 @@ public sealed record GetCardDefinitionResponse(CardDefinitionDto? Card);
|
|||||||
|
|
||||||
public sealed record GetTileModelsResponse(IEnumerable<TileModelDto> Bindings);
|
public sealed record GetTileModelsResponse(IEnumerable<TileModelDto> Bindings);
|
||||||
|
|
||||||
|
public sealed record GetTileBottomsResponse(IEnumerable<string> Urls);
|
||||||
|
|
||||||
public sealed record TileModelDto(
|
public sealed record TileModelDto(
|
||||||
string Affinity,
|
string Affinity,
|
||||||
string Shape,
|
string Shape,
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
namespace SOR.Content.Handlers;
|
||||||
|
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using SOR.Database.Contexts;
|
||||||
|
using SOR.Networking.Abstractions.Messaging;
|
||||||
|
using SOR.Networking.Abstractions.Transport;
|
||||||
|
using SOR.Shared.Networking;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// content.tile_bottoms — returns CDN URLs for all active tile-bottom (stalagmite) models.
|
||||||
|
/// The client randomly picks from this list when attaching an underside mesh to a tile.
|
||||||
|
/// </summary>
|
||||||
|
internal sealed class ContentGetTileBottomsHandler : IMessageHandler
|
||||||
|
{
|
||||||
|
private readonly IMessageSerializer _serializer;
|
||||||
|
private readonly CatalogDbContext _catalogDb;
|
||||||
|
|
||||||
|
public ContentGetTileBottomsHandler(IMessageSerializer serializer, CatalogDbContext catalogDb)
|
||||||
|
{
|
||||||
|
_serializer = serializer;
|
||||||
|
_catalogDb = catalogDb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string MessageType => "content.tile_bottoms";
|
||||||
|
|
||||||
|
public async Task<IServerMessage?> HandleAsync(
|
||||||
|
IClientMessage message,
|
||||||
|
AuthenticatedConnection connection,
|
||||||
|
CancellationToken ct)
|
||||||
|
{
|
||||||
|
var urls = await _catalogDb.TileBottomModels
|
||||||
|
.Where(m => m.IsActive)
|
||||||
|
.Select(m => m.PublicUrl)
|
||||||
|
.ToListAsync(ct);
|
||||||
|
|
||||||
|
return ServerMessage.Reply("content.tile_bottoms.ack", message.Seq,
|
||||||
|
new GetTileBottomsResponse(urls));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ public static class ServiceRegistration
|
|||||||
services.AddTransient<IMessageHandler, ContentGetCardSetsHandler>();
|
services.AddTransient<IMessageHandler, ContentGetCardSetsHandler>();
|
||||||
services.AddTransient<IMessageHandler, ContentGetCardDefinitionHandler>();
|
services.AddTransient<IMessageHandler, ContentGetCardDefinitionHandler>();
|
||||||
services.AddTransient<IMessageHandler, ContentGetTileModelsHandler>();
|
services.AddTransient<IMessageHandler, ContentGetTileModelsHandler>();
|
||||||
|
services.AddTransient<IMessageHandler, ContentGetTileBottomsHandler>();
|
||||||
services.AddTransient<IMessageHandler, ContentGetAudioConfigHandler>();
|
services.AddTransient<IMessageHandler, ContentGetAudioConfigHandler>();
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public sealed class CatalogDbContext : DbContext
|
|||||||
public DbSet<CardAnimationBinding> AnimationBindings => Set<CardAnimationBinding>();
|
public DbSet<CardAnimationBinding> AnimationBindings => Set<CardAnimationBinding>();
|
||||||
public DbSet<CdnUploadRecord> CdnUploadRecords => Set<CdnUploadRecord>();
|
public DbSet<CdnUploadRecord> CdnUploadRecords => Set<CdnUploadRecord>();
|
||||||
public DbSet<TileModelBinding> TileModelBindings => Set<TileModelBinding>();
|
public DbSet<TileModelBinding> TileModelBindings => Set<TileModelBinding>();
|
||||||
|
public DbSet<TileBottomModel> TileBottomModels => Set<TileBottomModel>();
|
||||||
public DbSet<GameAudioConfig> AudioConfigs => Set<GameAudioConfig>();
|
public DbSet<GameAudioConfig> AudioConfigs => Set<GameAudioConfig>();
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder builder)
|
protected override void OnModelCreating(ModelBuilder builder)
|
||||||
@@ -142,6 +143,15 @@ public sealed class CatalogDbContext : DbContext
|
|||||||
e.HasIndex(t => new { t.Affinity, t.Shape }).IsUnique();
|
e.HasIndex(t => new { t.Affinity, t.Shape }).IsUnique();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
builder.Entity<TileBottomModel>(e =>
|
||||||
|
{
|
||||||
|
e.ToTable("tile_bottom_models");
|
||||||
|
e.HasKey(t => t.Id);
|
||||||
|
e.Property(t => t.CdnKey).IsRequired();
|
||||||
|
e.Property(t => t.PublicUrl).IsRequired();
|
||||||
|
e.HasIndex(t => t.IsActive);
|
||||||
|
});
|
||||||
|
|
||||||
builder.Entity<GameAudioConfig>(e =>
|
builder.Entity<GameAudioConfig>(e =>
|
||||||
{
|
{
|
||||||
e.ToTable("game_audio_configs");
|
e.ToTable("game_audio_configs");
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
namespace SOR.Database.Entities.Catalog;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A stalagmite / underside 3D model that the client attaches below tile models.
|
||||||
|
/// The client randomly picks from all active records each time a tile loads.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class TileBottomModel
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; } = Guid.NewGuid();
|
||||||
|
|
||||||
|
/// <summary>S3 object key, e.g. "models/tiles/bottoms/stalactite_01.glb".</summary>
|
||||||
|
public string CdnKey { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>Publicly accessible CDN URL for the model file.</summary>
|
||||||
|
public string PublicUrl { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>When false the model is excluded from the pool returned to clients.</summary>
|
||||||
|
public bool IsActive { get; set; } = true;
|
||||||
|
|
||||||
|
public DateTimeOffset UpdatedAt { get; set; } = DateTimeOffset.UtcNow;
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace SOR.Database.Migrations.Catalog
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddTileBottomModels : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "tile_bottom_models",
|
||||||
|
schema: "catalog",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
CdnKey = table.Column<string>(type: "text", nullable: false),
|
||||||
|
PublicUrl = table.Column<string>(type: "text", nullable: false),
|
||||||
|
IsActive = table.Column<bool>(type: "boolean", nullable: false, defaultValue: true),
|
||||||
|
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_tile_bottom_models", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_tile_bottom_models_IsActive",
|
||||||
|
schema: "catalog",
|
||||||
|
table: "tile_bottom_models",
|
||||||
|
column: "IsActive");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "tile_bottom_models",
|
||||||
|
schema: "catalog");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user