Files
RobustToolbox/Robust.Shared/GameObjects/ComponentRegistration.cs
T
Pieter-Jan BriersandGitHub 2a9de462d5 Preserve tile maps when saving maps & related changes (#5003)
* Un-hardcode behavior to make a component not saved to map file.

MapSaveId is a special component that can't be saved to map files due to a hardcoded type check. This behavior can now be applied to any component with [UnsavedComponent].

Moved "component registration" attributes into a single file because they don't deserve their own (poorly organized) .cs files.

* Add ITileDefinitionManager.TryGetDefinition

Try-pattern version of the existing indexers.

* Preserve tile maps when saving maps

This changes the map saver and loader code so that the "tilemap" can be preserved between map modifications as much as possible.

The tile map from the loaded map gets stored onto MapSaveTileMapComponent components on all loaded grids. This tile map is then used when saving, meaning that changes to the engine's internal tile IDs do not cause diffs.

Fixes #5000

* Changelog

* Fix tests
2024-03-27 14:14:19 +11:00

57 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using Robust.Shared.Collections;
using Robust.Shared.GameStates;
namespace Robust.Shared.GameObjects;
/// <summary>
/// Represents a component registered into a <see cref="IComponentFactory" />.
/// </summary>
/// <seealso cref="IComponentFactory" />
/// <seealso cref="IComponent" />
public sealed class ComponentRegistration
{
/// <summary>
/// The name of the component.
/// This is used as the <c>type</c> field in the component declarations if entity prototypes.
/// </summary>
/// <seealso cref="IComponent.Name" />
public string Name { get; }
public CompIdx Idx { get; }
/// <summary>
/// If this is true, the component will not be saved when saving a map/grid.
/// </summary>
/// <seealso cref="UnsavedComponentAttribute"/>
public bool Unsaved { get; }
/// <summary>
/// ID used to reference the component type across the network.
/// If null, no network synchronization will be available for this component.
/// </summary>
/// <seealso cref="NetworkedComponentAttribute" />
public ushort? NetID { get; internal set; }
/// <summary>
/// The type that will be instantiated if this component is created.
/// </summary>
public Type Type { get; }
// Internal for sandboxing.
// Avoid content passing an instance of this to ComponentFactory to get any type they want instantiated.
internal ComponentRegistration(string name, Type type, CompIdx idx, bool unsaved = false)
{
Name = name;
Type = type;
Idx = idx;
Unsaved = unsaved;
}
public override string ToString()
{
return $"ComponentRegistration({Name}: {Type})";
}
}