Add modular story library and shared-progress translations
This commit is contained in:
+136
-128
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../domain/puzzle.dart';
|
||||
import 'paper.dart';
|
||||
import 'translation.dart';
|
||||
|
||||
class Board extends StatelessWidget {
|
||||
const Board({
|
||||
@@ -25,149 +26,155 @@ class Board extends StatelessWidget {
|
||||
final double maxWidth;
|
||||
@override
|
||||
Widget build(BuildContext context) => PageSwipeBlocker(
|
||||
child: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: maxWidth),
|
||||
child: AspectRatio(
|
||||
aspectRatio: 1,
|
||||
child: LayoutBuilder(
|
||||
builder: (context, c) {
|
||||
final n = puzzle.size,
|
||||
u = c.maxWidth / (n + 1.3),
|
||||
r = puzzle.regions.isEmpty
|
||||
? null
|
||||
: puzzle.regions[selectedArea];
|
||||
Widget clue(String text, bool complete) => SizedBox(
|
||||
width: u,
|
||||
height: u,
|
||||
child: Center(
|
||||
child: Text(
|
||||
text,
|
||||
style: hand(
|
||||
(u * .42).clamp(16, 23),
|
||||
color: complete ? blue : muted,
|
||||
child: Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: maxWidth),
|
||||
child: AspectRatio(
|
||||
aspectRatio: 1,
|
||||
child: LayoutBuilder(
|
||||
builder: (context, c) {
|
||||
final n = puzzle.size,
|
||||
u = c.maxWidth / (n + 1.3),
|
||||
r = puzzle.regions.isEmpty
|
||||
? null
|
||||
: puzzle.regions[selectedArea];
|
||||
Widget clue(String text, bool complete) => SizedBox(
|
||||
width: u,
|
||||
height: u,
|
||||
child: Center(
|
||||
child: Text(
|
||||
text,
|
||||
style: hand(
|
||||
(u * .42).clamp(16, 23),
|
||||
color: complete ? blue : muted,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
bool complete(Iterable<int> indices, int total) =>
|
||||
indices.where((i) => cells[i] == 1).length == total;
|
||||
return Align(
|
||||
alignment: Alignment.center,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(width: u, height: u),
|
||||
for (var col = 0; col < n; col++)
|
||||
clue(
|
||||
'${puzzle.cols[col]}',
|
||||
complete(
|
||||
List.generate(n, (i) => i * n + col),
|
||||
puzzle.cols[col],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
for (var row = 0; row < n; row++)
|
||||
);
|
||||
bool complete(Iterable<int> indices, int total) =>
|
||||
indices.where((i) => cells[i] == 1).length == total;
|
||||
return Align(
|
||||
alignment: Alignment.center,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
clue(
|
||||
'${puzzle.rows[row]}',
|
||||
complete(
|
||||
List.generate(n, (i) => row * n + i),
|
||||
puzzle.rows[row],
|
||||
),
|
||||
),
|
||||
SizedBox(width: u, height: u),
|
||||
for (var col = 0; col < n; col++)
|
||||
Builder(
|
||||
builder: (context) {
|
||||
final i = row * n + col,
|
||||
value = cells[i],
|
||||
fixed = puzzle.given[i],
|
||||
inside = r?.contains(i, n) ?? false;
|
||||
final state = value == 0
|
||||
? 'empty'
|
||||
: value == 1
|
||||
? 'lit'
|
||||
: 'crossed out';
|
||||
return Semantics(
|
||||
label:
|
||||
clue(
|
||||
'${puzzle.cols[col]}',
|
||||
complete(
|
||||
List.generate(n, (i) => i * n + col),
|
||||
puzzle.cols[col],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
for (var row = 0; row < n; row++)
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
clue(
|
||||
'${puzzle.rows[row]}',
|
||||
complete(
|
||||
List.generate(n, (i) => row * n + i),
|
||||
puzzle.rows[row],
|
||||
),
|
||||
),
|
||||
for (var col = 0; col < n; col++)
|
||||
Builder(
|
||||
builder: (context) {
|
||||
final i = row * n + col,
|
||||
value = cells[i],
|
||||
fixed = puzzle.given[i],
|
||||
inside = r?.contains(i, n) ?? false;
|
||||
final state = value == 0
|
||||
? 'empty'
|
||||
: value == 1
|
||||
? 'lit'
|
||||
: 'crossed out';
|
||||
return Semantics(
|
||||
label: CopyScope.text(
|
||||
context,
|
||||
'Row ${row + 1}, column ${col + 1}, $state${fixed ? ', fixed clue' : ''}',
|
||||
button: !fixed && !won,
|
||||
enabled: !fixed && !won,
|
||||
onTap: fixed || won ? null : () => onMark(i),
|
||||
excludeSemantics: true,
|
||||
child: GestureDetector(
|
||||
key: ValueKey('cell-$i'),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
),
|
||||
button: !fixed && !won,
|
||||
enabled: !fixed && !won,
|
||||
onTap: fixed || won
|
||||
? null
|
||||
: () => onMark(i),
|
||||
child: SizedBox(
|
||||
width: u,
|
||||
height: u,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(2),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: inside
|
||||
? amber.withValues(alpha: .22)
|
||||
: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(
|
||||
2,
|
||||
),
|
||||
border: Border.all(
|
||||
excludeSemantics: true,
|
||||
child: GestureDetector(
|
||||
key: ValueKey('cell-$i'),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: fixed || won
|
||||
? null
|
||||
: () => onMark(i),
|
||||
child: SizedBox(
|
||||
width: u,
|
||||
height: u,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(2),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: inside
|
||||
? const Color(0xffaa5b2a)
|
||||
: muted.withValues(
|
||||
alpha: .48,
|
||||
),
|
||||
width: inside ? 1.4 : .65,
|
||||
? amber.withValues(alpha: .22)
|
||||
: Colors.transparent,
|
||||
borderRadius:
|
||||
BorderRadius.circular(2),
|
||||
border: Border.all(
|
||||
color: inside
|
||||
? const Color(0xffaa5b2a)
|
||||
: muted.withValues(
|
||||
alpha: .48,
|
||||
),
|
||||
width: inside ? 1.4 : .65,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
if (value != 0)
|
||||
Positioned.fill(
|
||||
child: CustomPaint(
|
||||
painter: PencilMark(
|
||||
value: value,
|
||||
variation: i,
|
||||
child: Stack(
|
||||
children: [
|
||||
if (value != 0)
|
||||
Positioned.fill(
|
||||
child: CustomPaint(
|
||||
painter: PencilMark(
|
||||
value: value,
|
||||
variation: i,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (fixed)
|
||||
Positioned(
|
||||
right: 3,
|
||||
bottom: 3,
|
||||
child: Container(
|
||||
width: 4,
|
||||
height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: muted,
|
||||
shape: BoxShape.circle,
|
||||
if (fixed)
|
||||
Positioned(
|
||||
right: 3,
|
||||
bottom: 3,
|
||||
child: Container(
|
||||
width: 4,
|
||||
height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: muted,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -265,7 +272,7 @@ class PixelPicture extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) => Semantics(
|
||||
image: true,
|
||||
label: 'Recovered pixel picture: $label',
|
||||
label: CopyScope.text(context, 'Recovered pixel picture: $label'),
|
||||
child: Center(
|
||||
child: SizedBox(
|
||||
width: height,
|
||||
@@ -307,7 +314,7 @@ class PatternStamp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) => Semantics(
|
||||
image: true,
|
||||
label: 'Your restored seven by seven pattern: $label',
|
||||
label: CopyScope.text(context, 'Your restored pattern: $label'),
|
||||
child: SizedBox.square(
|
||||
dimension: height,
|
||||
child: CustomPaint(painter: _Pixels(picture)),
|
||||
@@ -320,10 +327,11 @@ class _Pixels extends CustomPainter {
|
||||
final List<int> picture;
|
||||
@override
|
||||
void paint(Canvas c, Size s) {
|
||||
final p = Paint()..color = blue, u = s.width / 7;
|
||||
for (var i = 0; i < 49; i++) {
|
||||
final n = math.sqrt(picture.length).round();
|
||||
final p = Paint()..color = blue, u = s.width / n;
|
||||
for (var i = 0; i < picture.length; i++) {
|
||||
if (picture[i] == 1) {
|
||||
c.drawRect(Rect.fromLTWH(i % 7 * u, i ~/ 7 * u, u + .3, u + .3), p);
|
||||
c.drawRect(Rect.fromLTWH(i % n * u, i ~/ n * u, u + .3, u + .3), p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user