Skip to content

Commit 0e58da5

Browse files
Merge branch 'development' into issue1206
2 parents 0075bcc + 5d5f41a commit 0e58da5

14 files changed

+267
-162
lines changed
-34.5 KB
Loading

assets/animations/ic_anim_picture.gif

-70 KB
Loading
118 KB
Loading

lib/bademagic_module/models/messages.dart

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,25 @@ class Message {
77
final bool marquee;
88
final Speed speed;
99
final Mode mode;
10+
final int? animationIndex; // 👈 NEW
1011

1112
Message({
1213
required this.text,
1314
this.flash = false,
1415
this.marquee = false,
15-
this.speed = Speed.one, // Default speed
16-
this.mode = Mode.left, // Default mode
16+
this.speed = Speed.one,
17+
this.mode = Mode.left,
18+
this.animationIndex, // 👈 NEW
1719
});
1820

1921
// Convert Message object to JSON
2022
Map<String, dynamic> toJson() => {
2123
'text': text,
2224
'flash': flash,
2325
'marquee': marquee,
24-
'speed': speed.hexValue, // Use hexValue for serialization
25-
'mode': mode.hexValue, // Use hexValue for serialization
26+
'speed': speed.hexValue,
27+
'mode': mode.hexValue,
28+
if (animationIndex != null) 'animationIndex': animationIndex, // 👈 NEW
2629
};
2730

2831
// Convert JSON to Message object
@@ -52,10 +55,9 @@ class Message {
5255
text: List<String>.from(textList),
5356
flash: (json['flash'] as bool?) ?? false,
5457
marquee: (json['marquee'] as bool?) ?? false,
55-
speed: Speed.fromHex(
56-
json['speed'] as String), // Using helper method for safety
57-
mode: Mode.fromHex(
58-
json['mode'] as String), // Using helper method for safety
58+
speed: Speed.fromHex(json['speed'] as String),
59+
mode: Mode.fromHex(json['mode'] as String),
60+
animationIndex: json['animationIndex'] as int?, // 👈 NEW
5961
);
6062
}
6163
}

lib/bademagic_module/models/mode.dart

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,27 @@ enum Mode {
44
up('0x02'),
55
down('0x03'),
66
fixed('0x04'),
7-
snowflake('0x05'),
8-
picture('0x06'),
9-
animation('0x07'),
7+
animation('0x05'),
8+
snowflake('0x06'),
9+
picture('0x07'),
1010
laser('0x08');
1111

1212
final String hexValue;
1313
const Mode(this.hexValue);
1414

15-
//method to get the integer value of the mode
1615
static int getIntValue(Mode mode) {
17-
String hexValue = mode.hexValue.substring(3, 4);
18-
int intValue = int.parse(hexValue, radix: 10);
19-
return intValue;
16+
return int.parse(mode.hexValue.substring(2), radix: 16);
2017
}
2118

22-
// Helper method to safely parse hex value
2319
static Mode fromHex(String hexValue) {
2420
return Mode.values.firstWhere(
2521
(mode) => mode.hexValue == hexValue,
26-
orElse: () => Mode.left, // Default to Mode.left if no match
22+
orElse: () => Mode.left,
2723
);
2824
}
25+
26+
static Mode fromInt(int value) {
27+
final hex = value.toRadixString(16).padLeft(2, '0');
28+
return fromHex('0x$hex');
29+
}
2930
}

