Skip to content

Commit

Permalink
Merge 121afd3 into dd217ab
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed May 22, 2024
2 parents dd217ab + 121afd3 commit 07867bf
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 61 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
enable_benchmarks: true
git_dependencies: |
https://github.com/BuckarooBanzay/promise
https://github.com/OgelGames/fakelib
additional_config: |
mtt_enable_selftest = true
- name: Coveralls
Expand Down
2 changes: 1 addition & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ read_globals = {
"VoxelArea", "vector",

-- deps
"Promise"
"Promise", "fakelib"
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ mtt.export_nodenames(filename)
mtt.validate_nodenames(minetest.get_modpath("my_mod") .. "/nodenames.txt")

-- simulate a player (EXPERIMENTAL, some methods aren't implemented yet)
-- NOTE: requires the `fakelib` mod to be present
local player = mtt.join_player("singleplayer")
player:leave()
```
Expand Down
6 changes: 4 additions & 2 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ if mtt.enabled then
loadfile(MP .. "/coverage.lua")(ie)
end

-- player api override
dofile(MP .. "/player.lua")
if minetest.get_modpath("fakelib") then
-- player api override
dofile(MP .. "/player.lua")
end

-- start test execution
dofile(MP .. "/execute.lua")
Expand Down
3 changes: 2 additions & 1 deletion mod.conf
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
name = mtt
name = mtt
optional_depends = fakelib
67 changes: 10 additions & 57 deletions player.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@


local function no_op() end

local players = {}

-- merged "real" and "fake" player list
Expand Down Expand Up @@ -36,58 +32,7 @@ function minetest.get_player_by_name(name)
end

function mtt.join_player(name)
local pos = {x=0, y=0, z=0}
local hud_flags = {}
local armor_groups = {}
local health = 20
local breath = 20
local properties = {
eye_height = {x=0, y=0.8, z=0}
}

local player = {
info = {
formspec_version = 4
},
get_player_name = function() return name end,
set_lighting = no_op,
set_inventory_formspec = no_op,
get_properties = function() return properties end,
set_properties = function(p)
for k, v in pairs(p) do
properties[k] = v
end
end,
set_local_animation = no_op,
set_animation = no_op,
set_formspec_prepend = no_op,
get_inventory = function()
local inv = minetest.get_inventory({type="detached", name=name})
if not inv then
inv = minetest.create_detached_inventory(name, {})
end
return inv
end,
hud_set_hotbar_image = no_op,
hud_set_hotbar_selected_image = no_op,
hud_get_flags = function() return hud_flags end,
hud_set_flags = function(f) hud_flags = f end,
get_armor_groups = function() return armor_groups end,
set_armor_groups = function(g) armor_groups = g end,
get_pos = function() return pos end,
set_pos = function(p) pos = p end,
get_health = function() return health end,
set_health = function(h) health = h end,
get_breath = function() return breath end,
set_breath = function(b) breath = b end,
leave = function(self, timed_out)
for _, fn in ipairs(minetest.registered_on_leaveplayers) do
fn(self, timed_out)
end
players[name] = nil
end
}

local player = fakelib.create_player({ name = name })
players[name] = player

local auth_handler = minetest.get_auth_handler()
Expand All @@ -104,5 +49,13 @@ function mtt.join_player(name)
fn(player)
end

-- custom leave function
player.leave = function(timed_out)
for _, fn in ipairs(minetest.registered_on_leaveplayers) do
fn(player, timed_out)
end
players[name] = nil
end

return player
end
end

0 comments on commit 07867bf

Please sign in to comment.