public void ExportPlayset(Playset playset)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter     =
                saveFileDialog.Filter = "Stellaris Playset Database|*.sqlite";
            saveFileDialog.DefaultExt = ".sqlite";
            saveFileDialog.FileName   = playset.Name;

            bool?  result = saveFileDialog.ShowDialog();
            string path;

            if (result == true)
            {
                path = saveFileDialog.FileName;
                Debug.WriteLine(path);
            }
            else
            {
                return;
            }

            using (FileStream stream = File.Create(path))
            {
            }

            using (SqliteConnection connection = new SqliteConnection($"Data Source={path}"))
            {
                connection.Open();
                InitExportDB(connection);
                CloneDataToExportDB(connection, playset);
            }
        }
        public bool ActivatePlayset(Playset playset)
        {
            using (SqliteConnection connection = new SqliteConnection($"Data Source={connectionPath}"))
            {
                connection.Open();

                SqliteTransaction transaction = connection.BeginTransaction();

                try
                {
                    SqliteCommand deactivateCurrentCommand = connection.CreateCommand();
                    deactivateCurrentCommand.CommandText = $"UPDATE playsets SET isActive = false WHERE isActive = true;";

                    deactivateCurrentCommand.ExecuteNonQuery();

                    SqliteCommand activateNewCommand = connection.CreateCommand();
                    activateNewCommand.CommandText = $"UPDATE playsets SET isActive = true WHERE id = @playsetID;";
                    activateNewCommand.Parameters.AddWithValue("@playsetID", playset.UUID);
                    activateNewCommand.Prepare();

                    activateNewCommand.ExecuteNonQuery();

                    transaction.Commit();
                    return(true);
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Exception: " + e.Message + "\r\nRolling Back!");
                    transaction.Rollback();
                    return(false);
                }
            }
        }
        public void ClonePlaysetToNew(string newPlaysetName, Playset fromPlayset)
        {
            using (SqliteConnection connection = new SqliteConnection($"Data Source={connectionPath}"))
            {
                connection.Open();
                SqliteTransaction transaction = connection.BeginTransaction();

                Playset newPlayset = createNewPlaysetOnConnection(newPlaysetName, connection);

                try
                {
                    SqliteCommand fillCommand = connection.CreateCommand();
                    fillCommand.CommandText = $"INSERT INTO playsets_mods(playsetId, modId, position, enabled) SELECT '{newPlayset.UUID}', modId, position, enabled FROM playsets_mods WHERE playsetId = @oldUUID;";
                    fillCommand.Parameters.AddWithValue("@oldUUID", fromPlayset.UUID);
                    fillCommand.Prepare();

                    Debug.WriteLine("Command: " + fillCommand.CommandText + " with oldUUID = " + fromPlayset.UUID);

                    fillCommand.ExecuteNonQuery();

                    transaction.Commit();
                }catch (Exception e)
                {
                    Debug.WriteLine("Exception: " + e.Message + "\r\nRolling Back!");
                    transaction.Rollback();
                }
            }
        }
