using LibXom.Exceptions; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LibXom.Data { public class XomType : XomFileComponent { private byte[] xBytes; private string name; private List xomContainers = new List(); public override int Id { get { return this.fileBelongs.calculateIdForXomFileComponent(this.Uuid, fileBelongs.XomTypes); } } public byte[] XBytes { get { return xBytes; } } public string Name { get { return name; } } public XomContainer[] Containers { get { return xomContainers.ToArray(); } } private int getContainerIndex(XomContainer container) { for (int i = 0; i < xomContainers.Count; i++) { if (xomContainers[i].Equals(container)) { return i; } } throw new XomContainerNotFoundException("container with uuid " + container.Uuid + " not found in type " + this.Name); } public void ReplaceContainerData(XomContainer container, byte[] newData) { int indx = this.getContainerIndex(container); this.xomContainers[indx].data = newData; } public XomContainer NewContainer() { XomContainer xomContainer = new XomContainer(this.fileBelongs, this.Name, new byte[0x3]); this.xomContainers.Add(xomContainer); return xomContainer; } public override int GetHashCode() { return this.Name.GetHashCode(); } public override bool Equals(object? obj) { if (obj is not XomType) return false; XomType xCompare = obj as XomType; return xCompare.Name.Equals(this.Name, StringComparison.InvariantCultureIgnoreCase); } public void DeleteContainer(XomContainer container) { int indx = this.getContainerIndex(container); this.xomContainers.RemoveAt(indx); if(this.xomContainers.Count == 0) this.fileBelongs.deleteXomType(this); } internal XomType(XomFile fileFrom, byte[] xBytes, string name, XomContainer[] xomContainers) { fileBelongs = fileFrom; this.xBytes = xBytes; this.name = name; this.xomContainers.AddRange(xomContainers); } } }