Replace spaces with tabs (#1)

This commit is contained in:
MrIbby 2017-03-21 09:48:56 -07:00 committed by Elijah Duffy
parent 39751eb34e
commit 194ce63d73
1 changed files with 49 additions and 56 deletions

105
init.lua
View File

@ -5,26 +5,19 @@ Copyright 2016-2017 - Auke Kok <sofar@foo-projects.org>
Copyright 2017 - Elijah Duffy <theoctacian@gmail.com> Copyright 2017 - Elijah Duffy <theoctacian@gmail.com>
License: License:
- Code: MIT - Code: MIT
- Models and textures: CC-BY-SA-3.0 - Models and textures: CC-BY-SA-3.0
Usage: /camera Usage: /camera
Execute command to start recording. While recording:
Execute command to start recording. While recording: - use up/down to accelerate/decelerate
- use up/down to accelerate/decelerate - use jump to brake
- use jump to brake - use crouch to stop recording
- use crouch to stop recording Use /camera play to play back the last recording. While playing back:
- use crouch to stop playing back
Use /camera play to play back the last recording. While playing back: Use /camera play <name> to play a specific recording
- use crouch to stop playing back Use /camera save <name> to save the last recording
- saved recordings exist through game restarts
Use /camera play <name> to play a specific recording Use /camera list to show all saved recording
Use /camera save <name> to save the last recording
- saved recordings exist through game restarts
Use /camera list to show all saved recording
--]] --]]
local recordings = {} local recordings = {}
@ -33,13 +26,13 @@ local recordings = {}
local path = minetest.get_worldpath() local path = minetest.get_worldpath()
local function load() local function load()
local res = io.open(path.."/recordings.txt", "r") local res = io.open(path.."/recordings.txt", "r")
if res then if res then
res = minetest.deserialize(res:read("*all")) res = minetest.deserialize(res:read("*all"))
if type(res) == "table" then if type(res) == "table" then
recordings = res recordings = res
end end
end end
end end
-- Call load -- Call load
@ -47,22 +40,22 @@ load()
-- [function] Save recordings -- [function] Save recordings
function save() function save()
io.open(path.."/recordings.txt", "w"):write(minetest.serialize(recordings)) io.open(path.."/recordings.txt", "w"):write(minetest.serialize(recordings))
end end
-- [function] Get recording list per-player for chat -- [function] Get recording list per-player for chat
function get_recordings(name) function get_recordings(name)
local recs = recordings[name] local recs = recordings[name]
local list = "" local list = ""
if recs then if recs then
for name, path in pairs(recs) do for name, path in pairs(recs) do
list = list..name..", " list = list..name..", "
end end
return list return list
else else
return "You do not saved any recordings." return "You do not saved any recordings."
end end
end end
-- [event] On shutdown save recordings -- [event] On shutdown save recordings
@ -99,7 +92,7 @@ local camera = {
-- [event] On step -- [event] On step
function camera:on_step(dtime) function camera:on_step(dtime)
-- if not driver, remove object -- if not driver, remove object
if not self.driver then if not self.driver then
self.object:remove() self.object:remove()
return return
@ -109,7 +102,7 @@ function camera:on_step(dtime)
local vel = self.object:getvelocity() local vel = self.object:getvelocity()
local dir = self.driver:get_look_dir() local dir = self.driver:get_look_dir()
-- if record mode -- if record mode
if self.mode == 0 then if self.mode == 0 then
-- Update path -- Update path
self.path[#self.path + 1] = { self.path[#self.path + 1] = {
@ -126,25 +119,25 @@ function camera:on_step(dtime)
-- Get controls -- Get controls
local ctrl = self.driver:get_player_control() local ctrl = self.driver:get_player_control()
-- Initialize speed -- Initialize speed
local speed = vector.distance(vector.new(), vel) local speed = vector.distance(vector.new(), vel)
-- if up, accelerate forward -- if up, accelerate forward
if ctrl.up then if ctrl.up then
speed = math.min(speed + 0.1, 20) speed = math.min(speed + 0.1, 20)
end end
-- if down, accelerate backward -- if down, accelerate backward
if ctrl.down then if ctrl.down then
speed = math.max(speed - 0.1, -20) speed = math.max(speed - 0.1, -20)
end end
-- if jump, brake -- if jump, brake
if ctrl.jump then if ctrl.jump then
speed = math.max(speed * 0.9, 0.0) speed = math.max(speed * 0.9, 0.0)
end end
-- if sneak, stop recording -- if sneak, stop recording
if ctrl.sneak then if ctrl.sneak then
self.driver:set_detach() self.driver:set_detach()
minetest.chat_send_player(self.driver:get_player_name(), "Recorded stopped after " .. #self.path .. " points") minetest.chat_send_player(self.driver:get_player_name(), "Recorded stopped after " .. #self.path .. " points")
@ -153,13 +146,13 @@ function camera:on_step(dtime)
return return
end end
-- Set updated velocity -- Set updated velocity
self.object:setvelocity(vector.multiply(self.driver:get_look_dir(), speed)) self.object:setvelocity(vector.multiply(self.driver:get_look_dir(), speed))
elseif self.mode == 1 then -- elseif playback mode elseif self.mode == 1 then -- elseif playback mode
-- Get controls -- Get controls
local ctrl = self.driver:get_player_control() local ctrl = self.driver:get_player_control()
-- if sneak or no path, stop playback -- if sneak or no path, stop playback
if ctrl.sneak or #self.path < 1 then if ctrl.sneak or #self.path < 1 then
self.driver:set_detach() self.driver:set_detach()
minetest.chat_send_player(self.driver:get_player_name(), "Playback stopped") minetest.chat_send_player(self.driver:get_player_name(), "Playback stopped")
@ -169,12 +162,12 @@ function camera:on_step(dtime)
-- Update position -- Update position
self.object:moveto(self.path[1].pos, true) self.object:moveto(self.path[1].pos, true)
-- Update yaw/pitch -- Update yaw/pitch
self.driver:set_look_yaw(self.path[1].yaw - (math.pi/2)) self.driver:set_look_yaw(self.path[1].yaw - (math.pi/2))
self.driver:set_look_pitch(0 - self.path[1].pitch) self.driver:set_look_pitch(0 - self.path[1].pitch)
-- Update velocity -- Update velocity
self.object:setvelocity(self.path[1].velocity) self.object:setvelocity(self.path[1].velocity)
-- Remove path table -- Remove path table
table.remove(self.path, 1) table.remove(self.path, 1)
end end
end end
@ -190,7 +183,7 @@ minetest.register_chatcommand("camera", {
local player = minetest.get_player_by_name(name) local player = minetest.get_player_by_name(name)
local param1, param2 = param:split(" ")[1], param:split(" ")[2] local param1, param2 = param:split(" ")[1], param:split(" ")[2]
-- if play, begin playback preperation -- if play, begin playback preperation
if param1 == "play" then if param1 == "play" then
local function play(path) local function play(path)
local object = minetest.add_entity(player:getpos(), "camera:camera") local object = minetest.add_entity(player:getpos(), "camera:camera")
@ -202,7 +195,7 @@ minetest.register_chatcommand("camera", {
-- Check for param2 (recording name) -- Check for param2 (recording name)
if param2 and param2 ~= "" then if param2 and param2 ~= "" then
-- if recording exists, start -- if recording exists, start
if recordings[name][param2] then if recordings[name][param2] then
play(table.copy(recordings[name][param2])) play(table.copy(recordings[name][param2]))
else -- else, return error else -- else, return error
@ -218,20 +211,20 @@ minetest.register_chatcommand("camera", {
return true, "Playback started" return true, "Playback started"
elseif param1 == "save" then -- elseif save, prepare to save path elseif param1 == "save" then -- elseif save, prepare to save path
-- if no table for player in recordings, initialize -- if no table for player in recordings, initialize
if not recordings[name] then if not recordings[name] then
recordings[name] = {} recordings[name] = {}
end end
-- if param2 is not blank, save -- if param2 is not blank, save
if param2 and param2 ~= "" then if param2 and param2 ~= "" then
recordings[name][param2] = temp[name] recordings[name][param2] = temp[name]
return true, "Saved recording as "..param2 return true, "Saved recording as "..param2
else -- else, return error else -- else, return error
return false, "Missing name to save recording under (/camera save <name>)" return false, "Missing name to save recording under (/camera save <name>)"
end end
elseif param1 == "list" then -- elseif list, list recordings elseif param1 == "list" then -- elseif list, list recordings
return true, "Recordings: "..get_recordings(name) return true, "Recordings: "..get_recordings(name)
else -- else, begin recording else -- else, begin recording
local object = minetest.add_entity(player:getpos(), "camera:camera") local object = minetest.add_entity(player:getpos(), "camera:camera")
object:get_luaentity():init(player, 0) object:get_luaentity():init(player, 0)