UI fixes and league

This commit is contained in:
Jan Pleterski
2026-11-28 12:22:02 +01:00
parent 2fc741a9f6
commit 258303deb8
118 changed files with 1439 additions and 537 deletions
+19 -4
View File
@@ -2,7 +2,7 @@ import 'dart:math';
import 'dart:ui';
/// The one scoring rule for a shot, in the 1200 × 1200 space every target
/// design shares (target-designs/v3: centre 600/600, ring 1 at r 510, the
/// design shares (target-designs/v5: centre 600/600, ring 1 at r 510, the
/// black at r 180). Saving, the preview and the target view all use it, so a
/// shot scores the same everywhere and on every design.
///
@@ -17,6 +17,16 @@ class TargetScoring {
static const double bulletRadius = 25;
static const double bulletDiameter = 53; // drawn size of a hit
// Where a hit's centre may be drawn: the 1200 square, less the dot's
// radius and a little air. Outside ring 1 a miss simply lies on the screen
// background, where it landed
static const double _hitInset = bulletDiameter / 2 + 2; // 28.5
/// [p] if its whole dot is inside the target's square, otherwise the
/// nearest place that is (only for shots that landed far off; still 0).
static Offset shown(Offset p) =>
Offset(p.dx.clamp(_hitInset, size - _hitInset), p.dy.clamp(_hitInset, size - _hitInset));
/// Outer edge of ring 10, 9, ... 1, measured from [center].
///
/// A shot touching a ring line counts the higher value, so each edge is the
@@ -50,15 +60,20 @@ class TargetScoring {
/// Where to draw a shot that was scored by hand, in direction [angle]
/// (radians): the middle of the band of positions [scoreAt] gives [score]
/// for, so the dot always scores what was entered.
/// for, so the dot always scores what was entered. A 0 goes towards the
/// corner nearest to [angle], clear of ring 1's decoration.
static Offset positionFor(int score, double angle) {
final s = score.clamp(0, 10);
if (s == 0) {
// Nearest diagonal, keeping a little of the angle so 0s don't stack
final diagonal = ((angle - pi / 4) / (pi / 2)).round() * (pi / 2) + pi / 4;
final a = diagonal + (angle - diagonal) * 0.3;
return shown(center + Offset(cos(a), sin(a)) * 700);
}
// Distance of the bullet's edge from the centre, middle of the band
final double edge;
if (s == 10) {
edge = (-bulletRadius + rings[0]) / 2; // bullet over the centre
} else if (s == 0) {
edge = rings.last + 30; // just outside the target
} else {
edge = (rings[9 - s] + rings[10 - s]) / 2;
}