public void ReloadStudySetLibrary()
    {
        string libSaveKey = SaveKeys.StudySetLibrary(SettingsManager.Instance.CurrForeignCode);

        //// QQQ if we can't find the correct key, use the OLD one. Should just be for ONE push to my phone.
        //if (SettingsManager.Instance.CurrForeignCode=="da" && !SaveStorage.HasKey(libSaveKey)) {
        //    if (SaveStorage.HasKey("StudySetLibrary")) {
        //        libSaveKey = "StudySetLibrary";
        //    }
        //}

        // NO save data?! Ok, default to Quizlet hardcoded ones! :)
        if (!SaveStorage.HasKey(libSaveKey))
        {
            //ReplaceAllStudySetsWithPremadeHardcodedOnes();
            library = new StudySetLibrary();
        }
        // Otherwise, YES load what's been saved!
        else
        {
            string jsonString = SaveStorage.GetString(libSaveKey);
            library = JsonUtility.FromJson <StudySetLibrary>(jsonString);
            // Convert the unpacked term list to our efficient dictionary.
            library.RemakeTermsDictionaryFromList();

            // Reaffiliate all terms with their sets.
            foreach (StudySet set in library.GetMainAndBenchedSetsList())
            {
                set.SetMyLibraryAndGiveMyTermsRefToMe(library);
            }
        }

        // Hardcoded. Set some properties manually.
        //library.setToughies.isRemixSet = true;
        //library.setSourdough.isRemixSet = true;
        //library.setAced.canIncludeMeInRemixes = false;
        //library.setInQueue.canIncludeMeInRemixes = false;
        //library.setShelved.canIncludeMeInRemixes = false;
        //library.setToValidate.canIncludeMeInRemixes = false;
        //library.setWantRecording.canIncludeMeInRemixes = false;
        //foreach (StudySet set in library.sets) {
        //    set.canIncludeMeInRemixes = true;
        //}

        // DEBUG. Print any terms that don't belong to the set they're in.
        foreach (StudySet set in library.sets)
        {
            for (int i = set.allTermGs.Count - 1; i >= 0; --i)
            {
                string termG = set.allTermGs[i];
                Term   term  = library.GetTerm(termG);
                if (term.mySet != set)
                {
                    AppDebugLog.LogError("MISMATCH BETWEEN SETS: " + set.name + ", " + term.MySetName() + ",   " + term.native);
                    set.RemoveTerm(termG); // Remove it from this set! ONLY trust the Term's set.
                }
            }
        }
    }
 // Initialize
 public StudySet(StudySetLibrary myLibrary, string name, SetTypes setType)
 {
     this.myLibrary             = myLibrary;
     this.name                  = name;
     this.isRemixSet            = setType == SetTypes.Remix;
     this.canIncludeMeInRemixes = setType == SetTypes.Regular; // only regular sets can go into remixes.
     this.allTermGs             = new List <string>();
 }
    //public StudySet(StudySetLibrary myLibrary, string name, bool isRemixSet, string allTermsStr) {
    //    this.myLibrary = myLibrary;
    //    this.name = name;
    //    this.isRemixSet = isRemixSet;
    //    string[] termStrings = allTermsStr.Split('\n');

    //    this.allTermGs = new List<string>();
    //    foreach (string str in termStrings) {
    //        try {
    //            int splitIndex;
    //            if (str.Contains(" — ")) splitIndex = str.IndexOf(" — "); // use double-sized hyphen, if that's how it's (optionally) formatted.
    //            else splitIndex = str.IndexOf(" - "); // otherwise, split by the regular hyphen.
    //            string native = str.Substring(splitIndex + 3);
    //            string foreign = str.Substring(0, splitIndex);
    //            string phonetic = "";
    //            // pull out the phonetic pronunciation
    //            int lbIndex = foreign.LastIndexOf('['); // left bracket index
    //            int rbIndex = foreign.LastIndexOf(']'); // right bracket index
    //            if (rbIndex == foreign.Length - 1) { // if this one ENDS in a phonetic explanation...
    //                phonetic = foreign.Substring(lbIndex + 1);
    //                phonetic = phonetic.Substring(0, phonetic.Length - 1); // get rid of that last ] char.
    //                foreign = foreign.Substring(0, lbIndex - 1);
    //            }
    //            //int splitIndexA = str.IndexOf(" — ");
    //            //int splitIndexB = str.LastIndexOf(" — ");
    //            //string native = str.Substring(splitIndex + 3);
    //            //string foreign = str.Substring(0, splitIndex);
    //            //string phonetic = "";
    //            //// pull out the phonetic pronunciation
    //            //int lbIndex = foreign.LastIndexOf('['); // left bracket index
    //            //int rbIndex = foreign.LastIndexOf(']'); // right bracket index
    //            //if (rbIndex == foreign.Length - 1) { // if this one ENDS in a phonetic explanation...
    //            //    phonetic = foreign.Substring(lbIndex + 1);
    //            //    phonetic = phonetic.Substring(0, phonetic.Length - 1); // get rid of that last ] char.
    //            //    foreign = foreign.Substring(0, lbIndex - 1);
    //            //}
    //            myLibrary.AddNewTerm(new Term(native, foreign, phonetic), this);
    //        }
    //        catch {
    //            AppDebugLog.LogError("Issue with imported term string: " + str);
    //        }
    //    }
    //    SetMyLibraryAndGiveMyTermsRefToMe(myLibrary);
    //}

    // Doers
    public void SetMyLibraryAndGiveMyTermsRefToMe(StudySetLibrary library)
    {
        this.myLibrary = library;
        foreach (string g in allTermGs)
        {
            myLibrary.GetTerm(g).mySet = this;                             // go through the list so they all know they belong to me.
        }
    }
    // ----------------------------------------------------------------
    //  DEBUG
    // ----------------------------------------------------------------
    public void ReplaceAllStudySetsWithPremadeHardcodedOnes()
    {
        library = new StudySetLibrary();

        // Pull what I need from this text file.
        TextAsset textAsset = Resources.Load <TextAsset>("Data/AllSetsBackup");

        string[] allLines         = textAsset.text.Split('\n');
        bool     wasPrevLineEmpty = true; // so we know if we've reached the name of a new StudySet, which always comes after a blank line.

        StudySet currSet = null;

        for (int i = 0; i < allLines.Length; i++)
        {
            string line = allLines[i];
            if (string.IsNullOrWhiteSpace(line))   // Skip blank lines.
            {
                wasPrevLineEmpty = true;
                continue;
            }
            if (wasPrevLineEmpty)   // We made it to a new set! Set the name, and move on to the next line.
            {
                string setName = line;
                switch (setName)
                {
                case "ACED": currSet = library.setAced; break;

                case "IN QUEUE": currSet = library.setInQueue; break;

                case "SHELVED": currSet = library.setShelved; break;

                case "TO VALIDATE": currSet = library.setToValidate; break;

                case "WANT RECORDING": currSet = library.setWantRecording; break;

                default:
                    currSet = new StudySet(library, line, SetTypes.Regular);
                    library.sets.Add(currSet);     // of course, add regular sets to the library right away.
                    break;
                }
                wasPrevLineEmpty = false;
                continue;
            }
            AddTermFromExportedString(currSet, line);
            wasPrevLineEmpty = false;
        }

        SaveStudySetLibrary();
    }
