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:
@@ -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