ProjectDDD/Assets/_Datas/SLShared/SLSystem/SLEntity/Values.cs
2025-06-17 20:47:57 +09:00

214 lines
4.6 KiB (Stored with Git LFS)
C#

using System.Collections.Generic;
namespace Superlazy
{
internal abstract class SLValue : SLEntity
{
public override bool IsValue => true;
protected string id;
public override string ID => id;
public override SLEntity Link()
{
SLLog.Error($"Value can't be link {id}: {GetString()}");
return false;
}
public override SLEntity Override()
{
SLLog.Error($"Value can't be override {id}: {GetString()}");
return false;
}
internal override bool IsExist()
{
return true;
}
public override bool HasChild(string attributeKey)
{
if (attributeKey == "ID") return true;
SLLog.Error($"Can't get Child in Value {id}: {GetObj()}");
return false;
}
public override IEnumerator<SLEntity> GetEnumerator()
{
SLLog.Error($"Can't get Enumerator in Value {id}: {GetObj()}");
yield break;
}
public override SLEntity this[string attributeKey]
{
get
{
if (attributeKey == "ID") return ID;
SLLog.Error($"Can't get attribute in Value {id}: {GetObj()}");
return false;
}
set => SLLog.Error($"Can't set attribute in Value : {GetObj()}");
}
internal override SLEntity ToChild(SLContainerBase parent, string id)
{
if (this.id != null)
{
return Clone().ToChild(parent, id);
}
this.id = id;
return this;
}
internal override void Move(SLEntity parent, string id)
{
this.id = id;
parent[id] = this;
}
//public override SLEntity Clone()
//{
// return this;
//}
public override bool IsModified(string child)
{
return false;
}
public override void EndModified()
{
}
}
internal class SLValueDouble : SLValue
{
private readonly double value;
public SLValueDouble(double value)
{
this.value = value;
}
public override bool IsNumeric => true;
internal override double GetDouble()
{
return value;
}
internal override int GetInt()
{
return (int)value;
}
internal override object GetObj()
{
return value;
}
protected override int GetEntityHashCode()
{
return value.GetHashCode();
}
internal override string GetString()
{
return value.ToString();
}
public override SLEntity Clone()
{
return new SLValueDouble(value);
}
}
internal class SLValueInt : SLValue
{
private readonly int value;
public SLValueInt(int value)
{
this.value = value;
}
public override bool IsNumeric => true;
internal override double GetDouble()
{
return value;
}
internal override int GetInt()
{
return value;
}
internal override object GetObj()
{
return value;
}
protected override int GetEntityHashCode()
{
return value.GetHashCode();
}
internal override string GetString()
{
return value.ToString();
}
public override SLEntity Clone()
{
return new SLValueInt(value);
}
}
internal class SLValueString : SLValue
{
private readonly string value;
public SLValueString(string value)
{
this.value = value;
}
public override bool IsNumeric => false;
internal override double GetDouble()
{
SLLog.Warn($"String is not number {ID}:{GetString()}");
return 0;
}
internal override int GetInt()
{
SLLog.Warn($"String is not number {ID}:{GetString()}");
return 0;
}
internal override object GetObj()
{
return value;
}
protected override int GetEntityHashCode()
{
return value.GetHashCode();
}
internal override string GetString()
{
return value;
}
public override SLEntity Clone()
{
return new SLValueString(value);
}
}
}