From cbfc0adf3de65d094031f0c83cc6b1a9b25eed1f Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Fri, 13 Aug 2021 06:22:14 +0200 Subject: [PATCH] Remove extra whitespace in inventory_sync plugin --- plugins/inventory_sync/README.md | 2 +- .../module/define_player_inventories.lua | 2 +- plugins/inventory_sync/module/download_inventory.lua | 2 +- .../inventory_sync/module/gui/handle_gui_events.lua | 2 +- plugins/inventory_sync/module/inventory_sync.lua | 6 +++--- plugins/inventory_sync/module/save_crafts.lua | 10 +++++----- plugins/inventory_sync/module/upload_inventory.lua | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/plugins/inventory_sync/README.md b/plugins/inventory_sync/README.md index f5d27ca7..0ef56ab1 100644 --- a/plugins/inventory_sync/README.md +++ b/plugins/inventory_sync/README.md @@ -45,6 +45,6 @@ This plugin does event based synchronization of inventories. The data flow is as 12. Once the entire command is transfered, the scenario script clears the old inventory, applies the new inventory from the scenario script and sets the player to survival mode. -Communication between the server and instance goes over stdout or rcon, depending on the size of the data. +Communication between the server and instance goes over stdout or rcon, depending on the size of the data. Communication between the instance and the master server goes over websockets. Overall, we are able to achieve a latency between 3 and infinite ticks from server join, depending on the size of the inventory. The major limiter is rcon transfer speeds with larger inventories, especially if they contain blueprints. diff --git a/plugins/inventory_sync/module/define_player_inventories.lua b/plugins/inventory_sync/module/define_player_inventories.lua index df13de05..fe5e0921 100644 --- a/plugins/inventory_sync/module/define_player_inventories.lua +++ b/plugins/inventory_sync/module/define_player_inventories.lua @@ -1,5 +1,5 @@ local inventories = { - defines.inventory.character_main, + defines.inventory.character_main, defines.inventory.character_guns, defines.inventory.character_ammo, defines.inventory.character_armor, diff --git a/plugins/inventory_sync/module/download_inventory.lua b/plugins/inventory_sync/module/download_inventory.lua index c669e0c6..c1f20934 100644 --- a/plugins/inventory_sync/module/download_inventory.lua +++ b/plugins/inventory_sync/module/download_inventory.lua @@ -77,7 +77,7 @@ function download_inventory(player_name, data, number, total) end -- Load crafting queue - load_crafting_queue(serialized_player.crafting_queue, player) + load_crafting_queue(serialized_player.crafting_queue, player) -- Misc player.cheat_mode = serialized_player.cheat_mode diff --git a/plugins/inventory_sync/module/gui/handle_gui_events.lua b/plugins/inventory_sync/module/gui/handle_gui_events.lua index 5935c058..b335c2d3 100644 --- a/plugins/inventory_sync/module/gui/handle_gui_events.lua +++ b/plugins/inventory_sync/module/gui/handle_gui_events.lua @@ -15,7 +15,7 @@ local handle_gui_events = function(event) -- Handle inventory dirtying if not global.inventory_sync.players[player.name].dirty_inventory then global.inventory_sync.players[player.name].dirty_inventory = true - + -- Restore player character ensure_character(player) end diff --git a/plugins/inventory_sync/module/inventory_sync.lua b/plugins/inventory_sync/module/inventory_sync.lua index a8c69ed0..9fb659c5 100644 --- a/plugins/inventory_sync/module/inventory_sync.lua +++ b/plugins/inventory_sync/module/inventory_sync.lua @@ -2,7 +2,7 @@ When a player leaves the game, serialize their inventory and upload it to the master. -When a player joins the game, wait until they have a character, then send a request to +When a player joins the game, wait until they have a character, then send a request to the master server for the players inventory. When the master sends an inventory, parse it and give it to the player. @@ -105,7 +105,7 @@ end -- Upload inventory when a player leaves the game. Triggers on restart after crash if player was online during crash. inventory_sync.events[defines.events.on_pre_player_left_game] = function(event) -- for some reason, on_pre_player_left_game gets called before on_server_startup so global isn't ready yet - if not global.inventory_sync then + if not global.inventory_sync then log("ERROR: Global inventory sync not defined") return end @@ -156,7 +156,7 @@ function inventory_sync.initiate_inventory_download(player) global.inventory_sync.players[player.name].sync_start_tick = game.tick end function inventory_sync.check_inventory_download_failed() - -- Used for letting the master report the inventory download failing, like when the master is offline or an + -- Used for letting the master report the inventory download failing, like when the master is offline or an -- error occurs somewhere in the server code. The player will be returned to a playable state. for name, data in pairs(global.inventory_sync.players) do if data.sync_start_tick ~= 0 and data.sync_start_tick <= game.tick - 600 then diff --git a/plugins/inventory_sync/module/save_crafts.lua b/plugins/inventory_sync/module/save_crafts.lua index 42ebbd93..6916be48 100644 --- a/plugins/inventory_sync/module/save_crafts.lua +++ b/plugins/inventory_sync/module/save_crafts.lua @@ -20,7 +20,7 @@ function save_crafts(event) while player.crafting_queue_size > 0 do local old_queue = player.crafting_queue local queueItem = player.crafting_queue[1] - + -- Cancel craft player.cancel_crafting { index = 1, @@ -29,10 +29,10 @@ function save_crafts(event) local rightmost_right_index = 0 -- 0 indexed since it is subtractive in a 1 indexed language local new_queue = player.crafting_queue - while + while new_queue ~= nil and new_queue[#new_queue - rightmost_right_index] ~= nil and - new_queue[#new_queue - rightmost_right_index].count >= old_queue[#old_queue - rightmost_right_index].count + new_queue[#new_queue - rightmost_right_index].count >= old_queue[#old_queue - rightmost_right_index].count do rightmost_right_index = rightmost_right_index + 1 end @@ -48,7 +48,7 @@ function save_crafts(event) added = oldItem.count - newItem.count if oldItem.recipe ~= newItem.recipe then log("ERROR: Old item "..oldItem.recipe.." is not equal "..newItem.recipe) - end + end end -- If the last item we added was of the same type, merge them in the queue @@ -63,7 +63,7 @@ function save_crafts(event) end -- game.print("Saved craft "..oldItem.recipe) end - + -- Find amount of items added and remove from inventory local new_items = inventory.get_contents() local difference = {} diff --git a/plugins/inventory_sync/module/upload_inventory.lua b/plugins/inventory_sync/module/upload_inventory.lua index acb1de27..43812dbc 100644 --- a/plugins/inventory_sync/module/upload_inventory.lua +++ b/plugins/inventory_sync/module/upload_inventory.lua @@ -73,7 +73,7 @@ function upload_inventory(playerIndex) end clusterio_api.send_json("inventory_sync_upload", serialized_player) - + -- Clear saved crafting queue global.inventory_sync.saved_crafting_queue[player.name] = nil end