-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mapping merge driver: continued (#2803)
Co-authored-by: DrSmugleaf <[email protected]> Co-authored-by: Pieter-Jan Briers <[email protected]>
- Loading branch information
1 parent
5cbb3f1
commit 2f01d78
Showing
14 changed files
with
1,026 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net5.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="YamlDotNet" Version="9.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\RobustToolbox\Robust.Shared\Robust.Shared.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System.IO; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using YamlDotNet.Core; | ||
using Robust.Shared.Utility; | ||
using YamlDotNet.RepresentationModel; | ||
|
||
namespace Content.Tools | ||
{ | ||
public class Map | ||
{ | ||
public Map(string path) | ||
{ | ||
Path = path; | ||
|
||
using var reader = new StreamReader(path); | ||
var stream = new YamlStream(); | ||
|
||
stream.Load(reader); | ||
|
||
Root = stream.Documents[0].RootNode; | ||
TilemapNode = (YamlMappingNode) Root["tilemap"]; | ||
GridsNode = (YamlSequenceNode) Root["grids"]; | ||
_entitiesNode = (YamlSequenceNode) Root["entities"]; | ||
|
||
foreach (var entity in _entitiesNode) | ||
{ | ||
var uid = uint.Parse(entity["uid"].AsString()); | ||
if (uid >= NextAvailableEntityId) | ||
NextAvailableEntityId = uid + 1; | ||
Entities[uid] = (YamlMappingNode) entity; | ||
} | ||
} | ||
|
||
// Core | ||
|
||
public string Path { get; } | ||
|
||
public YamlNode Root { get; } | ||
|
||
// Useful | ||
|
||
public YamlMappingNode TilemapNode { get; } | ||
|
||
public YamlSequenceNode GridsNode { get; } | ||
|
||
// Entities lookup | ||
|
||
private YamlSequenceNode _entitiesNode { get; } | ||
|
||
public Dictionary<uint, YamlMappingNode> Entities { get; } = new Dictionary<uint, YamlMappingNode>(); | ||
|
||
public uint MaxId => Entities.Max(entry => entry.Key); | ||
|
||
public uint NextAvailableEntityId { get; set; } | ||
|
||
// ---- | ||
|
||
public void Save(string fileName) | ||
{ | ||
// Update entities node | ||
_entitiesNode.Children.Clear(); | ||
foreach (var kvp in Entities) | ||
_entitiesNode.Add(kvp.Value); | ||
|
||
using var writer = new StreamWriter(fileName); | ||
var document = new YamlDocument(Root); | ||
var stream = new YamlStream(document); | ||
var emitter = new Emitter(writer); | ||
var fixer = new TypeTagPreserver(emitter); | ||
|
||
stream.Save(fixer, false); | ||
|
||
writer.Flush(); | ||
} | ||
|
||
public void Save() | ||
{ | ||
Save(Path); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using YamlDotNet.Core; | ||
using YamlDotNet.RepresentationModel; | ||
|
||
namespace Content.Tools | ||
{ | ||
internal static class MappingMergeDriver | ||
{ | ||
/// %A: Our file | ||
/// %O: Origin (common, base) file | ||
/// %B: Other file | ||
/// %P: Actual filename of the resulting file | ||
public static void Main(string[] args) | ||
{ | ||
var ours = new Map(args[0]); | ||
var based = new Map(args[1]); // On what? | ||
var other = new Map(args[2]); | ||
|
||
if ((ours.GridsNode.Children.Count != 1) || (based.GridsNode.Children.Count != 1) || (other.GridsNode.Children.Count != 1)) | ||
{ | ||
Console.WriteLine("one or more files had an amount of grids not equal to 1"); | ||
Environment.Exit(1); | ||
} | ||
|
||
if (!(new Merger(ours, based, other).Merge())) | ||
{ | ||
Console.WriteLine("unable to merge!"); | ||
Environment.Exit(1); | ||
} | ||
|
||
ours.Save(); | ||
Environment.Exit(0); | ||
} | ||
} | ||
} |
Oops, something went wrong.