mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-14 07:24:52 +09:00
Handle empty inventories serialized as objects
Factorio's table_to_json writes an empty inventory as {"i":{}}, which
made the summary throw for show and the web drawer.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f67097257b
commit
004fb13f1c
2 files changed
+11
-3
No files matched your search
@@ -65,6 +65,7 @@ describe("player_sync plugin", function() {
|
||||
});
|
||||
it("should handle empty inventories", function() {
|
||||
assert.deepEqual(summarizeInventory({}), []);
|
||||
assert.deepEqual(summarizeInventory(JSON.parse('{"i":{}}')), []);
|
||||
assert.deepEqual(
|
||||
summarizeInventory({ i: [{ n: "wood" }] }),
|
||||
[{ name: "wood", quality: undefined, count: 0 }],
|
||||
@@ -88,6 +89,10 @@ describe("player_sync plugin", function() {
|
||||
{ name: "main", items: [{ name: "stone", quality: undefined, count: 1 }] },
|
||||
]);
|
||||
});
|
||||
it("should handle empty serialized inventories", function() {
|
||||
const data = JSON.parse('{"generation":1,"name":"player","character":{"inventories":{"armor":{"i":{}}}}}');
|
||||
assert.deepEqual(summarizePlayerInventories(data), [{ name: "armor", items: [] }]);
|
||||
});
|
||||
it("should handle missing inventories", function() {
|
||||
assert.deepEqual(summarizePlayerInventories(playerData("player", 1)), []);
|
||||
assert.deepEqual(summarizePlayerInventories(playerData("player", 1, { character: {} })), []);
|
||||
|
||||
Reference in new issue
Block a user