Ivan Barsukov 1 год назад
Родитель
Сommit
29a6afbaee
2 измененных файлов с 56 добавлено и 0 удалено
  1. 46 0
      src/game_notifications.c
  2. 10 0
      src/game_notifications.h

+ 46 - 0
src/game_notifications.c

@@ -0,0 +1,46 @@
+#include "game_notifications.h"
+
+#include <notification/notification.h>
+#include <notification/notification_messages.h>
+
+#include "game.h"
+
+const NotificationSequence sequence_earn_point = {
+    &message_green_255, &message_vibro_on,  &message_note_c7, &message_delay_50,
+    &message_sound_off, &message_vibro_off, &message_green_0, NULL,
+};
+
+void
+game_notify(GameContext* game_context, const NotificationSequence* sequence)
+{
+    static const NotificationMessage* notification[20];
+
+    size_t input_index = 0;
+    size_t result_index = 0;
+
+    for (; (*sequence)[input_index] != NULL; ++input_index) {
+        const NotificationMessage* item = (*sequence)[input_index];
+
+        bool is_sound = item->type == NotificationMessageTypeSoundOn ||
+                        item->type == NotificationMessageTypeSoundOff;
+
+        bool is_led = item->type == NotificationMessageTypeLedRed ||
+                      item->type == NotificationMessageTypeLedGreen ||
+                      item->type == NotificationMessageTypeLedBlue;
+
+        bool is_vibro = item->type == NotificationMessageTypeVibro;
+
+        if ((is_sound && game_context->sound == StateOff) ||
+            (is_vibro && game_context->vibro == StateOff) ||
+            (is_led && game_context->led == StateOff)) {
+            continue;
+        }
+
+        notification[result_index] = item;
+        ++result_index;
+    }
+    notification[result_index] = NULL;
+
+    notification_message(game_context->notification,
+                         (const NotificationSequence*)notification);
+}

+ 10 - 0
src/game_notifications.h

@@ -0,0 +1,10 @@
+#pragma once
+
+#include <notification/notification.h>
+
+#include "game.h"
+
+extern const NotificationSequence sequence_earn_point;
+
+void
+game_notify(GameContext* game_context, const NotificationSequence* sequence);