Feature: tile spacing gap + 2D placeholder textures
Visual changes (client): - 0.1 gap between all tiles (TILE_SPACING = 1.1) - Placeholder tiles (no 3D model) are now 0.5 height instead of random 0.8-1.0, making undecorated tiles visually distinct - Placeholder tiles load a 2D CDN texture via HTTP and apply it as the albedo on the BoxMesh (same affinity-per-shape lookup as 3D models) - Placeholder tiles also attach a stalagmite bottom model, matching the look of fully-decorated tiles Server: - TileModelBinding.TexturePublicUrl (nullable text) added to entity, migration 20260317000001_AddTileTexture applied to DB - TileModelDto extended with TexturePublicUrl - ContentGetTileModelsHandler includes TexturePublicUrl in response Admin (/content/tile-models): - New "Square Texture" and "Hex Texture" columns in the bindings table - Texture picker modal browses the CDN textures/ prefix and shows image thumbnails; select + assign writes TexturePublicUrl to the binding - Texture can be assigned without a 3D model (creates a binding row with empty model fields) ContentCache: - Caches texturePublicUrl alongside modelPublicUrl from tile_models response - New get_tile_texture_url(affinity, shape) → String accessor 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:
@@ -36,6 +36,9 @@ var _is_syncing: bool = false
|
||||
## "Affinity_Shape" (e.g. "Forest_Square") → CDN model URL string
|
||||
var _tile_models: Dictionary = {}
|
||||
|
||||
## "Affinity_Shape" → CDN texture URL string (2D texture for placeholder tiles)
|
||||
var _tile_textures: Dictionary = {}
|
||||
|
||||
## Array of CDN URL strings for tile bottom (stalagmite) models.
|
||||
var _tile_bottom_urls: Array = []
|
||||
|
||||
@@ -115,6 +118,11 @@ func get_tile_model_url(affinity: String, shape: String) -> String:
|
||||
return _tile_models.get(affinity + "_" + shape, "")
|
||||
|
||||
|
||||
## Return the CDN URL for a tile's 2D placeholder texture, or "" if not assigned.
|
||||
func get_tile_texture_url(affinity: String, shape: String) -> String:
|
||||
return _tile_textures.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():
|
||||
@@ -193,13 +201,18 @@ func _on_tile_models(payload: Variant) -> void:
|
||||
var p := payload as Dictionary
|
||||
var bindings : Array = p.get("bindings", [])
|
||||
_tile_models.clear()
|
||||
_tile_textures.clear()
|
||||
for item in bindings:
|
||||
var d := item as Dictionary
|
||||
if d == null: continue
|
||||
var key := str(d.get("affinity", "")) + "_" + str(d.get("shape", ""))
|
||||
var url := str(d.get("modelPublicUrl", ""))
|
||||
if not key.is_empty() and not url.is_empty():
|
||||
_tile_models[key] = url
|
||||
if key.is_empty(): continue
|
||||
var model_url := str(d.get("modelPublicUrl", ""))
|
||||
if not model_url.is_empty():
|
||||
_tile_models[key] = model_url
|
||||
var tex_url := str(d.get("texturePublicUrl", ""))
|
||||
if not tex_url.is_empty() and tex_url != "null":
|
||||
_tile_textures[key] = tex_url
|
||||
_save_tile_models_to_disk()
|
||||
tile_models_ready.emit()
|
||||
|
||||
|
||||
@@ -376,9 +376,13 @@ func _touch_pair_dist() -> float:
|
||||
|
||||
# ── Coord helpers ─────────────────────────────────────────────────────────────
|
||||
|
||||
## Grid spacing: 1.0 tile + 0.1 gap between tiles (visual only).
|
||||
const TILE_SPACING := 1.1
|
||||
|
||||
func _coord_to_world(x: int, y: int) -> Vector3:
|
||||
return Vector3(x - (Game.board_width() - 1) * 0.5, 0.0,
|
||||
y - (Game.board_height() - 1) * 0.5)
|
||||
return Vector3(
|
||||
x * TILE_SPACING - (Game.board_width() - 1) * TILE_SPACING * 0.5, 0.0,
|
||||
y * TILE_SPACING - (Game.board_height() - 1) * TILE_SPACING * 0.5)
|
||||
|
||||
|
||||
func _mouse_to_tile_coord(mouse_pos: Vector2) -> Vector2i:
|
||||
@@ -449,13 +453,17 @@ 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)
|
||||
# Tiles with a 3D model get a small randomised height (0.8-1.0) for visual
|
||||
# variety. Placeholder tiles (no model assigned) are a fixed 0.5 height
|
||||
# so they read clearly as "undecorated" without towering over the board.
|
||||
var has_model : bool = not ContentCache.get_tile_model_url(affinity, "Square").is_empty()
|
||||
var h : float
|
||||
if has_model:
|
||||
var rng := RandomNumberGenerator.new()
|
||||
rng.seed = hash("%d_%d" % [x, y])
|
||||
h = rng.randf_range(0.8, 1.0)
|
||||
else:
|
||||
h = 0.5
|
||||
_tile_heights["%d,%d" % [x, y]] = h
|
||||
|
||||
var body := StaticBody3D.new()
|
||||
@@ -493,6 +501,14 @@ func _add_tile(x: int, y: int, affinity: String) -> void:
|
||||
func _try_load_tile_model(body: StaticBody3D, affinity: String) -> void:
|
||||
var model_url := ContentCache.get_tile_model_url(affinity, "Square")
|
||||
if model_url.is_empty():
|
||||
# No 3D model — apply a 2D texture to the placeholder box and attach
|
||||
# a stalagmite bottom so undecorated tiles still look coherent.
|
||||
var tex_url := ContentCache.get_tile_texture_url(affinity, "Square")
|
||||
if not tex_url.is_empty():
|
||||
_apply_tile_texture(body, tex_url)
|
||||
var bottom_url := ContentCache.get_random_tile_bottom_url()
|
||||
if not bottom_url.is_empty():
|
||||
_try_load_tile_bottom(weakref(body), bottom_url)
|
||||
return
|
||||
|
||||
var body_ref : Variant = weakref(body)
|
||||
@@ -554,6 +570,45 @@ func _try_load_tile_bottom(body_ref: Variant, url: String) -> void:
|
||||
)
|
||||
|
||||
|
||||
## Downloads a CDN image and applies it as the albedo texture on the
|
||||
## placeholder BoxMesh of a tile body (used when no 3D model is assigned).
|
||||
func _apply_tile_texture(body: StaticBody3D, tex_url: String) -> void:
|
||||
var mi : MeshInstance3D = null
|
||||
for child in body.get_children():
|
||||
if child is MeshInstance3D:
|
||||
mi = child as MeshInstance3D
|
||||
break
|
||||
if mi == null or tex_url.is_empty():
|
||||
return
|
||||
var requester := HTTPRequest.new()
|
||||
add_child(requester)
|
||||
requester.request_completed.connect(
|
||||
func(_result: int, code: int, _headers: PackedStringArray, data: PackedByteArray) -> void:
|
||||
requester.queue_free()
|
||||
if code < 200 or code >= 300 or not is_instance_valid(mi):
|
||||
return
|
||||
var img := Image.new()
|
||||
var ext := tex_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:
|
||||
return
|
||||
var tex := ImageTexture.create_from_image(img)
|
||||
var mat := mi.material_override as StandardMaterial3D
|
||||
if mat == null:
|
||||
mat = StandardMaterial3D.new()
|
||||
mat.roughness = 0.85
|
||||
mi.material_override = mat
|
||||
mat.albedo_texture = tex
|
||||
)
|
||||
requester.request(tex_url)
|
||||
|
||||
|
||||
## Scales model so its largest XZ dimension equals `tile_size`, then centres
|
||||
## it on XZ and seats the bottom at y = 0 in the parent body's local space.
|
||||
func _fit_model_to_tile(model: Node3D, tile_size: float) -> void:
|
||||
|
||||
Reference in New Issue
Block a user