From c3d3348dcc39a9826aaa17e74929d84a26e5cacd Mon Sep 17 00:00:00 2001 From: Hamlet Date: Wed, 19 Aug 2020 23:31:10 +0200 Subject: [PATCH] v1.1.0 --- README.md | 4 +- changelog.md | 8 +++ core/formspec.lua | 38 ++++++++++++++ core/moreores.lua | 44 ++++++++++++++++ core/moreores_procedures.lua | 97 ++++++++++++++++++++++++++++++++++++ core/procedures.lua | 32 ++++++++++++ init.lua | 37 +++++++++++++- locale/ores_stats.it.tr | 3 ++ locale/template.txt | 2 + mod.conf | 1 + 10 files changed, 264 insertions(+), 2 deletions(-) create mode 100644 core/moreores.lua create mode 100644 core/moreores_procedures.lua diff --git a/README.md b/README.md index 6284936..8ebceb9 100755 --- a/README.md +++ b/README.md @@ -2,10 +2,11 @@ ![Ores Stats' screenshot](screenshot.png) **_Provides informations about ores' percentages collected on map generation._** -**Version:** 1.0.0 +**Version:** 1.1.0 **Source code's license:** [EUPL v1.2][1] or later. **Dependencies:** default, sfinv (found in [Minetest Game][2]) +**Supported:** [More Ores][3] **NOTE:** To update the page's values switch to another tab. @@ -31,3 +32,4 @@ https://wiki.minetest.net/Help:Installing_Mods [1]: https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:32017D0863 [2]: https://github.com/minetest/minetest_game +[3]: https://forum.minetest.net/viewtopic.php?f=11&t=549 diff --git a/changelog.md b/changelog.md index 317b6dc..b93bf45 100755 --- a/changelog.md +++ b/changelog.md @@ -10,6 +10,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/). - No further features planned. + +## [1.1.0] - 2020-08-19 +### Added + + - Support for More Ores + + + ## [1.0.0] - 2020-07-23 ### Added diff --git a/core/formspec.lua b/core/formspec.lua index 9113e01..19fc82a 100644 --- a/core/formspec.lua +++ b/core/formspec.lua @@ -71,6 +71,24 @@ sfinv.register_page('ores_stats:ores_stats', { S('Tin: ') .. string.format("%.3f", ores_stats.f_valueTin) .. ',' + -- Support for More Ores' nodes + if (ores_stats.b_MORE_ORES == true) then + s_oresPerc = s_oresPerc .. ' ' .. + S('Mithril: ') .. string.format("%.3f", + ores_stats.f_percMithril) + .. '%' .. ',' .. ' ' .. + S('Silver: ') .. string.format("%.3f", ores_stats.f_percSilver) + .. '%' .. ',' + + s_oresValue = s_oresValue .. ' ' .. + S('Mithril: ') .. string.format("%.3f", + ores_stats.f_valueMithril) + .. ',' .. ' ' .. + S('Silver: ') .. string.format("%.3f", ores_stats.f_valueSilver) + .. ',' + end + + return sfinv.make_formspec(player, context, 'textlist[0,0;7.8,9.2;;' .. s_oresPerc .. s_oresValue .. ']', false) @@ -126,6 +144,26 @@ ores_stats.pr_UpdateFormspec = function() S('Tin: ') .. string.format("%.3f", ores_stats.f_valueTin) .. ',' + -- Support for More Ores' nodes + if (ores_stats.b_MORE_ORES == true) then + s_oresPerc = s_oresPerc .. ' ' .. + S('Mithril: ') .. string.format("%.3f", + ores_stats.f_percMithril) + .. '%' .. ',' .. ' ' .. + S('Silver: ') .. string.format("%.3f", + ores_stats.f_percSilver) + .. '%' .. ',' + + s_oresValue = s_oresValue .. ' ' .. + S('Mithril: ') .. string.format("%.3f", + ores_stats.f_valueMithril) + .. ',' .. ' ' .. + S('Silver: ') .. string.format("%.3f", + ores_stats.f_valueSilver) + .. ',' + end + + return sfinv.make_formspec(player, context, 'textlist[0,0;7.8,9.2;;' .. s_oresPerc .. s_oresValue .. ']', false) diff --git a/core/moreores.lua b/core/moreores.lua new file mode 100644 index 0000000..a7b12e0 --- /dev/null +++ b/core/moreores.lua @@ -0,0 +1,44 @@ +--[[ + Ores' Statistics - Provides informations about ores' percentages + Copyright © 2018, 2020 Hamlet and contributors. + + Licensed under the EUPL, Version 1.2 or – as soon they will be + approved by the European Commission – subsequent versions of the + EUPL (the "Licence"); + You may not use this work except in compliance with the Licence. + You may obtain a copy of the Licence at: + + https://joinup.ec.europa.eu/software/page/eupl + https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:32017D0863 + + Unless required by applicable law or agreed to in writing, + software distributed under the Licence is distributed on an + "AS IS" basis, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. + See the Licence for the specific language governing permissions + and limitations under the Licence. + +--]] + + +-- +-- Constants +-- + +ores_stats.id_mithril = minetest.get_content_id('moreores:mineral_mithril') +ores_stats.id_silver = minetest.get_content_id('moreores:mineral_silver') + + +-- +-- Variables +-- + +ores_stats.i_foundMithril = 0 +ores_stats.i_foundSilver = 0 + +ores_stats.f_percMithril = 0.0 +ores_stats.f_percSilver = 0.0 + +ores_stats.f_valueMithril = 0.0 +ores_stats.f_valueSilver = 0.0 diff --git a/core/moreores_procedures.lua b/core/moreores_procedures.lua new file mode 100644 index 0000000..29b2784 --- /dev/null +++ b/core/moreores_procedures.lua @@ -0,0 +1,97 @@ +--[[ + Ores' Statistics - Provides informations about ores' percentages + Copyright © 2018, 2020 Hamlet and contributors. + + Licensed under the EUPL, Version 1.2 or – as soon they will be + approved by the European Commission – subsequent versions of the + EUPL (the "Licence"); + You may not use this work except in compliance with the Licence. + You may obtain a copy of the Licence at: + + https://joinup.ec.europa.eu/software/page/eupl + https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:32017D0863 + + Unless required by applicable law or agreed to in writing, + software distributed under the Licence is distributed on an + "AS IS" basis, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. + See the Licence for the specific language governing permissions + and limitations under the Licence. + +--]] + + +-- +-- Procedures +-- + +-- Used to update the More Ores' variables +ores_stats.pr_MOupdateFromDB = function() + + ores_stats.i_foundMithril = + ores_stats.t_MOD_DATABASE:get_int('i_found_mithril') or 0 + + ores_stats.i_foundSilver = + ores_stats.t_MOD_DATABASE:get_int('i_found_silver') or 0 +end + +-- Used to save the More Ores' variables +ores_stats.pr_MOupdateSaveDB = function() + + ores_stats.t_MOD_DATABASE:set_int('i_found_mithril', + ores_stats.i_foundMithril) + + ores_stats.t_MOD_DATABASE:set_int('i_found_silver', + ores_stats.i_foundSilver) +end + +-- Used to update the More Ores' percentages variables +ores_stats.pr_MOupdateFromDBperc = function() + + ores_stats.f_percMithril = + ores_stats.t_MOD_DATABASE:get_float('f_percMithril') or 0.0 + + ores_stats.f_percSilver = + ores_stats.t_MOD_DATABASE:get_float('f_percSilver') or 0.0 + +end + +-- Used to save the More Ores' percentages variables +ores_stats.pr_MOupdateSaveDBperc = function() + + ores_stats.t_MOD_DATABASE:set_float('f_percMithril', + ores_stats.f_percMithril) + + ores_stats.t_MOD_DATABASE:set_float('f_percSilver', + ores_stats.f_percSilver) +end + +-- Used to update the More Ores' value variables +ores_stats.pr_MOupdateFromDBvalue = function() + + ores_stats.f_valueMithril = + ores_stats.t_MOD_DATABASE:get_float('f_valueMithril') or 0.0 + + ores_stats.f_valueSilver = + ores_stats.t_MOD_DATABASE:get_float('f_valueSilver') or 0.0 +end + +-- Used to save the More Ores' value variables +ores_stats.pr_MOupdateSaveDBvalue = function() + + ores_stats.t_MOD_DATABASE:set_float('f_valueMithril', + ores_stats.f_valueMithril) + + ores_stats.t_MOD_DATABASE:set_float('f_valueSilver', + ores_stats.f_valueSilver) +end + +-- Used to calculate the More Ores' ores values +ores_stats.pr_MOCalcValues = function() + + ores_stats.f_valueMithril = + ores_stats.fn_CalcValue(ores_stats.f_percMithril) + + ores_stats.f_valueSilver = ores_stats.fn_CalcValue(ores_stats.f_percSilver) +end diff --git a/core/procedures.lua b/core/procedures.lua index 609e8d0..67c71b9 100644 --- a/core/procedures.lua +++ b/core/procedures.lua @@ -119,12 +119,22 @@ end -- Used to update the total ores found variable ores_stats.pr_CalcTotalOres = function() + ores_stats.i_TotalOres = ( ores_stats.i_foundCoal + ores_stats.i_foundCopper + ores_stats.i_foundDiamonds + ores_stats.i_foundGold + ores_stats.i_foundIron + ores_stats.i_foundMese + ores_stats.i_foundTin ) + + -- Support for More Ores' nodes + if (ores_stats.b_MORE_ORES == true) then + ores_stats.i_TotalOres = ( + ores_stats.i_TotalOres + + ores_stats.i_foundMithril + + ores_stats.i_foundSilver + ) + end end -- Used to update the amounts of the ores found @@ -155,6 +165,17 @@ ores_stats.pr_OresScanner = function(a_s_node_id) ores_stats.i_foundTin = (ores_stats.i_foundTin + 1) end + + -- Support for More Ores' nodes + if (ores_stats.b_MORE_ORES == true) then + if (a_s_node_id == ores_stats.id_mithril) then + ores_stats.i_foundMithril = (ores_stats.i_foundMithril + 1) + + elseif (a_s_node_id == ores_stats.id_silver) then + ores_stats.i_foundSilver = (ores_stats.i_foundSilver + 1) + + end + end end -- Used to update the amounts of the ores found @@ -191,6 +212,17 @@ ores_stats.pr_OresPercentages = function() ores_stats.f_percTin = ores_stats.fn_CalcPercentage(ores_stats.i_foundTin, ores_stats.i_TotalOres) + + -- Support for More Ores' nodes + if (ores_stats.b_MORE_ORES == true) then + ores_stats.f_percMithril = + ores_stats.fn_CalcPercentage(ores_stats.i_foundMithril, + ores_stats.i_TotalOres) + + ores_stats.f_percSilver = + ores_stats.fn_CalcPercentage(ores_stats.i_foundSilver, + ores_stats.i_TotalOres) + end end -- Used to update the Minetest Game's value variables diff --git a/init.lua b/init.lua index f9512be..c62162b 100755 --- a/init.lua +++ b/init.lua @@ -36,6 +36,13 @@ ores_stats.t_MOD_DATABASE = minetest.get_mod_storage() ores_stats.f_GOLD_VALUE = minetest.settings:get('ores_stats_gold_value') or 50.0 +-- Support for More Ores +ores_stats.b_MORE_ORES = false + +if (minetest.get_modpath('moreores') ~= nil) then + ores_stats.b_MORE_ORES = true +end + -- -- Variables @@ -61,7 +68,7 @@ local pr_LogMessage = function() or (s_LOG_LEVEL == 'info') or (s_LOG_LEVEL == 'verbose') then - minetest.log('action', '[Mod] Ores Stats [v1.0.0] loaded.') + minetest.log('action', '[Mod] Ores Stats [v1.1.0] loaded.') end end @@ -76,6 +83,13 @@ local pr_LoadSubFiles = function() dofile(s_MOD_PATH .. '/core/functions.lua') dofile(s_MOD_PATH .. '/core/procedures.lua') dofile(s_MOD_PATH .. '/core/minetest_game.lua') + + -- Support for More Ores' nodes + if (ores_stats.b_MORE_ORES == true) then + dofile(s_MOD_PATH .. '/core/moreores_procedures.lua') + dofile(s_MOD_PATH .. '/core/moreores.lua') + end + dofile(s_MOD_PATH .. '/core/formspec.lua') end @@ -91,6 +105,13 @@ ores_stats.pr_MTGupdateFromDB() ores_stats.pr_MTGupdateFromDBperc() ores_stats.pr_MTGupdateFromDBvalue() +-- Support for More Ores' nodes +if (ores_stats.b_MORE_ORES == true) then + ores_stats.pr_MOupdateFromDB() + ores_stats.pr_MOupdateFromDBperc() + ores_stats.pr_MOupdateFromDBvalue() +end + -- Voxel manipulator minetest.register_on_generated(function() @@ -106,10 +127,24 @@ minetest.register_on_generated(function() ores_stats.pr_OresPercentages() ores_stats.pr_CalcValues() + -- Support for More Ores' nodes + if (ores_stats.b_MORE_ORES == true) then + ores_stats.pr_MOCalcValues() + end + + ores_stats.pr_MTGupdateSaveDB() ores_stats.pr_MTGupdateSaveDBperc() ores_stats.pr_MTGupdateSaveDBvalue() + -- Support for More Ores' nodes + if (ores_stats.b_MORE_ORES == true) then + ores_stats.pr_MOupdateSaveDB() + ores_stats.pr_MOupdateSaveDBperc() + ores_stats.pr_MOupdateSaveDBvalue() + end + + ores_stats.pr_UpdateFormspec() end) diff --git a/locale/ores_stats.it.tr b/locale/ores_stats.it.tr index e581829..2c1c037 100644 --- a/locale/ores_stats.it.tr +++ b/locale/ores_stats.it.tr @@ -9,3 +9,6 @@ Mese: =Mese: Diamonds: =Diamanti: Ores' percentages=Percentuali dei minerali Ores' values=Valori dei minerali +Mithril: =Mithril: +Silver: =Argento: + diff --git a/locale/template.txt b/locale/template.txt index 9542d74..737ca7c 100644 --- a/locale/template.txt +++ b/locale/template.txt @@ -9,3 +9,5 @@ Mese: = Diamonds: = Ores' percentages= Ores' values= +Mithril: = +Silver: = diff --git a/mod.conf b/mod.conf index 71674d5..4df895d 100755 --- a/mod.conf +++ b/mod.conf @@ -1,3 +1,4 @@ name = ores_stats description = Provides informations about ores' percentages collected on map generation. depends = default +optional_depends = moreores