From 283b7c7410b72ac3b1216481985ba4b5172649ba Mon Sep 17 00:00:00 2001 From: Michieal Date: Mon, 28 Nov 2022 22:06:26 +0000 Subject: [PATCH 1/9] Add in Versioning info using /ver command. --- mods/HUD/mcl_ver_info/init.lua | 33 +++++++++++++++++++++++++++++++++ mods/HUD/mcl_ver_info/mod.conf | 3 +++ 2 files changed, 36 insertions(+) create mode 100644 mods/HUD/mcl_ver_info/init.lua create mode 100644 mods/HUD/mcl_ver_info/mod.conf diff --git a/mods/HUD/mcl_ver_info/init.lua b/mods/HUD/mcl_ver_info/init.lua new file mode 100644 index 000000000..d5bc5d7e7 --- /dev/null +++ b/mods/HUD/mcl_ver_info/init.lua @@ -0,0 +1,33 @@ +--- +--- Generated by EmmyLua +--- Created by Michieal. +--- DateTime: 11/28/22 4:38 PM +--- + +-- register normal user access to debug levels 1 and 0. +minetest.register_chatcommand("ver", { + description = S("Display Mineclone 2 game version."), + func = function(name, params) + --[[ get_game_info's table data: + { + id = string, + title = string, + author = string, + -- The root directory of the game + path = string, + } + --]] + local game_info = minetest.get_game_info() + + if game_info.title == nil or game_info.title == "" then + game_info.title = "Mineclone 2" + end + if game_info.id == nil or game_info.id == "" then + game_info.id = " Please upgrade your version to the newest version for the /ver command to work." + end + + minetest.chat_send_player(name, string.format("Version: %s - %s",game_info.title, game_info.id) ) + return true + end +}) + diff --git a/mods/HUD/mcl_ver_info/mod.conf b/mods/HUD/mcl_ver_info/mod.conf new file mode 100644 index 000000000..66c5e5c7e --- /dev/null +++ b/mods/HUD/mcl_ver_info/mod.conf @@ -0,0 +1,3 @@ +name = mcl_ver_info +description = Prints game version information; /ver command. +depends = mcl_init From 51372da2b997566bce6c2a28641c547755e0f71d Mon Sep 17 00:00:00 2001 From: Michieal Date: Mon, 28 Nov 2022 22:08:20 +0000 Subject: [PATCH 2/9] update game.conf to have version id code for /ver command. --- game.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/game.conf b/game.conf index f059025c1..1e55bdff4 100644 --- a/game.conf +++ b/game.conf @@ -1,3 +1,4 @@ title = MineClone 2 description = A survival sandbox game. Survive, gather, hunt, build, explore, and do much more. disallowed_mapgens = v6 +id=MCL2-0.82-indev From dbe0437201ed7b33e4e7f861c13f951aab41f704 Mon Sep 17 00:00:00 2001 From: Michieal Date: Mon, 28 Nov 2022 22:34:56 +0000 Subject: [PATCH 3/9] add in translator code for S("") --- mods/HUD/mcl_ver_info/init.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mods/HUD/mcl_ver_info/init.lua b/mods/HUD/mcl_ver_info/init.lua index d5bc5d7e7..345f36833 100644 --- a/mods/HUD/mcl_ver_info/init.lua +++ b/mods/HUD/mcl_ver_info/init.lua @@ -4,6 +4,9 @@ --- DateTime: 11/28/22 4:38 PM --- +local modname = minetest.get_current_modname() +local S = minetest.get_translator(modname) + -- register normal user access to debug levels 1 and 0. minetest.register_chatcommand("ver", { description = S("Display Mineclone 2 game version."), From 43a69c445fe340c73347c36646391162bac30256 Mon Sep 17 00:00:00 2001 From: Michieal Date: Thu, 1 Dec 2022 23:44:38 +0000 Subject: [PATCH 4/9] Added in Error Handling The /ver command now has error handling, so that it will work regardless of minetest version, and will tell the user to update the minetest version for support. Also updated the mod.conf to have the author field filled out. todo: still needs translation files. --- mods/HUD/mcl_ver_info/init.lua | 28 ++++++++++++++++++++++++---- mods/HUD/mcl_ver_info/mod.conf | 1 + 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/mods/HUD/mcl_ver_info/init.lua b/mods/HUD/mcl_ver_info/init.lua index 345f36833..796245e56 100644 --- a/mods/HUD/mcl_ver_info/init.lua +++ b/mods/HUD/mcl_ver_info/init.lua @@ -3,10 +3,26 @@ --- Created by Michieal. --- DateTime: 11/28/22 4:38 PM --- - local modname = minetest.get_current_modname() local S = minetest.get_translator(modname) +local function xpcall_ver (error) + minetest.log("error", error) +end + +local function get_game_info () + local game_info + + if xpcall(minetest.get_game_info, xpcall_ver) then + game_info = minetest.get_game_info() + else + minetest.log( S("Sorry, but your version of Minetest doesn't support the latest API. Please upgrade your minetest.")) + return false + end + + return game_info +end + -- register normal user access to debug levels 1 and 0. minetest.register_chatcommand("ver", { description = S("Display Mineclone 2 game version."), @@ -20,7 +36,11 @@ minetest.register_chatcommand("ver", { path = string, } --]] - local game_info = minetest.get_game_info() + local game_info = get_game_info () + + if game_info == false then + return true + end if game_info.title == nil or game_info.title == "" then game_info.title = "Mineclone 2" @@ -29,8 +49,8 @@ minetest.register_chatcommand("ver", { game_info.id = " Please upgrade your version to the newest version for the /ver command to work." end - minetest.chat_send_player(name, string.format("Version: %s - %s",game_info.title, game_info.id) ) + minetest.chat_send_player(name, string.format("Version: %s - %s", game_info.title, game_info.id)) return true - end + end }) diff --git a/mods/HUD/mcl_ver_info/mod.conf b/mods/HUD/mcl_ver_info/mod.conf index 66c5e5c7e..b6f6dca98 100644 --- a/mods/HUD/mcl_ver_info/mod.conf +++ b/mods/HUD/mcl_ver_info/mod.conf @@ -1,3 +1,4 @@ name = mcl_ver_info description = Prints game version information; /ver command. depends = mcl_init +author = Michieal From d80dd41cb4ad110c02736bcee82d512538c142f4 Mon Sep 17 00:00:00 2001 From: Michieal Date: Thu, 1 Dec 2022 23:46:42 +0000 Subject: [PATCH 5/9] Add in template file for translations. --- mods/HUD/mcl_ver_info/locale/template.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 mods/HUD/mcl_ver_info/locale/template.txt diff --git a/mods/HUD/mcl_ver_info/locale/template.txt b/mods/HUD/mcl_ver_info/locale/template.txt new file mode 100644 index 000000000..75febe815 --- /dev/null +++ b/mods/HUD/mcl_ver_info/locale/template.txt @@ -0,0 +1,2 @@ +# textdomain: mcl_ver_info +Sorry, but your version of Minetest doesn't support the latest API. Please upgrade your minetest.= \ No newline at end of file From 0bc88b55e5586a9f545a9ce0d36bbe4e80683b55 Mon Sep 17 00:00:00 2001 From: Michieal Date: Sun, 4 Dec 2022 16:39:47 +0000 Subject: [PATCH 6/9] Added in Workaround for ID not yet implemented in 5.70-Dev Minetest. For more information, please see: https://github.com/minetest/minetest/pull/12989#issuecomment-1336407807 --- mods/HUD/mcl_ver_info/init.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/mods/HUD/mcl_ver_info/init.lua b/mods/HUD/mcl_ver_info/init.lua index 796245e56..7fe83270b 100644 --- a/mods/HUD/mcl_ver_info/init.lua +++ b/mods/HUD/mcl_ver_info/init.lua @@ -42,11 +42,20 @@ minetest.register_chatcommand("ver", { return true end + local conf = Settings(game_info.path .. "/game.conf") + local version = conf:get("version") + if game_info.title == nil or game_info.title == "" then game_info.title = "Mineclone 2" end - if game_info.id == nil or game_info.id == "" then - game_info.id = " Please upgrade your version to the newest version for the /ver command to work." + -- Notes: "game.conf doesn't support id currently, this is planned in the future" - rubenwardy from the github issue. + -- TODO: Remove workaround after minetest.get_game_info().id is implemented. + if version == "" or version == nil then -- workaround for id = not being implemented yet. + if game_info.id == nil or game_info.id == "" then + game_info.id = " Please upgrade your version to the newest version for the /ver command to work." + end + else + game_info.id = version end minetest.chat_send_player(name, string.format("Version: %s - %s", game_info.title, game_info.id)) From 1c1ae53cec65ec792cda6e2be2516e6547bfdb75 Mon Sep 17 00:00:00 2001 From: Michieal Date: Mon, 5 Dec 2022 22:26:19 +0000 Subject: [PATCH 7/9] Fixed game.conf to work with the workaround by reubenwardy. --- game.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/game.conf b/game.conf index 1e55bdff4..484b67178 100644 --- a/game.conf +++ b/game.conf @@ -2,3 +2,4 @@ title = MineClone 2 description = A survival sandbox game. Survive, gather, hunt, build, explore, and do much more. disallowed_mapgens = v6 id=MCL2-0.82-indev +version=MCL2-0.82-indev \ No newline at end of file From bceb9cd855ed88e750020cfc3d015cbb7107421a Mon Sep 17 00:00:00 2001 From: Michieal Date: Mon, 5 Dec 2022 23:16:16 +0000 Subject: [PATCH 8/9] Removed the id= line. Since we don't know when the api will be finished, I removed the ID line just in case. --- game.conf | 1 - 1 file changed, 1 deletion(-) diff --git a/game.conf b/game.conf index 484b67178..1fa1d6671 100644 --- a/game.conf +++ b/game.conf @@ -1,5 +1,4 @@ title = MineClone 2 description = A survival sandbox game. Survive, gather, hunt, build, explore, and do much more. disallowed_mapgens = v6 -id=MCL2-0.82-indev version=MCL2-0.82-indev \ No newline at end of file From 8256fe6f046f53e76a8c70938e6a96a3bd7181f4 Mon Sep 17 00:00:00 2001 From: Michieal Date: Tue, 6 Dec 2022 22:42:04 +0000 Subject: [PATCH 9/9] remove extraneous messages --- mods/HUD/mcl_ver_info/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/HUD/mcl_ver_info/init.lua b/mods/HUD/mcl_ver_info/init.lua index 7fe83270b..632847275 100644 --- a/mods/HUD/mcl_ver_info/init.lua +++ b/mods/HUD/mcl_ver_info/init.lua @@ -7,7 +7,7 @@ local modname = minetest.get_current_modname() local S = minetest.get_translator(modname) local function xpcall_ver (error) - minetest.log("error", error) + minetest.log("info", "mcl_ver_info:: Gamepath not supported in this version of Minetest.") end local function get_game_info () @@ -50,7 +50,7 @@ minetest.register_chatcommand("ver", { end -- Notes: "game.conf doesn't support id currently, this is planned in the future" - rubenwardy from the github issue. -- TODO: Remove workaround after minetest.get_game_info().id is implemented. - if version == "" or version == nil then -- workaround for id = not being implemented yet. + if version == nil or version == "" then -- workaround for id = not being implemented yet. if game_info.id == nil or game_info.id == "" then game_info.id = " Please upgrade your version to the newest version for the /ver command to work." end