Fix advisor craft count when skill is already ready to level up.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-22 15:48:34 +02:00
parent 43751ac7de
commit abdeab59e7
3 changed files with 11 additions and 5 deletions
+2 -2
View File
@@ -38,8 +38,8 @@ def missing_materials(
def crafts_to_next_level(xp_remaining: int, xp_per_item: float) -> int:
if xp_remaining <= 0 or xp_per_item <= 0:
return 1
return max(1, int((xp_remaining + xp_per_item - 1) // xp_per_item))
return 0
return int((xp_remaining + xp_per_item - 1) // xp_per_item)
def advise_skill(
+7 -3
View File
@@ -804,8 +804,11 @@ function renderSkillAdvisorCard() {
const eta = rec.eta_minutes_to_level > 0
? t("skills.advisorEta", { minutes: fmt(rec.eta_minutes_to_level) })
: "—";
const crafts = rec.crafts_to_next_level || 1;
const crafts = rec.crafts_to_next_level ?? 0;
const goalLabel = t("skills.advisorAdoptGoalFor", { name: rec.display_name, count: fmt(crafts) });
const goalCell = crafts > 0
? `<button type="button" class="goal-add-btn skill-advisor-goal-btn" data-activity-key="${esc(rec.activity_key)}" data-crafts="${crafts}" title="${esc(goalLabel)}" aria-label="${esc(goalLabel)}">+</button>`
: `<span class="inv-spark-empty">—</span>`;
return `<tr>
<td>${esc(rec.display_name)}</td>
<td class="num">${rec.xp_per_minute.toFixed(1)}</td>
@@ -813,7 +816,7 @@ function renderSkillAdvisorCard() {
<td class="skill-advisor-mats">${esc(mats)}</td>
<td class="num">${esc(eta)}</td>
<td class="col-actions">
<button type="button" class="goal-add-btn skill-advisor-goal-btn" data-activity-key="${esc(rec.activity_key)}" data-crafts="${crafts}" title="${esc(goalLabel)}" aria-label="${esc(goalLabel)}">+</button>
${goalCell}
</td>
</tr>`;
}).join("");
@@ -878,7 +881,8 @@ async function adoptAdvisorItemGoal(activityKey, crafts) {
if (!adv?.supported || !activityKey) return;
const rec = adv.recommendations?.find((r) => r.activity_key === activityKey);
const name = rec?.display_name || activityKey.replace(/_/g, " ");
const count = crafts > 0 ? crafts : 1;
const count = Number(crafts);
if (!count || count <= 0) return;
const res = await fetch(`${apiBase()}/goals`, {
method: "POST",
headers: { "Content-Type": "application/json" },
+2
View File
@@ -41,6 +41,8 @@ class AdvisorTests(unittest.TestCase):
def test_crafts_to_next_level(self) -> None:
self.assertEqual(crafts_to_next_level(100, 12.5), 8)
self.assertEqual(crafts_to_next_level(0, 12.5), 0)
self.assertEqual(crafts_to_next_level(10, 0), 0)
def test_item_goal_from_recipe_not_in_inventory(self) -> None:
from db import create_goal, get_connection, import_save, init_db