public void RemoveModFromPlayset(ModInPlayset mod) { using (SqliteConnection connection = new SqliteConnection($"Data Source={connectionPath}")) { connection.Open(); SqliteCommand command = connection.CreateCommand(); command.CommandText = $"DELETE FROM playsets_mods WHERE playsetID = @playsetID AND modID = @modID;"; command.Parameters.AddWithValue("@playsetID", mod.TargetPlayset.UUID); command.Parameters.AddWithValue("@modID", mod.TargetMod.UUID); command.Prepare(); int res = command.ExecuteNonQuery(); } }
public void UpdateModInPlaysetIndex(ModInPlayset mod) { using (SqliteConnection connection = new SqliteConnection($"Data Source={connectionPath}")) { connection.Open(); SqliteCommand command = connection.CreateCommand(); command.CommandText = $"UPDATE playsets_mods SET position = @newPos WHERE playsetID = @playsetID AND modID = @modID;"; command.Parameters.AddWithValue("@newPos", mod.DatabaseIndex); command.Parameters.AddWithValue("@playsetID", mod.TargetPlayset.UUID); command.Parameters.AddWithValue("@modID", mod.TargetMod.UUID); command.Prepare(); int res = command.ExecuteNonQuery(); } }
public void AddModToPlayset(ModInPlayset mod) { using (SqliteConnection connection = new SqliteConnection($"Data Source={connectionPath}")) { connection.Open(); SqliteCommand command = connection.CreateCommand(); command.CommandText = $"INSERT INTO playsets_mods(playsetID, modID, position, enabled) VALUES(@playsetID, @modID, @position, @enabled);"; command.Parameters.AddWithValue("@playsetID", mod.TargetPlayset.UUID); command.Parameters.AddWithValue("@modID", mod.TargetMod.UUID); command.Parameters.AddWithValue("@position", mod.DatabaseIndex); command.Parameters.AddWithValue("@enabled", mod.Active); command.Prepare(); int res = command.ExecuteNonQuery(); } }
public void ReloadPlaysetMods(Dictionary <string, Mod> allMods, ObservableCollection <ModInPlayset> toReloadSelected, ObservableCollection <Mod> toReloadUnselected, Playset playset) { toReloadSelected.Clear(); toReloadUnselected.Clear(); if (playset == null) { return; } using (SqliteConnection connection = new SqliteConnection($"Data Source={connectionPath}")) { connection.Open(); SqliteCommand command = connection.CreateCommand(); command.CommandText = $"SELECT modId, position, enabled FROM playsets_mods WHERE playsetID = @playsetID ORDER BY position ASC;"; command.Parameters.AddWithValue("@playsetID", playset.UUID); command.Prepare(); SqliteDataReader reader = command.ExecuteReader(); long fixCnt = -1; bool first = true; Debug.WriteLineIf(!FixLoadOrder, "Possibly wrong load Order due to string ordering instead of correct numbers. FixLoadOrder is off."); Debug.Assert(ModInPlayset.DBIndexToLongIndex(ModInPlayset.LongIndexToDbIndex(0)) == 0, "Index Test 0 Failed!"); Debug.Assert(ModInPlayset.DBIndexToLongIndex(ModInPlayset.LongIndexToDbIndex(33)) == 33, "Index Test 33 Failed!"); Debug.Assert(ModInPlayset.DBIndexToLongIndex(ModInPlayset.LongIndexToDbIndex(1300)) == 1300, "Index Test 1300 Failed!"); while (reader.Read()) { string modID = reader.GetString(0); string position = reader.GetString(1); bool enabled = reader.GetBoolean(2); if (first) { fixCnt = ModInPlayset.DBIndexToLongIndex(position); Debug.WriteLine("Fixcnt: " + fixCnt); first = false; } if (FixLoadOrder) { toReloadSelected.Add(new ModInPlayset(allMods[modID], playset, fixCnt, enabled, true)); fixCnt++; } else { toReloadSelected.Add(new ModInPlayset(allMods[modID], playset, ModInPlayset.DBIndexToLongIndex(position), enabled, true)); } } if (FixLoadOrder) { FixPlaysetLoadorderPositions(toReloadSelected, connection); } } foreach (Mod mod in allMods.Values) { if (!SelectedHasMod(mod, toReloadSelected)) { toReloadUnselected.Add(mod); } } Debug.WriteLine($"Now has {toReloadSelected.Count} entries."); Debug.WriteLine($"Now has {toReloadUnselected.Count} entries."); }
public override void Drop(IDropInfo dropInfo) { Debug.WriteLine("Drop TargetItem: " + dropInfo.TargetItem.GetType().Name); Debug.WriteLine("Drop Data: " + dropInfo.Data.GetType().Name); Debug.WriteLine("RelativePosition: " + dropInfo.InsertPosition); Debug.WriteLine("InsertIndex: " + dropInfo.InsertIndex); if (dropInfo.Data is ModInPlayset mip) { int source = (int)mip.Index; int target = dropInfo.InsertIndex; MoveItemInSeleced(source, target); Debug.WriteLine("MIP"); } else if (dropInfo.Data is IList <object> list) { if (list.Count > 0 && list[0] is ModInPlayset) { int target = dropInfo.InsertIndex; List <ModInPlayset> elements = new List <ModInPlayset>(); foreach (object item in list) { elements.Add((ModInPlayset)item); } elements.Sort((a, b) => { return(a.Index.CompareTo(b.Index)); }); foreach (ModInPlayset element in elements) { if (element.Index < target) { MoveItemInSeleced((int)element.Index, target); } else { //Items that get moved up would be prepended, increment target after each move MoveItemInSeleced((int)element.Index, target++); } } } else if (list.Count > 0 && list[0] is Mod) { int startIndex = dropInfo.InsertIndex; int target = dropInfo.InsertIndex; List <Mod> elements = new List <Mod>(); foreach (object item in list) { elements.Add((Mod)item); } foreach (Mod element in elements) { ModInPlayset newMip = new ModInPlayset(element, ViewModel.SelectedPlayset, target, true, false); newMip.AddThis(); ViewModel.SelectedMods.Insert(target, newMip); ViewModel.UnselectedMods.Remove(element); target++; } for (int cnt = target; cnt < ViewModel.SelectedMods.Count; cnt++) { ViewModel.SelectedMods[cnt].Index += elements.Count; } } } else if (dropInfo.Data is Mod mod) { int index = dropInfo.InsertIndex; ModInPlayset newMip = new ModInPlayset(mod, ViewModel.SelectedPlayset, index, true, false); newMip.AddThis(); for (int cnt = index; cnt < ViewModel.SelectedMods.Count; cnt++) { ViewModel.SelectedMods[cnt].Index++; } ViewModel.SelectedMods.Insert(index, newMip); ViewModel.UnselectedMods.Remove(mod); } }