Add basic map loader support for entity renaming (#15862)
This commit is contained in:
@@ -15,7 +15,7 @@ public sealed class DispenserTest : InteractionTest
|
|||||||
[Test]
|
[Test]
|
||||||
public async Task InsertEjectBuiTest()
|
public async Task InsertEjectBuiTest()
|
||||||
{
|
{
|
||||||
await SpawnTarget("chem_dispenser");
|
await SpawnTarget("ChemDispenser");
|
||||||
ToggleNeedPower();
|
ToggleNeedPower();
|
||||||
|
|
||||||
// Insert beaker
|
// Insert beaker
|
||||||
|
|||||||
76
Content.Server/Maps/MapMigrationSystem.cs
Normal file
76
Content.Server/Maps/MapMigrationSystem.cs
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using Robust.Server.GameObjects;
|
||||||
|
using Robust.Server.Maps;
|
||||||
|
using Robust.Shared.ContentPack;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
|
using Robust.Shared.Serialization.Markdown;
|
||||||
|
using Robust.Shared.Serialization.Markdown.Mapping;
|
||||||
|
using Robust.Shared.Serialization.Markdown.Value;
|
||||||
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
|
namespace Content.Server.Maps;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Performs basic map migration operations by listening for engine <see cref="MapLoaderSystem"/> events.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class MapMigrationSystem : EntitySystem
|
||||||
|
{
|
||||||
|
[Dependency] private readonly IPrototypeManager _protoMan = default!;
|
||||||
|
[Dependency] private readonly IResourceManager _resMan = default!;
|
||||||
|
|
||||||
|
private const string MigrationFile = "/migration.yml";
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
SubscribeLocalEvent<BeforeEntityReadEvent>(OnBeforeReadEvent);
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
if (!TryReadFile(out var mappings))
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach (var node in mappings.Values)
|
||||||
|
{
|
||||||
|
var newId = ((ValueDataNode) node).Value;
|
||||||
|
if (!string.IsNullOrEmpty(newId) && newId != "null")
|
||||||
|
DebugTools.Assert(_protoMan.HasIndex<EntityPrototype>(newId));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryReadFile([NotNullWhen(true)] out MappingDataNode? mappings)
|
||||||
|
{
|
||||||
|
mappings = null;
|
||||||
|
var path = new ResPath(MigrationFile);
|
||||||
|
if (!_resMan.TryContentFileRead(path, out var stream))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
using var reader = new StreamReader(stream, EncodingHelpers.UTF8);
|
||||||
|
var documents = DataNodeParser.ParseYamlStream(reader).FirstOrDefault();
|
||||||
|
|
||||||
|
if (documents == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
mappings = (MappingDataNode) documents.Root;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnBeforeReadEvent(BeforeEntityReadEvent ev)
|
||||||
|
{
|
||||||
|
if (!TryReadFile(out var mappings))
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach (var (key, value) in mappings)
|
||||||
|
{
|
||||||
|
if (key is not ValueDataNode keyNode || value is not ValueDataNode valueNode)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(valueNode.Value) || valueNode.Value == "null")
|
||||||
|
ev.DeletedPrototypes.Add(keyNode.Value);
|
||||||
|
else
|
||||||
|
ev.RenamedPrototypes.Add(keyNode.Value, valueNode.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -364,7 +364,7 @@
|
|||||||
- type: Sprite
|
- type: Sprite
|
||||||
state: medical
|
state: medical
|
||||||
- type: MachineBoard
|
- type: MachineBoard
|
||||||
prototype: chem_dispenser
|
prototype: ChemDispenser
|
||||||
requirements:
|
requirements:
|
||||||
Capacitor: 1
|
Capacitor: 1
|
||||||
materialRequirements:
|
materialRequirements:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
- type: entity
|
- type: entity
|
||||||
id: chem_dispenser
|
id: ChemDispenser
|
||||||
name: chemical dispenser
|
name: chemical dispenser
|
||||||
parent: ReagentDispenserBase
|
parent: ReagentDispenserBase
|
||||||
description: An industrial grade chemical dispenser with a sizeable chemical supply.
|
description: An industrial grade chemical dispenser with a sizeable chemical supply.
|
||||||
@@ -27,8 +27,8 @@
|
|||||||
- type: Machine
|
- type: Machine
|
||||||
board: ChemDispenserMachineCircuitboard
|
board: ChemDispenserMachineCircuitboard
|
||||||
- type: Wires
|
- type: Wires
|
||||||
BoardName: "chem_dispenser"
|
BoardName: "ChemDispenser"
|
||||||
LayoutId: chem_dispenser
|
LayoutId: ChemDispenser
|
||||||
- type: UpgradePowerDraw
|
- type: UpgradePowerDraw
|
||||||
powerDrawMultiplier: 0.75
|
powerDrawMultiplier: 0.75
|
||||||
scaling: Exponential
|
scaling: Exponential
|
||||||
|
|||||||
11
Resources/migration.yml
Normal file
11
Resources/migration.yml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# basic dictionary that maps old entity ids to new entity ids.
|
||||||
|
# an empty or "null" string results in the entity getting deleted.
|
||||||
|
|
||||||
|
# e.g., you can swap all walls with windows and delete all tables by adding lines like:
|
||||||
|
#
|
||||||
|
# Window: WallSolid
|
||||||
|
# WallSolid: Window
|
||||||
|
# Table: null
|
||||||
|
|
||||||
|
chem_dispenser: ChemDispenser
|
||||||
|
|
||||||
Reference in New Issue
Block a user