Exemple #1
0
    public EndgameHolder(TextAsset endgameFile)
    {
        string[][] allEndgameRows = RLUtilities.ReadSheet(endgameFile.text);
        endgames = new List <Endgame>();
        int numStats = RLConstants.STAT_NAMES.Count;

        Endgame.MinMaxStat ParseRange(int statIndex, string range)
        {
            if (string.IsNullOrEmpty(range))
            {
                return(null);
            }
            bool isValid = false;

            Endgame.MinMaxStat retval = new Endgame.MinMaxStat(statIndex);
            range = range.Replace(" ", "");
            if (range.Contains("<"))
            {
                isValid = int.TryParse(range.Substring(range.IndexOf("<") + 1), out retval.maxValue);
            }
            else if (range.Contains(">"))
            {
                isValid = int.TryParse(range.Substring(range.IndexOf(">") + 1), out retval.minValue);
            }
            else if (range.Contains("-"))
            {
                isValid = int.TryParse(range.Substring(0, range.IndexOf("-")), out retval.minValue) &&
                          int.TryParse(range.Substring(range.IndexOf("-") + 1), out retval.maxValue);
                retval.minInclusive = retval.maxInclusive = true;
            }
            return(isValid ? retval : null);
        }

        char[] upSplitChars = new char[] { ' ', '<', '>' };

        for (int r = 1; r < allEndgameRows.Length; r++)
        {
            Endgame curEG = new Endgame();

            for (int eg = 0; eg < allEndgameRows[r].Length; eg++)
            {
                string curField = allEndgameRows[r][eg].Trim();
                if (string.IsNullOrEmpty(curField))
                {
                    continue;
                }

                if (eg < numStats)
                {
                    // Stat requirements
                    Endgame.MinMaxStat curMinMax = ParseRange(eg, curField);
                    if (curMinMax == null)
                    {
                        continue;
                    }
                    curEG.statConditions.Add(curMinMax);
                }
                else if (eg == numStats)
                {
                    // Unlock path
                    string[] splitUP = curField.Split(RLConstants.STRING_SPLIT_AND, System.StringSplitOptions.RemoveEmptyEntries);
                    foreach (string untrimmedUP in splitUP)
                    {
                        string             up = untrimmedUP.Trim();
                        int                rangeStartIndex = up.IndexOfAny(upSplitChars);
                        string             statName        = up.Substring(0, rangeStartIndex);
                        Endgame.MinMaxStat curUP           = ParseRange(RLConstants.STAT_NAMES.IndexOf(statName), up.Substring(rangeStartIndex));
                        if (curUP != null)
                        {
                            curEG.unlockPath.Add(curUP);
                        }
                    }
                }
                else
                {
                    List <string> stringList = new List <string>(curField.Split(RLConstants.STRING_SPLIT_OR, System.StringSplitOptions.RemoveEmptyEntries));
                    switch (eg - numStats)
                    {
                    case 1:                     // Summary
                        curEG.summaries = stringList;
                        break;

                    case 2:                     // Hint
                        curEG.hints = stringList;
                        break;

                    case 3:                     // Learning outcomes
                        curEG.learning = stringList;
                        break;

                    default:                     // ???
                        break;
                    }
                }
            }

            if (curEG.statConditions.Count > 0 || curEG.unlockPath.Count > 0)
            {
                endgames.Add(curEG);
            }
        }

        GameManager.Instance.OnDecisionTaken += () => endgames.ForEach(endgame => endgame.UpdateUnlockPath());
    }