Exemple #5
0
    public void Show(Term currTerm)
    {
        this.currTerm = currTerm;
        this.gameObject.SetActive(true);

        t_currTermName.text = currTerm.native;

        // Destroy 'em all.
        for (int i = tiles.Count - 1; i >= 0; i--)
        {
            Destroy(tiles[i].gameObject);
        }
        tiles = new List <PopupMoveTermSetTile>();

        // Make 'em all.
        StudySetLibrary library    = GameManagers.Instance.DataManager.library;
        List <StudySet> setsToShow = new List <StudySet>();

        // Add regular set list.
        foreach (StudySet set in library.sets)
        {
            setsToShow.Add(set);
        }
        // Add special sets.
        setsToShow.Add(library.setInQueue);
        setsToShow.Add(library.setAced);
        setsToShow.Add(library.setShelved);
        setsToShow.Add(library.setToValidate);
        setsToShow.Add(library.setWantRecording);

        foreach (StudySet set in setsToShow)
        {
            PopupMoveTermSetTile newView = Instantiate(ResourcesHandler.Instance.PopupMoveTermSetTile).GetComponent <PopupMoveTermSetTile>();
            bool isSameSet = set == currTerm.mySet;
            newView.Initialize(this, rt_tilesContent, set, isSameSet);
            tiles.Add(newView);
        }
        const float tileHeight    = 60;
        const float tileSpacing   = 10;
        float       contentHeight = tiles.Count * (tileHeight + tileSpacing) + 200;

        rt_scrollContent.sizeDelta = new Vector2(rt_scrollContent.sizeDelta.x, contentHeight);
    }