1
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -36,8 +37,8 @@ namespace BITKit.Modification
|
||||
/// </summary>
|
||||
public interface IModifyElement
|
||||
{
|
||||
IModifyElement[] Require { get; }
|
||||
IModifyElement[] Incompatible { get; }
|
||||
IModifyElement[] Require => Array.Empty<IModifyElement>();
|
||||
IModifyElement[] Incompatible => Array.Empty<IModifyElement>();
|
||||
}
|
||||
/// <summary>
|
||||
/// 改装管理器
|
||||
@@ -65,17 +66,32 @@ namespace BITKit.Modification
|
||||
}
|
||||
public class ModifyManager : IModifyManager
|
||||
{
|
||||
public virtual IDictionary<IModifyElement, object> Modifies { get;private set; } =new Dictionary<IModifyElement,object>();
|
||||
public virtual IDictionary<IModifyElement, object> Modified => new Dictionary<IModifyElement, object>(Modifies.Where(x=>x.Value is not null));
|
||||
public virtual IDictionary<IModifyElement, object> Modifies { get; } =new Dictionary<IModifyElement,object>();
|
||||
public virtual IDictionary<IModifyElement, object> Modified { get; } = new Dictionary<IModifyElement, object>();
|
||||
|
||||
public virtual void Add(IModifyElement modify, object obj)
|
||||
{
|
||||
if(Modified.ContainsKey(modify))
|
||||
throw new NotSupportModifyException(new[]{modify});
|
||||
|
||||
var list = new List<IModifyElement>();
|
||||
list.AddRange(Modified.Keys);
|
||||
list.Add(modify);
|
||||
|
||||
if(list.All(x=>x.Require?.Any(y=>list.Contains(y)) is false))
|
||||
throw new NotRequireModifyException(list.ToArray());
|
||||
|
||||
foreach (var x in list)
|
||||
{
|
||||
if(x.Require is null or {Length:0})continue;
|
||||
|
||||
foreach (var _x in x.Require)
|
||||
{
|
||||
if (list.Contains(_x) is false)
|
||||
throw new NotRequireModifyException(x.Require);
|
||||
}
|
||||
}
|
||||
|
||||
//你知道怎么做,帮我做一下
|
||||
|
||||
|
||||
var incompatible = list.Where(x=>x.Incompatible is not null).SelectMany(x => x.Incompatible).ToArray();
|
||||
if(MathE.Contains(incompatible,list))
|
||||
|
Reference in New Issue
Block a user