feat: Added the generate command to load existing world saves

This commit is contained in:
Nicholas Novak
2023-11-13 16:22:46 -08:00
parent 822bda68d6
commit 89a6ddc9af
9 changed files with 189 additions and 23 deletions

47
storage/hashserver.go Normal file
View File

@@ -0,0 +1,47 @@
package storage
import "git.nicholasnovak.io/nnovak/spatial-db/world"
type HashServer struct {
blocks map[world.BlockPos]world.BlockID
}
func (hs *HashServer) SetStorageRoot(path string) {
hs.blocks = make(map[world.BlockPos]world.BlockID)
}
func (hs *HashServer) FetchChunk(pos world.ChunkPos) (world.ChunkData, error) {
panic("Unimplemented")
}
func (hs *HashServer) ChangeBlock(
worldPosition world.BlockPos,
targetState world.BlockID,
) error {
hs.blocks[worldPosition] = targetState
return nil
}
func (hs *HashServer) ChangeBlockRange(
targetState world.BlockID,
start, end world.BlockPos,
) error {
panic("Unimplemented")
}
func (hs *HashServer) ReadBlockAt(pos world.BlockPos) (world.BlockID, error) {
panic("Unimplemented")
}
func (hs *HashServer) ReadChunkAt(pos world.ChunkPos) (world.ChunkData, error) {
var data world.ChunkData
data.Pos = pos
for blockPos, state := range hs.blocks {
if blockPos.ToChunkPos() == pos {
sec := data.SectionFor(blockPos)
sec.UpdateBlock(blockPos, state)
}
}
return data, nil
}

View File

@@ -20,6 +20,10 @@ type SimpleServer struct {
StorageDir string
}
func (s *SimpleServer) SetStorageRoot(path string) {
s.StorageDir = path
}
// Filesystem operations
func (s *SimpleServer) FetchOrCreateChunk(pos world.ChunkPos) (world.ChunkData, error) {

View File

@@ -3,6 +3,9 @@ package storage
import "git.nicholasnovak.io/nnovak/spatial-db/world"
type StorageServer interface {
// Individual operations
SetStorageRoot(path string)
// Individual block-level interactions
ChangeBlock(targetState world.BlockID, world_position world.BlockPos) error
ChangeBlockRange(targetState world.BlockID, start, end world.BlockPos) error