From 0fa6341bf248c8a24fb18c80a74c30f2dd7d435d Mon Sep 17 00:00:00 2001 From: NullBite Date: Fri, 23 Jun 2023 16:43:58 -0400 Subject: [PATCH] Rename pings --- sharedstate.lua | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/sharedstate.lua b/sharedstate.lua index d9a60f9..f7f0b91 100644 --- a/sharedstate.lua +++ b/sharedstate.lua @@ -76,7 +76,8 @@ do --- Set value and run callback -- Sets a value in the state table, initializing it if neede, and runs - -- the callback if it has been previously set + -- the callback if it has been previously set. This function should + -- only be called within ping receiver functions ---@param key string key ---@param value any value ---@param callback? function callback function @@ -145,8 +146,8 @@ sharedstate.add=sharedstate.init ---directly ---@param index integer Index of key ---@param value any New value -function pings.sharedstate_transfer(index, value) - logging.trace("pings.sharedstate_transfer", index, value) +function pings.sharedstate_recv(index, value) + logging.trace("pings.sharedstate_recv", index, value) set_value(resolve_key(index), value) end @@ -155,11 +156,19 @@ end ---directly ---@param key string Key ---@param value any New value -function pings.sharedstate_ktransfer(key, value) - logging.trace("pings.sharedstate_ktransfer", key, value) +function pings.sharedstate_recv_named(key, value) + logging.trace("pings.sharedstate_recv_named", key, value) set_value(key, value) end +--- Internal; unpack a table of state into the local state store +---@param tbl table Table to unpack +function pings.sharedstate_recv_table(tbl) + for k, v in pairs(tbl) do + set_value(k, v["value"]) + end +end + --- Set shared value ---Sets a shared value. This sends a ping to transfer it over the network. ---@param key string key name @@ -171,8 +180,8 @@ function sharedstate.set(key, value) local errormsg="sharedstate: Key " .. key .. " has not been initialized." error(errormsg) end - pings.sharedstate_transfer(resolve_index(key), value) - -- pings.sharedstate_ktransfer(key, value) + pings.sharedstate_recv(resolve_index(key), value) + -- pings.sharedstate_recv_named(key, value) end ---Send queued entries