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