using System; using System.Collections.Generic; using System.Xml.Serialization; namespace Barotrauma.LuaCs.Data; /// /// Serves as a compound-key to refer to all resources and information that comes from a specific source. /// public interface IDataInfo : IEqualityComparer, IEquatable { /// /// Internal name unique within the resources inside a package. /// [XmlAttribute("Name")] string InternalName { get; } /// /// The package this information belongs to. /// ContentPackage OwnerPackage { get; } bool IEqualityComparer.Equals(IDataInfo x, IDataInfo y) { if (x is null || y is null) return false; if (x.OwnerPackage is null) throw new NullReferenceException($"ContentPackage not set for resource {x}!"); if (y.OwnerPackage is null) throw new NullReferenceException($"ContentPackage not set for resource {y}!"); if (x.InternalName.IsNullOrWhiteSpace()) throw new NullReferenceException($"InternalName not set for resource {x}!"); if (y.InternalName.IsNullOrWhiteSpace()) throw new NullReferenceException($"InternalName not set for resource {y}!"); return x.OwnerPackage == y.OwnerPackage && x.InternalName == y.InternalName; } bool IEquatable.Equals(IDataInfo other) { return Equals(this, other); } int IEqualityComparer.GetHashCode(IDataInfo obj) { if (obj.OwnerPackage is null) throw new NullReferenceException($"ContentPackage not set for resource {obj}!"); if (obj.InternalName.IsNullOrWhiteSpace()) throw new NullReferenceException($"InternalName is null for object {obj}!"); return obj.InternalName.GetHashCode() + obj.OwnerPackage.GetHashCode(); } }