Skip to content

Persistence overhaul

Ben Wallis requested to merge xvar/item-persistence into master
  • By opening this merge request, you agree to release your code and all other changes under the GPL 3 license and to abide by the terms set by this license.
  • Migrations have been added if applicable ...oh yes, yes they have.
  • Significant changes of this merge request have been added to the changelog.

TODO:

  • Ensure the migration is updated if there have been any new item assets added at the point this MR is merged
  • A play test using a clone of the live server database must be undertaken before this MR is merged

Summary

This MR is an overhaul of persistence, the key changes being:

  • Items are no longer stored as JSON in loadouts or inventories
  • Items are now stored individually as records in a new item table
  • Items now have a unique item_id once they have been persisted
  • Structs from the main game engine are no longer directly persisted as serialized JSON and now pass through a conversion layer (conversions.rs)
  • The concept of pesudo-container items has been introduced in order to allow items to belong to a specific player's inventory or loadout, without the need for separate inventory and loadout tables (see below for further description of containers).
  • The inventory and loadout tables have been removed as they are no longer necessary.
  • Item assets are no longer directly loaded via the asset system and are now created with Item::new_from_asset, Item::new_from_asset_expect or Item::new_from_asset_glob
  • Added additional all_items option to the item data export tool
  • Moved migrations to run earlier in server startup
  • Moved character loading and updating code out of character.rs into character_loader.rs and character_updater.rs

Migrations

A full migration from the previous schema is included - there should be no discernible difference for players after this change.

Items / Containers

The new item table supports infinitely nested containers, with each item having a parent_container_item_id which represents the container it exists within. To support this hierarchy, the concept of pseudo-containers has been introduced. These are "pseudo" items that are automatically created for characters - the following types currently exist:

  • World - This is created by the migration added by this MR, and acts as the root container of all items in the database.
  • Character - Created for each character created - uses the Character ID as its item_id and exists to provide a parent for the Inventory and Loadout pseudo-containers
  • Inventory - Created for each character created, the player's inventory items are contained within this pseudo-container
  • Loadout - Created for each character created, the player's loadout items are contained within this pseudo-container
[World]-+
 +--[Character]
 |  +--[Inventory]
 |  |  +--[Bag]
 |  |  |  +--Some Item
 |  |  |  +--[Another Bag]
 |  |  |     +--Cheese        
 |  |  +--Health Potion
 |  +--[Loadout]	
 |     +--Helm Item
 |     +--Boots Item

Although Veloren does not currently support actual containers within a player's inventory such as extra bags etc, this MR lays the foundation for such support to be added with relative ease.

Closes #678 (closed)

Edited by Joshua Yanovski

Merge request reports