Skip to content
Open
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
4 changes: 2 additions & 2 deletions data/items_vanilla.json
Original file line number Diff line number Diff line change
Expand Up @@ -5910,7 +5910,7 @@
"Description": "I蓄电器(满)",
"IconPath": "Icons/ItemRecipe/accumulator-full",
"IconTag": "mxdq",
"GridIndex": 2114,
"GridIndex": 2115,
"StackSize": 50,
"Type": 5,
"PreTechOverride": 1511,
Expand Down Expand Up @@ -9050,4 +9050,4 @@
"EnemyDropMask": 0,
"EnemyDropMaskRatio": 0.0
}
]
]
47 changes: 47 additions & 0 deletions tests/test_item_grid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import json
from pathlib import Path
import unittest


ROOT = Path(__file__).resolve().parents[1]
ITEM_FILES = [
ROOT / "data" / "items_vanilla.json",
ROOT / "data" / "items_mod.json",
]
MAX_PAGE = 5
MAX_ROW = 7
MAX_COLUMN = 17


class ItemGridTest(unittest.TestCase):
def test_non_zero_item_grid_indices_are_unique_and_in_picker_bounds(self):
seen = {}
for path in ITEM_FILES:
with path.open(encoding="utf-8-sig") as handle:
for item in json.load(handle):
grid_index = item["GridIndex"]
if grid_index == 0:
continue

item_id = item["ID"]
page = grid_index // 1000
row = (grid_index - page * 1000) // 100
column = grid_index % 100

self.assertGreaterEqual(page, 1, f"{item_id} has invalid page in {grid_index}")
self.assertLessEqual(page, MAX_PAGE, f"{item_id} has invalid page in {grid_index}")
self.assertGreaterEqual(row, 1, f"{item_id} has invalid row in {grid_index}")
self.assertLessEqual(row, MAX_ROW, f"{item_id} has invalid row in {grid_index}")
self.assertGreaterEqual(column, 1, f"{item_id} has invalid column in {grid_index}")
self.assertLessEqual(column, MAX_COLUMN, f"{item_id} has invalid column in {grid_index}")

self.assertNotIn(
grid_index,
seen,
f"{item_id} and {seen.get(grid_index)} share item GridIndex {grid_index}",
)
seen[grid_index] = item_id


if __name__ == "__main__":
unittest.main()