Extract side API functions to separate file

This commit is contained in:
mrkubax10 2024-09-08 22:31:26 +02:00
parent 9436c7033b
commit cb41e76742
3 changed files with 50 additions and 32 deletions

32
api.lua
View File

@ -16,32 +16,6 @@
local S=minetest.get_translator("industrialtest")
-- \brief Takes rotated node and side and outputs normalized side that can be used for ioConfig lookups
-- \param pos Vector with node position
-- \param side Node side. See industrialtest.api.addPowerStorage for possible values
-- \returns Normalized side or in case of failure side argument back
industrialtest.api.normalizeSide=function(pos,side)
local node=minetest.get_node(pos)
-- FIXME: improve code quality there
local translation={
[0]={
1,2,3,4,5,6
},
[1]={
5,6,3,4,2,1
},
[2]={
2,1,3,4,6,5
},
[3]={
6,5,3,4,1,2
}
}
if node.param2>3 then
return side
end
return translation[node.param2][side]
end
-- \brief Sets uses metadata value depending on item's definition
-- \param itemstack ItemStack which should be altered
-- \returns true if value was successfully added, false otherwise
@ -430,12 +404,6 @@ industrialtest.api.getNetwork=function(meta)
return minetest.deserialize(meta:get_string("industrialtest.network"))
end
-- \brief Returns opposite side of provided one
-- \param side Side number. See industrialtest.api.addPowerStorage for order
-- \returns Opposite side
industrialtest.api.getOppositeSide=function(side)
return (side%2==0 and side-1 or side+1)
end
-- \brief Returns connections of node with power storage. If direction is "i" only input connections will be returned, if direction is "o" only output connections
-- will be returned, if it's not provided all connections will be returned.
-- \param pos Vector

49
api/side.lua Normal file
View File

@ -0,0 +1,49 @@
-- IndustrialTest
-- Copyright (C) 2024 mrkubax10
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
-- \brief Takes rotated node and side and outputs normalized side that can be used for ioConfig lookups
-- \param pos Vector with node position
-- \param side Node side. See industrialtest.api.addPowerStorage for possible values
-- \returns Normalized side or in case of failure side argument back
function industrialtest.api.normalizeSide(pos,side)
local node=minetest.get_node(pos)
-- FIXME: improve code quality there
local translation={
[0]={
1,2,3,4,5,6
},
[1]={
5,6,3,4,2,1
},
[2]={
2,1,3,4,6,5
},
[3]={
6,5,3,4,1,2
}
}
if node.param2>3 then
return side
end
return translation[node.param2][side]
end
-- \brief Returns opposite side of provided one
-- \param side Side number. See industrialtest.api.addPowerStorage for order
-- \returns Opposite side
function industrialtest.api.getOppositeSide(side)
return (side%2==0 and side-1 or side+1)
end

View File

@ -33,6 +33,7 @@ dofile(modpath.."/minerals.lua")
dofile(modpath.."/api/common.lua")
dofile(modpath.."/api/power.lua")
dofile(modpath.."/api/side.lua")
dofile(modpath.."/api.lua")
dofile(modpath.."/machines/common.lua")