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.
                }
            }
        }
    }
Beispiel #2
0
 public Term GetCurrTerm()
 {
     // Safety check.
     if (pileQueueG == null || pileQueueG.Count <= 0)
     {
         AppDebugLog.LogError("Oops! Trying to GetCurrTerm, but there's nothing in this StudySet's pileQueue."); return(null);
     }
     return(myLibrary.GetTerm(pileQueueG[0]));
 }
    public void UpdateAllTiles()
    {
        t_header.text = SettingsManager.Instance.CurrForeignNameFull.ToUpper();

        // First, let's update JUST the special ones.
        setTile_aced.UpdateVisuals(this, dm.library.setAced);
        setTile_inQueue.UpdateVisuals(this, dm.library.setInQueue);
        setTile_shelved.UpdateVisuals(this, dm.library.setShelved);
        setTile_toValidate.UpdateVisuals(this, dm.library.setToValidate);
        setTile_wantRecording.UpdateVisuals(this, dm.library.setWantRecording);
        setTile_toughies.UpdateVisuals();

        List <StudySet> sets = dm.library.sets;

        // Destroy any extras.
        int count = 0;

        while (tileViews.Count > sets.Count)
        {
            StudySetTileView tile = tileViews[tileViews.Count - 1];
            tileViews.Remove(tile);
            Destroy(tile.gameObject);
            if (count++ > 9999)
            {
                AppDebugLog.LogError("Oops, count got too big in while loop in UpdateTileList."); break;
            }
        }
        // Add any missing.
        count = 0;
        while (tileViews.Count < sets.Count)
        {
            StudySetTileView newTile = Instantiate(ResourcesHandler.Instance.StudySetTileView).GetComponent <StudySetTileView>();
            newTile.Initialize(this, rt_tilesContent);
            tileViews.Add(newTile);
            if (count++ > 9999)
            {
                AppDebugLog.LogError("Oops, count got too big in while loop in UpdateTileList."); break;
            }
        }

        // Now update all the existing tiles!
        for (int i = 0; i < tileViews.Count; i++)
        {
            tileViews[i].SetMySet(sets[i]);
        }

        // Update the parent content RT height!
        float contentHeight = tileViews.Count * (tileHeight + tileSpacing) + 200;

        rt_scrollContent.sizeDelta = new Vector2(rt_scrollContent.sizeDelta.x, contentHeight);
    }
Beispiel #4
0
    private void UpdateTileList()
    {
        // -- TEXTS --
        if_setName.text = currSet.name; // update header

        // -- TILES --
        List <string> termGs = currSet.allTermGs;
        // Destroy any extras.
        int count = 0;

        while (termTiles.Count > termGs.Count)
        {
            TermEditableTile tile = termTiles[termTiles.Count - 1];
            termTiles.Remove(tile);
            Destroy(tile.gameObject);
            if (count++ > 9999)
            {
                AppDebugLog.LogError("Oops, count got too big in while loop in UpdateTileList."); break;
            }
        }
        // Add any missing.
        count = 0;
        while (termTiles.Count < termGs.Count)
        {
            TermEditableTile newTile = Instantiate(ResourcesHandler.Instance.TermEditableTile).GetComponent <TermEditableTile>();
            newTile.Initialize(true, rt_tilesContent);
            termTiles.Add(newTile);
            if (count++ > 9999)
            {
                AppDebugLog.LogError("Oops, count got too big in while loop in UpdateTileList."); break;
            }
        }

        // Now update all the existing tiles!
        for (int i = 0; i < termGs.Count; i++)
        {
            Term             term = dm.library.GetTerm(termGs[i]);
            TermEditableTile tile = termTiles[i];
            if (term == null)
            {
                Debug.LogError("Whoa, can't find a term in the library for this set.");
            }

            tile.SetMyTerm(i, term);
        }
    }
    //private void AddHardcodedSetFromString(string setName, string allTermsStr) {
    //    // Make and add empty new set.
    //    StudySet newSet = new StudySet(library, setName, SetTypes.Regular);
    //    library.sets.Add(newSet);

    //    // Make all the new terms.
    //    string[] termStrings = allTermsStr.Split('\n');
    //    foreach (string str in termStrings) {
    //        AddTermFromExportedString(newSet, str);
    //    }
    //}

    private void AddTermFromExportedString(StudySet set, string str)
    {
        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);
            //}
            Term newTerm = new Term(native, foreign, phonetic);
            // Add this term to the library!
            library.AddNewTerm(newTerm, set);
        }
        catch {
            AppDebugLog.LogError("Issue with imported term string: " + str);
        }
    }
