private void AddMazeToMazeList()
    {
        MazeLevelNamesData levelNamesData = new MazeLevelNamesData(_mazeName).AddLevelName(_mazeName);

        JsonMazeLevelListFileWriter fileWriter = new JsonMazeLevelListFileWriter();

        fileWriter.SerialiseData(levelNamesData);
    }
Пример #2
0
    private void ToggleLevelPlayability(string levelName, List <string> arguments)
    {
        if (arguments.Count < 1)
        {
            string message = "The command '<color=" + ConsoleConfiguration.HighlightColour + ">configure maze playable</color>' needs an additional argument saying 'true' or 'false'.";
            throw new NotEnoughArgumentsConsoleException(message);
        }

        MazeLevelNamesData levelNamesData = new JsonMazeLevelListFileReader().ReadData <MazeLevelNamesData>();

        string sanatisedLevelName = levelName.ToLower().Replace(" ", "-");
        int    levelNameIndex     = levelNamesData.LevelNames.FindIndex(l => l.LevelName == sanatisedLevelName);

        if (levelNameIndex == -1)
        {
            string message = $"Could not find the maze level '<color={sanatisedLevelName}>info maze</color>' in the list with known maze levels.";
            throw new MazeLevelNameNotFoundConsoleException(message);
        }

        MazeLevelNameData levelNameData = levelNamesData.LevelNames.ElementAt(levelNameIndex);

        if (levelNameData == null)
        {
            string message = $"Could not find the maze level '<color={sanatisedLevelName}>info maze</color>' in the list with known maze levels.";
            throw new MazeLevelNameNotFoundConsoleException(message);
        }

        switch (arguments[0])
        {
        case "true":
            levelNameData.IsPlayable = true;
            break;

        case "false":
            levelNameData.IsPlayable = false;
            break;

        default:
            string message = $"The command '<color={ConsoleConfiguration.HighlightColour}>configure maze {levelName} playable</color>' needs a last argument saying 'true' or 'false'.";
            throw new UnknownArgumentConsoleException(message);
        }

        levelNamesData.LevelNames[levelNameIndex] = levelNameData;
        JsonMazeLevelListFileWriter jsonMazeLevelListFileWriter = new JsonMazeLevelListFileWriter();

        jsonMazeLevelListFileWriter.SerialiseData(levelNamesData);
    }
Пример #3
0
    //Save changes to which levels are playable to the levels.json file
    public void SaveChanges()
    {
        JsonMazeLevelListFileWriter jsonMazeLevelListFileWriter = new JsonMazeLevelListFileWriter();
        MazeLevelNamesData          levelNamesData = new MazeLevelNamesData();

        foreach (KeyValuePair <PlayableMazeLevelNameToggle, MazeLevelNameData> mazeLevelNameToggleData in LevelNameToggleData)
        {
            MazeLevelNameData levelNameData = new MazeLevelNameData()
                                              .WithName(mazeLevelNameToggleData.Value.LevelName)
                                              .WithPlayability(mazeLevelNameToggleData.Key.Toggle.isOn);

            levelNamesData.LevelNames.Add(levelNameData);
        }

        jsonMazeLevelListFileWriter.SerialiseData(levelNamesData);

        Logger.Log("Playable level selection changes were saved.");

        ClosePanel();
    }