From 314eea91e28b6a4db6b979a1f275380ccf883e56 Mon Sep 17 00:00:00 2001 From: Balthazar Date: Mon, 23 Dec 2024 12:13:03 +0000 Subject: [PATCH] Failed map library communications now retryable, fixed log line break --- src/main.lua | 3 +++ src/ui/mapLib.lua | 15 ++++++++++++++- src/ui/menu.lua | 13 ++++++++++--- src/utils/threads/updateMaps.lua | 7 +++++-- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/main.lua b/src/main.lua index 69236b1..66a0e06 100644 --- a/src/main.lua +++ b/src/main.lua @@ -2,6 +2,9 @@ local uiMode function setUIMode(mode) uiMode = mode + if uiMode.load then + uiMode:load() + end love.update(0) love.mousemoved(love.mouse.getX() or 0, love.mouse.getY() or 0, 0, 0) end diff --git a/src/ui/mapLib.lua b/src/ui/mapLib.lua index 2976cef..f128f53 100644 --- a/src/ui/mapLib.lua +++ b/src/ui/mapLib.lua @@ -10,6 +10,7 @@ while true do } end ]]:start() +local libComError local mapsData, mapsDataUnfiltered local imageCache = {} local seton = love.graphics.newImage'graphics/map.png' @@ -176,7 +177,9 @@ local function getAndApplyLibraryData(self) mapsData = love.thread.getChannel'mapLibData':pop() if type(mapsData)=='string' then - feedback:push{{0.7, 0, 0.3}, mapsData} + feedback:push{{0.7, 0, 0.3}, mapsData, '\n'} + mapsData = nil + libComError = true return setUIMode(require'ui.menu') end @@ -278,6 +281,16 @@ local function getAndApplyLibraryData(self) end return { + load = function(self) + if libComError then + libComError = nil + love.thread.newThread[[ + love.thread.getChannel'mapLibData':push( + require'utils.network'.getMapLibData() + ) + ]]:start() + end + end, keypressed = function(self, key, ...) if key=='escape' then if deselectSearch() then diff --git a/src/ui/menu.lua b/src/ui/menu.lua index e1c7670..5169949 100644 --- a/src/ui/menu.lua +++ b/src/ui/menu.lua @@ -242,9 +242,16 @@ return { love.thread.newThread'utils/threads/updateMaps.lua':start() end, update = function(self, UI, delta) - if self.inactive and love.thread.getChannel'wastefulSingleUseChannelToMarkMapUpdateComplete':pop() then - self.text = 'Maps updated' - self.icon = nil + if self.inactive then + local val = love.thread.getChannel'wastefulSingleUseChannelToMarkMapUpdateComplete':pop() + if val=='yes' then + self.text = 'Maps updated' + self.icon = nil + elseif val=='no' then + self.text = 'Retry map update' + self.inactive = nil + self.icon = nil + end end self.iconAngle = love.timer.getTime()*2 end, diff --git a/src/utils/threads/updateMaps.lua b/src/utils/threads/updateMaps.lua index c896779..c40abba 100644 --- a/src/utils/threads/updateMaps.lua +++ b/src/utils/threads/updateMaps.lua @@ -4,7 +4,10 @@ local updatingMarker = love.thread.getChannel'updatingMarker' feedback:push'Fetching map library data' local libdata = network.getMapLibData() -if type(libdata) == 'string' then return feedback:push{{0.7, 0, 0.3}, libdata} end +if type(libdata) == 'string' then + love.thread.getChannel'wastefulSingleUseChannelToMarkMapUpdateComplete':push'no' + return feedback:push{{0.7, 0, 0.3}, libdata, '\n'} +end feedback:push'Checking maps' for i, data in ipairs(libdata) do @@ -20,4 +23,4 @@ for i, data in ipairs(libdata) do end end feedback:push'All maps up to date' -love.thread.getChannel'wastefulSingleUseChannelToMarkMapUpdateComplete':push("yes") +love.thread.getChannel'wastefulSingleUseChannelToMarkMapUpdateComplete':push'yes'