From 5cf67a983b54c0b3134d4d551c4e6fcbac9e4890 Mon Sep 17 00:00:00 2001 From: Lunovox Date: Mon, 18 Nov 2024 18:18:39 -0300 Subject: [PATCH] [fix] Fixedcritical glitch in clock bar of smartphone. --- api.lua | 76 ++++++++++++++++++++++++++++++++++++++++++++- functions.lua | 41 ++++++++++++++++++++++++ init.lua | 1 + item_smartphone.lua | 46 +++++---------------------- 4 files changed, 124 insertions(+), 40 deletions(-) create mode 100644 functions.lua diff --git a/api.lua b/api.lua index 000a9f5..5b07dbf 100644 --- a/api.lua +++ b/api.lua @@ -91,4 +91,78 @@ modComputing.get_app = function(appname) else return false, modComputing.log("modComputing.get_app(appname) : Invalid 'appname' variable!") end -end \ No newline at end of file +end + +modComputing.getTextNowWeekDay3S = function() + local txtWeekDays3S = { + modComputing.translate("Sun"), --Sunday + modComputing.translate("Mon"), --Monday + modComputing.translate("Tue"), --Tuesday + modComputing.translate("Wed"), --Wednesday + modComputing.translate("Thu"), --Thursday + modComputing.translate("Fri"), --Friday + modComputing.translate("Sat"), --Saturday + } + local totalDays = core.get_day_count() + 1 + local nowRow = math.floor((totalDays-1)/7)+1 + local nowCol = totalDays - ((nowRow-1)*7) + return txtWeekDays3S[nowCol] + +end + +modComputing.getTextNowTime = function() + local current_time = math.floor(core.get_timeofday() * 1440) + local minutes = current_time % 60 + local hour = (current_time - minutes) / 60 + return ("%02d:%02d"):format(hour, minutes) +end + +modComputing.getNowYear = function() + local totalDays = core.get_day_count() + local nowYear = totalDays/(28*4) + return nowYear +end + +modComputing.getTextNowDate = function() + local totalDays = core.get_day_count() + local nowMount = (math.floor(totalDays/28)%4)+1 + local txtMounts3S = { + modComputing.translate("SPR"), + modComputing.translate("SUM"), + modComputing.translate("AUT"), + modComputing.translate("WIN"), + } --SPRING, SUMMER, AUTUMN, WINTER + local nowDay = math.floor(totalDays%28)+1 + --local nowDate = ("%04d-%3s-%02d"):format((nowYear+1), txtMounts3S[nowMount], nowDay) + local nowDate = modComputing.translate( + "@1-@2", + ("%3s"):format(txtMounts3S[nowMount]), + ("%02d"):format(nowDay) + ) + --:format((nowYear+1), txtMounts3S[nowMount], nowDay) + return nowDate +end + +modComputing.doJumpDay = function(pular) + if type(tonumber(pular)) == "number" and tonumber(pular) >= 1 then + --modComputing.debug("pulando = "..pular) + for n = 1, tonumber(pular) do + core.set_timeofday(0.0) + core.set_timeofday(5/24) --It goes to 05h in the morning, time to wake up. + end + local diaAtual = core.get_day_count() + --core.chat_send_player(playername, + core.chat_send_all( + "[".. core.colorize("#00FFFF", modComputing.modname:upper()).."] " + ..modComputing.translate( + "Now this is the day @1°.", + string.format("%02d", diaAtual) + ) + + ) + --modComputing.update_cicle() + return true + else + return false + end +end diff --git a/functions.lua b/functions.lua new file mode 100644 index 0000000..5cf2976 --- /dev/null +++ b/functions.lua @@ -0,0 +1,41 @@ +-- skipped days +core.register_chatcommand("jumpday", { + params = "[number]", + description = modComputing.translate( + "Forces the calendar to jump a certain number of days.\n" + .."Maximum number of 112 days. Need 'settime' privilege." + ), + func = function(playername, param) + local isPriv = core.check_player_privs(playername, {settime=true}) + if isPriv then + local pular = 0 + --mobs_7dtc.debug("type('"..param.."') = "..type(param)) + if param == "" or tonumber(param) == nil or tonumber(param) < 1 then + pular = 1 + elseif tonumber(param) <= 112 then + pular = tonumber(param) + else + core.chat_send_player( + playername, + "[".. core.colorize("#FF0000", modComputing.modname:upper()..":"..modComputing.translate("FAILURE")).."] " + ..modComputing.translate( + "The maximum number of days is exactly '@1'!!!", + core.colorize("#FF0000","112") + ) + ) + return true --false = quando o comando falha. + end + modComputing.doJumpDay(pular) + return true --true=sucesso + else + core.chat_send_player( + playername, + "[".. core.colorize("#FF0000", modComputing.modname:upper()..":"..modComputing.translate("FAILURE")).."] " + ..modComputing.translate( + "You do not have the '@1' privilege to execute this command!!!", + core.colorize("#00FF00","settime") + ) + ) + end + end, +}) diff --git a/init.lua b/init.lua index 5199094..e19a4fc 100644 --- a/init.lua +++ b/init.lua @@ -5,6 +5,7 @@ modComputing = { dofile(modComputing.modpath.."/translate.lua") dofile(modComputing.modpath.."/api.lua") +dofile(modComputing.modpath.."/functions.lua") dofile(modComputing.modpath.."/item_smartphone.lua") diff --git a/item_smartphone.lua b/item_smartphone.lua index 8f2b193..4a8a085 100644 --- a/item_smartphone.lua +++ b/item_smartphone.lua @@ -1,45 +1,13 @@ -modComputing.getTextNowWeekDay3S = function() - local txtWeekDays3S = { - modComputing.translate("Sun"), --Sunday - modComputing.translate("Mon"), --Monday - modComputing.translate("Tue"), --Tuesday - modComputing.translate("Wed"), --Wednesday - modComputing.translate("Thu"), --Thursday - modComputing.translate("Fri"), --Friday - modComputing.translate("Sat"), --Saturday - } - local totalDays = core.get_day_count() - local nowRow = math.floor((totalDays-1)/7)+1 - local nowCol = totalDays - ((nowRow-1)*7) - return txtWeekDays3S[nowCol] - -end - -modComputing.getTextNowTime = function() - local current_time = math.floor(core.get_timeofday() * 1440) - local minutes = current_time % 60 - local hour = (current_time - minutes) / 60 - return ("%02d:%02d"):format(hour, minutes) -end - -modComputing.getTextNowDate = function() - local totalDays = core.get_day_count() - local nowYear = totalDays/(28*4) - local nowMount = (math.floor(totalDays/28)%4)+1 - local txtMounts3S = { - modComputing.translate("SPR"), - modComputing.translate("SUM"), - modComputing.translate("AUT"), - modComputing.translate("WIN"), - } --SPRING, SUMMER, AUTUMN, WINTER - local nowDay = math.floor(totalDays%28)+1 - local nowDate = ("%04d-%3s-%02d"):format((nowYear+1), txtMounts3S[nowMount], nowDay) - return nowDate -end modComputing.getTextClockBar = function() - return modComputing.getTextNowWeekDay3S()..", "..modComputing.getTextNowDate().." "..modComputing.getTextNowTime() + --return modComputing.getTextNowWeekDay3S()..", "..modComputing.getTextNowDate().." "..modComputing.getTextNowTime() + return modComputing.translate( + "@1, @2 @3", + modComputing.getTextNowWeekDay3S(), + modComputing.getTextNowDate(), + modComputing.getTextNowTime() + ) end modComputing.getFormSmartphone = function(player)