Skip to content

Commit

Permalink
Handle items specifying named variants and not groups
Browse files Browse the repository at this point in the history
Allow item variants to specify group+name to handle duplicates
Allow castable restrictions to define message & allow in/not in inventory, equipped/not equipped to be expressed
Add test for elemental belt handling
  • Loading branch information
baughj committed Aug 17, 2023
1 parent 347aeef commit 75aa33b
Show file tree
Hide file tree
Showing 207 changed files with 414 additions and 215 deletions.
41 changes: 40 additions & 1 deletion src/Extensions/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public partial class Item : ICategorizable, ILoadOnStart<Item>, IPostProcessable
[XmlIgnore] public Guid ParentGuid { get; set; }
[XmlIgnore] public Guid Variant { get; set; }

[XmlIgnore]
public bool HasVariants => Properties.Variants != null &&
(Properties.Variants.Group?.Count > 0 || Properties.Variants.Name?.Count > 0);

[XmlIgnore]
[Obsolete("Use ParentGuid instead")]
public Item ParentItem { get; set; }
Expand Down Expand Up @@ -94,7 +98,7 @@ public static void ProcessAll(IWorldDataManager manager)
{
var ret = new XmlProcessResult();
foreach (var item in manager
.Find<Item>(condition: x => x.Properties.Variants != null && x.Properties.Variants.Group.Count > 0)
.Find<Item>(condition: x => x.HasVariants)
.ToList())
{
foreach (var group in item.Properties.Variants.Group)
Expand Down Expand Up @@ -126,6 +130,41 @@ public static void ProcessAll(IWorldDataManager manager)
}
}

foreach (var name in item.Properties.Variants.Name)
{
item.Variants ??= new Dictionary<string, List<Item>>();
if (!manager.TryGetValue<VariantGroup>(name.Group, out var group))
{
manager.FlagAsError(item, XmlError.ProcessingError, $"Variant group {name.Group} does not exist");
ret.Errors[item.Guid] = $"Variant group {name.Group} does not exist";
continue;
}

if (!item.Variants.ContainsKey(name.Group))
item.Variants[name.Group] = new List<Item>();

var toApply = group.Variant.FirstOrDefault(x => x.Name == name.Value);

if (toApply == null)
{
manager.FlagAsError(item, XmlError.ProcessingError, $"Variant group {name.Group}: variant {name.Value} does not exist");
ret.Errors[item.Guid] = "Variant group {name.Group}: variant {name.Value} does not exist";
continue;
}

try
{
var variant = toApply.ResolveVariant(item);
item.Variants[name.Group].Add(variant);
manager.Add(variant);
ret.AdditionalCount++;
}
catch (Exception ex)
{
ret.Errors[item.Guid] = $"{item.Name}: failed to apply variant {toApply.Name}: {ex}";
}
}

ret.TotalProcessed++;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Extensions/Variant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace Hybrasyl.Xml.Objects;

public partial class Variant
{
public override string PrimaryKey => Name;

public Item ResolveVariant(Item originalItem)
{
var variantItem = originalItem.Clone<Item>(true);
Expand Down
11 changes: 9 additions & 2 deletions src/Extensions/VariantGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,22 @@

using System;
using System.Collections.Generic;
using System.Linq;
using Hybrasyl.Xml.Interfaces;

namespace Hybrasyl.Xml.Objects;

public partial class VariantGroup : ILoadOnStart<VariantGroup>
{
public override string PrimaryKey => Name;

public new static void LoadAll(IWorldDataManager manager, string path) =>

public new static void LoadAll(IWorldDataManager manager, string path)
{
HybrasylEntity<VariantGroup>.LoadAll(manager, path);
foreach (var group in manager.Values<VariantGroup>())
foreach (var variant in group.Variant)
manager.Add(variant, $"{group.Name}-{variant.Name}");
}

public Variant RandomVariant() => Variant.PickRandom();

Expand All @@ -49,4 +55,5 @@ public List<Item> ResolveVariants(Item originalItem)

return ret;
}

}
2 changes: 1 addition & 1 deletion src/Objects/Access.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/AddStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/Animation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/AnimationGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/ApiEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/Appearance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/BoardEffects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/BoardType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[XmlTypeAttribute(Namespace="http://www.hybrasyl.com/XML/Hybrasyl/2020-02")]
public enum BoardType
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/Book.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[XmlTypeAttribute(Namespace="http://www.hybrasyl.com/XML/Hybrasyl/2020-02")]
public enum Book
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/CastCost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/CastModifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/CastModifierAdd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/CastModifierReplace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/CastModifierSubtract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/CastRestriction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/Castable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/CastableConeIntent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/CastableCrossIntent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/CastableDamage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/CastableEffects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/CastableEffectsSound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/CastableHeal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/CastableIntent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/CastableLineIntent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/CastableMastery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/CastableMotion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/CastableReactor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/CastableSquareIntent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/CastableTileIntent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/Category.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/Chat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/Class.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Hybrasyl.Xml.Objects
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[XmlTypeAttribute(Namespace="http://www.hybrasyl.com/XML/Hybrasyl/2020-02")]
public enum Class
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/ClassCastCost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Hybrasyl.Xml.Objects
using System.Collections.Generic;

[XmlInclude(typeof(CastCost))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9037.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.9032.0")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategoryAttribute("code")]
Expand Down

0 comments on commit 75aa33b

Please sign in to comment.