forked from your-land/yl_cinema
352 lines
10 KiB
Lua
352 lines
10 KiB
Lua
if not (yl_cinema.settings.enable_screens and (yl_cinema.settings.enable_screens == true)) then
|
|
return
|
|
end
|
|
|
|
local warn = yl_cinema.warn
|
|
local action = yl_cinema.action
|
|
|
|
local bigscreen_entity_name = "yl_cinema:movie_bigscreen"
|
|
local screen_width = 12
|
|
local screen_height = 6.75
|
|
local bigscreen_entity_initial_properties = {}
|
|
local bigscreen_entity_definition = {
|
|
initial_properties = bigscreen_entity_initial_properties,
|
|
visual = "sprite",
|
|
visual_size = {
|
|
x = screen_width,
|
|
y = screen_height
|
|
},
|
|
glow = 15,
|
|
nametag = "",
|
|
nametag_color = "#ffcc00",
|
|
nametag_bgcolor = "#000000",
|
|
collisionbox = {0},
|
|
physical = false,
|
|
textures = {"yl_cinema_block_bigscreen.png^yl_cinema_icon_movie_inv.png"},
|
|
_yl_cinema_stored_movie = "",
|
|
on_blast = function()
|
|
return false, false, {}
|
|
end
|
|
}
|
|
|
|
minetest.register_entity(bigscreen_entity_name, bigscreen_entity_definition)
|
|
|
|
|
|
local flatscreen_entity_name = "yl_cinema:movie_flatscreen"
|
|
local flatscreen_entity_initial_properties = {}
|
|
local flatscreen_entity_definition = {
|
|
initial_properties = flatscreen_entity_initial_properties,
|
|
visual = "mesh",
|
|
mesh = "yl_cinema_unit_plane.obj",
|
|
backface_culling = false, -- make visible from both sides
|
|
visual_size = {
|
|
-- 1 unit in world coords is 10 units in model coords
|
|
x = screen_width * 10,
|
|
y = 1,
|
|
z = screen_height * 10,
|
|
},
|
|
glow = 15,
|
|
nametag = "",
|
|
nametag_color = "#ffcc00",
|
|
nametag_bgcolor = "#000000",
|
|
collisionbox = {0},
|
|
physical = false,
|
|
textures = {"yl_cinema_block_bigscreen.png^yl_cinema_icon_movie_inv.png"},
|
|
_yl_cinema_stored_movie = "",
|
|
on_blast = function()
|
|
return false, false, {}
|
|
end
|
|
}
|
|
|
|
minetest.register_entity(flatscreen_entity_name, flatscreen_entity_definition)
|
|
|
|
|
|
-- Helper
|
|
|
|
local function find_entity(pos)
|
|
local v = vector.new(0, 3.5, 0)
|
|
local center_pos = vector.add(pos, v)
|
|
for _, obj in pairs(minetest.get_objects_inside_radius(center_pos, 0.5)) do
|
|
if obj and obj:get_luaentity() and
|
|
(obj:get_luaentity().name == bigscreen_entity_name or
|
|
obj:get_luaentity().name == flatscreen_entity_name) then
|
|
return obj
|
|
end
|
|
end
|
|
end
|
|
|
|
-- Changepage
|
|
|
|
local function showpage(ent_obj, movie_id, pagenum)
|
|
|
|
if not movie_id or not pagenum then
|
|
warn("Movie_id or pagenum not found, movie_id=" .. dump(movie_id)..", pagenum="..dump(pagenum))
|
|
return ""
|
|
end
|
|
|
|
local movie = yl_cinema.get_movie(movie_id)
|
|
|
|
if not movie then
|
|
warn("Movie_id not found, movie_id=" .. dump(movie_id)..", pagenum="..dump(pagenum))
|
|
return ""
|
|
end
|
|
|
|
local pages = movie.pages or {}
|
|
|
|
if not ent_obj then
|
|
warn("Cinema Screen Object not found, movie_id=" .. dump(movie_id))
|
|
return ""
|
|
end
|
|
|
|
local ent_properties = ent_obj:get_properties()
|
|
if ent_properties._playing == true then
|
|
warn("Tried to play movie on running projector, movie_id=" .. dump(movie_id))
|
|
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)
|
|
|
|
local page = pages[pagenum] or {}
|
|
|
|
local delay = page.duration or 3
|
|
local nextpage = pagenum + 1
|
|
minetest.after(delay, showpage, ent_obj, movie_id, nextpage)
|
|
|
|
-- Payload
|
|
|
|
if pagenum == 0 then
|
|
local properties = {
|
|
textures = {movie.title_texture},
|
|
infotext = movie.name,
|
|
nametag = movie.decription,
|
|
_playing = true
|
|
}
|
|
ent_obj:set_properties(properties)
|
|
else
|
|
if not page then
|
|
warn("Page empty = " .. dump(page))
|
|
return ""
|
|
end
|
|
|
|
local properties = {
|
|
textures = {page.texture},
|
|
infotext = movie.name,
|
|
nametag = page.caption,
|
|
_playing = true
|
|
}
|
|
|
|
ent_obj:set_properties(properties)
|
|
|
|
end
|
|
else -- Fin
|
|
local properties = {
|
|
textures = {"yl_cinema_block_bigscreen.png^yl_cinema_icon_movie_inv.png"},
|
|
infotext = "Fin",
|
|
nametag = "Fin",
|
|
_playing = false
|
|
}
|
|
ent_obj:set_properties(properties)
|
|
end
|
|
end
|
|
|
|
local function start_movie(ent_obj, movie_id)
|
|
if ent_obj and movie_id then
|
|
showpage(ent_obj, movie_id, 0)
|
|
else
|
|
return false, "Object " .. dump(ent_obj) .. " not found."
|
|
end
|
|
end
|
|
|
|
-- Item
|
|
|
|
local function get_formspec(pos)
|
|
local formspec = {}
|
|
table.insert(formspec, "formspec_version[4]size[10.75,7]")
|
|
table.insert(formspec, "list[context;movie;0.5,0.5;1,1;]")
|
|
table.insert(formspec, "list[current_player;main;0.5,2;8,4;]")
|
|
table.insert(formspec, "listring[]")
|
|
table.insert(formspec, "button_exit[9.7,0.3;0.75,0.75;quit;X]")
|
|
table.insert(formspec, "button[1.6,0.5;1.8,1;start0;Start]")
|
|
table.insert(formspec, "button[3.6,0.5;1.8,1;start3;3 Seconds]")
|
|
table.insert(formspec, "button[5.6,0.5;1.8,1;start5;5 Seconds]")
|
|
table.insert(formspec, "button[7.6,0.5;1.8,1;start10;10 Seconds]")
|
|
return table.concat(formspec, "")
|
|
end
|
|
|
|
local function spawn_bigscreen(pos)
|
|
local v = vector.new(0, 3.5, 0)
|
|
local center_pos = vector.add(pos, v)
|
|
|
|
minetest.add_entity(center_pos, bigscreen_entity_name)
|
|
end
|
|
|
|
local function spawn_flatscreen(pos, rotation)
|
|
local v = vector.new(0, 3.5, 0)
|
|
local center_pos = vector.add(pos, v)
|
|
|
|
local screen = minetest.add_entity(center_pos, flatscreen_entity_name)
|
|
if screen then
|
|
screen:set_rotation(vector.new(math.pi/2.0, rotation, 0))
|
|
end
|
|
end
|
|
|
|
local function on_construct_base_node(pos)
|
|
local meta = minetest.get_meta(pos)
|
|
local formspec = get_formspec(pos)
|
|
meta:set_string("formspec", formspec)
|
|
|
|
local inv = meta:get_inventory()
|
|
inv:set_size("movie", 1)
|
|
end
|
|
|
|
local function on_construct_bigscreen_node(pos)
|
|
on_construct_base_node(pos)
|
|
spawn_bigscreen(pos)
|
|
end
|
|
|
|
local function on_construct_flatscreen_node(pos)
|
|
on_construct_base_node(pos)
|
|
|
|
local node = minetest.get_node(pos)
|
|
spawn_flatscreen(pos, node.param2 * math.pi/2)
|
|
end
|
|
|
|
local function on_destruct_node(pos)
|
|
local ent_obj = find_entity(pos)
|
|
if ent_obj then
|
|
ent_obj:remove()
|
|
else
|
|
yl_cinema.warn("Bigscreen entity not found at " .. minetest.pos_to_string(pos, 0))
|
|
end
|
|
end
|
|
|
|
local function on_blast_node(pos, intensity)
|
|
local ent_obj = find_entity(pos)
|
|
if ent_obj then
|
|
ent_obj:remove()
|
|
else
|
|
yl_cinema.warn("Bigscreen entity not found at " .. minetest.pos_to_string(pos, 0))
|
|
end
|
|
end
|
|
|
|
local function allow_metadata_inventory_put_node(pos, listname, index, stack, player)
|
|
local groupname = "movie"
|
|
local itemname = stack:get_name()
|
|
local playername = player:get_player_name()
|
|
if (not minetest.is_protected(pos, playername)) and (minetest.get_item_group(itemname, groupname) >= 1) then
|
|
return 1
|
|
else
|
|
return 0
|
|
end
|
|
end
|
|
|
|
local function allow_metadata_inventory_take_node(pos, listname, index, stack, player)
|
|
local playername = player:get_player_name()
|
|
if not minetest.is_protected(pos, playername) then
|
|
return 1
|
|
else
|
|
return 0
|
|
end
|
|
end
|
|
|
|
local function can_dig_node(pos, player)
|
|
local playername = player:get_player_name()
|
|
local inv = minetest.get_meta(pos):get_inventory()
|
|
return inv:is_empty("movie") and not minetest.is_protected(pos, playername)
|
|
end
|
|
|
|
local function on_receive_fields_node(pos, formname, fields, sender)
|
|
|
|
if (not next(fields)) or fields.quit then
|
|
return
|
|
end
|
|
|
|
local inv = minetest.get_meta(pos):get_inventory()
|
|
local itemstack = inv:get_stack("movie", 1)
|
|
local itemmeta = itemstack:get_meta()
|
|
local movie_id = itemmeta:get_string("_yl_cinema_movie_id")
|
|
local delay = 0
|
|
|
|
if fields.start0 then
|
|
delay = 0
|
|
elseif fields.start3 then
|
|
delay = 3
|
|
elseif fields.start5 then
|
|
delay = 5
|
|
elseif fields.start10 then
|
|
delay = 10
|
|
end
|
|
|
|
-- Grab entity
|
|
|
|
local ent_obj = find_entity(pos)
|
|
|
|
minetest.after(delay, start_movie, ent_obj, movie_id)
|
|
|
|
end
|
|
|
|
yl_cinema.bigscreen_block_name = "yl_cinema:bigscreen_base"
|
|
local bigscreen_block_definition = {
|
|
description = "Cinema Base with rotating screen",
|
|
drawtype = "nodebox",
|
|
node_box = {
|
|
type = "fixed",
|
|
fixed = {{-0.5, -0.5, -0.5, 0.5, -0.4, 0.5}}
|
|
},
|
|
groups = {
|
|
cracky = 3
|
|
},
|
|
tiles = {"yl_cinema_block_bigscreen.png^yl_cinema_icon_movie_inv.png", "yl_cinema_block_bigscreen.png",
|
|
"yl_cinema_block_bigscreen.png", "yl_cinema_block_bigscreen.png", "yl_cinema_block_bigscreen.png",
|
|
"yl_cinema_block_bigscreen.png"},
|
|
can_dig = can_dig_node,
|
|
on_construct = on_construct_bigscreen_node,
|
|
on_destruct = on_destruct_node,
|
|
on_blast = on_blast_node,
|
|
on_receive_fields = on_receive_fields_node,
|
|
allow_metadata_inventory_put = allow_metadata_inventory_put_node,
|
|
allow_metadata_inventory_take = allow_metadata_inventory_take_node,
|
|
allow_metadata_inventory_move = function()
|
|
return
|
|
end,
|
|
}
|
|
|
|
minetest.register_node(yl_cinema.bigscreen_block_name, bigscreen_block_definition)
|
|
|
|
|
|
yl_cinema.flatscreen_block_name = "yl_cinema:flatscreen_base"
|
|
local flatscreen_block_definition = {
|
|
description = "Cinema Base with fixed screen",
|
|
paramtype2 = "4dir",
|
|
drawtype = "nodebox",
|
|
node_box = {
|
|
type = "fixed",
|
|
fixed = {{-0.5, -0.5, -0.5, 0.5, -0.4, 0.5}}
|
|
},
|
|
groups = {
|
|
cracky = 3
|
|
},
|
|
tiles = {"yl_cinema_block_bigscreen.png^yl_cinema_icon_movie_inv.png", "yl_cinema_block_bigscreen.png",
|
|
"yl_cinema_block_bigscreen.png", "yl_cinema_block_bigscreen.png", "yl_cinema_block_bigscreen.png",
|
|
"yl_cinema_block_bigscreen.png"},
|
|
can_dig = can_dig_node,
|
|
on_construct = on_construct_flatscreen_node,
|
|
on_destruct = on_destruct_node,
|
|
on_blast = on_blast_node,
|
|
on_receive_fields = on_receive_fields_node,
|
|
allow_metadata_inventory_put = allow_metadata_inventory_put_node,
|
|
allow_metadata_inventory_take = allow_metadata_inventory_take_node,
|
|
allow_metadata_inventory_move = function()
|
|
return
|
|
end,
|
|
}
|
|
|
|
minetest.register_node(yl_cinema.flatscreen_block_name, flatscreen_block_definition)
|