From f6db3c438ee45170fc94d3baaab0abb536639c26 Mon Sep 17 00:00:00 2001 From: octacian Date: Tue, 7 Feb 2017 07:32:06 -0800 Subject: [PATCH] Allow saving recordings Recordings can now be saved with /camera save , played with /camera play , and listed with /camera list. --- init.lua | 99 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 88 insertions(+), 11 deletions(-) diff --git a/init.lua b/init.lua index 0abbfd7..be4c5ed 100644 --- a/init.lua +++ b/init.lua @@ -14,13 +14,60 @@ Usage: /camera - use jump to brake - use crouch to stop recording - Use /camera playback to play back a recording. While playing back: + Use /camera play to play back the last recording. While playing back: - use crouch to stop playing back + Use /camera play to play a specific recording + + Use /camera save to save the last recording + - saved recordings exist through game restarts + + Use /camera list to show all saved recording + --]] local recordings = {} +-- Load recordings +local path = minetest.get_worldpath() + +local function load() + local res = io.open(path.."/recordings.txt", "r") + if res then + res = minetest.deserialize(res:read("*all")) + if type(res) == "table" then + recordings = res + end + end +end + +load() + +function save() + io.open(path.."/recordings.txt", "w"):write(minetest.serialize(recordings)) +end + +-- [function] Get recording list for chat +function get_recordings(name) + local recs = recordings[name] + local list = "" + + if recs then + for name, path in pairs(recs) do + list = list..name..", " + end + return list + else + return "You do not saved any recordings." + end +end + +-- Register on shutdown +minetest.register_on_shutdown(save) + +-- Table for storing unsaved temporary recordings +local temp = {} + -- camera def local camera = { description = "Camera", @@ -90,7 +137,7 @@ function camera:on_step(dtime) -- stop recording! self.driver:set_detach() minetest.chat_send_player(self.driver:get_player_name(), "Recorded stopped after " .. #self.path .. " points") - recordings[self.driver:get_player_name()] = table.copy(self.path) + temp[self.driver:get_player_name()] = table.copy(self.path) self.object:remove() return end @@ -123,18 +170,48 @@ minetest.register_chatcommand("camera", { description = "Manipulate recording", params = "