Exemple #4
0
    public override void Enter(StateContext context)
    {
        base.Enter(context);
        SetMenuPanel(context.manager.elementsPanel);
        tweener      = pageMap.body.GetComponentInChildren <UITweener>();
        tweenerTrans = tweener.transform;
        tweenerTrans.localPosition = Vector3.zero;
        playset = context.playset;
        var title = pageMap.AddLabel(pageMap.head, context.manager.prefabs.styledLabel);

        title.text        = playset.name;
        title.effectStyle = UILabel.Effect.Outline;
        title.color       = Color.red;
        title.fontSize    = 26;
        var grid = pageMap.body.GetComponentInChildren <UIGrid>();

        grid.cellWidth = Screen.width;
        subPages       = new List <PlaysetElementsSubPage>(grid.GetComponentsInChildren <PlaysetElementsSubPage>());
        while (subPages.Count < 4)
        {
            subPages.Add(
                NGUITools.AddChild(grid.gameObject, context.manager.prefabs.elementsSubPage).GetComponent <PlaysetElementsSubPage>());
        }
        grid.Reposition();
        SetUpButtons();
        SetUpContents();
    }
        public void DeletePlayset(Playset playset)
        {
            using (SqliteConnection connection = new SqliteConnection($"Data Source={connectionPath}"))
            {
                connection.Open();

                SqliteTransaction transaction = connection.BeginTransaction();

                try
                {
                    SqliteCommand deleteChildrenCommand = connection.CreateCommand();
                    deleteChildrenCommand.CommandText = $"DELETE FROM playsets_mods WHERE playsetId = @playsetID;";
                    deleteChildrenCommand.Parameters.AddWithValue("@playsetID", playset.UUID);
                    deleteChildrenCommand.Prepare();

                    deleteChildrenCommand.ExecuteNonQuery();

                    SqliteCommand deleteParentCommand = connection.CreateCommand();
                    deleteParentCommand.CommandText = $"DELETE FROM playsets WHERE id = @playsetID;";
                    deleteParentCommand.Parameters.AddWithValue("@playsetID", playset.UUID);
                    deleteParentCommand.Prepare();

                    deleteParentCommand.ExecuteNonQuery();

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Exception: " + e.Message + "\r\nRolling Back!");
                    transaction.Rollback();
                }
            }
        }
        public void ImportPlayset()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter          = "Stellaris Playset Database|*.sqlite";
            openFileDialog.CheckFileExists = true;
            bool?  result = openFileDialog.ShowDialog();
            string path;

            if (result == true)
            {
                path = openFileDialog.FileName;
            }
            else
            {
                return;
            }

            TextInputDialog dialog = new TextInputDialog(Properties.Resources.EnterName, Properties.Resources.EnterPlaysetNameQuestion, openFileDialog.SafeFileName.Replace(".sqlite", ""));
            string          playsetName;

            if (dialog.ShowDialog() == true)
            {
                playsetName = dialog.ResultText;
            }
            else
            {
                return;
            }

            using (SqliteConnection connection = new SqliteConnection($"Data Source={path}"))
            {
                connection.Open();

                List <ImportMod> toImport = ToImport(connection);
                AttachLauncherDB(connection);
                List <ImportMod> missing = GetMissingMods(connection, toImport);
                if (missing == null)
                {
                    return;
                }
                if (missing.Count > 0)
                {
                    MissingModsMessageBox messageBox = new MissingModsMessageBox(Properties.Resources.MissingMods, missing);
                    if (messageBox.ShowDialog() == true)
                    {
                        return;
                    }
                    else
                    {
                        //Closed some other way. Eh whatever.
                        return;
                    }
                }

                Playset newPlayset = createNewPlaysetOnConnection(playsetName, connection);
                CloneDataFromImportDB(connection, newPlayset);
            }
        }
        private void CloneDataFromImportDB(SqliteConnection connection, Playset playset)
        {
            SqliteTransaction transaction = connection.BeginTransaction();
            string            insertBase  = "INSERT INTO LAUNCHERDATA.playsets_mods(playsetID, modID, position, enabled) SELECT @playsetID, LAUNCHERDATA.mods.id, main.playset_mods.position, main.playset_mods.active FROM main.playset_mods INNER JOIN LAUNCHERDATA.mods";

            try
            {
                SqliteCommand steamCopyCommand = connection.CreateCommand();
                steamCopyCommand.CommandText = insertBase + " ON main.playset_mods.steamID = LAUNCHERDATA.mods.steamId WHERE main.playset_mods.steamID IS NOT NULL AND main.playset_mods.pdxID IS NULL;";
                steamCopyCommand.Parameters.AddWithValue("@playsetID", playset.UUID);
                steamCopyCommand.Prepare();

                int res = steamCopyCommand.ExecuteNonQuery();
                Debug.WriteLine("Inserted " + res + " steam only rows.");

                SqliteCommand pdxCopyCommand = connection.CreateCommand();
                pdxCopyCommand.CommandText = insertBase + " ON main.playset_mods.pdxID = LAUNCHERDATA.mods.pdxId WHERE main.playset_mods.pdxID IS NOT NULL AND main.playset_mods.steamID IS NULL;";
                pdxCopyCommand.Parameters.AddWithValue("@playsetID", playset.UUID);
                pdxCopyCommand.Prepare();

                res = pdxCopyCommand.ExecuteNonQuery();
                Debug.WriteLine("Inserted " + res + " paradox only rows.");

                SqliteCommand bothCopyCommand = connection.CreateCommand();
                bothCopyCommand.CommandText = insertBase + " ON main.playset_mods.steamID = LAUNCHERDATA.mods.steamId WHERE main.playset_mods.pdxID IS NOT NULL AND main.playset_mods.steamID IS NOT NULL AND main.playset_mods.pdxID = LAUNCHERDATA.mods.pdxId;";
                bothCopyCommand.Parameters.AddWithValue("@playsetID", playset.UUID);
                bothCopyCommand.Prepare();

                res = bothCopyCommand.ExecuteNonQuery();
                Debug.WriteLine("Inserted " + res + " combined rows.");

                SqliteCommand localCopyCommand = connection.CreateCommand();
                localCopyCommand.CommandText = insertBase + " ON main.playset_mods.modname = LAUNCHERDATA.mods.displayName WHERE main.playset_mods.pdxID IS NULL AND main.playset_mods.steamID IS NULL;";
                localCopyCommand.Parameters.AddWithValue("@playsetID", playset.UUID);
                localCopyCommand.Prepare();

                res = localCopyCommand.ExecuteNonQuery();
                Debug.WriteLine("Inserted " + res + " local only rows.");

                transaction.Commit();
            }
            catch (Exception e)
            {
                Debug.WriteLine("Exception: " + e.Message + "\r\nRolling Back!");
                transaction.Rollback();
            }
        }
