This week we
added a system that lets you easily store files on the local disk for things like saved games, dupes, and any other user generated content. This api is designed to be as simple and open ended as possible.
// Create a new save game entry
var saveEntry = Storage.CreateEntry( "save" );
// Write game data to files
saveEntry.Files.WriteAllText( "player.json", playerJson );
saveEntry.Files.WriteAllBytes( "world.dat", worldData );
// You can also use JSON serialization
saveEntry.Files.WriteJson( "config.json", gameConfig );
// Set metadata for searching and display
saveEntry.SetMeta( "playerName", "John Doe" );
saveEntry.SetMeta( "level", 42 );
saveEntry.SetMeta( "playtime", 3600 );
// Create and set a thumbnail
var thumbnail = CreateThumbnailBitmap(); // Your method to create a Bitmap
saveEntry.SetThumbnail( thumbnail );
You can easily find and iterate each item on disk.
var allSaves = Storage.GetAll( "save" );
foreach ( var save in allSaves )
{
// hello
}
You should also have async/coroutine/whatever methods for reading/writing storage, since it looks like the ones you shared are synchronous. If they are called on the game loop thread (I assume any game scripts you write run there by default) with large files, you could get frame drops. Adding async variants will make the calls more complex (you start calling on one frame but finish on another) but developers can use this to minimize stutter.
https://sbox.game/api/Sandbox.BaseFileSystem