Пример #1
0
        private RankingEntry MapInfoToEntry(JamEntry jamEntry, EntryRatingsInfo?ratingsInfo, RatingCriteriaOverview criteria)
        {
            // building the list of entries
            var ratings           = criteria.Criteria.Select(criterion => criterion.CreateRating()).ToList();
            var ratingsDictionary = ratings.ToDictionary(rating => rating.Id, StringComparer.OrdinalIgnoreCase);

            // applying the rating values stored for the entry
            var infoRatings = ratingsInfo?.Ratings ?? Enumerable.Empty <RatingInfo>();

            foreach (var ratingsInfoEntry in infoRatings)
            {
                if (!ratingsDictionary.TryGetValue(ratingsInfoEntry.Id, out var rating))
                {
                    continue;
                }

                rating.Value = ratingsInfoEntry.Value;
            }

            // building and returning the ranking entry
            return(new RankingEntry
            {
                JamEntry = jamEntry,
                Ratings = ratings,
                Comment = ratingsInfo?.Comment ?? string.Empty,
            });
        }
Пример #2
0
    /// <summary>
    /// Parses a string for contents of a valid JamEntry. Will return null on failure.
    /// </summary>
    /// <param name="fullString">A string of a JamEntry.
    /// Line[1] = Version of Editor Tool.
    /// Line[3] = Entry's team name.
    /// Line[5] = Entry name.
    /// Line[7] = Entry Identifier.
    /// Line[9] = The names of the scenes separated by commas.
    /// This code exists in CycleJam.cs & CycleManager.cs, one being a runtime script, the other being an editor script. Be aware of this when editing.</param>
    /// <returns></returns>
    JamEntry ParseJamEntry(string fullString)
    {
        try
        {
            JamEntry entry = new JamEntry();

            char newLineSplit = '\n';
            char commaSplit   = ',';

            string[] segments = fullString.Split(newLineSplit);

            entry.versionNum = segments[1];
            entry.teamName   = segments[3];
            entry.entryName  = segments[5];
            entry.identifier = segments[7];

            string[] sceneSegments = segments[9].Split(commaSplit);

            for (int j = 0; j < sceneSegments.Length; j++)
            {
                entry.scenes.Add(sceneSegments[j]);
            }

            return(entry);
        }
        catch
        {
            Debug.LogError("CycleManager:\nImproper Asset in a Resources/Jam folder. CycleManager handled gracefully.\n");
            return(null);
        }
    }
Пример #3
0
    /// <summary>
    /// Locates all TextAsset in Resources/Jam.
    /// Uses ParseJamEntry to handle the text of each JamEntry TextAsset.
    /// Creates and returns a list of legal JamEntry objects. (Doesn't add incorrect JamEntry objects)
    /// This code is duplicated in CycleJam.cs & CycleManager.cs, one being runtime the other being editor. Any changes should be made to both.
    /// </summary>
    /// <returns></returns>
    List <JamEntry> FindJamEntries()
    {
        TextAsset[] jams = Resources.LoadAll <TextAsset>("Jam");

        List <JamEntry> jamEntries = new List <JamEntry>();

        for (int i = 0; i < jams.Length; i++)
        {
            //Parses the string and turns it into a Jam Entry object.
            JamEntry newEntry = ParseJamEntry(jams[i].text);
            if (newEntry != null)
            {
                jamEntries.Add(newEntry);
            }
        }

        return(jamEntries);
    }
Пример #4
0
    /// <summary>
    /// Loads a random JamEntry that has not been played in the current cycle.
    /// Updates the EntriesPlayed List.
    /// </summary>
    void LoadRandomEntry()
    {
        int nextLevel = -1;
        int nextEntry = -1;

        //This is for output information.
        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        //EntriesNotPlayed is reset every loop. If we still have an entries we have not played this loop
        if (entriesNotPlayed.Count > 0)
        {
            //We need to reset the time.
            timeLeft = timePerLevel;

            //Pick one of the unplayed entries at random.
            nextEntry = Random.Range(0, entriesNotPlayed.Count);

            sb.AppendLine("Changing Scene from \t[" + Application.loadedLevel + "]" + Application.loadedLevelName + "\tto\t" + entriesNotPlayed[nextEntry].scenes[0]);

            JamEntry selectedEntry = entriesNotPlayed[nextEntry];

            //Move the selected entry from the 'Not played' to the 'Played' list.
            entriesNotPlayed.RemoveAt(nextEntry);
            entriesPlayed.Add(selectedEntry);

            //Make sure we update the state otherwise it'll stay paused in the new entry.
            CycleManager.jamState = CycleState.Playing;

            //Clear any existing singletons from the previous scene out.
            ClearSingletons();

            //Load the first listed scene in the Selected Entry.
            Application.LoadLevel(selectedEntry.scenes[0]);
        }
        //This case occurs when we have no entries left unplayed this loop.
        else
        {
            //If we want to cycle forever like Groundhog day, just reset the list of unplayed entries.
            if (cycleForever)
            {
                entriesNotPlayed = FindJamEntries();

                //Note, we don't reset EntriesPlayed because that list will constantly grow in length giving a 'play path'
                //This does not support someone playing more entries than the maximum size of a list, but this is an unlikely problem.
            }
            //If we don't want to play forever, we go to the credits.
            else
            {
                //The credits scene should be the last scene. Could also load it by name.
                nextLevel = Application.levelCount - 1;
                sb.AppendLine("Changing to Credits Scene.");

                CycleManager.jamState = CycleState.End;

                //Clear any existing singletons from the previous scene out.
                ClearSingletons();

                Application.LoadLevel(nextLevel);

                //No time limit on the credits scene.
                timeLeft = float.MaxValue;

                //Don't even show the clock on the credits scene.
                enableTime = false;
            }
        }


#if UNITY_EDITOR
        //Will only print out in dev builds or in the editor. Minor computation saving in built versions.
        ConcatOutput(sb);
#else
        if (Debug.isDebugBuild)
        {
            ConcatOutput(sb);
        }
#endif
    }