Tile highlight texture system with cursor + hover glow

Server / DB:
- New HighlightConfig entity (catalog.highlight_configs): one row per
  highlight type (Movement/Attack/Ability/Terramorpha/Selector). Supports
  static texture URL or animated (base folder + frame count + FPS) with a
  FallbackHex RGBA colour for when no texture is configured.
- EF migration AddHighlightConfig.
- CosmeticType.HighlightPack added; AssetCdnUrl stores serialised JSON with
  per-type texture config so players can buy full highlight packs in the Bazaar.
- content.get_highlight_config handler in SOR.Content; response DTOs added to
  ContentMessages.cs; handler registered in ServiceRegistration.

Admin:
- /content/highlights page: inline editor for all five highlight types
  (CDN path, animated toggle, frame count, FPS, fallback hex with swatch).
  Upserts rows — no delete needed since there is always exactly one row per type.
- Highlights nav link added to Content section in NavMenu.
- CosmeticEditor: HighlightPack type renders a per-type table (Movement/
  Attack/Ability/Terramorpha/Selector), serialising to JSON in AssetCdnUrl.

Client (Godot):
- HighlightConfig autoload: fetches content.get_highlight_config on startup,
  caches to user://highlight_config.json. Provides get_texture(type) and
  get_color(type). Supports set_override/clear_override/apply_cosmetic_pack
  for cosmetic and settings overrides.
- Settings autoload: highlight_overrides Dictionary persisted in settings.cfg.
  set_highlight_override/clear_highlight_override push into HighlightConfig.
- settings_screen.gd: programmatic "Highlight Texture Overrides" section added
  with a LineEdit + Reset button per type; appended to Sections VBoxContainer.