Exemple #8
0
    public void LoadAllPlaysets()
    {
        //get list of all play-sets
        Debug.Log("Loading playsets...");
        var playsetText = (TextAsset)Resources.Load("playsets");
        var playsetData = JsonMapper.ToObject(playsetText.text);

        for (int i = 0; i < playsetData["playsets"].Count; i++)
        {
            var playsetName = playsetData["playsets"][i].ToString();
            var playset     = new Playset();
            playset.name = playsetName;
            var infoText = (TextAsset)Resources.Load(playsetName + "/" + playsetName + " Info");
            playset.info = JsonMapper.ToObject <PlaysetInfo>(infoText.text);
            var elementText = (TextAsset)Resources.Load(playsetName + "/" + playsetName + " Elements");
            playset.elements = new ElementParser().ParseElements(elementText.text);
            //TODO: images
            playsets.Add(playset);
            Debug.Log("Loading... " + playsets.IndexOf(playset) + ": " + playset.name);
        }
    }
    private void ChangePlayset(int screenTween)
    {
        var pageBody  = pageMap.body.gameObject;
        var tweener   = pageBody.GetComponentInChildren <UITweener>();
        var playsets  = initialContext.manager.Playsets;
        var viewIndex = playsets.IndexOf(initialContext.playset);
        var newPs     = Mathf.Clamp(screenTween + viewIndex, 0, playsets.Count - 1);

        queuedPlayset = playsets[newPs];
        //Debug.Log("Queue up "+ queuedPlayset + ", index " + newPs);
        screenTween        = queuedPlayset == initialContext.playset ? 0 : screenTween;
        tweener.onFinished = (screenTween == 0) ?
                             new List <EventDelegate>() : new List <EventDelegate>()
        {
            new EventDelegate(NewState)
        };
        var tweenerPos = tweener.transform.localPosition;
        var dest       = new Vector3(tweenerPos.x - screenTween * Screen.width, tweenerPos.y, tweenerPos.z);

        //Debug.Log("Move " + screenTween + ": "+ screenTween*Screen.width + ", from " + tweenerPos.x + "to "+ dest.x);
        TweenPosition.Begin(tweener.gameObject, 0.5f, dest);
    }
        private void CloneDataToExportDB(SqliteConnection connection, Playset playset)
        {
            SqliteTransaction transaction = connection.BeginTransaction();

            try
            {
                AttachLauncherDB(connection);

                SqliteCommand copyCommand = connection.CreateCommand();
                copyCommand.CommandText = "INSERT INTO main.playset_mods(position, modname, steamID, pdxID, active) SELECT LAUNCHERDATA.playsets_mods.position, LAUNCHERDATA.mods.displayName, LAUNCHERDATA.mods.steamId, LAUNCHERDATA.mods.pdxId, LAUNCHERDATA.playsets_mods.enabled FROM LAUNCHERDATA.playsets_mods INNER JOIN LAUNCHERDATA.mods ON LAUNCHERDATA.playsets_mods.modId = LAUNCHERDATA.mods.id WHERE LAUNCHERDATA.playsets_mods.playsetId = @playsetID ORDER BY position ASC;";
                copyCommand.Parameters.AddWithValue("@playsetID", playset.UUID);
                copyCommand.Prepare();

                int res = copyCommand.ExecuteNonQuery();

                transaction.Commit();
            }
            catch (Exception e)
            {
                Debug.WriteLine("Exception: " + e.Message + "\r\nRolling Back!");
                transaction.Rollback();
            }
        }
        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.");
        }
Exemple #12
0
 void SetPlayset(int playsetNumber)
 {
     currentPlaysetNumber = playsetNumber;
     currentPlayset = Playset.Playsets[playsetNumber];
     Array.Clear(playerDetailPin, 0, playerDetailPin.Length);
     Array.Clear(playerRelationshipPin, 0, playerRelationshipPin.Length);
 }
Exemple #13
0
 public StateContext(Playset playset)
 {
     manager      = StateManager.Instance;
     this.playset = playset;
 }
Exemple #14
0
 public void ClonePlayset(string newName, Playset from)
 {
     DatabaseFunctions.Singleton.ClonePlaysetToNew(newName, from);
     ReloadPlaysets();
 }