Change to require "prepend" to prefix sound files with "sounds_"...
"no_prepend" no longer used.
This commit is contained in:
parent
959db320cc
commit
127f2f4dfe
18
README.md
18
README.md
@ -72,12 +72,12 @@ local s_group3 = s_group1 + s_group2
|
||||
-- strings can also be concatenated to group with arithmetic operator
|
||||
s_group3 = s_group3 + "sound6"
|
||||
|
||||
-- to prevent sound file names from being prefixed with "sounds_" when played,
|
||||
-- the `no_prepend` field must be set to `true`
|
||||
s_group1(2) -- plays "sounds_sound2"
|
||||
|
||||
s_group1.no_prepend = true
|
||||
-- by setting the `prepend` attribute `true`, sound file names will be prepended
|
||||
-- with "sounds_" when played or accessed
|
||||
s_group1(2) -- plays "sound2"
|
||||
|
||||
s_group1.prepend = true
|
||||
s_group1(2) -- plays "sounds_sound2"
|
||||
```
|
||||
|
||||
There are many [pre-defined sound groups](https://antummt.github.io/mod-sounds/reference/latest/topics/groups.html).
|
||||
@ -115,14 +115,14 @@ minetest.register_node("foo:bar", {
|
||||
|
||||
Currently using `SoundGroup` for node sounds only works for "dig", "dug", & "place".
|
||||
|
||||
`SoundGroup` objects are tables & are indexed by integer. But using the `get` method is more reliable as it will return the string name with "sounds_" prefix if `no_prepend` isn't set:
|
||||
`SoundGroup` objects are tables & are indexed by integer. But using the `get` method is more reliable as it will return the string name with "sounds_" prefix if `prepend` is set:
|
||||
```lua
|
||||
local s_group1 = SoundGroup({"sound1", "sound2"})
|
||||
local s1 = s_group1:get(1) -- returns "sounds_sound1"
|
||||
local s1 = s_group1:get(1) -- returns "sound1"
|
||||
local s2 = s_group1[2] -- returns "sound2"
|
||||
|
||||
local s_group2 = SoundGroup({"sound3", "sound4", no_prepend=true})
|
||||
local s3 = s_group2:get(1) -- returns "sound3"
|
||||
local s_group2 = SoundGroup({"sound3", "sound4", prepend=true})
|
||||
local s3 = s_group2:get(1) -- returns "sounds_sound3"
|
||||
local s4 = s_group2[2] -- returns "sound4"
|
||||
```
|
||||
|
||||
|
1
TODO.txt
1
TODO.txt
@ -6,7 +6,6 @@ TODO:
|
||||
- create sounds.glass group
|
||||
- shorten length of rain_light, rain_medium, & wind
|
||||
- fix clock_tick loop
|
||||
- change using "no_prepend" to "prepend" so "sounds_" isn't prepended with explicit setting
|
||||
- tests:
|
||||
- fix wrong sound selected when changing groups (example: select #2, switch to group with one sound, switch to group with two sounds, press play)
|
||||
- add more sounds:
|
||||
|
16
api.lua
16
api.lua
@ -58,7 +58,7 @@ sounds.play_random = function(self, snds, sp)
|
||||
end
|
||||
|
||||
local play_group = table.copy(snds)
|
||||
if type(snds) == "SoundGroup" and snds.no_prepend ~= true then
|
||||
if type(snds) == "SoundGroup" and snds.prepend == true then
|
||||
for idx, snd in ipairs(play_group) do
|
||||
play_group[idx] = "sounds_" .. snd
|
||||
end
|
||||
@ -85,7 +85,7 @@ end
|
||||
-- @table SoundGroup
|
||||
-- @tfield SoundGroup:count count Retrieves number of available sounds.
|
||||
-- @tfield SoundGroup:play play Plays indexed or random sound.
|
||||
-- @tfield bool no_prepend If set to `true`, omits prepending "sounds_" to sound filenames when played.
|
||||
-- @tfield bool prepend If set to `true`, prepends "sounds_" to sound filenames when played or accessed.
|
||||
SoundGroup = {
|
||||
--- Constructor.
|
||||
--
|
||||
@ -94,8 +94,8 @@ SoundGroup = {
|
||||
-- @treturn SoundGroup Sound group definition table.
|
||||
-- @usage
|
||||
-- -- create new sound groups
|
||||
-- local s_group1 = SoundGroup({"sound1", "sound2"})
|
||||
-- local s_group2 = SoundGroup({"modname_sound1", "modname_sound2", no_prepend=true})
|
||||
-- local s_group1 = SoundGroup({"sound1", "sound2", prepend=true})
|
||||
-- local s_group2 = SoundGroup({"modname_sound1", "modname_sound2"})
|
||||
--
|
||||
-- -- play sound at index
|
||||
-- s_group1:play(2)
|
||||
@ -141,7 +141,7 @@ SoundGroup = {
|
||||
end
|
||||
end
|
||||
|
||||
new_group.no_prepend = self.no_prepend
|
||||
new_group.prepend = self.prepend
|
||||
return SoundGroup(new_group)
|
||||
end,
|
||||
}
|
||||
@ -214,7 +214,7 @@ SoundGroup = {
|
||||
end
|
||||
|
||||
local selected = self[idx]
|
||||
if type(selected) == "string" and self.no_prepend ~= true then
|
||||
if type(selected) == "string" and self.prepend == true then
|
||||
selected = "sounds_" .. selected
|
||||
end
|
||||
|
||||
@ -235,7 +235,7 @@ SoundGroup = {
|
||||
name = self[rand:next(1, s_count)]
|
||||
end
|
||||
|
||||
if self.no_prepend ~= true then
|
||||
if self.prepend == true then
|
||||
name = "sounds_" .. name
|
||||
end
|
||||
end
|
||||
@ -269,7 +269,7 @@ SoundGroup = {
|
||||
end
|
||||
end
|
||||
|
||||
if self.no_prepend ~= true then
|
||||
if self.prepend == true then
|
||||
local rtype = type(retval)
|
||||
if rtype == "string" then
|
||||
retval = "sounds_" .. retval
|
||||
|
@ -3,7 +3,8 @@ next
|
||||
----
|
||||
- added method "sounds:play_random"
|
||||
- added "random" play button to tests
|
||||
- fixed inheriting "no_prepend" attribute when concatenating SoundGroup instances with arithmetic operator
|
||||
- changed to require "prepend" to prefix sound files with "sounds_"
|
||||
- fixed inheriting "prepend" attribute when concatenating SoundGroup instances with arithmetic operator
|
||||
- renamed sounds:
|
||||
- some "ar_fire sounds" to "ar_burst"
|
||||
- added sounds:
|
||||
|
Loading…
x
Reference in New Issue
Block a user