World classes now support string dimension specifiers.

This commit is contained in:
Justin Aquadro 2013-05-18 22:10:00 -04:00
parent e20a1277c3
commit 5852184855
4 changed files with 146 additions and 32 deletions

View file

@ -19,15 +19,15 @@ namespace Substrate
private Level _level;
private Dictionary<int, AlphaChunkManager> _chunkMgrs;
private Dictionary<int, BlockManager> _blockMgrs;
private Dictionary<string, AlphaChunkManager> _chunkMgrs;
private Dictionary<string, BlockManager> _blockMgrs;
private PlayerManager _playerMan;
private AlphaWorld ()
{
_chunkMgrs = new Dictionary<int, AlphaChunkManager>();
_blockMgrs = new Dictionary<int, BlockManager>();
_chunkMgrs = new Dictionary<string, AlphaChunkManager>();
_blockMgrs = new Dictionary<string, BlockManager>();
}
/// <summary>
@ -99,7 +99,7 @@ namespace Substrate
{
_level.Save();
foreach (KeyValuePair<int, AlphaChunkManager> cm in _chunkMgrs) {
foreach (KeyValuePair<string, AlphaChunkManager> cm in _chunkMgrs) {
cm.Value.Save();
}
}
@ -128,6 +128,11 @@ namespace Substrate
/// <exclude/>
protected override IBlockManager GetBlockManagerVirt (int dim)
{
return GetBlockManagerVirt(DimensionFromInt(dim));
}
protected override IBlockManager GetBlockManagerVirt (string dim)
{
BlockManager rm;
if (_blockMgrs.TryGetValue(dim, out rm)) {
@ -140,6 +145,11 @@ namespace Substrate
/// <exclude/>
protected override IChunkManager GetChunkManagerVirt (int dim)
{
return GetChunkManagerVirt(DimensionFromInt(dim));
}
protected override IChunkManager GetChunkManagerVirt (string dim)
{
AlphaChunkManager rm;
if (_chunkMgrs.TryGetValue(dim, out rm)) {
@ -163,11 +173,19 @@ namespace Substrate
return _playerMan;
}
private void OpenDimension (int dim)
private string DimensionFromInt (int dim)
{
if (dim == Dimension.DEFAULT)
return "";
else
return "DIM" + dim;
}
private void OpenDimension (string dim)
{
string path = Path;
if (dim != Dimension.DEFAULT) {
path = IO.Path.Combine(path, "DIM" + dim);
if (!String.IsNullOrEmpty(dim)) {
path = IO.Path.Combine(path, dim);
}
if (!Directory.Exists(path)) {

View file

@ -22,11 +22,11 @@ namespace Substrate
private Level _level;
private Dictionary<int, AnvilRegionManager> _regionMgrs;
private Dictionary<int, RegionChunkManager> _chunkMgrs;
private Dictionary<int, BlockManager> _blockMgrs;
private Dictionary<string, AnvilRegionManager> _regionMgrs;
private Dictionary<string, RegionChunkManager> _chunkMgrs;
private Dictionary<string, BlockManager> _blockMgrs;
private Dictionary<int, ChunkCache> _caches;
private Dictionary<string, ChunkCache> _caches;
private PlayerManager _playerMan;
private BetaDataManager _dataMan;
@ -35,11 +35,11 @@ namespace Substrate
private AnvilWorld ()
{
_regionMgrs = new Dictionary<int, AnvilRegionManager>();
_chunkMgrs = new Dictionary<int, RegionChunkManager>();
_blockMgrs = new Dictionary<int, BlockManager>();
_regionMgrs = new Dictionary<string, AnvilRegionManager>();
_chunkMgrs = new Dictionary<string, RegionChunkManager>();
_blockMgrs = new Dictionary<string, BlockManager>();
_caches = new Dictionary<int, ChunkCache>();
_caches = new Dictionary<string, ChunkCache>();
}
/// <summary>
@ -75,6 +75,11 @@ namespace Substrate
return GetBlockManagerVirt(dim) as BlockManager;
}
public new BlockManager GetBlockManager (string dim)
{
return GetBlockManagerVirt(dim) as BlockManager;
}
/// <summary>
/// Gets a <see cref="RegionChunkManager"/> for the default dimension.
/// </summary>
@ -96,6 +101,11 @@ namespace Substrate
return GetChunkManagerVirt(dim) as RegionChunkManager;
}
public new RegionChunkManager GetChunkManager (string dim)
{
return GetChunkManagerVirt(dim) as RegionChunkManager;
}
/// <summary>
/// Gets a <see cref="RegionManager"/> for the default dimension.
/// </summary>
@ -115,6 +125,11 @@ namespace Substrate
/// <remarks>Regions are a higher-level unit of organization for blocks unique to worlds created in Beta 1.3 and beyond.
/// Consider using the <see cref="RegionChunkManager"/> if you are interested in working with blocks.</remarks>
public AnvilRegionManager GetRegionManager (int dim)
{
return GetRegionManager(DimensionFromInt(dim));
}
public AnvilRegionManager GetRegionManager (string dim)
{
AnvilRegionManager rm;
if (_regionMgrs.TryGetValue(dim, out rm)) {
@ -149,7 +164,7 @@ namespace Substrate
{
_level.Save();
foreach (KeyValuePair<int, RegionChunkManager> cm in _chunkMgrs) {
foreach (KeyValuePair<string, RegionChunkManager> cm in _chunkMgrs) {
cm.Value.Save();
}
}
@ -169,6 +184,11 @@ namespace Substrate
/// <param name="dim">The id of a dimension to look up.</param>
/// <returns>The <see cref="ChunkCache"/> for the given dimension, or null if the dimension was not found.</returns>
public ChunkCache GetChunkCache (int dim)
{
return GetChunkCache(DimensionFromInt(dim));
}
public ChunkCache GetChunkCache (string dim)
{
if (_caches.ContainsKey(dim)) {
return _caches[dim];
@ -230,6 +250,11 @@ namespace Substrate
/// <exclude/>
protected override IBlockManager GetBlockManagerVirt (int dim)
{
return GetBlockManagerVirt(DimensionFromInt(dim));
}
protected override IBlockManager GetBlockManagerVirt(string dim)
{
BlockManager rm;
if (_blockMgrs.TryGetValue(dim, out rm)) {
@ -242,6 +267,11 @@ namespace Substrate
/// <exclude/>
protected override IChunkManager GetChunkManagerVirt (int dim)
{
return GetChunkManagerVirt(DimensionFromInt(dim));
}
protected override IChunkManager GetChunkManagerVirt (string dim)
{
RegionChunkManager rm;
if (_chunkMgrs.TryGetValue(dim, out rm)) {
@ -276,14 +306,22 @@ namespace Substrate
return _dataMan;
}
private void OpenDimension (int dim)
private string DimensionFromInt (int dim)
{
if (dim == Dimension.DEFAULT)
return "";
else
return "DIM" + dim;
}
private void OpenDimension (string dim)
{
string path = Path;
if (dim == Dimension.DEFAULT) {
if (String.IsNullOrEmpty(dim)) {
path = IO.Path.Combine(path, _REGION_DIR);
}
else {
path = IO.Path.Combine(path, "DIM" + dim);
path = IO.Path.Combine(path, dim);
path = IO.Path.Combine(path, _REGION_DIR);
}

View file

@ -22,11 +22,11 @@ namespace Substrate
private Level _level;
private Dictionary<int, BetaRegionManager> _regionMgrs;
private Dictionary<int, RegionChunkManager> _chunkMgrs;
private Dictionary<int, BlockManager> _blockMgrs;
private Dictionary<string, BetaRegionManager> _regionMgrs;
private Dictionary<string, RegionChunkManager> _chunkMgrs;
private Dictionary<string, BlockManager> _blockMgrs;
private Dictionary<int, ChunkCache> _caches;
private Dictionary<string, ChunkCache> _caches;
private PlayerManager _playerMan;
private BetaDataManager _dataMan;
@ -35,11 +35,11 @@ namespace Substrate
private BetaWorld ()
{
_regionMgrs = new Dictionary<int, BetaRegionManager>();
_chunkMgrs = new Dictionary<int, RegionChunkManager>();
_blockMgrs = new Dictionary<int, BlockManager>();
_regionMgrs = new Dictionary<string, BetaRegionManager>();
_chunkMgrs = new Dictionary<string, RegionChunkManager>();
_blockMgrs = new Dictionary<string, BlockManager>();
_caches = new Dictionary<int, ChunkCache>();
_caches = new Dictionary<string, ChunkCache>();
}
/// <summary>
@ -75,6 +75,11 @@ namespace Substrate
return GetBlockManagerVirt(dim) as BlockManager;
}
public new BlockManager GetBlockManager (string dim)
{
return GetBlockManagerVirt(dim) as BlockManager;
}
/// <summary>
/// Gets a <see cref="RegionChunkManager"/> for the default dimension.
/// </summary>
@ -96,6 +101,11 @@ namespace Substrate
return GetChunkManagerVirt(dim) as RegionChunkManager;
}
public new RegionChunkManager GetChunkManager (string dim)
{
return GetChunkManagerVirt(dim) as RegionChunkManager;
}
/// <summary>
/// Gets a <see cref="RegionManager"/> for the default dimension.
/// </summary>
@ -115,6 +125,11 @@ namespace Substrate
/// <remarks>Regions are a higher-level unit of organization for blocks unique to worlds created in Beta 1.3 and beyond.
/// Consider using the <see cref="RegionChunkManager"/> if you are interested in working with blocks.</remarks>
public BetaRegionManager GetRegionManager (int dim)
{
return GetRegionManager(DimensionFromInt(dim));
}
public BetaRegionManager GetRegionManager (string dim)
{
BetaRegionManager rm;
if (_regionMgrs.TryGetValue(dim, out rm)) {
@ -149,7 +164,7 @@ namespace Substrate
{
_level.Save();
foreach (KeyValuePair<int, RegionChunkManager> cm in _chunkMgrs) {
foreach (KeyValuePair<string, RegionChunkManager> cm in _chunkMgrs) {
cm.Value.Save();
}
}
@ -169,6 +184,11 @@ namespace Substrate
/// <param name="dim">The id of a dimension to look up.</param>
/// <returns>The <see cref="ChunkCache"/> for the given dimension, or null if the dimension was not found.</returns>
public ChunkCache GetChunkCache (int dim)
{
return GetChunkCache(DimensionFromInt(dim));
}
public ChunkCache GetChunkCache (string dim)
{
if (_caches.ContainsKey(dim)) {
return _caches[dim];
@ -230,6 +250,11 @@ namespace Substrate
/// <exclude/>
protected override IBlockManager GetBlockManagerVirt (int dim)
{
return GetBlockManagerVirt(DimensionFromInt(dim));
}
protected override IBlockManager GetBlockManagerVirt (string dim)
{
BlockManager rm;
if (_blockMgrs.TryGetValue(dim, out rm)) {
@ -242,6 +267,11 @@ namespace Substrate
/// <exclude/>
protected override IChunkManager GetChunkManagerVirt (int dim)
{
return GetChunkManagerVirt(DimensionFromInt(dim));
}
protected override IChunkManager GetChunkManagerVirt (string dim)
{
RegionChunkManager rm;
if (_chunkMgrs.TryGetValue(dim, out rm)) {
@ -276,14 +306,22 @@ namespace Substrate
return _dataMan;
}
private void OpenDimension (int dim)
private string DimensionFromInt (int dim)
{
if (dim == Dimension.DEFAULT)
return "";
else
return "DIM" + dim;
}
private void OpenDimension (string dim)
{
string path = Path;
if (dim == Dimension.DEFAULT) {
if (String.IsNullOrEmpty(dim)) {
path = IO.Path.Combine(path, _REGION_DIR);
}
else {
path = IO.Path.Combine(path, "DIM" + dim);
path = IO.Path.Combine(path, dim);
path = IO.Path.Combine(path, _REGION_DIR);
}

View file

@ -73,6 +73,11 @@ namespace Substrate
return GetBlockManagerVirt(dim);
}
public IBlockManager GetBlockManager (string dim)
{
return GetBlockManagerVirt(dim);
}
/// <summary>
/// Gets an <see cref="IChunkManager"/> for the default dimension.
/// </summary>
@ -92,6 +97,11 @@ namespace Substrate
return GetChunkManagerVirt(dim);
}
public IChunkManager GetChunkManager (string dim)
{
return GetChunkManagerVirt(dim);
}
/// <summary>
/// Gets an <see cref="IPlayerManager"/> for maanging players on multiplayer worlds.
/// </summary>
@ -162,6 +172,16 @@ namespace Substrate
/// <returns>An <see cref="IChunkManager"/> for the given dimension in the world.</returns>
protected abstract IChunkManager GetChunkManagerVirt (int dim);
protected virtual IBlockManager GetBlockManagerVirt (string dim)
{
throw new NotImplementedException();
}
protected virtual IChunkManager GetChunkManagerVirt (string dim)
{
throw new NotImplementedException();
}
/// <summary>
/// Virtual implementor of <see cref="GetPlayerManager"/>.
/// </summary>