Esempio n. 1
0
        public void OnClick_EditMode_Resize()
        {
            if (!int.TryParse(_editModeInputWidth.text, out var width))
            {
                return;
            }

            if (!int.TryParse(_editModeInputHeight.text, out var height))
            {
                return;
            }

            LevelConfig.ResizeLevel(width, height, ref _levelConfig);
            LevelConfig.ExportLevelFile(_levelIndex, _levelConfig);

            // reload the level
            Level.ExecuteCommand(new Level.LoadLevelCommand(_levelIndex));
        }
Esempio n. 2
0
        public void OnClick_EditMode_Save()
        {
            if (!GameConfig.AllMatchRules.Any(rule => rule.ID == _editModeTextMatchRules.text))
            {
                MessagePopup.ShowMessage($"Invalid Match Rules: '{_editModeTextMatchRules.text}'");
                return;
            }

            var allCategories = GameConfig.GetAllGridItemCategories();

            if (!allCategories.Contains(_editModeTextCategory.text))
            {
                MessagePopup.ShowMessage($"Invalid Category: '{_editModeTextCategory.text}'");
                return;
            }

            if (!int.TryParse(_editModeInputMaxItemTypes.text, out var maxItemTypes))
            {
                MessagePopup.ShowMessage($"Invalid Max Item Types: '{_editModeInputMaxItemTypes.text}'");
                return;
            }

            if (!Enum.TryParse(_editModeTextGoalType.text, out LevelGoalType goalType))
            {
                MessagePopup.ShowMessage($"Invalid Goal Type: '{_editModeTextGoalType.text}'");
                return;
            }

            string goalItemId = null;

            if (!string.IsNullOrEmpty(_editModeInputGoalItem.text))
            {
                goalItemId = _editModeInputGoalItem.text;
                if (GameConfig.GetGridItem(goalItemId).ID == null)
                {
                    MessagePopup.ShowMessage($"Invalid Goal Item ID: '{_editModeInputGoalItem.text}'");
                    return;
                }
            }

            if (!int.TryParse(_editModeInputGoal1.text, out var goal1))
            {
                MessagePopup.ShowMessage($"Invalid Goal #1: '{_editModeInputGoal1.text}'");
                return;
            }

            if (!int.TryParse(_editModeInputGoal2.text, out var goal2))
            {
                MessagePopup.ShowMessage($"Invalid Goal #2: '{_editModeInputGoal2.text}'");
                return;
            }

            if (!int.TryParse(_editModeInputGoal3.text, out var goal3))
            {
                MessagePopup.ShowMessage($"Invalid Goal #3: '{_editModeInputGoal3.text}'");
                return;
            }

            if (!Enum.TryParse(_editModeTextChallengeType.text, out LevelChallengeType challengeType))
            {
                MessagePopup.ShowMessage($"Invalid Challenge Type: '{_editModeTextChallengeType.text}'");
                return;
            }

            if (!int.TryParse(_editModeInputChallengeValue.text, out var moves) || moves < 1)
            {
                MessagePopup.ShowMessage($"Invalid Max Moves: '{_editModeInputChallengeValue.text}'");
                return;
            }

            _levelConfig.category       = _editModeTextCategory.text;
            _levelConfig.excludeItemIds = EditMode_ConvertMaxItemTypesToExcludedItemIds(_editModeTextCategory.text, Mathf.Max(0, maxItemTypes));
            _levelConfig.matchRules     = _editModeTextMatchRules.text;
            _levelConfig.goalType       = goalType;
            _levelConfig.goalItemId     = goalItemId;
            _levelConfig.goal1          = Mathf.Max(0, goal1);
            _levelConfig.goal2          = Mathf.Max(0, goal2);
            _levelConfig.goal3          = Mathf.Max(0, goal3);
            _levelConfig.challengeType  = challengeType;
            _levelConfig.challengeValue = moves;

            foreach (var gridNode in _gridNodeInstances)
            {
                var gridItem   = TryGetGridItem(gridNode.Index);
                var nodeLayout = _levelConfig.GetNodeLayout(gridNode.Index);
                nodeLayout.nodeId = gridNode.ID;
                nodeLayout.itemId = (gridItem != null && gridNode.GridNodeConfig.IsOpen) ? gridItem.ID : null;
                _levelConfig.SetNodeLayout(gridNode.Index, nodeLayout);
            }

            LevelConfig.ExportLevelFile(_levelIndex, _levelConfig);
        }