From cb41e7674297933f08aba8a14ce3eb1993f8937c Mon Sep 17 00:00:00 2001 From: mrkubax10 Date: Sun, 8 Sep 2024 22:31:26 +0200 Subject: [PATCH] Extract side API functions to separate file --- api.lua | 32 -------------------------------- api/side.lua | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ init.lua | 1 + 3 files changed, 50 insertions(+), 32 deletions(-) create mode 100644 api/side.lua diff --git a/api.lua b/api.lua index cf022c4..dcabe57 100644 --- a/api.lua +++ b/api.lua @@ -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 diff --git a/api/side.lua b/api/side.lua new file mode 100644 index 0000000..3b764a6 --- /dev/null +++ b/api/side.lua @@ -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 . + +-- \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 diff --git a/init.lua b/init.lua index 5010bdf..bb190bf 100644 --- a/init.lua +++ b/init.lua @@ -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")