Skip to content

Commit

Permalink
Migration file split (new-frontiers-14#2315)
Browse files Browse the repository at this point in the history
* GodHelpMe

* Update migration.yml

* MapMigrationSystem: use fixed list

---------

Co-authored-by: Whatstone <[email protected]>
  • Loading branch information
dvir001 and whatston3 authored Oct 26, 2024
1 parent 1cf18c1 commit a698d0d
Show file tree
Hide file tree
Showing 3 changed files with 242 additions and 217 deletions.
66 changes: 49 additions & 17 deletions Content.Server/Maps/MapMigrationSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using Robust.Server.GameObjects;
Expand All @@ -21,31 +21,58 @@ public sealed class MapMigrationSystem : EntitySystem
[Dependency] private readonly IPrototypeManager _protoMan = default!;
[Dependency] private readonly IResourceManager _resMan = default!;

private const string MigrationFile = "/migration.yml";
private static readonly string[] MigrationFiles = { "/migration.yml", "/_NF/migration.yml" }; // Frontier: use array of migration files

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BeforeEntityReadEvent>(OnBeforeReadEvent);

#if DEBUG
if (!TryReadFile(out var mappings))
if (!TryReadFiles(out var mappings)) // Frontier: TryReadFile<TryReadFiles
return;

// Verify that all of the entries map to valid entity prototypes.
foreach (var node in mappings.Values)
// Delta-V: use list of migrations
foreach (var mapping in mappings)
{
var newId = ((ValueDataNode) node).Value;
if (!string.IsNullOrEmpty(newId) && newId != "null")
DebugTools.Assert(_protoMan.HasIndex<EntityPrototype>(newId), $"{newId} is not an entity prototype.");
foreach (var node in mapping.Values)
{
var newId = ((ValueDataNode)node).Value;
if (!string.IsNullOrEmpty(newId) && newId != "null")
DebugTools.Assert(_protoMan.HasIndex<EntityPrototype>(newId),
$"{newId} is not an entity prototype.");
}
}
// End Delta-V
#endif
}

private bool TryReadFile([NotNullWhen(true)] out MappingDataNode? mappings)
// Frontier: wrap single file reader
private bool TryReadFiles([NotNullWhen(true)] out List<MappingDataNode>? mappings)
{
mappings = null;
var path = new ResPath(MigrationFile);

if (MigrationFiles.Count() <= 0)
return false;

foreach (var migrationFile in MigrationFiles)
{
if (!TryReadFile(migrationFile, out var mapping))
continue;

mappings = mappings ?? new List<MappingDataNode>();
mappings.Add(mapping);
}

return mappings != null && mappings.Count > 0;
}
// End Frontier

private bool TryReadFile(string migrationFile, [NotNullWhen(true)] out MappingDataNode? mappings) // Frontier: add migrationFile
{
mappings = null;
var path = new ResPath(migrationFile); // Frontier: MigrationFile<migrationFile
if (!_resMan.TryContentFileRead(path, out var stream))
return false;

Expand All @@ -61,18 +88,23 @@ private bool TryReadFile([NotNullWhen(true)] out MappingDataNode? mappings)

private void OnBeforeReadEvent(BeforeEntityReadEvent ev)
{
if (!TryReadFile(out var mappings))
if (!TryReadFiles(out var mappings))
return;

foreach (var (key, value) in mappings)
// Delta-V: apply a set of mappings
foreach (var mapping in mappings)
{
if (key is not ValueDataNode keyNode || value is not ValueDataNode valueNode)
continue;
foreach (var (key, value) in mapping)
{
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);
if (string.IsNullOrWhiteSpace(valueNode.Value) || valueNode.Value == "null")
ev.DeletedPrototypes.Add(keyNode.Value);
else
ev.RenamedPrototypes.Add(keyNode.Value, valueNode.Value);
}
}
// End Delta-V
}
}
92 changes: 92 additions & 0 deletions Resources/_NF/migration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# 2023-09-10
ClothingUniformMailCarrier: ClothingUniformJumpsuitMailCarrier
ClothingUniformSkirtMailCarrier: ClothingUniformJumpskirtMailCarrier

# 2023-11-29
# Merc to Mercenary
ClothingMaskGasMerc: ClothingMaskGasMercenary
ClothingBackpackMerc: ClothingBackpackMercenary
ClothingShoesBootsMerc: ClothingShoesBootsMercenary
ClothingShoesBootsMercFilled: ClothingShoesBootsMercenaryFilled
ClothingHandsMercGlovesCombat: ClothingHandsMercenaryGlovesCombat
ClothingHeadHatBeretMerc: ClothingHeadHatBeretMercenary
ClothingOuterVestWebMerc: ClothingOuterVestWebMercenary
ClothingBeltMercWebbing: ClothingBeltMercenaryWebbing
ClothingHeadHelmetMerc: ClothingHeadHelmetMercenary
ClothingHeadBandMerc: ClothingHeadBandMercenary

