various fixes / changes

This commit is contained in:
Thomas Rudin 2020-02-12 21:11:00 +01:00
parent 14dbdb9a27
commit 3095c1af26
12 changed files with 80 additions and 59 deletions

View File

@ -46,7 +46,7 @@ minetest.register_node("epic:function", {
if fields.execute then
local name = "function@" .. minetest.pos_to_string(pos)
epic.execute_epic(sender, pos, nil, nil, name)
epic.execute_epic(sender, pos, name)
end
end

View File

@ -118,12 +118,14 @@ minetest.register_node("epic:loop_sound", {
}
})
local function cleanup(_, state)
if state and state.data and state.data.loop_sound_handle then
minetest.sound_stop(state.data.loop_sound_handle)
state.data.loop_sound_handle = nil
end
end
epic.register_hook({
on_epic_exit = function(_, state)
if state and state.data and state.data.loop_sound_handle then
minetest.sound_stop(state.data.loop_sound_handle)
state.data.loop_sound_handle = nil
end
end
on_epic_exit = cleanup,
on_epic_abort = cleanup
})

View File

@ -22,7 +22,7 @@ minetest.register_node("epic:on_abort", {
"epic_node_bg.png",
"epic_node_bg.png",
"epic_node_bg.png",
"epic_node_bg.png^epic_call.png",
"epic_node_bg.png^epic_call.png^[colorize:#FF0000:100",
},
paramtype2 = "facedir",
groups = {cracky=3,oddly_breakable_by_hand=3,epic=1},
@ -110,12 +110,15 @@ end)
epic.register_hook({
-- called on epic abort
on_epic_abort = function(playername, state)
if state.data.exit_callback_pos then
if state.data.abort_callback_pos then
local node = epic.get_node(state.data.abort_callback_pos)
if node.name == "epic:function" then
-- modify instruction pointer on state, flush stack
state.ip = state.data.abort_callback_pos
state.abort = nil
state.data.abort_callback_pos = nil
state.stack = {}
epic.state[playername] = nil
epic.execute_player_state(playername, state)
end
end

View File

@ -22,7 +22,7 @@ minetest.register_node("epic:on_exit", {
"epic_node_bg.png",
"epic_node_bg.png",
"epic_node_bg.png",
"epic_node_bg.png^epic_call.png",
"epic_node_bg.png^epic_call.png^[colorize:#FF0000:100",
},
paramtype2 = "facedir",
groups = {cracky=3,oddly_breakable_by_hand=3,epic=1},
@ -115,7 +115,9 @@ epic.register_hook({
if node.name == "epic:function" then
-- modify instruction pointer on state, flush stack
state.ip = state.data.exit_callback_pos
state.data.exit_callback_pos = nil
state.stack = {}
epic.state[playername] = nil
epic.execute_player_state(playername, state)
end
end

View File

@ -70,12 +70,14 @@ minetest.register_node("epic:daynightratio", {
}
})
local function cleanup(playername)
local player = minetest.get_player_by_name(playername)
if player then
player:override_day_night_ratio(nil)
end
end
epic.register_hook({
on_epic_exit = function(playername)
local player = minetest.get_player_by_name(playername)
if player then
player:override_day_night_ratio(nil)
end
end
on_epic_exit = cleanup,
on_epic_abort = cleanup
})

View File

@ -62,15 +62,18 @@ minetest.register_node("epic:set_gravity", {
}
})
epic.register_hook({
on_epic_exit = function(playername)
local player = minetest.get_player_by_name(playername)
if player then
if use_player_monoids then
player_monoids.gravity:del_change(player, "epic:set_gravity")
else
player:set_physics_override({ gravity = 1 })
end
local function cleanup(playername)
local player = minetest.get_player_by_name(playername)
if player then
if use_player_monoids then
player_monoids.gravity:del_change(player, "epic:set_gravity")
else
player:set_physics_override({ gravity = 1 })
end
end
end
epic.register_hook({
on_epic_exit = cleanup,
on_epic_abort = cleanup
})

View File

@ -37,9 +37,9 @@ epic.abort = function(playername)
local state = epic.state[playername]
if state then
if epic.log_executor then
minetest.log("action", "[epic] player died: " .. playername)
minetest.log("action", "[epic] player aborted manually: " .. playername)
end
epic.run_hook("on_epic_abort", { playername, state, "manual" })
state.abort = "manual"
end
end

View File

@ -29,8 +29,8 @@ function epic.execute_player_state(playername, state)
epic.execute_player_state(playername, state)
else
-- done
epic.state[playername] = nil
epic.run_hook("on_epic_exit", {playername, state})
epic.state[playername] = nil
end
return
@ -38,7 +38,7 @@ function epic.execute_player_state(playername, state)
local result_next = false
local result_next_pos = nil
local abort_flag
local abort_flag = state.abort
local ctx = {
-- next step
@ -70,9 +70,6 @@ function epic.execute_player_state(playername, state)
step_data = state.step_data
}
minetest.log("action", "[epic] player " .. playername ..
" executes block at " .. minetest.pos_to_string(pos))
local nodedef = minetest.registered_nodes[node.name]
local epicdef = nodedef.epic
local meta = minetest.get_meta(pos)
@ -108,7 +105,6 @@ function epic.execute_player_state(playername, state)
if abort_flag then
epic.run_hook("on_epic_abort", { playername, epic.state[playername], abort_flag })
epic.state[playername] = nil
return
end
@ -159,6 +155,7 @@ minetest.register_on_leaveplayer(function(player, timed_out)
minetest.log("action", "[epic] player left the game: " .. playername)
end
epic.run_hook("on_epic_abort", { playername, state, reason })
epic.state[playername] = nil
end
end)
@ -170,5 +167,6 @@ minetest.register_on_dieplayer(function(player)
minetest.log("action", "[epic] player died: " .. playername)
end
epic.run_hook("on_epic_abort", { playername, state, "died" })
epic.state[playername] = nil
end
end)

View File

@ -39,29 +39,32 @@ local function setup(playername, name)
hud[playername] = data
end
local function exit_cleanup(playername)
local data = hud[playername]
local player = minetest.get_player_by_name(playername)
if not data or not player then
return
end
if data.name then
player:hud_remove(data.name)
end
if data.time then
player:hud_remove(data.time)
end
hud[playername] = nil
end
epic.register_hook({
on_execute_epic = function(player, _, state)
setup(player:get_player_name(), state.name)
end,
on_epic_exit = function(playername)
local data = hud[playername]
local player = minetest.get_player_by_name(playername)
if not data or not player then
return
end
if data.name then
player:hud_remove(data.name)
end
if data.time then
player:hud_remove(data.time)
end
hud[playername] = nil
end,
on_epic_exit = exit_cleanup,
on_epic_abort = exit_cleanup
})
local update

View File

@ -11,7 +11,7 @@ epic.form.epic_configure = function(pos, playername)
local name = meta:get_string("name")
local main_pos = meta:get_string("main_pos") or "<none>"
local formspec = "size[8,8;]" ..
local formspec = "size[8,6;]" ..
"label[0,0;Epic start block]" ..
"field[0.2,1.5;8,1;name;Name;" .. name .. "]" ..

View File

@ -7,7 +7,14 @@ epic.register_hook({
" state=" .. dump(state))
end,
on_before_node_enter = function(pos, player)
on_before_node_check = function(pos, player)
minetest.log("action", "[epic] on_before_node_check player=" ..
player:get_player_name() ..
" pos=" .. minetest.pos_to_string(pos) ..
" node=" .. minetest.get_node(pos).name)
end,
on_before_node_enter = function(pos, player)
minetest.log("action", "[epic] on_before_node_enter player=" ..
player:get_player_name() ..
" pos=" .. minetest.pos_to_string(pos) ..

View File

@ -11,22 +11,23 @@ local function enable_hud(player)
end
local function update_hud(player)
local trace_player_name = player:get_player_name()
local hud_data = hud[player:get_player_name()]
for _, other_player in ipairs(minetest.get_connected_players()) do
local name = other_player:get_player_name()
local state = epic.get_state(name)
if hud_data[name] and state then
if hud_data[trace_player_name] and state then
-- update existing entry
player:hud_change(hud_data[name], "world_pos", state.ip)
player:hud_change(hud_data[trace_player_name], "world_pos", state.ip)
elseif hud_data[name] and not state then
elseif hud_data[trace_player_name] and not state then
-- remove entry
player:hud_remove(hud_data[name])
player:hud_remove(hud_data[trace_player_name])
elseif not hud_data[name] and state then
elseif not hud_data[trace_player_name] and state then
-- add existing entry
hud_data[name] = player:hud_add({
hud_data[trace_player_name] = player:hud_add({
hud_elem_type = "waypoint",
name = "EPIC:" .. name,
text = "m",