]> git.lizzy.rs Git - nothing.git/commitdiff
(#1108) add development ding
authorrexim <reximkut@gmail.com>
Sun, 20 Oct 2019 17:29:43 +0000 (00:29 +0700)
committerrexim <reximkut@gmail.com>
Sun, 20 Oct 2019 17:29:43 +0000 (00:29 +0700)
assets/sounds/dev/ding.wav [new file with mode: 0644]
src/game.c
src/game/level/level_editor.c
src/game/level/level_editor.h
src/game/level/level_editor/undo_history.h
src/main.c

diff --git a/assets/sounds/dev/ding.wav b/assets/sounds/dev/ding.wav
new file mode 100644 (file)
index 0000000..0f07fbc
Binary files /dev/null and b/assets/sounds/dev/ding.wav differ
index 2398f689718321a5aebf6346fad85e0cbf718cf2..dcfa5a8f0333826c6a0d872773f0ab0bb9e19edc 100644 (file)
@@ -171,7 +171,10 @@ int game_sound(Game *game)
     case GAME_STATE_LEVEL:
         return level_sound(game->level, game->sound_samples);
     case GAME_STATE_LEVEL_PICKER:
+        return 0;
     case GAME_STATE_LEVEL_EDITOR:
+        level_editor_sound(game->level_editor, game->sound_samples);
+        return 0;
     case GAME_STATE_QUIT:
         return 0;
     }
index caf8efa33bab3261eb054c4d78988b16ffbde116..aadd23d1339f9264167ef591fb706b670fce6550 100644 (file)
@@ -1,6 +1,7 @@
 #include <stdbool.h>
 
 #include "game/camera.h"
+#include "game/sound_samples.h"
 #include "game/level_metadata.h"
 #include "game/level/boxes.h"
 #include "game/level/level_editor/color_picker.h"
@@ -432,7 +433,9 @@ int level_editor_idle_event(LevelEditor *level_editor,
 
         case SDLK_z: {
             if (event->key.keysym.mod & KMOD_CTRL) {
-                log_info("Undo\n");
+                if (undo_history_empty(&level_editor->undo_history)) {
+                    level_editor->bell = 1;
+                }
                 undo_history_pop(&level_editor->undo_history);
             }
         } break;
@@ -581,3 +584,14 @@ int level_editor_update(LevelEditor *level_editor, float delta_time)
 {
     return fading_wiggly_text_update(&level_editor->notice, delta_time);
 }
+
+void level_editor_sound(LevelEditor *level_editor, Sound_samples *sound_samples)
+{
+    // trace_assert(level_editor);
+    trace_assert(sound_samples);
+
+    if (level_editor && level_editor->bell) {
+        level_editor->bell = 0;
+        sound_samples_play_sound(sound_samples, 2);
+    }
+}
index 93f4e3b14698694ce1054473e71cc884c1ac1a27..1eaedbfbc907b65623914e6c0fa9a39b566f880b 100644 (file)
@@ -12,6 +12,7 @@ typedef struct RectLayer RectLayer;
 typedef struct PointLayer PointLayer;
 typedef struct LabelLayer LabelLayer;
 typedef struct Edit_field Edit_field;
+typedef struct Sound_samples Sound_samples;
 
 typedef enum {
     LEVEL_EDITOR_IDLE = 0,
@@ -44,6 +45,7 @@ struct LevelEditor
     UndoHistory undo_history;
 
     bool drag;
+    int bell;
 
     const char *file_name;
 };
@@ -60,5 +62,6 @@ int level_editor_event(LevelEditor *level_editor,
 int level_editor_focus_camera(LevelEditor *level_editor,
                               Camera *camera);
 int level_editor_update(LevelEditor *level_editor, float delta_time);
+void level_editor_sound(LevelEditor *level_editor, Sound_samples *sound_samples);
 
 #endif  // LEVEL_EDITOR_H_
index f9623f38f9c7f9bbc06608a49847ec81f94f8f22..bb671d123afbe16840872d4de33652c339b06bf1 100644 (file)
@@ -21,4 +21,10 @@ void undo_history_push(UndoHistory *undo_history,
                        size_t context_data_size);
 void undo_history_pop(UndoHistory *undo_history);
 
+static inline
+int undo_history_empty(UndoHistory *undo_history)
+{
+    return undo_history->actions.size == 0;
+}
+
 #endif  // UNDO_HISTORY_H_
index 2a3b0e040260274d49506f0b902b87ba3390e85c..9cdbc66bab4c9757fb733c6764a85aaf90e42aab 100644 (file)
@@ -116,7 +116,8 @@ int main(int argc, char *argv[])
 
     const char * sound_sample_files[] = {
         "./sounds/nothing.wav",
-        "./sounds/something.wav"
+        "./sounds/something.wav",
+        "./sounds/dev/ding.wav",
     };
     const size_t sound_sample_files_count = sizeof(sound_sample_files) / sizeof(char*);