From 90bf9b061ad58fdf4c62d2d064cf7826a466f9b6 Mon Sep 17 00:00:00 2001
From: Wuzzy <almikes@aol.com>
Date: Thu, 1 Sep 2016 16:05:42 +0200
Subject: Add notification sound

License of default sound: CC-0
Source: https://www.freesound.org/people/Kastenfrosch/sounds/162482/
---
 api.lua                       |  14 ++++++++++++++
 readme.md                     |   3 ++-
 sounds/awards_got_generic.ogg | Bin 0 -> 76652 bytes
 3 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 sounds/awards_got_generic.ogg

diff --git a/api.lua b/api.lua
index 19f055f..23a9ef9 100644
--- a/api.lua
+++ b/api.lua
@@ -227,6 +227,11 @@ function awards.unlock(name, award)
 	local desc = awdef.description or ""
 	local background = awdef.background or "awards_bg_default.png"
 	local icon = awdef.icon or "awards_unknown.png"
+	local sound = awdef.sound
+	if sound == nil then
+		-- Explicit check for nil because sound could be `false` to disable it
+		sound = {name="awards_got_generic", gain=0.25}
+	end
 	local custom_announce = awdef.custom_announce
 	if not custom_announce then
 		if awdef.secret then
@@ -237,6 +242,15 @@ function awards.unlock(name, award)
 	end
 
 	-- Do Notification
+	if sound then
+		-- Enforce sound delay to prevent sound spamming
+		local lastsound = awards.players[name].lastsound
+		if lastsound == nil or os.difftime(os.time(), lastsound) >= 1 then
+			minetest.sound_play(sound, {to_player=name})
+			awards.players[name].lastsound = os.time()
+		end
+	end
+
 	if awards.show_mode == "formspec" then
 		-- use a formspec to send it
 		minetest.show_formspec(name, "achievements:unlocked", "size[4,2]"..
diff --git a/readme.md b/readme.md
index f2f2683..db5fc41 100644
--- a/readme.md
+++ b/readme.md
@@ -13,7 +13,8 @@ old fork in Carbone, under same license.
 * awards.register_achievement(name, def)
 	* name
 	* desciption
-	* sound [optional]
+	* sound [optional] - set a custom sound (SimpleSoundSpec) or `false` to play no sound.
+          If not specified, a default sound is played
 	* image [optional] - texture name, eg: award_one.png
 	* background [optional] - texture name, eg: award_one.png
 	* trigger [optional] [table]
diff --git a/sounds/awards_got_generic.ogg b/sounds/awards_got_generic.ogg
new file mode 100644
index 0000000..3ae982b
Binary files /dev/null and b/sounds/awards_got_generic.ogg differ
-- 
cgit v1.2.3