You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
4.3 KiB

  1. /*
  2. Copyright 2020 rupa <rupa@lrrr.us> @rupa
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include "unicode.h"
  15. combined_mode_t combined_mode = CM_NULL;
  16. bool _seeded = false;
  17. #if defined(UNICODEMAP_ENABLE)
  18. const uint32_t PROGMEM unicode_map[] = {
  19. [CCIR] = 0x20DD, // COMBINING CIRCLE ⃝
  20. [CENT] = 0x00A2, // ¢
  21. [CHEK] = 0x2713, // ✓
  22. [CKEY] = 0x20E3, // COMBINING KEYCAP ⃣
  23. [CUI] = 0x26A0, // ⚠
  24. [ECKS] = 0x2716, // ✖
  25. [EFF] = 0x017F, // ſ
  26. [HAS] = 0x262D, // ☭
  27. [HUN] = 0x1F4AF, // 💯
  28. [IBNG] = 0x203D, // ‽
  29. [IRNY] = 0x2E2E, // ⸮
  30. [LALL] = 0x2200, // ∀
  31. [LELM] = 0x2208, // ∈
  32. [LEXI] = 0x2203, // ∃
  33. [LPRO] = 0x22A2, // ⊢
  34. [M4] = 0x2669, // ♩
  35. [M8] = 0x266A, // ♪
  36. [M8B] = 0x266B, // ♫
  37. [M16] = 0x266C, // ♬
  38. [NEG] = 0x20E0, // COMBINING NO ⃠
  39. [NOPE] = 0x1F6AB, // 🚫
  40. [NUM] = 0x2116, // №
  41. [OM] = 0x0950, // ॐ
  42. [SMB] = 0x263A, // ☻
  43. [SMW] = 0x263B, // ☺
  44. [STB] = 0x2605, // ★
  45. [STOP] = 0x26D4, // ⛔
  46. [STW] = 0x2606, // ☆
  47. };
  48. #endif
  49. const char *d6_map[] = {
  50. "", "", "", "", "", ""
  51. };
  52. const char *dance_map[] = {
  53. "〜( ̄▽ ̄〜)",
  54. "(〜 ̄▽ ̄)〜"
  55. };
  56. const char *dance_more_map[] = {
  57. "ƪ(˘⌣˘)┐",
  58. "┌(˘⌣˘)ʃ"
  59. };
  60. const char *flip_map[] = {
  61. "(╯°□°)╯︵ ┻━━┻",
  62. "(ノ-_-)ノ・・ ┻━━┻",
  63. "(ノꐦ⊙曲ఠ)ノ彡┻━┻"
  64. };
  65. const char *flip_back_map[] = {
  66. "┬──┬◡ノ(° -°ノ)",
  67. "┬──┬ノ( ゜-゜ノ)",
  68. "┬──┬ノ(ಠ_ಠノ)"
  69. };
  70. const char *joy_map[] = {
  71. "ᕕ( ᐛ )ᕗ ",
  72. "٩(ˊᗜˋ*)و",
  73. "٩( ᐛ )و"
  74. };
  75. const char *joy_harder_map[] = {
  76. "\\ ٩( ᐛ )و //",
  77. "✧*。٩(ˊᗜˋ*)و✧*。"
  78. };
  79. const char *choice(const char *choices[], int size) {
  80. if (_seeded == false) {
  81. srand(timer_read32());
  82. dprintf("_seeded the roll\n");
  83. _seeded = true;
  84. }
  85. return choices[rand() % size];
  86. }
  87. const char *d6(void) {
  88. return choice(d6_map, 6);
  89. }
  90. const char *dance(bool more) {
  91. if (more) {
  92. return choice(dance_more_map, 2);
  93. }
  94. return choice(dance_map, 2);
  95. }
  96. const char *flip(bool flip_back) {
  97. if (flip_back) {
  98. return choice(flip_back_map, 3);
  99. }
  100. return choice(flip_map, 3);
  101. }
  102. const char *joy(bool harder) {
  103. if (harder) {
  104. return choice(joy_harder_map, 2);
  105. }
  106. return choice(joy_map, 3);
  107. }
  108. bool u_x(const char *text) {
  109. send_unicode_string(text);
  110. return false;
  111. };
  112. bool u_xp(bool is_shifted, const char *shifted, const char *plain) {
  113. send_unicode_string(is_shifted ? shifted : plain);
  114. return false;
  115. };
  116. void zalgo(void) {
  117. int number = (rand() % (8 + 1 - 2)) + 2;
  118. unsigned int index;
  119. for (index=0; index<number; index++) {
  120. uint16_t hex = (rand() % (0x036F + 1 - 0x0300)) + 0x0300;
  121. register_hex(hex);
  122. }
  123. }
  124. bool combined_text(uint16_t keycode) {
  125. if (keycode < KC_A || (keycode > KC_0 && keycode < KC_MINUS) || keycode > KC_SLASH) {
  126. return false;
  127. }
  128. tap_code(keycode);
  129. unicode_input_start();
  130. switch (combined_mode) {
  131. case CM_CIRCLE:
  132. register_hex(0x20DD);
  133. break;
  134. case CM_NO:
  135. register_hex(0x20E0);
  136. break;
  137. case CM_KEYCAP:
  138. register_hex(0x20E3);
  139. break;
  140. case CM_ZALGO:
  141. zalgo();
  142. break;
  143. default:
  144. break;
  145. }
  146. unicode_input_finish();
  147. return true;
  148. }
  149. void cycle_combined_mode(void) {
  150. if (combined_mode++ >= CM_MAX - 1) {
  151. combined_mode = CM_NULL;
  152. }
  153. }
  154. combined_mode_t set_combined_mode(combined_mode_t mode) {
  155. combined_mode = combined_mode == mode ? CM_NULL : mode;
  156. return combined_mode;
  157. }