- game_screen.gd:
  • _add_highlight() rewritten to use flat PlaneMesh quads with textured
    StandardMaterial3D. Accepts a string type key ("movement", "attack",
    "ability", "terramorpha", "selector") instead of a Color constant.
  • _cursor_highlight + _hover_team_overlay: two permanently-allocated quads
    that are never freed. The selector highlights the tile under the mouse at
    all times; the team overlay shows a coloured tint when hovering an occupied
    tile. Both are preserved across _clear_highlights() and _build_board().
  • _update_hover(): called on every InputEventMouseMotion event. Moves the
    selector quad, shows the team-colour overlay when hovering an occupied tile,
    and boosts MeshInstance3D emission on the hovered unit via
    set_surface_override_material (reset when hover leaves).
  • All existing _highlight_tiles() / _add_highlight() callers updated from
    HI_* Color constants to type key strings.

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-23 06:50:00 -04:00
co-authored by Claude Happy
parent 9c44657deb
commit fe293f6bee
17 changed files with 1655 additions and 67 deletions
@@ -0,0 +1,209 @@
extends Node
## HighlightConfig autoload — fetches and caches tile highlight texture configuration.
##
## Usage:
## HighlightConfig.get_texture("movement") → Texture2D or null
## HighlightConfig.get_color("movement") → Color (parsed from fallbackHex)
## HighlightConfig.is_ready → bool
##
## Cosmetic overrides (via Settings.highlight_overrides or equipped HighlightPack):
## HighlightConfig.set_override("movement", { cdnPath=…, isAnimated=false, … })
## HighlightConfig.clear_override("movement")
## HighlightConfig.clear_all_overrides()
##
## Texture loading is async. Callers should handle null gracefully and fall back to
## get_color() when get_texture() returns null.
signal loaded
const CACHE_PATH := "user://highlight_config.json"
const REQUEST_TYPE := "content.get_highlight_config"
## Default fallback colours used when no server config exists.
const DEFAULT_HEX : Dictionary = {
"movement": "#33FF3366",
"attack": "#FF404080",
"ability": "#3380FF66",
"terramorpha": "#FF990073",
"selector": "#FFFFFF40",
}
## Whether the server config has been loaded (or the cache has been used).
var is_ready : bool = false
# ── Internal state ─────────────────────────────────────────────────────────────
# Server-provided configs keyed by lowercase type name.
# Each entry: { cdnPath, isAnimated, frameCount, fps, fallbackHex }
var _server_configs : Dictionary = {}
# Admin/cosmetic overrides — same structure, keyed by lowercase type name.
var _overrides : Dictionary = {}
# Loaded textures: type → Texture2D (null while loading or if failed).
var _textures : Dictionary = {}
# HTTP fetch nodes keyed by type (to avoid duplicate requests).
var _pending_fetches : Dictionary = {}
# ── Lifecycle ──────────────────────────────────────────────────────────────────
func _ready() -> void:
_load_cache()
_fetch_from_server()
# ── Public API ─────────────────────────────────────────────────────────────────
## Returns the loaded Texture2D for this highlight type, or null if not yet loaded.
## Starts loading the texture on first call if not already in progress.
func get_texture(type: String) -> Texture2D:
var key := type.to_lower()
if _textures.has(key):
return _textures[key]
# Start loading if we have a config for this type.
var cfg := _effective_config(key)
if not cfg.is_empty() and not cfg.get("cdnPath", "").is_empty():
_start_texture_load(key, cfg)
return null
## Returns the fallback Color for this highlight type.
func get_color(type: String) -> Color:
var key := type.to_lower()
var cfg := _effective_config(key)
var hex : String = cfg.get("fallbackHex", DEFAULT_HEX.get(key, "#FFFFFF66"))
return _parse_hex(hex)
## Override a highlight type with a custom config dict.
## Config keys: cdnPath (String), isAnimated (bool), frameCount (int), fps (float), fallbackHex (String).
func set_override(type: String, config: Dictionary) -> void:
var key := type.to_lower()
_overrides[key] = config
_textures.erase(key) # Invalidate cached texture so next get_texture() reloads.
_pending_fetches.erase(key)
## Remove override for one type.
func clear_override(type: String) -> void:
var key := type.to_lower()
_overrides.erase(key)
_textures.erase(key)
_pending_fetches.erase(key)
## Remove all cosmetic/settings overrides.
func clear_all_overrides() -> void:
_overrides.clear()
_textures.clear()
_pending_fetches.clear()
## Apply an equipped HighlightPack cosmetic (parsed from AssetCdnUrl JSON).
## pack_data: Dictionary keyed by lowercase type name, each value is a config dict.
func apply_cosmetic_pack(pack_data: Dictionary) -> void:
for key in pack_data:
set_override(str(key).to_lower(), pack_data[key] as Dictionary)
# ── Internal ───────────────────────────────────────────────────────────────────
func _effective_config(key: String) -> Dictionary:
if _overrides.has(key):
return _overrides[key] as Dictionary
if _server_configs.has(key):
return _server_configs[key] as Dictionary
return {}
func _fetch_from_server() -> void:
Network.request(
REQUEST_TYPE,
{},
func(_type: String, resp: Variant) -> void:
_on_server_response(resp),
func(_code: String, _msg: String) -> void:
# Use cached config if available; set is_ready anyway.
is_ready = true
loaded.emit()
)
func _on_server_response(resp: Variant) -> void:
var configs : Array = (resp as Dictionary).get("configs", [])
for entry : Dictionary in configs:
var key : String = str(entry.get("highlightType", "")).to_lower()
if key.is_empty():
continue
_server_configs[key] = {
"cdnPath": str(entry.get("cdnPath", "")),
"isAnimated": bool(entry.get("isAnimated", false)),
"frameCount": int(entry.get("frameCount", 1)),
"fps": float(entry.get("fps", 12.0)),
"fallbackHex": str(entry.get("fallbackHex", DEFAULT_HEX.get(key, "#FFFFFF66"))),
}
_save_cache()
is_ready = true
loaded.emit()
func _start_texture_load(key: String, cfg: Dictionary) -> void:
if _pending_fetches.has(key):
return
_pending_fetches[key] = true
var url : String = cfg.get("cdnPath", "")
if url.is_empty():
return
var http := HTTPRequest.new()
add_child(http)
http.request_completed.connect(
func(result: int, _code: int, _headers: PackedStringArray, body: PackedByteArray) -> void:
http.queue_free()
_pending_fetches.erase(key)
if result != HTTPRequest.RESULT_SUCCESS or body.is_empty():
return
var img := Image.new()
if img.load_png_from_buffer(body) != OK:
if img.load_webp_from_buffer(body) != OK:
return
var tex := ImageTexture.create_from_image(img)
_textures[key] = tex
)
http.request(url)
func _parse_hex(hex: String) -> Color:
var s := hex.strip_edges()
if s.begins_with("#"):
s = s.substr(1)
match s.length():
6: return Color(s.hex_to_int() << 8 | 0xFF) / float(0xFFFFFFFF)
8:
var v := s.hex_to_int()
var r := ((v >> 24) & 0xFF) / 255.0
var g := ((v >> 16) & 0xFF) / 255.0
var b := ((v >> 8) & 0xFF) / 255.0
var a := ( v & 0xFF) / 255.0
return Color(r, g, b, a)
return Color.WHITE
func _load_cache() -> void:
var f := FileAccess.open(CACHE_PATH, FileAccess.READ)
if f == null:
return
var text := f.get_as_text()
f.close()
var parsed := JSON.parse_string(text)
if parsed is Dictionary:
_server_configs = parsed as Dictionary
func _save_cache() -> void:
var f := FileAccess.open(CACHE_PATH, FileAccess.WRITE)
if f == null:
return
f.store_string(JSON.stringify(_server_configs))
f.close()
+52 -8
View File
@@ -9,10 +9,11 @@ extends Node
##
## Changing any property automatically applies it to the AudioServer and saves.
const SAVE_PATH := "user://settings.cfg"
const SECTION := "audio"
const SECTION_GAMEPLAY := "gameplay"
const SECTION_VISUAL := "visual"
const SAVE_PATH := "user://settings.cfg"
const SECTION := "audio"
const SECTION_GAMEPLAY := "gameplay"
const SECTION_VISUAL := "visual"
const SECTION_HIGHLIGHTS := "highlights"
## Audio bus names as configured in the Godot project.
const BUS_MUSIC := "Music"
@@ -65,6 +66,31 @@ var skybox_mode : String = "live" :
_save()
settings_changed.emit()
## Per-type highlight texture URL overrides entered by the player.
## Keys: "movement", "attack", "ability", "terramorpha", "selector"
## Value: URL string, or "" to use the server default.
var highlight_overrides : Dictionary = {} :
set(v):
highlight_overrides = v
_apply_highlight_overrides()
_save()
settings_changed.emit()
func set_highlight_override(type: String, url: String) -> void:
var key := type.to_lower()
if url.is_empty():
highlight_overrides.erase(key)
else:
highlight_overrides[key] = url
_apply_highlight_overrides()
_save()
settings_changed.emit()
func clear_highlight_override(type: String) -> void:
set_highlight_override(type.to_lower(), "")
# ── Lifecycle ─────────────────────────────────────────────────────────────────
func _ready() -> void:
@@ -82,6 +108,20 @@ func _apply_music() -> void:
AudioServer.set_bus_mute(idx, music_muted)
func _apply_highlight_overrides() -> void:
if not is_node_ready():
return
# Wait until HighlightConfig has initialised (it's an autoload, loaded after Settings).
if not Engine.has_singleton("HighlightConfig"):
return
HighlightConfig.clear_all_overrides()
for key in highlight_overrides:
var url : String = str(highlight_overrides[key])
if not url.is_empty():
HighlightConfig.set_override(key, { "cdnPath": url, "isAnimated": false,
"frameCount": 1, "fps": 12.0, "fallbackHex": "" })
func _apply_sfx() -> void:
var idx := AudioServer.get_bus_index(BUS_SFX)
if idx < 0:
@@ -98,8 +138,11 @@ func _load() -> void:
music_muted = bool(cfg.get_value(SECTION, "music_muted", false))
sfx_volume = float(cfg.get_value(SECTION, "sfx_volume", 1.0))
sfx_muted = bool(cfg.get_value(SECTION, "sfx_muted", false))
camera_follow_unit = bool(cfg.get_value(SECTION_GAMEPLAY, "camera_follow_unit", true))
skybox_mode = str(cfg.get_value(SECTION_VISUAL, "skybox_mode", "live"))
camera_follow_unit = bool(cfg.get_value(SECTION_GAMEPLAY, "camera_follow_unit", true))
skybox_mode = str(cfg.get_value(SECTION_VISUAL, "skybox_mode", "live"))
var raw_overrides = cfg.get_value(SECTION_HIGHLIGHTS, "highlight_overrides", {})
if raw_overrides is Dictionary:
highlight_overrides = raw_overrides as Dictionary
func _save() -> void:
@@ -108,6 +151,7 @@ func _save() -> void:
cfg.set_value(SECTION, "music_muted", music_muted)
cfg.set_value(SECTION, "sfx_volume", sfx_volume)
cfg.set_value(SECTION, "sfx_muted", sfx_muted)
cfg.set_value(SECTION_GAMEPLAY, "camera_follow_unit", camera_follow_unit)
cfg.set_value(SECTION_VISUAL, "skybox_mode", skybox_mode)
cfg.set_value(SECTION_GAMEPLAY, "camera_follow_unit", camera_follow_unit)
cfg.set_value(SECTION_VISUAL, "skybox_mode", skybox_mode)
cfg.set_value(SECTION_HIGHLIGHTS, "highlight_overrides", highlight_overrides)
cfg.save(SAVE_PATH)