constants.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include <gui/icon.h>
  2. #include "dice_app_icons.h"
  3. #define TAG "DiceApp"
  4. #define DICE_TYPES 8
  5. #define MAX_DICE_COUNT 10
  6. #define MAX_COIN_FRAMES 9
  7. #define MAX_DICE_FRAMES 4
  8. #define DICE_X 45
  9. #define DICE_Y 6
  10. #define DICE_Y_T 0
  11. #define DICE_GAP 44
  12. #define SWIPE_DIST 11
  13. const Icon* coin_heads_start[] = {&I_coin_1, &I_coin_2};
  14. const Icon* coin_heads_end[] = {&I_coin_7, &I_coin_1};
  15. const Icon* coin_tails_start[] = {&I_coin_5, &I_coin_6};
  16. const Icon* coin_tails_end[] = {&I_coin_4, &I_coin_5};
  17. const Icon* coin_frames[] = {
  18. &I_coin_1,
  19. &I_coin_2,
  20. &I_coin_3,
  21. &I_coin_4,
  22. &I_coin_5,
  23. &I_coin_6,
  24. &I_coin_3,
  25. &I_coin_7,
  26. &I_coin_1,
  27. };
  28. const Icon* dice_frames[] = {
  29. &I_d4_1, &I_d4_2, &I_d4_3, &I_d4_1, // d4
  30. &I_d6_1, &I_d6_2, &I_d6_3, &I_d6_4, // d6
  31. &I_d8_1, &I_d8_2, &I_d8_3, &I_d8_4, // d8
  32. &I_d10_1, &I_d10_2, &I_d10_3, &I_d10_4, // d10
  33. &I_d12_1, &I_d12_2, &I_d12_3, &I_d12_4, // d12
  34. &I_d20_1, &I_d20_2, &I_d20_3, &I_d20_4, // d20
  35. &I_d100_1, &I_d100_2, &I_d100_3, &I_d100_4, // d100
  36. };
  37. typedef struct {
  38. uint8_t type;
  39. int x;
  40. int y;
  41. char* name;
  42. } Dice;
  43. const uint8_t screen_pos[] = {};
  44. static const Dice dice_types[] = {
  45. {2, 0, 0, "Coin"},
  46. {4, 0, 0, "d4"},
  47. {6, 0, 0, "d6"},
  48. {8, 0, 0, "d8"},
  49. {10, 0, 0, "d10"},
  50. {12, 0, 0, "d12"},
  51. {20, 0, 0, "d20"},
  52. {100, 0, 0, "d100"},
  53. };
  54. typedef enum { EventTypeTick, EventTypeKey } EventType;
  55. typedef enum { SelectState, SwipeLeftState, SwipeRightState, AnimState, ResultState } AppState;
  56. typedef struct {
  57. EventType type;
  58. InputEvent input;
  59. } AppEvent;
  60. typedef struct {
  61. FuriMutex* mutex;
  62. AppState app_state;
  63. uint16_t roll_result;
  64. uint8_t rolled_dices[MAX_DICE_COUNT];
  65. uint8_t anim_frame;
  66. uint8_t dice_index;
  67. uint8_t dice_count;
  68. Dice dices[DICE_TYPES];
  69. } State;
  70. void init(State* const state) {
  71. state->app_state = SelectState;
  72. state->roll_result = 0;
  73. state->dice_index = 0;
  74. state->anim_frame = 0;
  75. state->dice_count = 1;
  76. for(uint8_t i = 0; i < DICE_TYPES; i++) {
  77. state->dices[i] = dice_types[i];
  78. state->dices[i].x = DICE_X + (i * DICE_GAP);
  79. state->dices[i].y = i == 0 ? DICE_Y_T : DICE_Y;
  80. }
  81. }
  82. void coin_set_start(uint16_t type) {
  83. if(type == 1) {
  84. coin_frames[0] = coin_heads_start[0];
  85. coin_frames[1] = coin_heads_start[1];
  86. } else {
  87. coin_frames[0] = coin_tails_start[0];
  88. coin_frames[1] = coin_tails_start[1];
  89. }
  90. }
  91. void coin_set_end(uint16_t type) {
  92. if(type == 1) {
  93. coin_frames[MAX_COIN_FRAMES - 2] = coin_heads_end[0];
  94. coin_frames[MAX_COIN_FRAMES - 1] = coin_heads_end[1];
  95. } else {
  96. coin_frames[MAX_COIN_FRAMES - 2] = coin_tails_end[0];
  97. coin_frames[MAX_COIN_FRAMES - 1] = coin_tails_end[1];
  98. }
  99. }