Extend board template builder with hex SVG canvas + filter client by grid type

- Admin builder: SVG hex canvas renders when GridType=Hexagon (pointy-top hexagons, correct axial layout); square CSS grid otherwise
- Admin builder: ApplyHexSides / OnGridTypeChanged handle dimension/tile pruning; canvas header shows N/diameter for hex
- BoardTemplateDto now includes GridType and HexSides so clients can filter
- rules_editor_dialog: Board Width/Height/Shape hidden when hex selected; Hex Sides hidden when square; template picker filtered to matching grid type with live toggle

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-04-01 21:22:07 -04:00
co-authored by Claude Happy
parent a4badc276b
commit 0572aea4d2
4 changed files with 248 additions and 68 deletions
@@ -116,42 +116,72 @@ func _build_fields(r: Dictionary) -> void:
var cur_is_hex : bool = get_s.call("boardShape", "Default") == "Hexagon"
add_option.call("Grid Type", "_gridType", ["Square", "Hexagon"],
"Hexagon" if cur_is_hex else "Square")
add_int.call("Board Width", "boardWidth", 3, 12, 6, "")
add_int.call("Board Height", "boardHeight", 3, 12, 6, "")
add_int.call("Starting Tile Affinity %","startingRandomTilePct",0, 100, 0, "% of tiles with a random basic affinity")
add_option.call("Board Shape", "boardShape", ["Default", "Rectangle", "Cross", "Triangular", "RadialStar", "HexRing"], "Default")
add_int.call("Hex Sides", "hexSides", 3, 10, 5, "Hexagon only: tiles per side (3–10)")
var gt_opt := _controls["_gridType"] as OptionButton
# Board template picker — populate from BoardTemplateCache (GUID values, not labels).
var tmpl_key := "boardTemplateIdOverride"
var cur_tmpl_id : Variant = get_s.call(tmpl_key, "")
var custom_tmpls : Array = BoardTemplateCache.get_templates_for_custom()
# Square-only rows
add_int.call("Board Width", "boardWidth", 3, 12, 6, "")
var sq_width_row := fields_box.get_child(fields_box.get_child_count() - 1)
add_int.call("Board Height", "boardHeight", 3, 12, 6, "")
var sq_height_row := fields_box.get_child(fields_box.get_child_count() - 1)
add_int.call("Starting Tile Affinity %", "startingRandomTilePct", 0, 100, 0, "% of tiles with a random basic affinity")
add_option.call("Board Shape", "boardShape", ["Default", "Rectangle", "Cross", "Triangular", "RadialStar", "HexRing"], "Default")
var sq_shape_row := fields_box.get_child(fields_box.get_child_count() - 1)
# Hex-only rows
add_int.call("Hex Sides", "hexSides", 3, 10, 5, "Hexagon only: tiles per side (3–10)")
var hex_sides_row := fields_box.get_child(fields_box.get_child_count() - 1)
# Board template picker — filtered by current grid type.
var tmpl_key := "boardTemplateIdOverride"
var cur_tmpl_id : Variant = get_s.call(tmpl_key, "")
var all_custom_tmpls : Array = BoardTemplateCache.get_templates_for_custom()
var tmpl_hbox := HBoxContainer.new()
var tmpl_lbl := Label.new()
tmpl_lbl.text = "Board Template"
tmpl_lbl.tooltip_text = "Overrides the board layout with an admin-defined template. Ignores Board Shape when set."
tmpl_lbl.text = "Board Template"
tmpl_lbl.tooltip_text = "Overrides the board layout with an admin-defined template. Ignores Board Shape when set."
tmpl_lbl.size_flags_horizontal = Control.SIZE_EXPAND_FILL
tmpl_hbox.add_child(tmpl_lbl)
var tmpl_opt := OptionButton.new()
var tmpl_ids : Array[String] = []
tmpl_opt.add_item("— None —")
tmpl_ids.append("")
var tmpl_sel := 0
for i: int in range(custom_tmpls.size()):
var t := custom_tmpls[i] as Dictionary
var tid := str(t.get("id", ""))
var tname := str(t.get("name", tid.substr(0, 8)))
var tw := int(t.get("width", 0))
var th := int(t.get("height", 0))
tmpl_opt.add_item("%s (%d×%d)" % [tname, tw, th])
tmpl_ids.append(tid)
if tid == cur_tmpl_id:
tmpl_sel = i + 1
tmpl_opt.selected = tmpl_sel
tmpl_hbox.add_child(tmpl_opt)
fields_box.add_child(tmpl_hbox)
_controls[tmpl_key] = tmpl_opt
_option_ids[tmpl_key] = tmpl_ids
_option_ids[tmpl_key] = []
# Rebuilds template picker items to match the given grid type.
var _fill_tmpl := func(is_hex: bool) -> void:
var opt := _controls.get(tmpl_key) as OptionButton
if not is_instance_valid(opt):
return
var ids : Array[String] = []
opt.clear()
opt.add_item("— None —")
ids.append("")
var sel := 0
for t: Dictionary in all_custom_tmpls:
var t_is_hex := str(t.get("gridType", "Square")) == "Hexagon"
if t_is_hex != is_hex:
continue
var tid := str(t.get("id", ""))
var tname := str(t.get("name", tid.substr(0, min(8, tid.length()))))
var tw := int(t.get("width", 0))
var th := int(t.get("height", 0))
opt.add_item("%s (%d×%d)" % [tname, tw, th])
ids.append(tid)
if tid == cur_tmpl_id:
sel = ids.size() - 1
opt.selected = sel
_option_ids[tmpl_key] = ids
# Toggles visibility of grid-type-specific rows and refreshes the template picker.
var _update_board_vis := func(is_hex: bool) -> void:
sq_width_row.visible = not is_hex
sq_height_row.visible = not is_hex
sq_shape_row.visible = not is_hex
hex_sides_row.visible = is_hex
_fill_tmpl.call(is_hex)
_update_board_vis.call(cur_is_hex)
gt_opt.item_selected.connect(func(idx: int): _update_board_vis.call(idx == 1))
# ── Deck ───────────────────────────────────────────────────────────────────
_section("DECK")