testing slot
This commit is contained in:
parent
ac9a0389d1
commit
b384d65e80
|
|
@ -401,7 +401,9 @@ class _SlotMachineDrawAnimationState extends State<SlotMachineDrawAnimation>
|
|||
bool _isAnimating = false;
|
||||
bool _isComplete = false;
|
||||
String? _winnerId;
|
||||
final List<String> _baseNames = [];
|
||||
List<String> _displayNames = [];
|
||||
int _currentIndex = 0;
|
||||
Timer? _slotTimer;
|
||||
|
||||
@override
|
||||
|
|
@ -434,8 +436,7 @@ class _SlotMachineDrawAnimationState extends State<SlotMachineDrawAnimation>
|
|||
curve: Curves.easeInOut,
|
||||
));
|
||||
|
||||
// Prepare display names
|
||||
_displayNames = widget.members.map((m) => m['name']?.toString() ?? 'Unknown').toList();
|
||||
_prepareDisplayNames();
|
||||
|
||||
// Auto-start after delay
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
|
|
@ -451,6 +452,50 @@ class _SlotMachineDrawAnimationState extends State<SlotMachineDrawAnimation>
|
|||
super.dispose();
|
||||
}
|
||||
|
||||
void _prepareDisplayNames() {
|
||||
_baseNames.clear();
|
||||
_baseNames.addAll(
|
||||
widget.members.map((m) => m['name']?.toString() ?? 'Unknown'),
|
||||
);
|
||||
|
||||
if (_baseNames.isEmpty) {
|
||||
_baseNames.add('Unknown');
|
||||
}
|
||||
|
||||
// Ensure we have at least 7 entries to fill the slot windows
|
||||
if (_baseNames.length < 7) {
|
||||
final original = List<String>.from(_baseNames);
|
||||
while (_baseNames.length < 7) {
|
||||
_baseNames.addAll(original);
|
||||
}
|
||||
}
|
||||
|
||||
_shuffleBaseNames();
|
||||
_currentIndex = 0;
|
||||
_updateDisplayWindow();
|
||||
}
|
||||
|
||||
void _shuffleBaseNames() {
|
||||
final seedSource = DateTime.now().millisecondsSinceEpoch.toString();
|
||||
final hash = _generateHash(seedSource);
|
||||
final randomValue = _hashToNumber(hash);
|
||||
final random = math.Random(randomValue);
|
||||
|
||||
for (var i = _baseNames.length - 1; i > 0; i--) {
|
||||
final j = random.nextInt(i + 1);
|
||||
final temp = _baseNames[i];
|
||||
_baseNames[i] = _baseNames[j];
|
||||
_baseNames[j] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
void _updateDisplayWindow() {
|
||||
_displayNames = List.generate(
|
||||
7,
|
||||
(index) => _baseNames[(_currentIndex + index) % _baseNames.length],
|
||||
);
|
||||
}
|
||||
|
||||
void _startAnimation() {
|
||||
if (_isAnimating) return;
|
||||
|
||||
|
|
@ -488,8 +533,8 @@ class _SlotMachineDrawAnimationState extends State<SlotMachineDrawAnimation>
|
|||
}
|
||||
|
||||
setState(() {
|
||||
// Shuffle the display names for effect
|
||||
_displayNames.shuffle();
|
||||
_currentIndex = (_currentIndex + 1) % _baseNames.length;
|
||||
_updateDisplayWindow();
|
||||
});
|
||||
|
||||
_slotController.forward().then((_) {
|
||||
|
|
@ -512,7 +557,8 @@ class _SlotMachineDrawAnimationState extends State<SlotMachineDrawAnimation>
|
|||
}
|
||||
|
||||
setState(() {
|
||||
_displayNames.shuffle();
|
||||
_currentIndex = (_currentIndex + 1) % _baseNames.length;
|
||||
_updateDisplayWindow();
|
||||
});
|
||||
|
||||
_slotController.forward().then((_) {
|
||||
|
|
@ -528,20 +574,23 @@ class _SlotMachineDrawAnimationState extends State<SlotMachineDrawAnimation>
|
|||
|
||||
void _completeAnimation() {
|
||||
final winnerName = widget.members.firstWhere((m) => m['id'] == _winnerId)['name'];
|
||||
final winnerIndex = _baseNames.indexOf(winnerName);
|
||||
|
||||
setState(() {
|
||||
_isAnimating = false;
|
||||
_isComplete = true;
|
||||
// Show winner in center position (index 3) with padding names for 7 slots
|
||||
_displayNames = [
|
||||
_displayNames.isNotEmpty ? _displayNames[0] : '',
|
||||
_displayNames.length > 1 ? _displayNames[1] : '',
|
||||
_displayNames.length > 2 ? _displayNames[2] : '',
|
||||
winnerName, // Center (index 3) - the winner!
|
||||
_displayNames.length > 4 ? _displayNames[4] : '',
|
||||
_displayNames.length > 5 ? _displayNames[5] : '',
|
||||
_displayNames.length > 6 ? _displayNames[6] : '',
|
||||
];
|
||||
if (winnerIndex != -1) {
|
||||
final List<String> window = [];
|
||||
for (int offset = -3; offset <= 3; offset++) {
|
||||
final index = (winnerIndex + offset) % _baseNames.length;
|
||||
final adjustedIndex = index < 0 ? index + _baseNames.length : index;
|
||||
window.add(_baseNames[adjustedIndex]);
|
||||
}
|
||||
_displayNames = window;
|
||||
} else {
|
||||
_displayNames = List.filled(7, '', growable: false);
|
||||
_displayNames[3] = winnerName;
|
||||
}
|
||||
});
|
||||
|
||||
_pulseController.stop();
|
||||
|
|
|
|||
Loading…
Reference in New Issue