1
0
mirror of https://github.com/mt-mods/homedecor_modpack.git synced 2024-12-23 08:20:21 +01:00

reduce some unnecessarily verbose boolean expressions in door_and_gates.lua

This commit is contained in:
Tim 2015-01-23 18:30:53 +01:00 committed by Vanessa Ezekowitz
parent b5188493cc
commit cfff6490cb

View File

@ -20,12 +20,7 @@ local function countSolids(pos,node,level)
local solids = 0 local solids = 0
for x = -1, 1 do for x = -1, 1 do
for z = -1, 1 do for z = -1, 1 do
local y = 0 local y = (node.param2 == 5) and -level or level
if node.param2 == 5 then
y = -level
else
y = level
end
-- special cases when x == z == 0 -- special cases when x == z == 0
if x == 0 and z == 0 then if x == 0 and z == 0 then
if level == 1 then if level == 1 then
@ -76,12 +71,7 @@ local function calculateClosed(pos)
return true return true
end end
end end
local x local x = (direction == 1) and 1 or -1
if direction == 1 then
x = 1
else
x = -1
end
if isSolid(pos,{x,0,-1}) and not isSolid(pos,{x,0,0}) and isSolid(pos,{x,0,1}) then if isSolid(pos,{x,0,-1}) and not isSolid(pos,{x,0,0}) and isSolid(pos,{x,0,1}) then
if string.find(node.name,'_bottom_') then if string.find(node.name,'_bottom_') then
return calculateClosed({x=pos.x,y=pos.y+1,z=pos.z}) return calculateClosed({x=pos.x,y=pos.y+1,z=pos.z})
@ -99,12 +89,7 @@ local function calculateClosed(pos)
return true return true
end end
end end
local z local z = (direction == 3) and 1 or -1
if direction == 3 then
z = 1
else
z = -1
end
if isSolid(pos,{-1,0,z}) and not isSolid(pos,{0,0,z}) and isSolid(pos,{1,0,z}) then if isSolid(pos,{-1,0,z}) and not isSolid(pos,{0,0,z}) and isSolid(pos,{1,0,z}) then
if string.find(node.name,'_bottom_') then if string.find(node.name,'_bottom_') then
return calculateClosed({x=pos.x,y=pos.y+1,z=pos.z}) return calculateClosed({x=pos.x,y=pos.y+1,z=pos.z})
@ -122,11 +107,7 @@ end
local function getClosed(pos) local function getClosed(pos)
local isClosed = minetest.get_meta(pos):get_string('closed') local isClosed = minetest.get_meta(pos):get_string('closed')
if isClosed=='' then if isClosed=='' then
if calculateClosed(pos) then return calculateClosed(pos)
return true
else
return false
end
else else
isClosed = tonumber(isClosed) isClosed = tonumber(isClosed)
-- may be closed or open (1 or 0) -- may be closed or open (1 or 0)
@ -135,13 +116,8 @@ local function getClosed(pos)
end end
local function addDoorNode(pos,def,isClosed) local function addDoorNode(pos,def,isClosed)
if isClosed then minetest.set_node(pos, def)
isClosed = 1 minetest.get_meta(pos):set_int('closed', isClosed and 1 or 0)
else
isClosed = 0
end
minetest.add_node(pos, def)
minetest.get_meta(pos):set_int('closed',isClosed)
end end
local sides = {"left", "right"} local sides = {"left", "right"}
@ -438,12 +414,7 @@ function homedecor.flip_door(pos, node, player, name, side, isClosed)
nfdir=ofdir + 1 nfdir=ofdir + 1
if nfdir > 3 then nfdir = 0 end if nfdir > 3 then nfdir = 0 end
end end
local sound; local sound = isClosed and 'close' or 'open'
if isClosed then
sound = 'close'
else
sound = 'open'
end
minetest.sound_play("homedecor_door_"..sound, { minetest.sound_play("homedecor_door_"..sound, {
pos=pos, pos=pos,
max_hear_distance = 5, max_hear_distance = 5,