Exemple #2
0
    public DecisionHolder(TextAsset decisionsFile)
    {
        alwaysAvailable = new List <Decision>();
        unavailable     = new List <Decision>();
        decisionQueue   = new List <Decision>();
        string[][] allDecisions = RLUtilities.ReadSheet(decisionsFile.text);
        int        decisionFieldIndex = -1, fieldsPerButton = 0, fieldsBeforeButtons = 0, numResults = 0;

        for (int d = 0; d < allDecisions.Length; d++)
        {
            if (d == 0)                  // Column names
            {
                string curButtonName = string.Empty;

                for (int i = 0; i < allDecisions[d].Length; i++)
                {
                    string curField = allDecisions[d][i];
                    if (decisionFieldIndex < 0)
                    {
                        if (curField == "Decision")
                        {
                            decisionFieldIndex = i;
                        }
                        continue;
                    }
                    if (curField.StartsWith("Button:"))
                    {
                        if (!string.IsNullOrEmpty(curButtonName))
                        {
                            break;
                        }
                        curButtonName       = curField.Replace("Button:", "").Trim();
                        fieldsBeforeButtons = i;
                    }
                    else if (i >= fieldsBeforeButtons + BUTTON_INFO_FIELDS)
                    {
                        numResults++;
                    }
                }
                fieldsPerButton = BUTTON_INFO_FIELDS + numResults;
                continue;                   // That's all we want from the first row
            }

            if (allDecisions[d].Length < 1 || string.IsNullOrEmpty(allDecisions[d][decisionFieldIndex]))
            {
                continue;                                                                                                      // Invalid row. REJECTED
            }
            Decision curDec = new Decision()
            {
                decisionText = RLUtilities.ApplyBoldItalic(allDecisions[d][decisionFieldIndex]),
                decisionID   = allDecisions[d][0].Substring(0, allDecisions[d][0].IndexOf('\n')),
            };

            ImagesHolder.DecisionImages curImages = ImagesHolder.GetImages(curDec.decisionID);
            if (curImages != null)
            {
                curDec.decisionImage = curImages.decisionImage;
            }

            for (int b = 0; b < BUTTON_COUNT; b++)
            {
                int           i = fieldsBeforeButtons + (b * fieldsPerButton);          // Button info start index
                List <string> curStatEffects = new List <string>();

                for (int s = 0; s < numResults; s++)
                {
                    // Stat effects
                    string curEffect = allDecisions[d][i + BUTTON_INFO_FIELDS + s];
                    if (!string.IsNullOrEmpty(curEffect))
                    {
                        curStatEffects.Add(curEffect);
                    }
                }
                curDec.buttonResults.Add(new Decision.ButtonResult(allDecisions[d][i], allDecisions[d][i + 1], curStatEffects, curImages == null ? null : curImages.resultImages[b]));
            }

            int reqIndex      = fieldsBeforeButtons + (BUTTON_COUNT * fieldsPerButton),
                freeTurnIndex = reqIndex + 1;
            curDec.SetRequirements(allDecisions[d][reqIndex]);
            curDec.turnCost = allDecisions[d][freeTurnIndex] == "TRUE" ? 0 : 1;

            (string.IsNullOrEmpty(allDecisions[d][reqIndex]) ? alwaysAvailable : unavailable).Add(curDec);
        }

        // Set up decision queue
        decisionQueue.Clear();
        decisionQueue.InsertRange(0, alwaysAvailable);
        decisionQueue.Sort((d1, d2) => {         // Shuffle
            return(Random.value > 0.5f ? 1 : -1);
        });
        UpdateAvailableDecisions();

        GameManager.Instance.OnDecisionTaken += UpdateAvailableDecisions;
    }
Exemple #3
0
    public static void Initialize(TextAsset submissions, TextAsset mapping)
    {
        string[][] submissionStrings = RLUtilities.ReadSheet(submissions.text),
        mapStrings = RLUtilities.ReadSheet(mapping.text);

        spriteIDLookup = new Dictionary <string, Sprite>();
        decisionLookup = new Dictionary <string, DecisionImages>();

        for (int r = 1; r < mapStrings.Length; r++)
        {
            string[] mapRow       = mapStrings[r];
            string   spriteName   = mapRow[0];
            int      fileExtIndex = spriteName.LastIndexOf('.');
            if (fileExtIndex >= 0)
            {
                spriteName = spriteName.Remove(fileExtIndex);
            }
            Sprite mapSprite = Resources.Load <Sprite>(IMAGE_LOCATION + spriteName);
            if (mapSprite)
            {
                spriteIDLookup[mapRow[1]] = mapSprite;
            }
        }

        // Process the submissions

        for (int r = 1; r < submissionStrings.Length; r++)
        {
            string[] subRow = submissionStrings[r];
            if (string.IsNullOrEmpty(subRow[0]))
            {
                continue;
            }

            DecisionImages curDI = new DecisionImages()
            {
                decisionID   = subRow[1],
                resultImages = new List <Sprite> [Mathf.CeilToInt((subRow.Length - 3) / (float)RLConstants.STAT_NAMES.Count)]
            };
            for (int ri = 0; ri < curDI.resultImages.Length; ri++)
            {
                curDI.resultImages[ri] = new List <Sprite>();
            }

            for (int i = 2; i < subRow.Length; i++)
            {
                if (string.IsNullOrEmpty(subRow[i]))
                {
                    continue;
                }
                try {
                    subRow[i] = subRow[i].Remove(0, subRow[i].IndexOf(REMOVE_URL_UPTO) + REMOVE_URL_UPTO.Length);                     // URL into sprite ID
                } catch (System.Exception) {
                    Debug.LogError(subRow[i]);
                }
                Sprite curSprite = GetSprite(subRow[i]);
                if (!curSprite)
                {
                    continue;
                }
                if (i == 2)
                {
                    curDI.decisionImage = curSprite;
                }
                else
                {
                    curDI.resultImages[(i - 3) / RLConstants.STAT_NAMES.Count].Add(curSprite);
                }
            }

            decisionLookup[curDI.decisionID] = curDI;
        }
    }