diff --git a/api.lua b/api.lua new file mode 100644 index 0000000..dbd94fb --- /dev/null +++ b/api.lua @@ -0,0 +1,3 @@ +function yl_cinema.listmovies(searchterm) + return yl_cinema.search_movies(yl_cinema.movies, searchterm) +end \ No newline at end of file diff --git a/chatcommand_listmovies.lua b/chatcommand_listmovies.lua new file mode 100644 index 0000000..5bef7de --- /dev/null +++ b/chatcommand_listmovies.lua @@ -0,0 +1,30 @@ +local chatcommand_cmd = "listmovies" +local chatcommand_definition = { + params = "[]", -- Short parameter description + description = "Shows the whole movielist to you that match the , if given", -- Full description + privs = { + [yl_cinema.settings.admin_priv] = true + }, -- Require the "privs" privilege to run + func = function(name, param) + + local args = string.split(param, " ") + + if (#args > 1) then + return false, "Usage: /listmovies []" + end + + local searchterm = args[1] or "" + + core.log("action", "[yl_cinema] Player " .. name .. " searches for movie " .. searchterm) + + local success, msg = yl_cinema.listmovies(searchterm) + + if success then + return true, dump(msg) + else + return false, "No movies matching your criteria were found." + end + end +} + +minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition) diff --git a/chatcommands.lua b/chatcommands.lua index 89cd404..aab7f14 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -1,2 +1,2 @@ -dofile(yl_template.modpath .. "chatcommand_admin.lua") -dofile(yl_template.modpath .. "chatcommand_player.lua") \ No newline at end of file +--dofile(yl_cinema.modpath .. "chatcommand_showmovie.lua") +dofile(yl_cinema.modpath .. "chatcommand_listmovies.lua") \ No newline at end of file diff --git a/init.lua b/init.lua index a419794..43c6716 100644 --- a/init.lua +++ b/init.lua @@ -25,10 +25,10 @@ dofile(yl_cinema.modpath .. "dependencies.lua") dofile(yl_cinema.modpath .. "config.lua") dofile(yl_cinema.modpath .. "setup.lua") dofile(yl_cinema.modpath .. "internal.lua") ---dofile(yl_cinema.modpath .. "api.lua") +dofile(yl_cinema.modpath .. "api.lua") dofile(yl_cinema.modpath .. "initialize.lua") --dofile(yl_cinema.modpath .. "features.lua") ---dofile(yl_cinema.modpath .. "chatcommands.lua") +dofile(yl_cinema.modpath .. "chatcommands.lua") local mod_end_time = (core.get_us_time() - mod_start_time) / 1000000 core.log("action", "[MOD] yl_cinema loaded in [" .. mod_end_time .. "s]") diff --git a/internal.lua b/internal.lua index f339cff..953af1b 100644 --- a/internal.lua +++ b/internal.lua @@ -117,13 +117,17 @@ end local function search_movies(movies, search_term) local results = {} - for _, movie in ipairs(movies) do - if string.match(movie.id, search_term) or string.match(movie.name, search_term) or + for movie_id, movie in pairs(movies) do + if string.match(movie_id, search_term) or string.match(movie.name, search_term) or string.match(movie.description, search_term) then - table.insert(results, movie.id) + table.insert(results, movie_id) end end - return results + if #results > 0 then + return true, results + else + return false, results + end end -- Public functions wrap the private ones, so they can be exchanged easily @@ -182,5 +186,9 @@ function yl_cinema.load_images_of_movie(movie_id, ...) return load_images_of_movie(movie_id, ...) end +function yl_cinema.get_movie(movie_id, ...) + return get_movie(movie_id, ...) +end + yl_cinema.action = action yl_cinema.warn = warn \ No newline at end of file