mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
* Refactor map loading & saving * test fixes * ISerializationManager tweaks * Fix component composition * Try fix entity deserialization component composition * comments * CL * error preinit * a * cleanup * error if version is too new * Add AlwaysPushSerializationTest * Add auto-inclusion test * Better categorization * Combine test components * Save -> TrySave Also better handling for saving multiple entities individually * Create new partial class for map loading * Add OrphanSerializationTest * Include MapIds in BeforeSerializationEvent * Addd LifetimeSerializationTest * Add TestMixedLifetimeSerialization * Add CategorizationTest * explicitly serialize list of nullspace entities * Add backwards compatibility test * Version comments also fixes wrong v4 format * add MapMergeTest * Add NetEntity support * Optimize EntityDeserializer Avoid unnecessary component deserialization * fix assert & other bugs * fucking containers strike again * Fix deletion of pre-init entities * fix release note merge conflict * Update Robust.Shared/Map/MapManager.GridCollection.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * VV --------- Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
103 lines
3.1 KiB
C#
103 lines
3.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Robust.Shared.Map
|
|
{
|
|
[Virtual]
|
|
internal class TileDefinitionManager : ITileDefinitionManager
|
|
{
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
protected readonly List<ITileDefinition> TileDefs;
|
|
private readonly Dictionary<string, ITileDefinition> _tileNames;
|
|
private readonly Dictionary<string, List<string>> _awaitingAliases;
|
|
|
|
/// <summary>
|
|
/// Default Constructor.
|
|
/// </summary>
|
|
public TileDefinitionManager()
|
|
{
|
|
TileDefs = new List<ITileDefinition>();
|
|
_tileNames = new Dictionary<string, ITileDefinition>();
|
|
_awaitingAliases = new();
|
|
}
|
|
|
|
public virtual void Initialize()
|
|
{
|
|
}
|
|
|
|
public virtual void Register(ITileDefinition tileDef)
|
|
{
|
|
var name = tileDef.ID;
|
|
if (_tileNames.ContainsKey(name))
|
|
{
|
|
throw new ArgumentException("Another tile definition or alias 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;
|
|
}
|
|
|
|
|
|
public Tile GetVariantTile(string name, IRobustRandom random)
|
|
{
|
|
var tileDef = this[name];
|
|
return GetVariantTile(tileDef, random);
|
|
}
|
|
|
|
public Tile GetVariantTile(string name, System.Random random)
|
|
{
|
|
var tileDef = this[name];
|
|
return GetVariantTile(tileDef, random);
|
|
}
|
|
|
|
public Tile GetVariantTile(ITileDefinition tileDef, IRobustRandom random)
|
|
{
|
|
return new Tile(tileDef.TileId, variant: random.NextByte(tileDef.Variants));
|
|
}
|
|
|
|
public Tile GetVariantTile(ITileDefinition tileDef, System.Random random)
|
|
{
|
|
return new Tile(tileDef.TileId, variant: random.NextByte(tileDef.Variants));
|
|
}
|
|
|
|
public ITileDefinition this[string name] => _tileNames[name];
|
|
|
|
public ITileDefinition this[int id] => TileDefs[id];
|
|
|
|
public bool TryGetDefinition(string name, [NotNullWhen(true)] out ITileDefinition? definition)
|
|
{
|
|
return _tileNames.TryGetValue(name, out definition);
|
|
}
|
|
|
|
public bool TryGetDefinition(int id, [NotNullWhen(true)] out ITileDefinition? definition)
|
|
{
|
|
if (id >= TileDefs.Count)
|
|
{
|
|
definition = null;
|
|
return false;
|
|
}
|
|
|
|
definition = TileDefs[id];
|
|
return true;
|
|
}
|
|
|
|
public int Count => TileDefs.Count;
|
|
|
|
public IEnumerator<ITileDefinition> GetEnumerator()
|
|
{
|
|
return TileDefs.GetEnumerator();
|
|
}
|
|
|
|
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
|
{
|
|
return GetEnumerator();
|
|
}
|
|
}
|
|
}
|