convert mod from sound api to xcompat

This commit is contained in:
wsor4035 2024-02-25 00:10:30 -05:00
parent fe6ea96fa0
commit ed57962bbd
6 changed files with 50 additions and 38 deletions

View File

@ -1,5 +1,24 @@
unused_args = false
allow_defined_top = true
exclude_files = {".luacheckrc"}
globals = { globals = {
"sound_api", "minetest", "mcl_sounds", "default", "ks_sounds", "minetest", "sound_api", "xcompat", "default",
"nodes_nature", "fl_stone", "fl_topsoil", "fl_trees", "mcl_sounds", "ks_sounds", "nodes_nature", "fl_stone",
"hades_sounds", "rp_sounds", "fl_topsoil", "fl_trees", "hades_sounds", "rp_sounds",
}
read_globals = {
string = {fields = {"split"}},
table = {fields = {"copy", "getn"}},
--luac
"math", "table",
-- Builtin
"vector", "ItemStack", "dump", "DIR_DELIM", "VoxelArea", "Settings", "PcgRandom", "VoxelManip", "PseudoRandom",
--mod produced
"fl_dyes", "fl_hand", "fl_tools", "mobkit", "fl_tnt", "i3",
} }

25
DEV.md
View File

@ -1,20 +1,8 @@
# Sound API # Xcompat dev docs
This mod is a wrapper for [sound api library](https://github.com/mt-mods/sound_api_core/). ## Sound API
## Usage of the sound api ### Option 1: Agnostically depend
### Option 1: embed
You can insert the [sound api library](https://github.com/mt-mods/sound_api_core/) directly into your mod as a submodule and use the following to load it.
```lua
local sound_api = dofile(modpath .. "/sound_api_core/init.lua")
```
additionally the author recommends that you use dependabot(github) or similar to help you keep the submodule up to date.
### Option 2: Agnostically depend
You can do this by using a custom field in your node def instead of the `sounds` key. You can do this by using a custom field in your node def instead of the `sounds` key.
@ -34,17 +22,20 @@ where:
* key: string name of the field from the sound api you want to use, for example `node_sound_stone_defaults` * key: string name of the field from the sound api you want to use, for example `node_sound_stone_defaults`
* input: table input of fields you want passed to the key field, used to override specific sounds. * input: table input of fields you want passed to the key field, used to override specific sounds.
### Option 3: Hard depend ### Option 2: Hard depend
add this mod to your mod.confs depends and directly call the sound_api as follows add this mod to your mod.confs depends and directly call the sound_api as follows
```lua ```lua
minetest.register_node(nodename, { minetest.register_node(nodename, {
... ...
sounds = sound_api.node_sound_stone_defaults(input) sounds = xcompat.sounds.node_sound_stone_defaults(input)
... ...
}) })
``` ```
* input: optional table to override some or all of returned values * input: optional table to override some or all of returned values
## Materials API
consult `/src/materials.lua` at this time

View File

@ -1,18 +1,14 @@
# Sound API # xcompat
a mod that aims to facilitate other mods to be game agnostic by handling sounds and crafting
thanks to:
* MisterE, OgelGames, and Blockhead for naming advice/suggestion
* luk3yx, Blockhead, Buckaroo for bouncing ideas on the concept of this mod
mod that enables sound to be game agnostic
## Installing ## Installing
* `git clone https://github.com/mt-mods/sound_api.git` clone via git or install via contentdb (soon)
* `cd sound_api`
* `git submodule init`
* `git submodule update`
to update please use the following commands starting inside the mod directory
* `git pull`
* `git submodule sync`
* `git submodule update`
## Dev Docs ## Dev Docs

View File

@ -1,9 +1,15 @@
local modpath = minetest.get_modpath("sound_api") local modpath = minetest.get_modpath("xcompat")
sound_api = dofile(modpath .. "/sound_api_core/init.lua") xcompat = {
sounds = dofile(modpath .. "/src/sounds.lua"),
materials = dofile(modpath .. "/src/materials.lua"),
}
--this exists for legacy compat reasons
sound_api = xcompat.sounds -- luacheck: ignore
local function validate_sound(key) local function validate_sound(key)
if key and sound_api[key] then if key and xcompat.sounds[key] then
return true return true
elseif key then elseif key then
minetest.log("warning", "attempted to call invalid sound: "..key) minetest.log("warning", "attempted to call invalid sound: "..key)
@ -17,7 +23,7 @@ minetest.register_on_mods_loaded(function()
for name, def in pairs(minetest.registered_nodes) do for name, def in pairs(minetest.registered_nodes) do
if def._sound_def and validate_sound(def._sound_def.key) then if def._sound_def and validate_sound(def._sound_def.key) then
minetest.override_item(name, { minetest.override_item(name, {
sounds = sound_api[def._sound_def.key](def._sound_def.input) sounds = xcompat.sounds[def._sound_def.key](def._sound_def.input)
}) })
end end
end end
@ -25,7 +31,7 @@ minetest.register_on_mods_loaded(function()
local old_reg_node = minetest.register_node local old_reg_node = minetest.register_node
function minetest.register_node(name, def) function minetest.register_node(name, def)
if def._sound_def and validate_sound(def._sound_def.key) then if def._sound_def and validate_sound(def._sound_def.key) then
def.sounds = sound_api[def._sound_def.key](def._sound_def.input) def.sounds = xcompat.sounds[def._sound_def.key](def._sound_def.input)
end end
old_reg_node(name, def) old_reg_node(name, def)

View File

@ -1,2 +1,2 @@
name = sound_api name = xcompat
optional_depends = default, fl_stone, fl_trees, mcl_sounds, hades_sounds, ks_sounds, nodes_nature, fl_topsoil, fl_trees optional_depends = default, fl_stone, fl_trees, mcl_sounds, hades_sounds, ks_sounds, nodes_nature, fl_topsoil, fl_trees