fix(player): 放慢随机飘心并验证完整时长
This commit is contained in:
1 parent
f3dd4a9b5c
commit
e7afd316f8
2 files changed
+64
-7
No files matched your search
@@ -18,6 +18,7 @@ class PlayerDoubleTapHeartBurst extends StatefulWidget {
|
||||
|
||||
static const int minParticleCount = 4;
|
||||
static const int maxParticleCount = 5;
|
||||
static const int minimumBurstDurationMs = 2000;
|
||||
|
||||
final int burstId;
|
||||
final VoidCallback onCompleted;
|
||||
@@ -60,11 +61,11 @@ class _PlayerDoubleTapHeartBurstState extends State<PlayerDoubleTapHeartBurst>
|
||||
1,
|
||||
),
|
||||
(index) {
|
||||
if (index > 0) delay += 40 + random.nextInt(21);
|
||||
if (index > 0) delay += 80 + random.nextInt(41);
|
||||
return _HeartParticle(
|
||||
delay: delay,
|
||||
duration: 900 + random.nextInt(201),
|
||||
travel: 120 + random.nextInt(41),
|
||||
duration: 1500 + random.nextInt(301),
|
||||
travel: 100 + random.nextInt(31),
|
||||
drift: -30 + random.nextInt(61),
|
||||
size: (22 + random.nextInt(13)).toDouble(),
|
||||
color: random.nextBool()
|
||||
@@ -73,9 +74,22 @@ class _PlayerDoubleTapHeartBurstState extends State<PlayerDoubleTapHeartBurst>
|
||||
);
|
||||
},
|
||||
);
|
||||
final total = _particles
|
||||
var total = _particles
|
||||
.map((particle) => particle.delay + particle.duration)
|
||||
.reduce(max);
|
||||
if (total < PlayerDoubleTapHeartBurst.minimumBurstDurationMs) {
|
||||
final last = _particles.last;
|
||||
final requiredDuration =
|
||||
PlayerDoubleTapHeartBurst.minimumBurstDurationMs - last.delay;
|
||||
final adjustedDuration = max(
|
||||
last.duration,
|
||||
requiredDuration,
|
||||
).clamp(1500, 1800).toInt();
|
||||
_particles[_particles.length - 1] = last.withDuration(adjustedDuration);
|
||||
total = _particles
|
||||
.map((particle) => particle.delay + particle.duration)
|
||||
.reduce(max);
|
||||
}
|
||||
if (kDebugMode) {
|
||||
debugPrint('[player] phase=heart-burst-init id=${widget.burstId}');
|
||||
debugPrint(
|
||||
@@ -97,7 +111,7 @@ class _PlayerDoubleTapHeartBurstState extends State<PlayerDoubleTapHeartBurst>
|
||||
final elapsedMs = _controller.duration?.inMilliseconds ?? 0;
|
||||
debugPrint(
|
||||
'[player] phase=heart-burst-complete '
|
||||
'id=${widget.burstId} elapsedMs=$elapsedMs',
|
||||
'id=${widget.burstId} configuredMs=$elapsedMs',
|
||||
);
|
||||
}
|
||||
widget.onCompleted();
|
||||
@@ -106,9 +120,12 @@ class _PlayerDoubleTapHeartBurstState extends State<PlayerDoubleTapHeartBurst>
|
||||
@override
|
||||
void dispose() {
|
||||
if (kDebugMode) {
|
||||
final elapsedMs = _completed
|
||||
? _controller.duration?.inMilliseconds ?? 0
|
||||
: _lifetime.elapsedMilliseconds;
|
||||
debugPrint(
|
||||
'[player] phase=heart-burst-dispose '
|
||||
'id=${widget.burstId} elapsedMs=${_lifetime.elapsedMilliseconds} '
|
||||
'id=${widget.burstId} elapsedMs=$elapsedMs '
|
||||
'completed=${_completed ? 1 : 0}',
|
||||
);
|
||||
}
|
||||
@@ -184,4 +201,15 @@ class _HeartParticle {
|
||||
final int drift;
|
||||
final double size;
|
||||
final Color color;
|
||||
|
||||
_HeartParticle withDuration(int nextDuration) {
|
||||
return _HeartParticle(
|
||||
delay: delay,
|
||||
duration: nextDuration,
|
||||
travel: travel,
|
||||
drift: drift,
|
||||
size: size,
|
||||
color: color,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user