Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
AssetMergePolicies.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using SiliconStudio.Assets.Visitors;
4 
5 namespace SiliconStudio.Assets.Diff
6 {
7  /// <summary>
8  /// Contains different default merge policies to use with <see cref="AssetMerge"/>.
9  /// </summary>
10  public static class AssetMergePolicies
11  {
12  /// <summary>
13  /// The merge policy is expecting <c>asset2</c> to be the new base of <c>asset1</c>, and <c>base</c> the current base of <c>asset1</c>.
14  /// In case of conflicts:
15  /// <ul>
16  /// <li>If there is a type conflict, leave as-is</li>
17  /// <li>If there is a <see cref="Diff3ChangeType.Conflict"/>:
18  /// <ul>
19  /// <li>If it is on a member, and both <c>asset1</c> and <c>asset2</c> are not null and changes were done
20  /// in <c>asset2</c> but not in <c>asset1</c>, select <c>asset2</c> else select <c>asset1</c></li>
21  /// <li>If it is on a list item, we can't resolve it and leave the conflict as-is</li>
22  /// <li>If it is on a array item, we select <c>asset2</c></li>
23  /// </ul>
24  /// </li>
25  /// </ul>
26  /// </summary>
27  /// <param name="diff3Node">The diff3 node.</param>
28  /// <returns>.</returns>
30  {
31  var hasConflicts = diff3Node.ChangeType > Diff3ChangeType.Conflict;
32  if (hasConflicts)
33  {
34  return diff3Node.ChangeType;
35  }
36 
37  switch (diff3Node.ChangeType)
38  {
39  case Diff3ChangeType.Conflict:
40  case Diff3ChangeType.MergeFromAsset2:
41 
42  var dataNode = diff3Node.Asset2Node ?? diff3Node.Asset1Node ?? diff3Node.BaseNode;
43 
44  if (dataNode is DataVisitMember)
45  {
46  if (diff3Node.Asset1Node != null && diff3Node.Asset2Node != null && diff3Node.ChangeType == Diff3ChangeType.MergeFromAsset2)
47  {
48  return Diff3ChangeType.MergeFromAsset2;
49  }
50 
51  return Diff3ChangeType.MergeFromAsset1;
52  }
53 
54  if (dataNode is DataVisitListItem)
55  {
56  // If we have a conflict in a list, we can't really resolve it here, so we are breaking out of the loop
57  if (diff3Node.ChangeType == Diff3ChangeType.Conflict)
58  {
59  return Diff3ChangeType.Conflict;
60  }
61  return Diff3ChangeType.MergeFromAsset2;
62  }
63 
64  if (dataNode is DataVisitDictionaryItem)
65  {
66  return Diff3ChangeType.MergeFromAsset2;
67  }
68 
69  if (dataNode is DataVisitArrayItem)
70  {
71  if (diff3Node.Asset1Node != null && ((DataVisitArrayItem)diff3Node.Asset1Node).Index == ((DataVisitArrayItem)dataNode).Index)
72  {
73  return Diff3ChangeType.MergeFromAsset2;
74  }
75  }
76  break;
77  }
78 
79  return diff3Node.ChangeType;
80  }
81  }
82 }
Contains different default merge policies to use with AssetMerge.
A diff element for a member (field or property) of a class.
static Diff3ChangeType MergePolicyAsset2AsNewBaseOfAsset1(Diff3Node diff3Node)
The merge policy is expecting asset2 to be the new base of asset1, and base the current base of asset...