Files
LuaCsForBarotraumaEP/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Data/IDataInfo.cs
T
MapleWheels d2b9ca4c1b [Refactor-Minor]
- Refactored interface definition.
- Plugin Loading System Refactor (incomplete).
2026-02-07 20:10:39 -05:00

53 lines
2.0 KiB
C#

using System;
using System.Collections.Generic;
namespace Barotrauma.LuaCs.Data;
/// <summary>
/// Serves as a compound-key to refer to all resources and information that comes from a specific source.
/// </summary>
public interface IDataInfo : IEqualityComparer<IDataInfo>, IEquatable<IDataInfo>
{
/// <summary>
/// Internal name unique within the resources inside a package.
/// </summary>
string InternalName { get; }
/// <summary>
/// The package this information belongs to.
/// </summary>
ContentPackage OwnerPackage { get; }
/// <summary>
/// Used in place of the package data when the OwnerPackage is missing.
/// </summary>
string FallbackPackageName { get; }
bool IEqualityComparer<IDataInfo>.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<IDataInfo>.Equals(IDataInfo other)
{
return Equals(this, other);
}
int IEqualityComparer<IDataInfo>.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();
}
}