forked from your-land/yl_cinema
your-land/bugtracker#4668 .27 /movies_list shows table including itemstring
This commit is contained in:
parent
8ae2d03929
commit
0b564fc78a
@ -15,3 +15,5 @@ yl_cinema.settings.enable_craft_bigscreen = minetest.settings:get("yl_cinema.ena
|
||||
|
||||
yl_cinema.settings.enable_craft_bigscreen_recipe = minetest.settings:get("yl_cinema.enable_craft_bigscreen_recipe") or
|
||||
"wool:grey,wool:grey,wool:grey,wool:grey,wool:grey,wool:grey,wool:black,,wool:black"
|
||||
|
||||
yl_cinema.settings.movie_item_name = minetest.settings:get("yl_cinema.movie_item_name") or "yl_cinema:movie"
|
||||
|
@ -1,19 +1,7 @@
|
||||
if yl_cinema.settings.enable_movieitems ~= true then
|
||||
return
|
||||
end
|
||||
if yl_cinema.settings.enable_movieitems ~= true then return end
|
||||
|
||||
local function remove_forbidden_characters(str)
|
||||
local pattern = "[^%w_]"
|
||||
return string.gsub(str, pattern, "_")
|
||||
end
|
||||
|
||||
local movie_item_name = "yl_cinema:movie"
|
||||
local movie_item_definition = {
|
||||
groups = {
|
||||
movie = 1,
|
||||
not_in_creative_inventory = 1,
|
||||
media = 1
|
||||
},
|
||||
groups = {movie = 1, not_in_creative_inventory = 1, media = 1},
|
||||
inventory_image = "yl_cinema_icon_movie_inv.png",
|
||||
wield_image = "yl_cinema_icon_movie_inv.png",
|
||||
stack_max = 1,
|
||||
@ -25,9 +13,12 @@ for movie_id, movie in pairs(yl_cinema.movies) do
|
||||
if movie.item and (movie.item == true) then
|
||||
local item_definition = movie_item_definition
|
||||
item_definition._yl_cinema_movie_id = movie_id
|
||||
core.log("action", "item_definition._yl_cinema_movie_id=" .. item_definition._yl_cinema_movie_id)
|
||||
core.log("action", "item_definition._yl_cinema_movie_id=" ..
|
||||
item_definition._yl_cinema_movie_id)
|
||||
item_definition.short_description = minetest.formspec_escape(movie.name)
|
||||
item_definition.description = minetest.formspec_escape(movie.description)
|
||||
minetest.register_craftitem(movie_item_name .. "_" .. remove_forbidden_characters(movie_id), item_definition)
|
||||
item_definition.description =
|
||||
minetest.formspec_escape(movie.description)
|
||||
local item_string = yl_cinema.get_itemstring(movie_id)
|
||||
minetest.register_craftitem(item_string, item_definition)
|
||||
end
|
||||
end
|
||||
|
63
internal.lua
63
internal.lua
@ -24,6 +24,47 @@ end
|
||||
|
||||
-- internal functions
|
||||
|
||||
local function format_table(t)
|
||||
-- Format of t must be {{row1,row2,row3, ...},{row1,row2,row3, ...},...}
|
||||
local blanks_between_rows = 3
|
||||
local max_row_length = {}
|
||||
for linenumber = 1, #t do
|
||||
for rownumber = 1, #t[linenumber] do
|
||||
local row_length = #tostring(t[linenumber][rownumber])
|
||||
if (max_row_length[rownumber] or 0) < row_length then
|
||||
max_row_length[rownumber] = row_length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local ret = {}
|
||||
|
||||
for linenumber = 1, #t do
|
||||
local line_s = ""
|
||||
for rownumber = 1, #t[linenumber] do
|
||||
local text = t[linenumber][rownumber]
|
||||
local text_length = #tostring(text)
|
||||
local add_blanks = max_row_length[rownumber] - text_length
|
||||
local newtext = t[linenumber][rownumber]
|
||||
for add = 1, (add_blanks + blanks_between_rows) do
|
||||
newtext = newtext .. " "
|
||||
end
|
||||
line_s = line_s .. newtext
|
||||
end
|
||||
table.insert(ret,line_s)
|
||||
end
|
||||
return table.concat(ret, "\n")
|
||||
end
|
||||
|
||||
local function remove_forbidden_characters(str)
|
||||
local pattern = "[^%w_]"
|
||||
return string.gsub(str, pattern, "_")
|
||||
end
|
||||
|
||||
local function get_itemstring(movie_id)
|
||||
return yl_cinema.settings.movie_item_name .. "_" .. remove_forbidden_characters(movie_id)
|
||||
end
|
||||
|
||||
local function remove_invisible_folders(folder_list)
|
||||
local filtered_list = {}
|
||||
for _, folder in ipairs(folder_list) do
|
||||
@ -149,7 +190,11 @@ local function search_movies(movies, search_term)
|
||||
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)
|
||||
local item_string = ""
|
||||
if movie.item == true then
|
||||
item_string = get_itemstring(movie_id)
|
||||
end
|
||||
table.insert(results, {movie_id, movie.name, item_string or ""})
|
||||
end
|
||||
end
|
||||
if #results > 0 then
|
||||
@ -269,10 +314,18 @@ function yl_cinema.cmd_list_movies(name, param)
|
||||
|
||||
minetest.log("action", "[yl_cinema] Player " .. name .. " searches for movie " .. searchterm)
|
||||
|
||||
local success, msg = yl_cinema.listmovies(searchterm)
|
||||
local display_table = {{"movie_id","name","itemstring"}}
|
||||
|
||||
local success, t = yl_cinema.listmovies(searchterm)
|
||||
|
||||
for _,movies in ipairs(t) do
|
||||
table.insert(display_table, movies)
|
||||
end
|
||||
|
||||
local nice_format = format_table(display_table)
|
||||
|
||||
if success then
|
||||
return true, dump(msg)
|
||||
return true, nice_format
|
||||
else
|
||||
return false, "No movies matching your criteria were found."
|
||||
end
|
||||
@ -353,5 +406,9 @@ function yl_cinema.orderpages(a, b, ...)
|
||||
return orderpages(a, b, ...)
|
||||
end
|
||||
|
||||
function yl_cinema.get_itemstring(movie_id, ...)
|
||||
return get_itemstring(movie_id, ...)
|
||||
end
|
||||
|
||||
yl_cinema.action = action
|
||||
yl_cinema.warn = warn
|
||||
|
Loading…
Reference in New Issue
Block a user