feat: replace ENABLE_SMART_LANDS env var with per-build checkbox in New Deck modal (#64)

This commit is contained in:
mwisnowski 2026-03-25 22:08:25 -07:00 committed by GitHub
parent 94765622ba
commit b808f411ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 1209 additions and 5046 deletions

View file

@ -10,8 +10,8 @@ from .. import builder_utils as bu
"""Phase 2 (pre-step): Smart land base analysis (Roadmap 14, M1).
LandAnalysisMixin.run_land_analysis() is called from run_deck_build_step2()
AFTER ideal_counts defaults are seeded, so ENABLE_SMART_LANDS, LAND_PROFILE,
and LAND_COUNT env overrides win over the calculated values.
AFTER ideal_counts defaults are seeded, so LAND_PROFILE and LAND_COUNT env
overrides win over the calculated values.
Responsibilities:
- compute_pip_density(): delegate to builder_utils
@ -38,9 +38,10 @@ class LandAnalysisMixin:
self._land_report_data dict persisted for M3 diagnostics export
Mutates:
self.ideal_counts['lands'] and self.ideal_counts['basic_lands']
(only when ENABLE_SMART_LANDS=1; env overrides honoured after)
(only when enable_smart_lands is True on the builder; LAND_PROFILE/LAND_COUNT env overrides honoured after)
"""
if not os.environ.get('ENABLE_SMART_LANDS'):
# Per-build toggle from UI checkbox (defaults True = opted in)
if not getattr(self, 'enable_smart_lands', True):
return
try:

View file

@ -126,6 +126,7 @@ async def build_new_modal(request: Request) -> HTMLResponse:
"use_owned_only": bool(sess.get("use_owned_only")),
"prefer_owned": bool(sess.get("prefer_owned")),
"swap_mdfc_basics": bool(sess.get("swap_mdfc_basics")),
"enable_smart_lands": bool(sess.get("enable_smart_lands", True)),
# Add ideal values from session (will be None on first load, triggering defaults)
"ramp": sess.get("ideals", {}).get("ramp"),
"lands": sess.get("ideals", {}).get("lands"),
@ -417,6 +418,7 @@ async def build_new_submit(
use_owned_only: bool = Form(False),
prefer_owned: bool = Form(False),
swap_mdfc_basics: bool = Form(False),
enable_smart_lands: bool = Form(False),
# Integrated Multi-Copy (optional)
multi_choice_id: str | None = Form(None),
multi_count: int | None = Form(None),
@ -472,6 +474,7 @@ async def build_new_submit(
"use_owned_only": bool(use_owned_only),
"prefer_owned": bool(prefer_owned),
"swap_mdfc_basics": bool(swap_mdfc_basics),
"enable_smart_lands": bool(enable_smart_lands),
"include_cards": include_cards or "",
"exclude_cards": exclude_cards or "",
"enforcement_mode": enforcement_mode or "warn",
@ -819,6 +822,10 @@ async def build_new_submit(
sess["swap_mdfc_basics"] = bool(swap_mdfc_basics)
except Exception:
sess["swap_mdfc_basics"] = False
try:
sess["enable_smart_lands"] = bool(enable_smart_lands)
except Exception:
sess["enable_smart_lands"] = True
# Combos config from modal
try:
if combo_count is not None:

View file

@ -185,6 +185,7 @@ def start_ctx_from_session(sess: dict, *, set_on_session: bool = True) -> Dict[s
include_cards=sess.get("include_cards"),
exclude_cards=sess.get("exclude_cards"),
swap_mdfc_basics=bool(sess.get("swap_mdfc_basics")),
enable_smart_lands=bool(sess.get("enable_smart_lands", True)),
partner_feature_enabled=partner_enabled,
secondary_commander=secondary_commander,
background_commander=background_choice,

View file

@ -2516,6 +2516,7 @@ def start_build_ctx(
include_cards: List[str] | None = None,
exclude_cards: List[str] | None = None,
swap_mdfc_basics: bool | None = None,
enable_smart_lands: bool | None = None,
partner_feature_enabled: bool | None = None,
secondary_commander: str | None = None,
background_commander: str | None = None,
@ -2682,6 +2683,8 @@ def start_build_ctx(
pass
# Smart land analysis — mirrors run_deck_build_step2() so web builds get profiles too
try:
if enable_smart_lands is not None:
b.enable_smart_lands = bool(enable_smart_lands)
b.run_land_analysis()
except Exception:
pass

View file

@ -104,6 +104,10 @@
<input type="checkbox" name="swap_mdfc_basics" id="swap-mdfc-chk" value="1" {% if form and form.swap_mdfc_basics %}checked{% endif %} />
<span>Swap basics for MDFC lands</span>
</label>
<label for="smart-lands-chk" class="form-checkbox-label" title="When enabled, the builder automatically adjusts the land count and mana-base profile based on your commander's speed and color complexity.">
<input type="checkbox" name="enable_smart_lands" id="smart-lands-chk" value="1" {% if form and form.enable_smart_lands %}checked{% endif %} />
<span>Smart Land Bases</span>
</label>
</div>
</div>
</div>