forked from your-land/yl_cinema
Added chatcommands imprint and reload
This commit is contained in:
parent
a2f1d3741c
commit
f178a2ac22
11
chatcommand_movie_imprint.lua
Normal file
11
chatcommand_movie_imprint.lua
Normal file
@ -0,0 +1,11 @@
|
||||
local chatcommand_cmd = "movie_imprint"
|
||||
local chatcommand_definition = {
|
||||
params = "<movie>", -- Short parameter description
|
||||
description = "Imprints the <movie> on the wielded reel", -- Full description
|
||||
privs = {
|
||||
[yl_cinema.settings.admin_priv] = true
|
||||
}, -- Require the "privs" privilege to run
|
||||
func = yl_cinema.cmd_movie_imprint
|
||||
}
|
||||
|
||||
minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition)
|
@ -1,4 +1,4 @@
|
||||
dofile(yl_cinema.modpath .. "chatcommand_movie_show.lua")
|
||||
dofile(yl_cinema.modpath .. "chatcommand_movie_list.lua")
|
||||
dofile(yl_cinema.modpath .. "chatcommand_movie_reload.lua")
|
||||
--dofile(yl_cinema.modpath .. "chatcommand_movie_imprint.lua")
|
||||
dofile(yl_cinema.modpath .. "chatcommand_movie_imprint.lua")
|
@ -19,5 +19,8 @@ yl_cinema.settings.enable_craft_bigscreen_recipe = minetest.settings:get("yl_cin
|
||||
yl_cinema.settings.enable_craft_flatscreen_recipe = minetest.settings:get("yl_cinema.enable_craft_flatscreen_recipe") or
|
||||
"wool:grey,wool:grey,wool:grey,wool:grey,wool:grey,wool:grey,wool:black,,wool:black"
|
||||
|
||||
--yl_cinema.settings.enable_craft_moviereel_recipe = minetest.settings:get("yl_cinema.enable_craft_moviereel_recipe") or
|
||||
--"default:steel_ingot,cottages:wagon_wheel,default:steel_ingot,default:mese_crystal_fragment,basic_materials:empty_spool,default:paper,default:steel_ingot,cottages:wagon_wheel,default:steel_ingot"
|
||||
|
||||
yl_cinema.settings.enable_craft_moviereel_recipe = minetest.settings:get("yl_cinema.enable_craft_moviereel_recipe") or
|
||||
"default:steel_ingot,cottages:wagon_wheel,default:steel_ingot,default:mese_crystal_fragment,basic_materials:empty_spool,default:paper,default:steel_ingot,cottages:wagon_wheel,default:steel_ingot"
|
||||
"wool:grey,wool:grey,wool:grey,wool:grey,wool:grey,wool:grey,wool:black,,wool:green"
|
@ -86,8 +86,8 @@ local function showpage(ent_obj, movie_id, pagenum)
|
||||
|
||||
local movie = yl_cinema.get_movie(movie_id)
|
||||
|
||||
if not movie or pagenum then
|
||||
warn("Movie_id or pagenum not found, movie_id=" .. dump(movie_id)..", pagenum="..dump(pagenum))
|
||||
if not movie then
|
||||
warn("Movie_id not found, movie_id=" .. dump(movie_id)..", pagenum="..dump(pagenum))
|
||||
return ""
|
||||
end
|
||||
|
||||
@ -104,6 +104,11 @@ local function showpage(ent_obj, movie_id, pagenum)
|
||||
return ""
|
||||
end
|
||||
|
||||
if not ent_obj then
|
||||
warn("Cinema Screen Object not found, movie_id=" .. dump(movie_id))
|
||||
return ""
|
||||
end
|
||||
|
||||
if pagenum <= #pages then
|
||||
|
||||
table.sort(pages, yl_cinema.orderpages)
|
||||
@ -265,8 +270,8 @@ local function on_receive_fields_node(pos, formname, fields, sender)
|
||||
|
||||
local inv = minetest.get_meta(pos):get_inventory()
|
||||
local itemstack = inv:get_stack("movie", 1)
|
||||
local itemdef = itemstack:get_definition()
|
||||
local movie_id = itemdef._yl_cinema_movie_id
|
||||
local itemmeta = itemstack:get_meta()
|
||||
local movie_id = itemmeta:get_string("_yl_cinema_movie_id")
|
||||
local delay = 0
|
||||
|
||||
if fields.start0 then
|
||||
|
@ -4,7 +4,7 @@ end
|
||||
|
||||
-- Empty reel
|
||||
|
||||
local movie_item_name_empty = "yl_cinema:movie_reel"
|
||||
yl_cinema.movie_item_name_empty = "yl_cinema:movie_reel"
|
||||
local movie_item_definition_empty = {
|
||||
groups = {
|
||||
movie = 1,
|
||||
@ -12,14 +12,13 @@ local movie_item_definition_empty = {
|
||||
},
|
||||
inventory_image = "yl_cinema_icon_movie_empty_inv.png",
|
||||
wield_image = "yl_cinema_icon_movie_empty_inv.png",
|
||||
_yl_cinema_movie_id = ""
|
||||
}
|
||||
|
||||
minetest.register_craftitem(movie_item_name_empty, movie_item_definition_empty)
|
||||
minetest.register_craftitem(yl_cinema.movie_item_name_empty, movie_item_definition_empty)
|
||||
|
||||
-- Written reel
|
||||
|
||||
local movie_item_name_written = "yl_cinema:movie_print"
|
||||
yl_cinema.movie_item_name_written = "yl_cinema:movie_print"
|
||||
local movie_item_definition = {
|
||||
groups = {
|
||||
movie = 1,
|
||||
@ -29,10 +28,9 @@ local movie_item_definition = {
|
||||
inventory_image = "yl_cinema_icon_movie_inv.png",
|
||||
wield_image = "yl_cinema_icon_movie_inv.png",
|
||||
stack_max = 1,
|
||||
_yl_cinema_movie_id = ""
|
||||
}
|
||||
|
||||
minetest.register_craftitem(movie_item_name_written, movie_item_definition)
|
||||
minetest.register_craftitem(yl_cinema.movie_item_name_written, movie_item_definition)
|
||||
|
||||
-- Craft the empty reel
|
||||
|
||||
@ -41,7 +39,7 @@ local recipe = yl_cinema.string_to_recipe(yl_cinema.settings.enable_craft_movier
|
||||
if type(recipe) == "table" then
|
||||
minetest.register_craft({
|
||||
type = "shaped",
|
||||
output = movie_item_name_empty,
|
||||
output = yl_cinema.movie_item_name_empty,
|
||||
recipe = recipe
|
||||
})
|
||||
else
|
||||
|
@ -1,19 +1,6 @@
|
||||
|
||||
local function load_images(movies)
|
||||
for movie_id, _ in pairs(movies) do
|
||||
local loaded_count, total_count = yl_cinema.load_images_of_movie(movie_id)
|
||||
if loaded_count ~= total_count then
|
||||
yl_cinema.warn(loaded_count .. "/" .. total_count .. " images loaded for movie " .. movie_id)
|
||||
else
|
||||
yl_cinema.action(loaded_count .. "/" .. total_count .. " images loaded for movie " .. movie_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function run_each_serverstart()
|
||||
local movies = yl_cinema.init_movies()
|
||||
minetest.after(0, load_images, movies)
|
||||
yl_cinema.movies = movies
|
||||
minetest.after(0,yl_cinema.load_all_movies)
|
||||
end
|
||||
|
||||
run_each_serverstart()
|
||||
|
90
internal.lua
90
internal.lua
@ -18,6 +18,8 @@ local function parse_json(json_str)
|
||||
return json.decode(json_str)
|
||||
end
|
||||
|
||||
-- Initialize files
|
||||
|
||||
local function get_files_in_directory(folderpath)
|
||||
return minetest.get_dir_list(folderpath, true)
|
||||
end
|
||||
@ -56,15 +58,6 @@ local function format_table(t)
|
||||
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
|
||||
@ -367,6 +360,64 @@ function yl_cinema.cmd_show_movie(name, param)
|
||||
end
|
||||
end
|
||||
|
||||
function yl_cinema.load_all_movies()
|
||||
yl_cinema.movies = yl_cinema.init_movies()
|
||||
for movie_id, _ in pairs(yl_cinema.movies) do
|
||||
local loaded_count, total_count = load_images_of_movie(movie_id)
|
||||
if loaded_count ~= total_count then
|
||||
yl_cinema.warn(loaded_count .. "/" .. total_count .. " images loaded for movie " .. movie_id)
|
||||
else
|
||||
yl_cinema.action(loaded_count .. "/" .. total_count .. " images loaded for movie " .. movie_id)
|
||||
end
|
||||
end
|
||||
return true, "Done."
|
||||
end
|
||||
|
||||
function yl_cinema.imprint_movie(name, movie_id)
|
||||
-- Defense
|
||||
if not yl_cinema.movies or not yl_cinema.movies[movie_id] then
|
||||
return false, "Cannot find movie_id"
|
||||
end
|
||||
local pobj = minetest.get_player_by_name(name)
|
||||
if not pobj then
|
||||
return false, "Cannot find player"
|
||||
end
|
||||
local old_stack = pobj:get_wielded_item()
|
||||
if (not old_stack) or (old_stack:get_name() ~= yl_cinema.movie_item_name_empty) then
|
||||
return false, "Please wield an empty movie reel"
|
||||
end
|
||||
|
||||
-- Prepare new itemstack
|
||||
local new_stack = ItemStack(yl_cinema.movie_item_name_written)
|
||||
local new_meta = new_stack:get_meta()
|
||||
new_meta:set_string("_yl_cinema_movie_id", movie_id)
|
||||
new_meta:set_string("description", movie_id)
|
||||
|
||||
-- Replace or add
|
||||
if old_stack:get_count() == 1 then
|
||||
-- replace
|
||||
pobj:set_wielded_item(new_stack)
|
||||
return true, ""
|
||||
|
||||
else
|
||||
-- can we add?
|
||||
local inv = pobj:get_inventory()
|
||||
local listname = "main"
|
||||
|
||||
if not inv:room_for_item(listname, new_stack) then
|
||||
return false, "No space in inventory for new print."
|
||||
end
|
||||
|
||||
-- remove old
|
||||
old_stack:take_item(1)
|
||||
pobj:set_wielded_item(old_stack)
|
||||
-- add new
|
||||
inv:add_item(listname, new_stack)
|
||||
return true, ""
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function yl_cinema.cmd_movie_reload(name, param)
|
||||
local args = string.split(param, " ")
|
||||
|
||||
@ -378,11 +429,24 @@ function yl_cinema.cmd_movie_reload(name, param)
|
||||
|
||||
action("[yl_cinema] Player " .. name .. " reloads movie " .. movie_id)
|
||||
|
||||
|
||||
|
||||
return yl_cinema.load_all_movies()
|
||||
|
||||
end
|
||||
|
||||
function yl_cinema.cmd_movie_imprint(name, param)
|
||||
local args = string.split(param, " ")
|
||||
|
||||
if (#args > 1) then
|
||||
return false, "Usage: /movie_imprint [<movie_id>]"
|
||||
end
|
||||
|
||||
local movie_id = args[1] or ""
|
||||
|
||||
action("[yl_cinema] Player " .. name .. " imprints movie " .. movie_id)
|
||||
|
||||
return yl_cinema.imprint_movie(name, movie_id)
|
||||
|
||||
end
|
||||
|
||||
function yl_cinema.listmovies(searchterm)
|
||||
return search_movies(yl_cinema.movies, searchterm)
|
||||
@ -435,9 +499,5 @@ 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
|
||||
|
4
internal_initialize.lua
Normal file
4
internal_initialize.lua
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
local function get_files_in_directory(folderpath)
|
||||
return minetest.get_dir_list(folderpath, true)
|
||||
end
|
Loading…
Reference in New Issue
Block a user