# 2023-09-12
# EMP Immune moved to grid based.
APCBasicEmpImmune: APCBasic

# 2024-02-09
Ashtray: NFAshtray

# 2024-05-25
BoxSurvival: BoxSurvivalNFOxygen
BoxSurvivalEngineering: BoxSurvivalNFOxygenExtended
BoxSurvivalMedical: BoxSurvivalNFOxygen
BoxHug: BoxSurvivalNFOxygen

# 2024-07-19
ComputerTabletopComputerIFFPOI: ComputerTabletopIFFPOI

# 2024-07-26
SalvageHumanCorpse: SpawnDungeonRandomHumanCorpse
MobRandomServiceCorpse: DungeonHumanCorpseRandomService
MobRandomEngineerCorpse: DungeonHumanCorpseRandomEngineer
MobRandomCargoCorpse: DungeonHumanCorpseRandomCargo
MobRandomMedicCorpse: DungeonHumanCorpseRandomMedic
MobRandomScienceCorpse: DungeonHumanCorpseRandomScience
MobRandomCommandCorpse: DungeonHumanCorpseRandomCommand
MobRandomSecurityCorpse: DungeonHumanCorpseRandomSecurity

# 2024-08-17
# Adjustible frequency radios
RadioHandheld: RadioHandheldNF

# 2024-09-06
TilePrinterNF: CutterMachine

# 2024-09-12
# Smuggling dead drop location rework
RandomPosterContrabandDeadDrop100: RandomPosterContrabandDeadDrop

# 2024-09-22
SignBusNF: NFSignBus
SignDockNF: NFSignDock

# 2024-09-25 Frontier: weapon racks update
WeaponRackBase: StructureGunRack
WeaponRackWallmountedBase: StructureGunRackWallmounted
WeaponRackMeleeBase: StructureMeleeWeaponRack
WeaponRackMeleeWallmountedBase: StructureMeleeWeaponRackWallmounted
WeaponRackPistolBase: StructurePistolRack
WeaponRackPistolWallmountedBase: StructurePistolRackWallmounted
WeaponRackCaptain: StructureGunRack
WeaponRackWallmountedCaptain: StructureGunRackWallmounted
WeaponRackMeleeCaptain: StructureMeleeWeaponRack
WeaponRackMeleeWallmountedCaptain: StructureMeleeWeaponRackWallmounted
WeaponRackPistolBaseCaptain: StructurePistolRack
WeaponRackPistolWallmountedCaptain: StructurePistolRackWallmounted
WeaponRackMercenary: StructureGunRackMercenary
WeaponRackWallmountedMercenary: StructureGunRackWallmountedMercenary
WeaponRackMeleeMercenary: StructureMeleeWeaponRackMercenary
WeaponRackMeleeWallmountedMercenary: StructureMeleeWeaponRackWallmountedMercenary
WeaponRackPistolBaseMercenary: StructurePistolRackMercenary
WeaponRackPistolWallmountedMercenary: StructurePistolRackWallmountedMercenary
WeaponRackSalvage: StructureGunRackSalvage
WeaponRackWallmountedSalvage: StructureGunRackWallmountedSalvage
WeaponRackMeleeSalvage: StructureMeleeWeaponRackSalvage
WeaponRackMeleeWallmountedSalvage: StructureMeleeWeaponRackWallmountedSalvage
WeaponRackPistolBaseSalvage: StructurePistolRackSalvage
WeaponRackPistolWallmountedSalvage: StructurePistolRackWallmountedSalvage
WeaponRackSecurity: StructureGunRackNfsd
WeaponRackWallmountedSecurity: StructureGunRackWallmountedNfsd
WeaponRackMeleeSecurity: StructureMeleeWeaponRackNfsd
WeaponRackMeleeWallmountedSecurity: StructureMeleeWeaponRackWallmountedNfsd
WeaponRackPistolBaseSecurity: StructurePistolRackNfsd
WeaponRackPistolWallmountedSecurity: StructurePistolRackWallmountedNfsd

# 2024-10-09 Frontier: Fixups
SpawnPointDetectiveNF: NFSpawnPointDetective
Loading

0 comments on commit a698d0d

Please sign in to comment.