Beispiel #6
0
 public void ReplaceAllTermsAndShuffleStartNewRound(List <Term> newTerms)
 {
     if (!isRemixSet)
     {
         AppDebugLog.LogError("Whoa! Trying to ReplaceAndShuffleAllTerms on a set that OWNS its terms. This function is only meant for remix sets, which DON'T own their terms, like the Sourdough/Toughies sets.");
     }
     // Clear lists.
     allTermGs.Clear();
     pileYesG.Clear();
     pileNoG.Clear();
     pileQueueG.Clear();
     pileYesesAndNosG.Clear();
     // Replenish me.
     for (int i = 0; i < newTerms.Count; i++)
     {
         allTermGs.Add(newTerms[i].myGuid);
     }
     // Make that sweet, sweet new round.
     ShuffleAndRestartDeck();
 }
Beispiel #7
0
    public void AddTerm(string termGuid)
    {
        Term term = myLibrary.GetTerm(termGuid);

        if (allTermGs.Contains(termGuid))
        {
            AppDebugLog.LogError("Oops! Attempting to add a Term to a list it's already in. Add aborted. Term: " + term.native); return;
        }                                                                                                                                                                  // Safety check! ONLY add if it's not already in our list. No dupes.
        if (!isRemixSet)
        {
            term.mySet = this;              // ONLY set mySet if I own my terms! (So, don't do it for the Remix sets.)
        }
        allTermGs.Add(termGuid);
        // Are we in a round? Great, insert it randomly into the queue!
        if (pileQueueG.Count > 0)
        {
            int randIndex = UnityEngine.Random.Range(0, pileQueueG.Count - 1);
            pileQueueG.Insert(randIndex, termGuid);
        }
    }
Beispiel #8
0
    }                                                       // e.g. "Danish"


    private void UpdateForeignCodeValues()
    {
        switch (currForeignCode)
        {
        case "da":
            CurrForeignNameAbbr = "Dan";
            CurrForeignNameFull = "Danish";
            break;

        case "en":
            CurrForeignNameAbbr = "Eng";
            CurrForeignNameFull = "English";
            break;

        case "fr":
            CurrForeignNameAbbr = "Fre";
            CurrForeignNameFull = "French";
            break;

        case "it":
            CurrForeignNameAbbr = "Ita";
            CurrForeignNameFull = "Italian";
            break;

        case "de":
            CurrForeignNameAbbr = "Ger";
            CurrForeignNameFull = "German";
            break;

        case "es":
            CurrForeignNameAbbr = "Spa";
            CurrForeignNameFull = "Spanish";
            break;

        default:
            CurrForeignNameAbbr = "Und";
            CurrForeignNameFull = "Undefined";
            AppDebugLog.LogError("Oops! Foreign code not supported: " + currForeignCode);
            break;
        }
    }
Beispiel #9
0
    public void RewindOneCard()
    {
        if (pileYesesAndNosG.Count == 0)
        {
            AppDebugLog.LogError("Oops, trying to rewind, but we have nothing in pileYesesAndNos list."); return;
        }
        string prevG = pileYesesAndNosG[pileYesesAndNosG.Count - 1];
        Term   prevT = myLibrary.GetTerm(prevG);

        pileQueueG.Insert(0, prevG);
        pileYesesAndNosG.Remove(prevG);
        if (pileYesG.Contains(prevG))
        {
            pileYesG.Remove(prevG);
            prevT.totalYeses--;
        }
        else
        {
            pileNoG.Remove(prevG);
            prevT.totalNos--;
        }
    }
    public void OnEndEditPastedNewTerms()
    {
        string pastedTerms = if_pastedTerms.text;

        if (string.IsNullOrWhiteSpace(pastedTerms))
        {
            return;
        }                                                       // No string? Get outta here.

        string[] termStrings = pastedTerms.Split('\n');

        string      errorStr = ""; // we'll add to this as we find issues.
        List <Term> newTerms = new List <Term>();

        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);
                }
                newTerms.Add(new Term(native, foreign, phonetic));
            }
            catch {
                AppDebugLog.LogError("Some issue with an imported term string: \"" + str + "\"");
            }
        }

        // Print any issues.
        if (!string.IsNullOrWhiteSpace(errorStr))
        {
            AppDebugLog.LogError(errorStr);
        }

        // Okay, NOW let's go ahead and add all the new terms to the StudySet!
        foreach (Term term in newTerms)
        {
            dm.library.AddNewTerm(term, currSet);
        }
        GameManagers.Instance.DataManager.SaveStudySetLibrary();


        // Clear text field
        if_pastedTerms.text = "";
        // Dispatch event!
        eventManager.OnAnySetContentsChanged();
    }
