Exemple #1
0
 public ChunkMeshBuilder(Chunk <BlockVoxel> blockChunk,
                         BlockRegistry blockRegistry)
 {
     chunk = blockChunk ??
             throw new ArgumentNullException(nameof(blockChunk));
     registry = blockRegistry ??
                throw new ArgumentNullException(nameof(blockRegistry));
 }
        public BlockChunkManager(BlockRegistry blockRegistry,
                                 ResourceManager applicationResourceManager,
                                 IFileSystem userDataFileSystem, FileSystemPath worldDataPathRoot)
        {
            BlockRegistry = blockRegistry ??
                            throw new ArgumentNullException(nameof(blockRegistry));
            Resources = applicationResourceManager ??
                        throw new ArgumentNullException(
                                  nameof(applicationResourceManager));
            this.userDataFileSystem = userDataFileSystem ??
                                      throw new ArgumentNullException(nameof(userDataFileSystem));
            this.worldDataPathRoot = worldDataPathRoot;

            if (!userDataFileSystem.IsWritable)
            {
                Log.Information("The game file system is read-only - any " +
                                "modifications to the game world in this session will " +
                                "not be saved.");
            }

            try
            {
                if (this.worldDataPathRoot.IsEmpty)
                {
                    throw new Exception("The path is empty.");
                }
                if (!this.worldDataPathRoot.IsAbsolute)
                {
                    throw new Exception("The path is not absolute.");
                }
                if (!this.worldDataPathRoot.IsDirectoryPath)
                {
                    throw new Exception("The path references a file, not a " +
                                        "directory.");
                }

                this.worldDataPathRoot = worldDataPathRoot;

                ProbeSaveDirectory();
            }
            catch (Exception exc)
            {
                throw new ArgumentException("The specified save root path " +
                                            "is invalid or inaccessible.", exc);
            }

            if (blockRegistry.HasTexture)
            {
                Resources.LoadTexture(blockRegistry.Texture,
                                      TextureFilter.Nearest).Subscribe(r => BlockTexture = r);
            }
        }