add player compatibility api (#41)

This commit is contained in:
wsor4035
2024-09-08 18:01:52 -04:00
committed by GitHub
parent 931a16803e
commit b18dc7ba14
10 changed files with 210 additions and 12 deletions

8
src/player.lua Normal file
View File

@@ -0,0 +1,8 @@
local filename = xcompat.gameid
--if we dont have a player file for the game, use minetest
if not xcompat.utilities.file_exists(xcompat.modpath .. "/src/player/" .. filename .. ".lua") then
filename = "xcompat_agnostic"
end
return dofile(xcompat.modpath .. "/src/player/" .. filename .. ".lua")

View File

@@ -0,0 +1,51 @@
local papi = {}
local models = {}
function papi.register_model(name, def)
models[name] = def
end
function papi.set_model(player, model_name)
local model = models[model_name]
if not model then return end
player:set_properties({
mesh = model_name,
textures = model.textures,
visual = "mesh",
visual_size = model.visual_size,
stepheight = model.stepheight
})
end
function papi.get_animation(_)
--stub to keep from crashing
end
function papi.get_textures(player)
return player:get_properties().textures
end
function papi.set_textures(player, textures)
player:set_properties({textures = textures})
end
function papi.set_animation(player, anim_name, speed, loop)
player:set_animation(fl_player.animations[anim_name], speed, 0, loop)
end
local metatable = {
__index = function (_, key)
return fl_player.ignore[key]
end,
__newindex = function (_, key, value)
rawset(fl_player.ignore, key, value)
end
}
papi.player_attached = {}
setmetatable(papi.player_attached, metatable)
return papi

40
src/player/mineclonia.lua Normal file
View File

@@ -0,0 +1,40 @@
local papi = {}
function papi.register_model(name, def)
return mcl_player.player_register_model(name, def)
end
function papi.set_model(player, model)
return mcl_player.player_set_model(player, model)
end
function papi.get_animation(player)
return mcl_player.player_get_animation(player)
end
function papi.get_textures(player)
return player:get_properties().textures
end
function papi.set_textures(player, textures)
player:set_properties({textures = textures})
end
function papi.set_animation(player, anim_name, speed, _)
return mcl_player.player_set_animation(player, anim_name, speed)
end
local metatable = {
__index = function (_, key)
return mcl_player.player_attached[key]
end,
__newindex = function (_, key, value)
rawset(mcl_player.player_attached, key, value)
end
}
papi.player_attached = {}
setmetatable(papi.player_attached, metatable)
return papi

41
src/player/minetest.lua Normal file
View File

@@ -0,0 +1,41 @@
local papi = {}
function papi.register_model(name, def)
return player_api.register_model(name, def)
end
function papi.set_model(player, model)
return player_api.set_model(player, model)
end
function papi.get_animation(player)
return player_api.get_animation(player)
end
function papi.get_textures(player)
return player_api.get_textures(player)
end
function papi.set_textures(player, texture)
return player_api.set_textures(player, texture)
end
function papi.set_animation(player, anim_name, speed, loop)
return player_api.set_animation(player, anim_name, speed, loop)
end
local metatable = {
__index = function (_, key)
return player_api.player_attached[key]
end,
__newindex = function (_, key, value)
rawset(player_api.player_attached, key, value)
end
}
papi.player_attached = {}
setmetatable(papi.player_attached, metatable)
return papi

View File

@@ -0,0 +1,41 @@
local papi = {}
local models = {}
function papi.register_model(name, def)
models[name] = def
end
function papi.set_model(player, model_name)
local model = models[model_name]
if not model then return end
player:set_properties({
mesh = model_name,
textures = model.textures,
visual = "mesh",
visual_size = model.visual_size,
stepheight = model.stepheight
})
end
function papi.get_animation(_)
--stub to keep from crashing
end
function papi.get_textures(player)
return player:get_properties().textures
end
function papi.set_textures(player, textures)
player:set_properties({textures = textures})
end
function papi.set_animation(_, _, _, _)
--stub to keep from crashing
end
--nothing to do here as we have no globalstep .....that we know about anyways
papi.player_attached = {}
return papi