lib/badge_animation/ani_animation.dart

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,26 @@ class AniAnimation extends BadgeAnimation {
44
@override
55
void processAnimation(int badgeHeight, int badgeWidth, int animationIndex,
66
List<List<bool>> processGrid, List<List<bool>> canvas) {
7-
int newWidth = processGrid[0].length;
8-
int newHeight = processGrid.length;
9-
int verticalOffset = (badgeHeight - newHeight) ~/ 2;
10-
int displayWidth = newWidth > badgeWidth ? badgeWidth : newWidth;
11-
int horizontalOffset = (badgeWidth - displayWidth) ~/ 2;
12-
var totalAnimationLength = badgeWidth;
13-
int frame = animationIndex % totalAnimationLength;
14-
var firstHalf = frame < badgeWidth ~/ 2;
15-
var secondHalf = frame >= badgeWidth ~/ 2;
16-
7+
int newGridHeight = processGrid.length;
8+
int newGridWidth = processGrid[0].length;
179
for (int i = 0; i < badgeHeight; i++) {
1810
for (int j = 0; j < badgeWidth; j++) {
19-
bool lineShow = false;
20-
bool bitmapShowcenter = false;
21-
bool bitmapShowOut = false;
22-
23-
int sourceRow = i - verticalOffset;
24-
int sourceCol = j - horizontalOffset;
25-
26-
bool isWithinNewGrid = sourceRow >= 0 &&
27-
sourceRow < newHeight &&
28-
sourceCol >= 0 &&
29-
sourceCol < displayWidth;
30-
31-
int leftCenterCol = badgeWidth ~/ 2 - 1;
32-
int rightCenterCol = badgeWidth ~/ 2;
33-
34-
int maxDistance = leftCenterCol;
35-
36-
int currentAnimationIndex = animationIndex % (maxDistance + 1);
11+
// Calculate the total number of frames that fit the badge width
12+
int framesCount = (newGridWidth / badgeWidth).ceil();
3713

38-
int leftColPos = leftCenterCol - currentAnimationIndex;
39-
int rightColPos = rightCenterCol + currentAnimationIndex;
14+
// Determine the current frame based on the animation value
15+
int currentcountFrame = animationIndex ~/ badgeWidth % framesCount;
4016

41-
if (leftColPos < 0) leftColPos += badgeWidth;
42-
if (rightColPos >= badgeWidth) rightColPos -= badgeWidth;
17+
// Calculate the starting column for the current frame in newGrid
18+
int startCol = currentcountFrame * badgeWidth;
4319

44-
if (j == leftColPos || j == rightColPos) {
45-
lineShow = true;
46-
} else {
47-
lineShow = false;
48-
}
20+
bool isNewGridCell = i < newGridHeight && (startCol + j) < newGridWidth;
4921

50-
if (firstHalf) {
51-
if (isWithinNewGrid && j > leftColPos && j < rightColPos) {
52-
bitmapShowcenter = processGrid[sourceRow][sourceCol];
53-
}
54-
}
55-
if (secondHalf) {
56-
if (isWithinNewGrid && (j < leftColPos || j > rightColPos)) {
57-
bitmapShowOut = processGrid[sourceRow][sourceCol];
58-
}
59-
}
22+
// Update the grid based on the current frame's data
23+
bool animationCondition =
24+
(isNewGridCell && processGrid[i][startCol + j]);
6025

61-
canvas[i][j] = (lineShow || bitmapShowOut || bitmapShowcenter);
26+
canvas[i][j] = animationCondition;
6227
}
6328
}
6429
}

lib/badge_animation/ani_picture.dart

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,60 @@ class PictureAnimation extends BadgeAnimation {
55
void processAnimation(int badgeHeight, int badgeWidth, int animationIndex,
66
List<List<bool>> processGrid, List<List<bool>> canvas) {
77
int newWidth = processGrid[0].length;
8-
int totalAnimationLength = badgeHeight * 16;
8+
int newHeight = processGrid.length;
9+
int verticalOffset = (badgeHeight - newHeight) ~/ 2;
10+
int displayWidth = newWidth > badgeWidth ? badgeWidth : newWidth;
11+
int horizontalOffset = (badgeWidth - displayWidth) ~/ 2;
12+
var totalAnimationLength = badgeWidth;
913
int frame = animationIndex % totalAnimationLength;
14+
var firstHalf = frame < badgeWidth ~/ 2;
15+
var secondHalf = frame >= badgeWidth ~/ 2;
1016

11-
int horizontalOffset = (badgeWidth - newWidth) ~/ 2;
17+
for (int i = 0; i < badgeHeight; i++) {
18+
for (int j = 0; j < badgeWidth; j++) {
19+
bool lineShow = false;
20+
bool bitmapShowcenter = false;
21+
bool bitmapShowOut = false;
1222

13-
bool phase1 = frame < badgeHeight * 4;
14-
bool phase2 = frame >= badgeHeight * 4 && frame < badgeHeight * 8;
23+
int sourceRow = i - verticalOffset;
24+
int sourceCol = j - horizontalOffset;
1525

16-
if (phase1) {
17-
for (int row = badgeHeight - 1; row >= 0; row--) {
18-
int fallPosition = frame - (badgeHeight - 1 - row) * 2;
19-
int stoppingPosition = row;
20-
fallPosition =
21-
fallPosition >= stoppingPosition ? stoppingPosition : fallPosition;
26+
bool isWithinNewGrid = sourceRow >= 0 &&
27+
sourceRow < newHeight &&
28+
sourceCol >= 0 &&
29+
sourceCol < displayWidth;
2230

23-
if (fallPosition >= 0 && fallPosition < badgeHeight) {
24-
for (int col = 0; col < badgeWidth; col++) {
25-
int sourceCol = col - horizontalOffset;
26-
bool isWithinNewGrid = sourceCol >= 0 && sourceCol < newWidth;
27-
if (isWithinNewGrid) {
28-
canvas[fallPosition][col] = processGrid[row][sourceCol];
29-
}
30-
}
31-
}
32-
}
33-
} else if (phase2) {
34-
for (int row = badgeHeight - 1; row >= 0; row--) {
35-
int fallOutStartFrame = (badgeHeight - 1 - row) * 2;
36-
int fallOutPosition =
37-
row + (frame - badgeHeight * 4 - fallOutStartFrame);
31+
int leftCenterCol = badgeWidth ~/ 2 - 1;
32+
int rightCenterCol = badgeWidth ~/ 2;
3833

39-
if (fallOutPosition < row) {
40-
for (int col = 0; col < badgeWidth; col++) {
41-
int sourceCol = col - horizontalOffset;
42-
bool isWithinNewGrid = sourceCol >= 0 && sourceCol < newWidth;
43-
if (isWithinNewGrid) {
44-
canvas[row][col] = processGrid[row][sourceCol];
45-
}
46-
}
34+
int maxDistance = leftCenterCol;
35+
36+
int currentAnimationIndex = animationIndex % (maxDistance + 1);
37+
38+
int leftColPos = leftCenterCol - currentAnimationIndex;
39+
int rightColPos = rightCenterCol + currentAnimationIndex;
40+
41+
if (leftColPos < 0) leftColPos += badgeWidth;
42+
if (rightColPos >= badgeWidth) rightColPos -= badgeWidth;
43+
44+
if (j == leftColPos || j == rightColPos) {
45+
lineShow = true;
46+
} else {
47+
lineShow = false;
4748
}
4849

49-
if (fallOutPosition >= row && fallOutPosition < badgeHeight) {
50-
for (int col = 0; col < badgeWidth; col++) {
51-
canvas[row][col] = false;
50+
if (firstHalf) {
51+
if (isWithinNewGrid && j > leftColPos && j < rightColPos) {
52+
bitmapShowcenter = processGrid[sourceRow][sourceCol];
5253
}
53-
54-
for (int col = 0; col < badgeWidth; col++) {
55-
int sourceCol = col - horizontalOffset;
56-
bool isWithinNewGrid = sourceCol >= 0 && sourceCol < newWidth;
57-
if (isWithinNewGrid && fallOutPosition < badgeHeight) {
58-
canvas[fallOutPosition][col] = processGrid[row][sourceCol];
59-
}
54+
}
55+
if (secondHalf) {
56+
if (isWithinNewGrid && (j < leftColPos || j > rightColPos)) {
57+
bitmapShowOut = processGrid[sourceRow][sourceCol];
6058
}
6159
}
60+
61+
canvas[i][j] = (lineShow || bitmapShowOut || bitmapShowcenter);
6262
}
6363
}
6464
}

lib/badge_animation/ani_snowflake.dart

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,61 @@ class SnowFlakeAnimation extends BadgeAnimation {
44
@override
55
void processAnimation(int badgeHeight, int badgeWidth, int animationIndex,
66
List<List<bool>> processGrid, List<List<bool>> canvas) {
7-
int newGridHeight = processGrid.length;
8-
int newGridWidth = processGrid[0].length;
9-
for (int i = 0; i < badgeHeight; i++) {
10-
for (int j = 0; j < badgeWidth; j++) {
11-
// Calculate the total number of frames that fit the badge width
12-
int framesCount = (newGridWidth / badgeWidth).ceil();
7+
int newWidth = processGrid[0].length;
8+
int totalAnimationLength = badgeHeight * 16;
9+
int frame = animationIndex % totalAnimationLength;
1310

14-
// Determine the current frame based on the animation value
15-
int currentcountFrame = animationIndex ~/ badgeWidth % framesCount;
11+
int horizontalOffset = (badgeWidth - newWidth) ~/ 2;
1612

17-
// Calculate the starting column for the current frame in newGrid
18-
int startCol = currentcountFrame * badgeWidth;
13+
bool phase1 = frame < badgeHeight * 4;
14+
bool phase2 = frame >= badgeHeight * 4 && frame < badgeHeight * 8;
1915

20-
bool isNewGridCell = i < newGridHeight && (startCol + j) < newGridWidth;
16+
if (phase1) {
17+
for (int row = badgeHeight - 1; row >= 0; row--) {
18+
int fallPosition = frame - (badgeHeight - 1 - row) * 2;
19+
int stoppingPosition = row;
20+
fallPosition =
21+
fallPosition >= stoppingPosition ? stoppingPosition : fallPosition;
2122

22-
// Update the grid based on the current frame's data
23-
bool snowflakeCondition =
24-
(isNewGridCell && processGrid[i][startCol + j]);
23+
if (fallPosition >= 0 && fallPosition < badgeHeight) {
24+
for (int col = 0; col < badgeWidth; col++) {
25+
int sourceCol = col - horizontalOffset;
26+
bool isWithinNewGrid = sourceCol >= 0 && sourceCol < newWidth;
27+
if (isWithinNewGrid) {
28+
canvas[fallPosition][col] = processGrid[row][sourceCol];
29+
}
30+
}
31+
}
32+
}
33+
} else if (phase2) {
34+
for (int row = badgeHeight - 1; row >= 0; row--) {
35+
int fallOutStartFrame = (badgeHeight - 1 - row) * 2;
36+
int fallOutPosition =
37+
row + (frame - badgeHeight * 4 - fallOutStartFrame);
38+
39+
if (fallOutPosition < row) {
40+
for (int col = 0; col < badgeWidth; col++) {
41+
int sourceCol = col - horizontalOffset;
42+
bool isWithinNewGrid = sourceCol >= 0 && sourceCol < newWidth;
43+
if (isWithinNewGrid) {
44+
canvas[row][col] = processGrid[row][sourceCol];
45+
}
46+
}
47+
}
48+
49+
if (fallOutPosition >= row && fallOutPosition < badgeHeight) {
50+
for (int col = 0; col < badgeWidth; col++) {
51+
canvas[row][col] = false;
52+
}
2553

26-
canvas[i][j] = snowflakeCondition;
54+
for (int col = 0; col < badgeWidth; col++) {
55+
int sourceCol = col - horizontalOffset;
56+
bool isWithinNewGrid = sourceCol >= 0 && sourceCol < newWidth;
57+
if (isWithinNewGrid && fallOutPosition < badgeHeight) {
58+
canvas[fallOutPosition][col] = processGrid[row][sourceCol];
59+
}
60+
}
61+
}
2762
}
2863
}
2964
}

lib/constants.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const String aniLaser = 'assets/animations/ic_anim_laser.gif';
3333
const String aniPicture = 'assets/animations/ic_anim_picture.gif';
3434
const String aniUp = 'assets/animations/ic_anim_up.gif';
3535
const String aniRight = 'assets/animations/ic_anim_right.gif';
36+
const String aniSnowflake = 'assets/animations/ic_anim_snowflake.gif';
3637

3738
//path to all the effects assets used
3839
const String effFlash = 'assets/effects/ic_effect_flash.gif';

lib/providers/animation_badge_provider.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ Map<int, BadgeAnimation?> animationMap = {
2424
2: UpAnimation(),
2525
3: DownAnimation(),
2626
4: FixedAnimation(),
27-
5: SnowFlakeAnimation(),
28-
6: PictureAnimation(),
29-
7: AniAnimation(),
27+
5: AniAnimation(),
28+
6: SnowFlakeAnimation(),
29+
7: PictureAnimation(),
3030
8: LaserAnimation(),
3131
};
3232

0 commit comments

Comments
 (0)