private ShipBuildData(ShipBuildSerializable serializable, Database database) { ItemId = new ItemId <ShipBuildData>(serializable.Id, serializable.FileName); ShipId = database.GetShipId(serializable.ShipId); NotAvailableInGame = serializable.NotAvailableInGame; DifficultyClass = serializable.DifficultyClass; BuildFaction = database.GetFactionId(serializable.BuildFaction); Components = serializable.Components?.Select(item => InstalledComponentData.Deserialize(item, database)).ToArray(); }
public ShipBuildSerializable Serialize() { var serializable = new ShipBuildSerializable(); serializable.Id = ItemId.Id; serializable.FileName = ItemId.Name; serializable.ItemType = (int)ItemType.ShipBuild; serializable.ShipId = ShipId.Id; serializable.NotAvailableInGame = NotAvailableInGame; serializable.DifficultyClass = DifficultyClass; serializable.BuildFaction = BuildFaction.Id; serializable.Components = Components?.Select(item => item.Serialize()).ToArray(); return(serializable); }
public ShipBuild(ShipBuildSerializable serializable, Database database) { Id = new ItemId <ShipBuild>(serializable.Id, serializable.FileName); Ship = database.GetShipId(serializable.ShipId); if (Ship.IsNull) { throw new DatabaseException(this.GetType().Name + ".Ship cannot be null"); } NotAvailableInGame = serializable.NotAvailableInGame; DifficultyClass = serializable.DifficultyClass; BuildFaction = database.GetFactionId(serializable.BuildFaction); Components = serializable.Components?.Select(item => new InstalledComponent(item, database)).ToArray(); OnDataDeserialized(serializable, database); }
public void Save(ShipBuildSerializable serializable) { serializable.ShipId = Ship.Value; serializable.NotAvailableInGame = NotAvailableInGame; serializable.DifficultyClass = DifficultyClass; serializable.BuildFaction = BuildFaction.Value; if (Components == null || Components.Length == 0) { serializable.Components = null; } else { serializable.Components = Components.Select(item => item.Serialize()).ToArray(); } OnDataSerialized(ref serializable); }
private ShipBuild(ShipBuildSerializable serializable, Database.Loader loader) { Id = new ItemId <ShipBuild>(serializable.Id); loader.AddShipBuild(serializable.Id, this); Ship = loader.GetShip(new ItemId <Ship>(serializable.ShipId)); if (Ship == null) { throw new DatabaseException(this.GetType().Name + ".Ship cannot be null - " + serializable.ShipId); } NotAvailableInGame = serializable.NotAvailableInGame; DifficultyClass = serializable.DifficultyClass; BuildFaction = loader.GetFaction(new ItemId <Faction>(serializable.BuildFaction)); Components = new ImmutableCollection <InstalledComponent>(serializable.Components?.Select(item => InstalledComponent.Create(item, loader))); OnDataDeserialized(serializable, loader); }
partial void OnDataSerialized(ref ShipBuildSerializable serializable);
partial void OnDataDeserialized(ShipBuildSerializable serializable, Database database);
public static ShipBuild Create(ShipBuildSerializable serializable, Database.Loader loader) { return(new ShipBuild(serializable, loader)); }
partial void OnDataDeserialized(ShipBuildSerializable serializable, Database.Loader loader);
public static ShipBuildData Deserialize(ShipBuildSerializable serializable, Database database) { return(new ShipBuildData(serializable, database)); }