Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions lib/nakama/engine/love2d.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ local M = {}
-- @return The mac address string.
local function get_mac_address()
local ifaddrs = sys.get_ifaddrs()
for _,interface in ipairs(ifaddrs) do
for _, interface in ipairs(ifaddrs) do
if interface.mac then
return interface.mac
end
Expand All @@ -42,9 +42,9 @@ function M.uuid()
return uuid(mac)
end


local make_http_request
make_http_request = function(url, method, callback, headers, post_data, options, retry_intervals, retry_count, cancellation_token)
make_http_request = function(url, method, callback, headers, post_data, options, retry_intervals, retry_count,
cancellation_token)
if cancellation_token and cancellation_token.cancelled then
callback(nil)
return
Expand All @@ -58,22 +58,23 @@ make_http_request = function(url, method, callback, headers, post_data, options,
data = post_data and post_data or nil
})

local ok, decoded = pcall(json.decode, response)
local ok, decoded = pcall(json.decode, response)

if status_code >= 200 and status_code <= 299 then
callback(decoded)
elseif retry_count > #retry_intervals then
if not ok then
callback({ error = true, message = "Unable to decode response" })
else
callback({error = decoded.error or true, message = decoded.message, code = decoded.code})
end
if status_code >= 200 and status_code <= 299 then
callback(decoded)
elseif retry_count > #retry_intervals then
if not ok then
callback({ error = true, message = "Unable to decode response" })
else
-- Retry
local retry_interval = retry_intervals[retry_count]
love.timer.sleep(retry_interval)
make_http_request(url, method, callback, headers, post_data, options, retry_intervals, retry_count + 1, cancellation_token)
callback({ error = decoded.error or true, message = decoded.message, code = decoded.code })
end
else
-- Retry
local retry_interval = retry_intervals[retry_count]
love.timer.sleep(retry_interval)
make_http_request(url, method, callback, headers, post_data, options, retry_intervals, retry_count + 1,
cancellation_token)
end
end


Expand All @@ -89,13 +90,15 @@ end
function M.http(config, url_path, query_params, method, post_data, retry_policy, cancellation_token, callback)
local query_string = ""
if next(query_params) then
for query_key,query_value in pairs(query_params) do
for query_key, query_value in pairs(query_params) do
if type(query_value) == "table" then
for _,v in ipairs(query_value) do
query_string = ("%s%s%s=%s"):format(query_string, (#query_string == 0 and "?" or "&"), query_key, uri_encode_component(tostring(v)))
for _, v in ipairs(query_value) do
query_string = ("%s%s%s=%s"):format(query_string, (#query_string == 0 and "?" or "&"), query_key,
uri_encode_component(tostring(v)))
end
else
query_string = ("%s%s%s=%s"):format(query_string, (#query_string == 0 and "?" or "&"), query_key, uri_encode_component(tostring(query_value)))
query_string = ("%s%s%s=%s"):format(query_string, (#query_string == 0 and "?" or "&"), query_key,
uri_encode_component(tostring(query_value)))
end
end
end
Expand All @@ -117,7 +120,8 @@ function M.http(config, url_path, query_params, method, post_data, retry_policy,

log("HTTP", method, url)
log("DATA", post_data)
make_http_request(url, method, callback, headers, post_data, options, retry_policy or config.retry_policy, 1, cancellation_token)
make_http_request(url, method, callback, headers, post_data, options, retry_policy or config.retry_policy, 1,
cancellation_token)
end

--- Create a new socket with message handler.
Expand Down Expand Up @@ -172,7 +176,7 @@ function M.socket_connect(socket, callback)
callback(true)

function ws:onmessage(message)
print('ws message', message)
-- print('ws message', message)

log("EVENT_MESSAGE: ", message)
on_message(socket, message)
Expand Down
2 changes: 2 additions & 0 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ local Toast = require('src.ui.toast')
function love.load()
love.graphics.setFont(Fonts.jura(24))

math.randomseed(os.time() + math.floor(os.clock() * 100000))

-- initialize the global state manager
CONTEXT = Context;
CONTEXT:load()
Expand Down
4 changes: 3 additions & 1 deletion src/assets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ local Assets = {
TOWER = love.graphics.newImage('assets/tower.png'),
}

Assets.TOWER:setFilter('nearest', 'nearest')

setmetatable(Assets, {
__index = function(_, key)
error(string.format('the assets: "%s" is not set in assets', key))
error(string.format('the assets: "%s" is not set in assets', key))
end
})

Expand Down
143 changes: 0 additions & 143 deletions src/cards/caveman.lua

This file was deleted.

Loading
Loading