Skip to content

Commit

Permalink
Merge branch 'master' into ci-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay authored Jun 4, 2024
2 parents 923bcb2 + 37a7fd6 commit 38913e9
Show file tree
Hide file tree
Showing 31 changed files with 1,326 additions and 750 deletions.
2 changes: 1 addition & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

globals = {
"minetest",
"xcompat",
Expand All @@ -15,4 +14,5 @@ read_globals = {
"hades_sounds",
"rp_sounds",
"mtt",
"sounds",
}
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Thanks to:

## Usage

See [DEV.md](DEV.md) for detailed documentation.
See the respective sub apis doc file in /doc for detailed documentation.

## Directly supported games and mods

Expand All @@ -24,6 +24,9 @@ See [DEV.md](DEV.md) for detailed documentation.
| Farlands Reloaded | x | x | x |
| Exile | x | | |
| KSurvive 2 | x | | |
| Forgotten Lands | x | | |

For functions see /doc/functions.md for the specifics relating to the function

**Mods**
* `basic_materials`
Expand Down
13 changes: 13 additions & 0 deletions doc/functions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Functions API

## `can_interact_with_node(player, pos)`
returns `bool`

checks for the ability to interact with a node via:
* if a player
* owner metadata key
* protection_bypass

supports
* minetest game default if present
* else polyfill
12 changes: 12 additions & 0 deletions doc/gameid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# GameId API

## minetest versions >= 5.7

simply returns `minetest.get_game_info().id`

## minetest versions < 5.7

approximates the gameid value via a hardcoded table of gameid=>modname
and then checks via `minetest.get_modpath()`. If it fails, it falls
back to using `xcompat_unknown_gameid` as the id. See the chart in the
readme for which games are supported
3 changes: 3 additions & 0 deletions doc/materials.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Materials API

consult `/src/materials/minetest.lua` at this time
14 changes: 4 additions & 10 deletions DEV.md → doc/sounds.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Xcompat dev docs
# Sound API

## Sound API

### Option 1: Agnostically depend
## Option 1: Agnostically depend

You can do this by using a custom field in your node def instead of the `sounds` key.

Expand All @@ -22,7 +20,7 @@ where:
* 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.

### Option 2: Hard depend
## Option 2: Hard depend

add this mod to your mod.confs depends and directly call the sound_api as follows

Expand All @@ -34,8 +32,4 @@ minetest.register_node(nodename, {
})
```

* input: optional table to override some or all of returned values

## Materials API

consult `/src/materials.lua` at this time
* input: optional table to override some or all of returned values
3 changes: 3 additions & 0 deletions doc/textures.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Textures API

consult `/src/texture/minetest.lua` at this time
16 changes: 12 additions & 4 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
local modpath = minetest.get_modpath("xcompat")

xcompat = {
sounds = dofile(modpath .. "/src/sounds.lua"),
materials = dofile(modpath .. "/src/materials.lua"),
textures = dofile(modpath .. "/src/textures.lua"),
modpath = modpath,
}

xcompat.gameid = dofile(modpath .. "/src/gameid.lua")
xcompat.utilities = dofile(modpath .. "/src/utilities.lua")

xcompat.sounds = dofile(modpath .. "/src/sounds.lua")
xcompat.materials = dofile(modpath .. "/src/materials.lua")
xcompat.textures = dofile(modpath .. "/src/textures.lua")
xcompat.functions = dofile(modpath .. "/src/functions.lua")

local function validate_sound(key)
if key and xcompat.sounds[key] then
return true
Expand Down Expand Up @@ -36,7 +42,9 @@ minetest.register_on_mods_loaded(function()
end
end)

dofile(modpath .. "/src/commands.lua")

if minetest.get_modpath("mtt") then
-- register tests
dofile(modpath .. "/mtt.lua")
end
end
2 changes: 1 addition & 1 deletion mod.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name = xcompat
description = Provides cross compatibility between mods and games for sounds and crafting materials.
optional_depends = default, fl_stone, fl_trees, mcl_sounds, hades_sounds, ks_sounds, nodes_nature, fl_topsoil, fl_trees, mcl_core, mtt
optional_depends = default, fl_stone, fl_trees, mcl_sounds, hades_sounds, ks_sounds, nodes_nature, fl_topsoil, fl_trees, mcl_core, farming, x_farming, sounds, mtt
76 changes: 76 additions & 0 deletions src/commands.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
local materials_list = minetest.get_dir_list(xcompat.modpath.."/src/materials", false)
local materials = {}
for _, material in ipairs(materials_list) do
local gameid = material:sub(1, -5)
materials[gameid] = dofile(xcompat.modpath.."/src/materials/"..material)
end

local textures_list = minetest.get_dir_list(xcompat.modpath.."/src/textures", false)
local textures = {}
for _, texture in ipairs(textures_list) do
local gameid = texture:sub(1, -5)
textures[gameid] = dofile(xcompat.modpath.."/src/textures/"..texture)
end

local sounds_list = minetest.get_dir_list(xcompat.modpath.."/src/sounds", false)
local sounds = {}
for _, sound in ipairs(sounds_list) do
local gameid = sound:sub(1, -5)
sounds[gameid] = dofile(xcompat.modpath.."/src/sounds/"..sound)
end

minetest.register_chatcommand("xcompat_test_materials", {
description = "Test materials",
privs = {server=true},
func = function(name, _)
local reference_materials = materials["minetest"]

for gameid, game_materials in pairs(materials) do
for material, _ in pairs(reference_materials) do
if not game_materials[material] then
minetest.chat_send_player(name, "Missing material: "..material.." in game: "..gameid)
end
end
end

minetest.chat_send_player(name, "Materials test complete")
end
})

--WARNING: only handles top level of table currently
--TODO: handle nested tables
minetest.register_chatcommand("xcompat_test_textures", {
description = "Test textures",
privs = {server=true},
func = function(name, _)
local reference_textures = textures["xcompat_agnostic"]

for gameid, game_textures in pairs(textures) do
for texture, _ in pairs(reference_textures) do
if not game_textures[texture] then
minetest.chat_send_player(name, "Missing texture: "..texture.." in game: "..gameid)
end
end
end

minetest.chat_send_player(name, "Textures test complete")
end
})

minetest.register_chatcommand("xcompat_test_sounds", {
description = "Test sounds",
privs = {server=true},
func = function(name, _)
local reference_sounds = sounds["xcompat_agnostic"]

for gameid, game_sounds in pairs(sounds) do
for sound, _ in pairs(reference_sounds) do
if not game_sounds[sound] then
minetest.chat_send_player(name, "Missing material: "..sound.." in game: "..gameid)
end
end
end

minetest.chat_send_player(name, "Sounds test complete")
end
})
19 changes: 19 additions & 0 deletions src/functions.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
local functions = {}

function functions.can_interact_with_node(player, pos)
--if we have default, use it
if default then return default.can_interact_with_node(player, pos) end

local owner = minetest.get_meta(pos):get_string("owner") or ""

--check that we have a valid player
if not player or not player:is_player() then return false end
--check there privs for compat with areas
if minetest.check_player_privs(player, "protection_bypass") then return true end
--if a normal player, check if they are the owner
if owner == "" or owner == player:get_player_name() then return true end

return false
end

return functions
33 changes: 33 additions & 0 deletions src/gameid.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
local game_alias = {
mineclone2 = "mineclonia",
}

local game_modnames = {
mineclonia = "mcl_core",
farlands_reloaded = "fl_core",
minetest = "default",
hades = "hades_core",
exile = "exile_env_sounds",
ksurvive2 = "ks_metals",
}

local gameid = "xcompat_unknown_gameid"

if type(minetest.get_game_info) == "function" then
gameid = minetest.get_game_info().id
else
for game, modname in pairs(game_modnames) do
if minetest.get_modpath(modname) then
gameid = game
break
end
end
end

--for games that are similar/derviatives of other games
if game_alias[gameid] then gameid = game_alias[gameid] end

--while minetest game derviates are not supported, we can still try to detect them
if minetest.get_modpath("default") then gameid = "minetest" end

return gameid
Loading

0 comments on commit 38913e9

Please sign in to comment.