mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-15 14:52:35 +02:00
* Removed the Interfaces folder. * All objects inside the GameObjects subfolders are now in the GameObjects namespace. * Added a Resharper DotSettings file to mark the GameObjects subfolders as not providing namespaces. * Simplified Robust.client.Graphics namespace. * Automated remove redundant using statements.
58 lines
1.7 KiB
C#
58 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Robust.Shared.Map
|
|
{
|
|
internal class TileDefinitionManager : ITileDefinitionManager
|
|
{
|
|
protected readonly List<ITileDefinition> TileDefs;
|
|
private readonly Dictionary<string, ITileDefinition> _tileNames;
|
|
private readonly Dictionary<ITileDefinition, ushort> _tileIds;
|
|
|
|
/// <summary>
|
|
/// Default Constructor.
|
|
/// </summary>
|
|
public TileDefinitionManager()
|
|
{
|
|
TileDefs = new List<ITileDefinition>();
|
|
_tileNames = new Dictionary<string, ITileDefinition>();
|
|
_tileIds = new Dictionary<ITileDefinition, ushort>();
|
|
}
|
|
|
|
public virtual void Initialize()
|
|
{
|
|
}
|
|
|
|
public virtual void Register(ITileDefinition tileDef)
|
|
{
|
|
var name = tileDef.Name;
|
|
if (_tileNames.ContainsKey(name))
|
|
{
|
|
throw new ArgumentException("Another tile definition with the same name has already been registered.", nameof(tileDef));
|
|
}
|
|
|
|
var id = checked((ushort) TileDefs.Count);
|
|
tileDef.AssignTileId(id);
|
|
TileDefs.Add(tileDef);
|
|
_tileNames[name] = tileDef;
|
|
_tileIds[tileDef] = id;
|
|
}
|
|
|
|
public ITileDefinition this[string name] => _tileNames[name];
|
|
|
|
public ITileDefinition this[int id] => TileDefs[id];
|
|
|
|
public int Count => TileDefs.Count;
|
|
|
|
public IEnumerator<ITileDefinition> GetEnumerator()
|
|
{
|
|
return TileDefs.GetEnumerator();
|
|
}
|
|
|
|
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
|
{
|
|
return GetEnumerator();
|
|
}
|
|
}
|
|
}
|