Refactor audio out of api.lua
This commit is contained in:
parent
43406ded7e
commit
51ef36c50c
10
audio.lua
Normal file
10
audio.lua
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
local audio = {
|
||||||
|
-- Play a feedback sound localized on the given player
|
||||||
|
-- sound: The sound to play
|
||||||
|
-- player: The player who triggered the sound
|
||||||
|
play_feedback = function(sound, player)
|
||||||
|
minetest.sound_play(sound, { pos=player:get_pos(), max_hear_distance=5 }, true);
|
||||||
|
end
|
||||||
|
};
|
||||||
|
|
||||||
|
return audio;
|
@ -1,4 +1,4 @@
|
|||||||
local chunk, map_formspec = ...;
|
local chunk, audio, map_formspec = ...;
|
||||||
|
|
||||||
local MAXINT = 2147483647;
|
local MAXINT = 2147483647;
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ minetest.register_chatcommand("map", {
|
|||||||
scale = 1;
|
scale = 1;
|
||||||
end
|
end
|
||||||
|
|
||||||
cartographer.map_sound("cartographer_open_map", player);
|
audio.play_feedback("cartographer_open_map", player);
|
||||||
minetest.show_formspec(name, "map", map_formspec.from_coords(math.floor((player_x / scale) + 0.5), math.floor((player_z / scale) + 0.5), 40, 40, detail, scale, true));
|
minetest.show_formspec(name, "map", map_formspec.from_coords(math.floor((player_x / scale) + 0.5), math.floor((player_z / scale) + 0.5), 40, 40, detail, scale, true));
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
7
init.lua
7
init.lua
@ -49,12 +49,13 @@ local marker_lookup = {};
|
|||||||
-- Includes
|
-- Includes
|
||||||
local skin = loadfile(modpath .. "/skin_api.lua") ();
|
local skin = loadfile(modpath .. "/skin_api.lua") ();
|
||||||
local gui = loadfile(modpath .. "/formspec.lua") ();
|
local gui = loadfile(modpath .. "/formspec.lua") ();
|
||||||
|
local audio = loadfile(modpath .. "/audio.lua") ();
|
||||||
|
|
||||||
local scanner = loadfile(modpath .. "/scanner.lua") (map_data, chunk);
|
local scanner = loadfile(modpath .. "/scanner.lua") (map_data, chunk);
|
||||||
loadfile(modpath .. "/map_api.lua") (map_data, chunk, scanner, biome_lookup, marker_lookup);
|
loadfile(modpath .. "/map_api.lua") (map_data, chunk, scanner, biome_lookup, marker_lookup);
|
||||||
local map_formspec = loadfile(modpath .. "/map_formspec.lua") (map_data, gui, skin);
|
local map_formspec = loadfile(modpath .. "/map_formspec.lua") (map_data, gui, skin);
|
||||||
loadfile(modpath .. "/items.lua") (chunk, marker_lookup, gui, skin, map_formspec);
|
loadfile(modpath .. "/items.lua") (chunk, marker_lookup, gui, skin, audio, map_formspec);
|
||||||
loadfile(modpath .. "/commands.lua") (chunk, map_formspec);
|
loadfile(modpath .. "/commands.lua") (chunk, audio, map_formspec);
|
||||||
loadfile(modpath .. "/table.lua") (gui, skin);
|
loadfile(modpath .. "/table.lua") (gui, skin, audio);
|
||||||
|
|
||||||
cartographer.skin = skin;
|
cartographer.skin = skin;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local chunk, marker_lookup, gui, skin, map_formspec = ...;
|
local chunk, marker_lookup, gui, skin, audio, map_formspec = ...;
|
||||||
|
|
||||||
-- The list of players looking at maps, and the map IDs that they're looking at
|
-- The list of players looking at maps, and the map IDs that they're looking at
|
||||||
local player_maps = {};
|
local player_maps = {};
|
||||||
@ -248,7 +248,7 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
|
|||||||
local player_x, player_z = map:to_coordinates(pos.x, pos.z);
|
local player_x, player_z = map:to_coordinates(pos.x, pos.z);
|
||||||
map:set_marker(player_x, player_z, marker);
|
map:set_marker(player_x, player_z, marker);
|
||||||
|
|
||||||
cartographer.map_sound("cartographer_write", player);
|
audio.play_feedback("cartographer_write", player);
|
||||||
show_map_id_formspec(map.id, pos.x, pos.z, player:get_player_name(), data.page);
|
show_map_id_formspec(map.id, pos.x, pos.z, player:get_player_name(), data.page);
|
||||||
elseif k == "prev_button" then
|
elseif k == "prev_button" then
|
||||||
show_map_id_formspec(map.id, pos.x, pos.z, player:get_player_name(), data.height_mode, data.page - 1);
|
show_map_id_formspec(map.id, pos.x, pos.z, player:get_player_name(), data.height_mode, data.page - 1);
|
||||||
@ -317,7 +317,7 @@ minetest.register_node("cartographer:map", {
|
|||||||
-- pos: The position of the node
|
-- pos: The position of the node
|
||||||
-- player: The player that right-clicked the node
|
-- player: The player that right-clicked the node
|
||||||
on_rightclick = function(pos, _, player)
|
on_rightclick = function(pos, _, player)
|
||||||
cartographer.map_sound("cartographer_open_map", player);
|
audio.play_feedback("cartographer_open_map", player);
|
||||||
show_map_meta(minetest.get_meta(pos), player);
|
show_map_meta(minetest.get_meta(pos), player);
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -326,7 +326,7 @@ minetest.register_node("cartographer:map", {
|
|||||||
-- stack: The itemstack
|
-- stack: The itemstack
|
||||||
-- player: The player that used the item
|
-- player: The player that used the item
|
||||||
on_use = function(stack, player)
|
on_use = function(stack, player)
|
||||||
cartographer.map_sound("cartographer_open_map", player);
|
audio.play_feedback("cartographer_open_map", player);
|
||||||
show_map_meta(stack:get_meta(), player);
|
show_map_meta(stack:get_meta(), player);
|
||||||
return stack;
|
return stack;
|
||||||
end,
|
end,
|
||||||
|
@ -261,10 +261,3 @@ function cartographer.get_marker_texture(id, detail)
|
|||||||
|
|
||||||
return nil;
|
return nil;
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Play a feedback sound localized on the given player
|
|
||||||
-- sound: The sound to play
|
|
||||||
-- player: The player who triggered the sound
|
|
||||||
function cartographer.map_sound(sound, player)
|
|
||||||
minetest.sound_play(sound, { pos=player:get_pos(), max_hear_distance=5 }, true);
|
|
||||||
end
|
|
||||||
|
18
table.lua
18
table.lua
@ -1,4 +1,4 @@
|
|||||||
local gui, gui_skin = ...;
|
local gui, gui_skin, audio = ...;
|
||||||
|
|
||||||
local MAP_SIZE = 40;
|
local MAP_SIZE = 40;
|
||||||
local SCALE_SMALL = 1;
|
local SCALE_SMALL = 1;
|
||||||
@ -728,7 +728,7 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
|
|||||||
inv:set_stack("output", 1, stack);
|
inv:set_stack("output", 1, stack);
|
||||||
end
|
end
|
||||||
|
|
||||||
cartographer.map_sound("cartographer_write", player);
|
audio.play_feedback("cartographer_write", player);
|
||||||
end
|
end
|
||||||
elseif fields["copy"] then
|
elseif fields["copy"] then
|
||||||
local cost = get_copy_material_cost(meta);
|
local cost = get_copy_material_cost(meta);
|
||||||
@ -736,7 +736,7 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
|
|||||||
meta:set_int("paper", meta:get_int("paper") - cost.paper);
|
meta:set_int("paper", meta:get_int("paper") - cost.paper);
|
||||||
meta:set_int("pigment", meta:get_int("pigment") - cost.pigment);
|
meta:set_int("pigment", meta:get_int("pigment") - cost.pigment);
|
||||||
|
|
||||||
cartographer.map_sound("cartographer_write", player);
|
audio.play_feedback("cartographer_write", player);
|
||||||
|
|
||||||
local inv = meta:get_inventory();
|
local inv = meta:get_inventory();
|
||||||
inv:set_stack("copy_output", 1, cartographer.copy_map_item(inv:get_stack("copy_input", 1)));
|
inv:set_stack("copy_output", 1, cartographer.copy_map_item(inv:get_stack("copy_input", 1)));
|
||||||
@ -759,13 +759,13 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
|
|||||||
meta:set_int("scale", SCALE_HUGE);
|
meta:set_int("scale", SCALE_HUGE);
|
||||||
elseif fields["tab1"] then
|
elseif fields["tab1"] then
|
||||||
player_tables[player:get_player_name()].tab = 1;
|
player_tables[player:get_player_name()].tab = 1;
|
||||||
cartographer.map_sound("cartographer_turn_page", player);
|
audio.play_feedback("cartographer_turn_page", player);
|
||||||
elseif fields["tab2"] then
|
elseif fields["tab2"] then
|
||||||
player_tables[player:get_player_name()].tab = 2;
|
player_tables[player:get_player_name()].tab = 2;
|
||||||
cartographer.map_sound("cartographer_turn_page", player);
|
audio.play_feedback("cartographer_turn_page", player);
|
||||||
elseif fields["tab3"] then
|
elseif fields["tab3"] then
|
||||||
player_tables[player:get_player_name()].tab = 3;
|
player_tables[player:get_player_name()].tab = 3;
|
||||||
cartographer.map_sound("cartographer_turn_page", player);
|
audio.play_feedback("cartographer_turn_page", player);
|
||||||
end
|
end
|
||||||
|
|
||||||
if not fields["quit"] then
|
if not fields["quit"] then
|
||||||
@ -864,7 +864,7 @@ minetest.register_node("cartographer:simple_table", {
|
|||||||
tab = 1,
|
tab = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
cartographer.map_sound("cartographer_open_map", player);
|
audio.play_feedback("cartographer_open_map", player);
|
||||||
table_formspec(player:get_player_name())
|
table_formspec(player:get_player_name())
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -904,7 +904,7 @@ minetest.register_node("cartographer:standard_table", {
|
|||||||
tab = 1,
|
tab = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
cartographer.map_sound("cartographer_open_map", player);
|
audio.play_feedback("cartographer_open_map", player);
|
||||||
table_formspec(player:get_player_name())
|
table_formspec(player:get_player_name())
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -944,7 +944,7 @@ minetest.register_node("cartographer:advanced_table", {
|
|||||||
tab = 1,
|
tab = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
cartographer.map_sound("cartographer_open_map", player);
|
audio.play_feedback("cartographer_open_map", player);
|
||||||
table_formspec(player:get_player_name())
|
table_formspec(player:get_player_name())
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user