-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #405 from MUnique/custom-plugin-config-ext
Support references to config objects in custom plugin configurations
- Loading branch information
Showing
25 changed files
with
263 additions
and
88 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
18 changes: 18 additions & 0 deletions
18
...GameLogic/PlayerActions/ItemConsumeActions/BlessJewelConsumeHandlerPlugInConfiguration.cs
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,18 @@ | ||
// <copyright file="BlessJewelConsumeHandlerPlugInConfiguration.cs" company="MUnique"> | ||
// Licensed under the MIT License. See LICENSE file in the project root for full license information. | ||
// </copyright> | ||
|
||
namespace MUnique.OpenMU.GameLogic.PlayerActions.ItemConsumeActions; | ||
|
||
using MUnique.OpenMU.DataModel.Configuration.Items; | ||
|
||
/// <summary> | ||
/// The configuration for the <see cref="BlessJewelConsumeHandlerPlugIn"/>. | ||
/// </summary> | ||
public class BlessJewelConsumeHandlerPlugInConfiguration | ||
{ | ||
/// <summary> | ||
/// Gets or sets the items which can be repaired by consuming a bless on them. | ||
/// </summary> | ||
public ICollection<ItemDefinition> RepairTargetItems { get; set; } = new List<ItemDefinition>(); | ||
} |
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,34 @@ | ||
// <copyright file="ByDataSourceReferenceHandler.cs" company="MUnique"> | ||
// Licensed under the MIT License. See LICENSE file in the project root for full license information. | ||
// </copyright> | ||
|
||
namespace MUnique.OpenMU.Persistence; | ||
|
||
using System.Text.Json.Serialization; | ||
using MUnique.OpenMU.DataModel.Configuration; | ||
|
||
/// <summary> | ||
/// A reference handler which uses a <see cref="IDataSource{T}"/> to resolve references. | ||
/// </summary> | ||
public class ByDataSourceReferenceHandler : ReferenceHandler | ||
{ | ||
/// <summary> | ||
/// The data source. | ||
/// </summary> | ||
private readonly IDataSource<GameConfiguration> _dataSource; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ByDataSourceReferenceHandler"/> class. | ||
/// </summary> | ||
/// <param name="dataSource">The data source.</param> | ||
public ByDataSourceReferenceHandler(IDataSource<GameConfiguration> dataSource) | ||
{ | ||
this._dataSource = dataSource; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override ReferenceResolver CreateResolver() | ||
{ | ||
return new ByDataSourceReferenceResolver(this._dataSource); | ||
} | ||
} |
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,54 @@ | ||
// <copyright file="ByDataSourceReferenceResolver.cs" company="MUnique"> | ||
// Licensed under the MIT License. See LICENSE file in the project root for full license information. | ||
// </copyright> | ||
|
||
namespace MUnique.OpenMU.Persistence; | ||
|
||
using System.Text.Json.Serialization; | ||
using MUnique.OpenMU.DataModel.Configuration; | ||
|
||
/// <summary> | ||
/// A reference resolver which uses a <see cref="IDataSource{T}"/> to resolve references. | ||
/// </summary> | ||
public class ByDataSourceReferenceResolver : ReferenceResolver | ||
{ | ||
/// <summary> | ||
/// The data source. | ||
/// </summary> | ||
private readonly IDataSource<GameConfiguration> _dataSource; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ByDataSourceReferenceResolver"/> class. | ||
/// </summary> | ||
/// <param name="dataSource">The data source.</param> | ||
public ByDataSourceReferenceResolver(IDataSource<GameConfiguration> dataSource) | ||
{ | ||
this._dataSource = dataSource; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override void AddReference(string referenceId, object value) | ||
{ | ||
// do nothing here, because the data source is the source of truth. | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override string GetReference(object value, out bool alreadyExists) | ||
{ | ||
if (value is IIdentifiable identifiable) | ||
{ | ||
alreadyExists = this._dataSource.Get(identifiable.Id) is { }; | ||
return identifiable.Id.ToString(); | ||
} | ||
|
||
alreadyExists = false; | ||
return string.Empty; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override object ResolveReference(string referenceId) | ||
{ | ||
var id = Guid.Parse(referenceId); | ||
return this._dataSource.Get(id) ?? throw new KeyNotFoundException($"Reference with id '{referenceId}' not found."); | ||
} | ||
} |
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
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
Oops, something went wrong.