[F8-08] Формат чисел: моноширинный, фикс. точность, выравнивание #51
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Подзадача полировки UI (этап F8), родительский #43.
Цель: Единый формат чисел: моноширинно, фиксированная точность, выравнивание по правому краю, без разделителей разрядов.
Пункты из #43:
Заметка. Общий util формата; точность: legacy 2 знака / game engine 3 знака после запятой (эталон —
tools/local-dev/reports/dg/KNNTS041.REP, секция Status of Players); п.25 — drive/weapons/shields/cargo это уровни технологий, не проценты, отображать as-is. Затрагивает inspector (п.17) и turn report (п.26/27) — один util на оба.Порядок обработки: F8-08 из 12. Создано в рамках #43; зонтичный issue остаётся открытым до закрытия всех подзадач.
Working log (issue-agent) — click to expand
State: blocked
Updated: 2026-05-26 (UTC)
Branch / PR: —
Confirmed:
Player.{drive,weapons,shields,cargo}come fromr.TechLevel(...)(game/internal/controller/report.go:67-70) — they are tech LEVELS (e.g., 4.51), not fractions. Same fields render inlib/active-view/report/section-player-status.svelte:76-79ANDlib/active-view/table-races.svelte:270-277throughformatPercent→ multiplied by 100. Sciences (Science/OtherScience) ARE fractions in[0,1]summing to 1 —formatPercentis correct there.formatNumber(planetlib/inspectors/planet.svelte:106, ship-grouplib/inspectors/ship-group.svelte:85, ship-groupslib/inspectors/planet/ship-groups.svelte:93, ship-group/actionslib/inspectors/ship-group/actions.svelte:678) all usetoLocaleString({maximumFractionDigits:2})— locale separators + varying width.lib/active-view/report/format.ts(formatFloat= 0–2 dec w/ separators;formatCount= 0 dec w/ separators;formatVotes= 0–2 dec;formatPercent= ×100 + 1 dec).FloatwithFixed3quantisation (pkg/model/report/report.go:11-15); legacy text reports undertools/local-dev/reports/dg/*.REPhave 2 decimals (e.g.,KNNTS041.REPStatus of Players).planets:uint16, shipcount:uint64) — 0 decimals.(${x}, ${y})— drop parens; field labelsindustry stockpile ($)/materials stockpile (M)(en.ts:252-253, ru.ts:253-254) — drop the word "stockpile".--font-monoinlib/theme/tokens.css:39.tests/inspector-planet.test.ts:88-90asserts"(100.25, 200)"literally — needs update to the unparenthesized 3-decimal form; othertoHaveTextContent("500")style assertions stay valid because they're substrings of"500.000".Open question: Posted to the owner (RU): (1) scope — fix
table-races.sveltein the same diff or treat as a follow-up? (2) sciences — keep at 1-dec percent (recommendation), or push them through the new 3-decimal level format too?Decisions: (pending owner reply) Util to live at
ui/frontend/src/lib/util/number-format.ts; the existingreport/format.tswill become a thin re-export to keep the report imports compact. CSS: switch inspectorddand report.grid tdtofont-family: var(--font-mono)plustext-align: rightfor numeric cells.Next: Wait for owner answers to the scope/sciences fork, then branch
feature/issue-51-number-format, implement, update i18n + tests, open PR todevelopmentrequestingowneras reviewer.@owner — пара вопросов перед тем, как браться за код. ✦
Закопалась в данные:
Player.{drive,weapons,shields,cargo}идут из движка как уровни технологий (r.TechLevel(...)вgame/internal/controller/report.go:67-70), а в UI везде, где они показываются, прогоняются черезformatPercent(× 100). Это и есть баг п.25 в секции turn report → player status. Точно тот же баг есть в активной view «расы» (ui/frontend/src/lib/active-view/table-races.svelte:270-277): там тожеformatPercent(r.drive)+ заголовок «drive %». После фикса player status покажет «drive: 4.510», а Races продолжит показывать «drive %: 451.0».1. Чинить ли заодно
table-races.svelteв этом же PR? Объём — те же 4 поля + правка i18n-заголовков (убрать «%»). Pro: данные не разойдутся между экранами; общий util ровно для этого и заводим. Con: формально вне scope F8-08 (issue прямо называет inspector + turn report). Я бы починила здесь — но за тобой решение.2. Точность для наук. Формулы наук (
Science/OtherScience) — это пропорции в[0,1], сумма = 1.0. СейчасformatPercent→ «15.0» при 0.15, заголовок «drive %». Это семантически процент формулы, не уровень технологии. Моё предложение — оставить науки как 1-знаковый процент, чинить только уровни. Ок?Чтобы не ждать ответа по мелочам, остальное сделаю по своему чтению:
)» → «industry ()», «materials stockpile (M)» → «materials (M)».«x, y»без скобок.FloatчерезFixed3): 3 знака после точки, без разделителей разрядов, моноширинно (--font-mono). Целочисленные счётчики (planet count, shipcount) — как есть, без дробной части.ui/frontend/src/lib/util/number-format.ts,lib/active-view/report/format.tsоставлю тонким re-export, чтобы сохранить минимальный diff в секциях.text-align: rightдля числовых колонок иfont-family: var(--font-mono).По ответам — пойду открывать PR.