-
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.
Object references in custom plugin configurations
- Loading branch information
Showing
22 changed files
with
230 additions
and
87 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,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 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) | ||
{ | ||
//throw new NotImplementedException(); | ||
} | ||
|
||
/// <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.