Skip to content

Commit

Permalink
Failed map library communications now retryable, fixed log line break
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Balthazar committed Dec 23, 2024
1 parent c24dbde commit 314eea9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion src/ui/mapLib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ while true do
}
end
]]:start()
local libComError
local mapsData, mapsDataUnfiltered
local imageCache = {}
local seton = love.graphics.newImage'graphics/map.png'
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions src/ui/menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions src/utils/threads/updateMaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'

0 comments on commit 314eea9

Please sign in to comment.