Skip to content

Commit

Permalink
ICloneable and IAssignable for AttributeRelationship
Browse files Browse the repository at this point in the history
  • Loading branch information
sven-n committed Nov 17, 2024
1 parent ea4af9c commit 8c14e1e
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/Persistence/BasicModel/AttributeRelationship.Custom.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// <copyright file="AttributeRelationship.Custom.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>

using MUnique.OpenMU.DataModel;

namespace MUnique.OpenMU.Persistence.BasicModel;

/// <summary>
/// A plain implementation of <see cref="MUnique.OpenMU.AttributeSystem.AttributeRelationship"/>.
/// </summary>
public partial class AttributeRelationship :
IAssignable,
IAssignable<MUnique.OpenMU.AttributeSystem.AttributeRelationship>,
ICloneable<MUnique.OpenMU.AttributeSystem.AttributeRelationship>
{
/// <inheritdoc />
public virtual AttributeSystem.AttributeRelationship Clone(DataModel.Configuration.GameConfiguration gameConfiguration)
{
var clone = new AttributeRelationship();
clone.AssignValuesOf(this, gameConfiguration);
return clone;
}

/// <inheritdoc />
public virtual void AssignValuesOf(object other, DataModel.Configuration.GameConfiguration gameConfiguration)
{
if (other is AttributeSystem.AttributeRelationship typedOther)
{
AssignValuesOf(typedOther, gameConfiguration);
}
}

/// <inheritdoc />
public virtual void AssignValuesOf(AttributeSystem.AttributeRelationship other, DataModel.Configuration.GameConfiguration gameConfiguration)
{
this.InputAttribute = gameConfiguration.Attributes.FirstOrDefault(a => a.Id == other.InputAttribute?.Id) ?? other.InputAttribute;
this.OperandAttribute = gameConfiguration.Attributes.FirstOrDefault(a => a.Id == other.OperandAttribute?.Id) ?? other.OperandAttribute;
this.TargetAttribute = gameConfiguration.Attributes.FirstOrDefault(a => a.Id == other.TargetAttribute?.Id) ?? other.TargetAttribute;
this.InputOperand = other.InputOperand;
this.InputOperator = other.InputOperator;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// <copyright file="AttributeRelationship.Custom.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>

namespace MUnique.OpenMU.Persistence.EntityFramework.Model;

using MUnique.OpenMU.DataModel;

/// <summary>
/// The Entity Framework Core implementation of <see cref="MUnique.OpenMU.AttributeSystem.AttributeRelationship"/>.
/// </summary>
internal partial class AttributeRelationship :
IAssignable,
IAssignable<MUnique.OpenMU.AttributeSystem.AttributeRelationship>,
ICloneable<MUnique.OpenMU.AttributeSystem.AttributeRelationship>
{
/// <inheritdoc />
public virtual AttributeSystem.AttributeRelationship Clone(DataModel.Configuration.GameConfiguration gameConfiguration)
{
var clone = new AttributeRelationship();
clone.AssignValuesOf(this, gameConfiguration);
return clone;
}

/// <inheritdoc />
public virtual void AssignValuesOf(object other, DataModel.Configuration.GameConfiguration gameConfiguration)
{
if (other is AttributeSystem.AttributeRelationship typedOther)
{
AssignValuesOf(typedOther, gameConfiguration);
}
}

/// <inheritdoc />
public virtual void AssignValuesOf(AttributeSystem.AttributeRelationship other, DataModel.Configuration.GameConfiguration gameConfiguration)
{
this.InputAttribute = gameConfiguration.Attributes.FirstOrDefault(a => a.Id == other.InputAttribute?.Id) ?? other.InputAttribute;
this.OperandAttribute = gameConfiguration.Attributes.FirstOrDefault(a => a.Id == other.OperandAttribute?.Id) ?? other.OperandAttribute;
this.TargetAttribute = gameConfiguration.Attributes.FirstOrDefault(a => a.Id == other.TargetAttribute?.Id) ?? other.TargetAttribute;
this.InputOperand = other.InputOperand;
this.InputOperator = other.InputOperator;
}
}

0 comments on commit 8c14e1e

Please sign in to comment.