From d8fd8533cf60802350a6077d302ca5307de1a583 Mon Sep 17 00:00:00 2001 From: Robert Zenz Date: Sat, 12 Sep 2015 14:33:49 +0200 Subject: [PATCH] Initial commit. --- .gitmodules | 3 ++ README | 23 ++++++++++++ README.md | 1 + deps/utils | 1 + mods/sneak_cam/depends.txt | 1 + mods/sneak_cam/init.lua | 35 +++++++++++++++++ mods/sneak_cam/sneakcam.lua | 75 +++++++++++++++++++++++++++++++++++++ mods/utils | 1 + 8 files changed, 140 insertions(+) create mode 100644 .gitmodules create mode 100644 README create mode 120000 README.md create mode 160000 deps/utils create mode 100644 mods/sneak_cam/depends.txt create mode 100644 mods/sneak_cam/init.lua create mode 100644 mods/sneak_cam/sneakcam.lua create mode 120000 mods/utils diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..125a12e --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "deps/utils"] + path = deps/utils + url = https://github.com/RobertZenz/minetest-australopithecus-utils.git diff --git a/README b/README new file mode 100644 index 0000000..7e7b5f4 --- /dev/null +++ b/README @@ -0,0 +1,23 @@ +minetest-australopithecus-sneak-cam +=================================== + +A simple system that lowers the viewpoint of the players when they are sneaking. + + +Usage +===== + +The systems activates itself, you just need to add the mod to the subgame. + + +Configuration +============= + +The system can be configured by adding settings to `minetest.conf` file. + + # If the system should be active or not, defaults to true. + sneakcam_activate = true + + # The offset by which the viewpoing is lowered, defaults to 1.65. + sneakcam_offset = 1.65 + diff --git a/README.md b/README.md new file mode 120000 index 0000000..100b938 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +README \ No newline at end of file diff --git a/deps/utils b/deps/utils new file mode 160000 index 0000000..fed1918 --- /dev/null +++ b/deps/utils @@ -0,0 +1 @@ +Subproject commit fed191891f263d353cd7d8484e1692fa3c14325f diff --git a/mods/sneak_cam/depends.txt b/mods/sneak_cam/depends.txt new file mode 100644 index 0000000..9487075 --- /dev/null +++ b/mods/sneak_cam/depends.txt @@ -0,0 +1 @@ +utils diff --git a/mods/sneak_cam/init.lua b/mods/sneak_cam/init.lua new file mode 100644 index 0000000..e4ac3a2 --- /dev/null +++ b/mods/sneak_cam/init.lua @@ -0,0 +1,35 @@ +--[[ +Copyright (c) 2015, Robert 'Bobby' Zenz +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--]] + + +-- Load all files +local base_path = minetest.get_modpath(minetest.get_current_modname()) + +dofile(base_path .. "/sneakcam.lua") + + +sneakcam.activate() + diff --git a/mods/sneak_cam/sneakcam.lua b/mods/sneak_cam/sneakcam.lua new file mode 100644 index 0000000..cfcc4d8 --- /dev/null +++ b/mods/sneak_cam/sneakcam.lua @@ -0,0 +1,75 @@ +--[[ +Copyright (c) 2015, Robert 'Bobby' Zenz +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--]] + + +--- The main object for the sneak cam mod. +sneakcam = { + --- The offset by which the camera is lowered if the player is sneaking. + offset = settings.get_number("sneakcam_offset", 1.65), + + --- The state of all players the last time the system has seen them. + sneak_state = {} +} + + +--- Activates the sneakcam system. But checks if it is has been disabled via +-- the configuration. +function sneakcam.activate() + if settings.get_bool("sneakcam_activate", true) then + minetest.register_globalstep(sneakcam.update_player_cams) + end +end + +--- Updates the camera of the given player. +-- +-- @param player The Player object. +function sneakcam.update_player_cam(player) + local controls = player:get_player_control() + local player_name = player:get_player_name() + + if sneakcam.sneak_state[player_name] == nil then + sneakcam.sneak_state[player_name] = controls.sneak + elseif controls.sneak ~= sneakcam.sneak_state[player_name] then + local eye_offset_first, eye_offset_third = player:get_eye_offset() + + if controls.sneak then + eye_offset_first.y = eye_offset_first.y - sneakcam.offset + else + eye_offset_first.y = eye_offset_first.y + sneakcam.offset + end + + player:set_eye_offset(eye_offset_first, eye_offset_third) + sneakcam.sneak_state[player_name] = controls.sneak + end +end + +--- Updates the cameras of players. +function sneakcam.update_player_cams() + for index, player in ipairs(minetest.get_connected_players()) do + sneakcam.update_player_cam(player) + end +end + diff --git a/mods/utils b/mods/utils new file mode 120000 index 0000000..4c431f4 --- /dev/null +++ b/mods/utils @@ -0,0 +1 @@ +../deps/utils/utils \ No newline at end of file