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:
@@ -17,10 +17,12 @@ extends Node
|
||||
## ContentCache.get_tile_model_url("Forest", "Square") → String or ""
|
||||
## ContentCache.sync_complete.connect(...)
|
||||
|
||||
const CACHE_DIR := "user://content"
|
||||
const CACHE_PATH := "user://content/defs.json"
|
||||
const TILE_MODELS_PATH := "user://content/tile_models.json"
|
||||
const PAGE_SIZE := 200
|
||||
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 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_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
|
||||
var _tile_models: Dictionary = {}
|
||||
|
||||
## Array of CDN URL strings for tile bottom (stalagmite) models.
|
||||
var _tile_bottom_urls: Array = []
|
||||
|
||||
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
||||
|
||||
func _ready() -> void:
|
||||
_load_from_disk()
|
||||
_load_tile_models_from_disk()
|
||||
_load_tile_bottoms_from_disk()
|
||||
|
||||
# ── Public API ────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -74,13 +80,14 @@ func is_syncing() -> bool:
|
||||
|
||||
## Start (or resume) the incremental sync.
|
||||
## 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:
|
||||
if _is_syncing:
|
||||
return
|
||||
_is_syncing = true
|
||||
_fetch_page(_sync_version)
|
||||
fetch_tile_models()
|
||||
fetch_tile_bottoms()
|
||||
|
||||
|
||||
## 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, "")
|
||||
|
||||
|
||||
## 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.
|
||||
## Emits tile_models_ready when done (even on error, using cached data).
|
||||
func fetch_tile_models() -> void:
|
||||
@@ -151,6 +176,10 @@ func _on_page(payload: Variant) -> void:
|
||||
_is_syncing = false
|
||||
_save_to_disk()
|
||||
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:
|
||||
@@ -174,6 +203,16 @@ func _on_tile_models(payload: Variant) -> void:
|
||||
_save_tile_models_to_disk()
|
||||
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 ───────────────────────────────────────────────────────────────
|
||||
|
||||
func _load_from_disk() -> void:
|
||||
@@ -225,3 +264,24 @@ func _save_tile_models_to_disk() -> void:
|
||||
return
|
||||
file.store_string(JSON.stringify(_tile_models))
|
||||
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 _move_anims : Dictionary = {} # instanceId → Tween (active movement tweens)
|
||||
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.
|
||||
var _pending_rebuild : Dictionary = {} # latest state waiting for the delayed rebuild
|
||||
@@ -438,6 +439,7 @@ func _build_board(board: Dictionary) -> void:
|
||||
_tile_bodies.clear()
|
||||
_unit_meshes.clear()
|
||||
_unit_bodies.clear()
|
||||
_tile_heights.clear()
|
||||
for tile: Dictionary in board.get("tiles", []):
|
||||
var coord : Dictionary = tile.get("coord", {})
|
||||
_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:
|
||||
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()
|
||||
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_height", h) # used by bottom-model loader
|
||||
|
||||
var shape := CollisionShape3D.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
|
||||
body.add_child(shape)
|
||||
|
||||
# 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 bm := BoxMesh.new()
|
||||
bm.size = Vector3(0.98, vis_h, 0.98)
|
||||
mi.position = Vector3(0, (0.5 - vis_h) * 0.5, 0) # shift down to keep top at body-local +0.25
|
||||
bm.size = Vector3(0.98, h, 0.98)
|
||||
mi.mesh = bm
|
||||
var mat := StandardMaterial3D.new()
|
||||
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.
|
||||
## Also attaches a random stalagmite bottom model below the tile when available.
|
||||
## Safe to call any time affinity changes — replaces existing mesh if present.
|
||||
func _try_load_tile_model(body: StaticBody3D, affinity: String) -> void:
|
||||
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)
|
||||
# Scale so the XZ footprint fits the 0.98-unit tile square.
|
||||
_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:
|
||||
var pd : Dictionary = unit.get("position", {})
|
||||
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 iid : String = unit.get("instanceId", "")
|
||||
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()
|
||||
cs.radius = 0.22; cs.height = 0.8
|
||||
shape.shape = cs
|
||||
y_offset = 0.5 + 0.4
|
||||
y_offset = tile_h + 0.4
|
||||
"Ruin":
|
||||
var bm := BoxMesh.new()
|
||||
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()
|
||||
bs.size = Vector3(0.25, 1.0, 0.25)
|
||||
shape.shape = bs
|
||||
y_offset = 0.5 + 0.5
|
||||
y_offset = tile_h + 0.5
|
||||
_:
|
||||
var sm := SphereMesh.new()
|
||||
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()
|
||||
ss.radius = 0.28
|
||||
shape.shape = ss
|
||||
y_offset = 0.5 + 0.28
|
||||
y_offset = tile_h + 0.28
|
||||
|
||||
mi.material_override = mat
|
||||
if exhausted:
|
||||
@@ -1267,8 +1305,9 @@ func _add_highlight(x: int, y: int, color: Color) -> void:
|
||||
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
|
||||
mat.albedo_color.a = 0.75
|
||||
mi.material_override = mat
|
||||
# Position clearly above the tile top (tile top = Y 0.50).
|
||||
mi.position = _coord_to_world(x, y) + Vector3(0, 0.58, 0)
|
||||
# Position just above the tile top (varies per-tile).
|
||||
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)
|
||||
print("[Highlight] added (%d,%d) hi_root children=%d" % [x, y, _hi_root.get_child_count()])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user