public void Loadout(int id, string ship, string shipfd, string name, string ident, List <JournalLoadout.ShipModule> modulelist) { string sid = Key(shipfd, id); //System.Diagnostics.Debug.WriteLine("Loadout {0} {1} {2} {3}", id, ship, name, ident); ShipInformation sm = EnsureShip(sid); // this either gets current ship or makes a new one. Ships[sid] = sm = sm.Set(ship, shipfd, name, ident); // update ship key, make a fresh one if required. //System.Diagnostics.Debug.WriteLine("Loadout " + sm.ID + " " + sm.ShipFullInfo()); ShipInformation newsm = null; // if we change anything, we need a new clone.. foreach (JournalLoadout.ShipModule m in modulelist) { if (!sm.Contains(m.Slot) || !sm.Same(m)) // no slot, or not the same data.. (ignore localised item) { if (m.LocalisedItem == null && itemlocalisation.ContainsKey(m.Item)) // if we have a cached localisation, use it { m.LocalisedItem = itemlocalisation[m.Item]; } if (newsm == null) // if not cloned { newsm = sm.ShallowClone(); // we need a clone, pointing to the same modules, but with a new dictionary Ships[sid] = newsm; // update our record of last module list for this ship } newsm.Set(m); // update entry only.. rest will still point to same entries } } }
public void Loadout(int id, string ship, string shipfd, string name, string ident, List <ShipModule> modulelist, long HullValue, long ModulesValue, long Rebuy, bool?Hot) { string sid = Key(shipfd, id); //System.Diagnostics.Debug.WriteLine("Loadout {0} {1} {2} {3}", id, ship, name, ident); ShipInformation sm = EnsureShip(sid); // this either gets current ship or makes a new one. Ships[sid] = sm = sm.SetShipDetails(ship, shipfd, name, ident, 0, 0, HullValue, ModulesValue, Rebuy, Hot); // update ship key, make a fresh one if required. //System.Diagnostics.Debug.WriteLine("Loadout " + sid); ShipInformation newsm = null; // if we change anything, we need a new clone.. Dictionary <string, ShipModule> moduleSlots = sm.Modules.ToDictionary(kvp => kvp.Key, kvp => kvp.Value); foreach (ShipModule m in modulelist) { if (!sm.Contains(m.Slot) || !sm.Same(m)) // no slot, or not the same data.. (ignore localised item) { if (m.LocalisedItem == null && itemlocalisation.ContainsKey(m.Item)) // if we have a cached localisation, use it { m.LocalisedItem = itemlocalisation[m.Item]; // System.Diagnostics.Debug.WriteLine("Have localisation for " + m.Item + ": " + m.LocalisedItem); } if (newsm == null) // if not cloned { newsm = sm.ShallowClone(); // we need a clone, pointing to the same modules, but with a new dictionary Ships[sid] = newsm; // update our record of last module list for this ship } newsm.SetModule(m); // update entry only.. rest will still point to same entries } moduleSlots.Remove(m.Slot); } // Remove modules not in loadout if (moduleSlots.Count != 0) { List <ShipModule> modulesToRemove = moduleSlots.Values.ToList(); if (newsm == null) { newsm = sm.ShallowClone(); } foreach (ShipModule m in modulesToRemove) { System.Diagnostics.Trace.WriteLine($"Warning: Module {m.Item} in slot {m.Slot} is missing from loadout"); newsm = newsm.RemoveModule(m.Slot, m.Item); } Ships[sid] = newsm; } VerifyList(); }