Beispiel #11
0
    IEnumerator LoadAudioClipCoroutine(string fullPath, bool doPlayImmediately)
    {
        fullPath = "file:///" + fullPath; // HACK for Mac? We can't find the audio file without this prefix, but *only* for loading, not saving.
        using (var uwr = UnityWebRequestMultimedia.GetAudioClip(fullPath, AudioType.WAV)) {
            ((DownloadHandlerAudioClip)uwr.downloadHandler).streamAudio = true;

            audioSource.clip = null; // default this to null, in case we fail.

            yield return(uwr.SendWebRequest());

            if (uwr.isNetworkError || uwr.isHttpError)
            {
                AppDebugLog.LogError(uwr.error);
                yield break;
            }

            DownloadHandlerAudioClip dlHandler = (DownloadHandlerAudioClip)uwr.downloadHandler;
            yield return(dlHandler);

            if (dlHandler.isDone)
            {
                audioSource.clip = dlHandler.audioClip;

                if (audioSource.clip != null)
                {
                    WWW download = new WWW(fullPath); // HACKED, using WWW! I think DownloadHandlerAudioClip doesn't support getting the file samples. Not sure tho.
                    yield return(download);

                    bool      threeD = false;
                    bool      stream = false;
                    AudioClip clip   = download.GetAudioClip(threeD, stream, AudioType.WAV);
                    //float[] samples = new float[clip.samples * clip.channels];
                    //clip.GetData(samples, 0);
                    //for (int s = 0; s < 100; s++) Debug.Log(samples[s]);


                    //AudioClip clip = DownloadHandlerAudioClip.GetContent(uwr);
                    if (SettingsManager.Instance.DoTrimAudioClips)
                    {
                        clip = AudioEditor.GetQuietTrimmed(clip);
                    }
                    if (SettingsManager.Instance.DoNormalizeAudioClips)
                    {
                        clip = AudioEditor.GetNormalized(clip);
                    }
                    audioSource.clip = clip;
                    GameManagers.Instance.EventManager.OnClipLoadSuccess(clip);
                    if (doPlayImmediately)
                    {
                        Play();
                    }
                }
                else
                {
                    GameManagers.Instance.EventManager.OnClipLoadFail();
                    Debug.Log("Couldn't load a valid AudioClip.");
                }
            }
            else
            {
                Debug.Log("The download process is not completely finished.");
            }
        }
    }
Beispiel #12
0
    public void RefreshTermTiles()
    {
        // Update resultTerms!
        string searchStr = if_search.text.ToUpperInvariant();

        resultTerms = new List <Term>();
        if (searchStr.Length > 0)
        {
            foreach (Term term in allTerms)
            {
                if (term.native.ToUpperInvariant().Contains(searchStr) ||
                    term.foreign.ToUpperInvariant().Contains(searchStr) ||
                    term.phonetic.ToUpperInvariant().Contains(searchStr))
                {
                    resultTerms.Add(term);
                }
            }
        }

        // Update t_andMore.
        int numHiddenResults = resultTerms.Count - MaxResultsToShow;

        t_andMore.gameObject.SetActive(numHiddenResults > 0);
        if (numHiddenResults > 0)
        {
            t_andMore.text = "...and " + numHiddenResults + " more";
        }

        // Update t_numResults
        t_numResults.text = searchStr.Length == 0 ? "" : resultTerms.Count + " results";


        // Destroy any extras.
        int count = 0;

        while (termTiles.Count > resultTerms.Count)
        {
            TermEditableTile tile = termTiles[termTiles.Count - 1];
            termTiles.Remove(tile);
            Destroy(tile.gameObject);
            if (count++ > 9999)
            {
                AppDebugLog.LogError("Oops, count got too big in while loop in UpdateTileList."); break;
            }
        }
        // Add any missing.
        count = 0;
        while (termTiles.Count < resultTerms.Count && termTiles.Count < MaxResultsToShow)
        {
            TermEditableTile newTile = Instantiate(ResourcesHandler.Instance.TermEditableTile).GetComponent <TermEditableTile>();
            newTile.Initialize(false, rt_tilesContent);
            termTiles.Add(newTile);
            if (count++ > 9999)
            {
                AppDebugLog.LogError("Oops, count got too big in while loop in UpdateTileList."); break;
            }
        }

        // Now update all the tiles!
        for (int i = 0; i < resultTerms.Count && i < MaxResultsToShow; i++)
        {
            TermEditableTile tile = termTiles[i];
            tile.SetMyTerm(i, resultTerms[i]);
        }

        // Update the parent content RT height!
        const float tileHeight    = 130;
        float       tileSpacing   = rt_tilesContent.GetComponent <VerticalLayoutGroup>().spacing;
        float       contentHeight = termTiles.Count * (tileHeight + tileSpacing) + 450;

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