61 lines
2.1 KiB
C#
61 lines
2.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using BITFALL.Items;
|
|
using BITKit;
|
|
using BITKit.Modification;
|
|
using UnityEngine;
|
|
|
|
namespace BITFALL.Industry
|
|
{
|
|
[Serializable]
|
|
public struct ComputerRAM : IModifyElement
|
|
{
|
|
public override string ToString() => "RAM";
|
|
}
|
|
[Serializable]
|
|
public struct ComputerCPU:IModifyElement{ public override string ToString() => "CPU";}
|
|
[Serializable]
|
|
public struct ComputerExternalHDD:IModifyElement{ public override string ToString() => "外部HDD";}
|
|
[Serializable]
|
|
public struct ComputerGPU:IModifyElement{ public override string ToString() => "GPU";}
|
|
|
|
[CustomType(typeof(IModifyManager))]
|
|
[Serializable]
|
|
public class GameComputerModified:IModifyManager,IProperty
|
|
{
|
|
public override string ToString()
|
|
{
|
|
var reportBuilder = new StringBuilder();
|
|
foreach (var pair in Modifies)
|
|
{
|
|
reportBuilder.AppendLine(Modified.TryGetValue(pair.Key, out var obj)
|
|
? $"{pair.Key} : {obj}"
|
|
: $"{pair.Key} : ");
|
|
}
|
|
return reportBuilder.ToString();
|
|
}
|
|
|
|
public IDictionary<IModifyElement, object> Modifies { get;} = new Dictionary<IModifyElement, object>
|
|
{
|
|
{new ComputerRAM(),null},
|
|
{new ComputerCPU(),null},
|
|
{new ComputerExternalHDD(),null},
|
|
{new ComputerGPU(),null}
|
|
};
|
|
public IDictionary<IModifyElement, object> Modified { get; } = new Dictionary<IModifyElement, object>();
|
|
public void Add(IModifyElement modify, object obj)
|
|
{
|
|
if(obj is not IBasicItem item)throw new NotSupportModifyException(new IModifyElement[]{modify});
|
|
if(item.GetAssetable() is not ScriptableIndustryComponent component) throw new NotSupportModifyException(new IModifyElement[]{modify});
|
|
if(Modified.TryAdd(modify,item) is false)throw new NotSupportModifyException(new IModifyElement[]{modify});
|
|
}
|
|
public void Remove(IModifyElement modify, out object obj)
|
|
{
|
|
if(Modified.TryGetValue(modify,out obj) is false)throw new NotSupportModifyException(new IModifyElement[]{modify});
|
|
if(Modified.Remove(modify) is false)throw new NotSupportModifyException(new IModifyElement[]{modify});
|
|
}
|
|
}
|
|
}
|