| 587 | |
| 588 | |
| 589 | bool cInventory::LoadFromJson(Json::Value & a_Value) |
| 590 | { |
| 591 | int SlotIdx = 0; |
| 592 | |
| 593 | for (Json::Value::iterator itr = a_Value.begin(); itr != a_Value.end(); ++itr, SlotIdx++) |
| 594 | { |
| 595 | cItem Item; |
| 596 | Item.FromJson(*itr); |
| 597 | |
| 598 | // The JSON originally included the 4 crafting slots and the result slot, so we need to skip the first 5 items: |
| 599 | if (SlotIdx < 5) |
| 600 | { |
| 601 | continue; |
| 602 | } |
| 603 | |
| 604 | // If we loaded all the slots, stop now, even if the JSON has more: |
| 605 | if (SlotIdx - 5 >= invNumSlots) |
| 606 | { |
| 607 | break; |
| 608 | } |
| 609 | |
| 610 | int GridSlotNum = 0; |
| 611 | cItemGrid * Grid = GetGridForSlotNum(SlotIdx - 5, GridSlotNum); |
| 612 | ASSERT(Grid != NULL); |
| 613 | Grid->SetSlot(GridSlotNum, Item); |
| 614 | } // for itr - a_Value[] |
| 615 | return true; |
| 616 | } |
| 617 | |
| 618 | |
| 619 | |