Пример #1
0
        public static LevelConfig CreateDefaultLevel(int width, int height)
        {
            string defaultCategory  = GameConfig.GetAllGridItemCategories().First();
            var    defaultMatchRule = GameConfig.AllMatchRules.First(rule => rule.Category == defaultCategory && rule.IsDefault);

            var config = new LevelConfig
            {
                width          = width,
                height         = height,
                layout         = new GridNodeLayout[width * height],
                category       = defaultCategory,
                excludeItemIds = new string[] {},
                matchRules     = defaultMatchRule.ID,
                goalType       = LevelGoalType.Points,
                goalItemId     = null,
                goal1          = 3000,
                goal2          = 7000,
                goal3          = 10000,
                challengeType  = LevelChallengeType.Moves,
                challengeValue = 10
            };

            var defaultGridItem = GameConfig.GetDefaultLayoutGridItem(config.category);
            var openNode        = GameConfig.AllGridNodes.First(node => node.IsOpen);

            for (int y = 0; y < config.height; y++)
            {
                for (int x = 0; x < config.width; x++)
                {
                    config.SetNodeLayout(x, y, new GridNodeLayout()
                    {
                        nodeId = openNode.ID, itemId = defaultGridItem.ID
                    });
                }
            }

            return(config);
        }
Пример #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);
        }