public static void ResizeLevel(int width, int height, ref LevelConfig config) { var resizedLayout = new GridNodeLayout[width * height]; var defaultGridItem = GameConfig.GetDefaultLayoutGridItem(config.category); var openNode = GameConfig.AllGridNodes.First(node => node.IsOpen); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (config.IsInBounds(x, y)) { resizedLayout[GetLinearIndex(x, y, width)] = config.GetNodeLayout(x, y); } else { resizedLayout[GetLinearIndex(x, y, width)] = new GridNodeLayout() { nodeId = openNode.ID, itemId = defaultGridItem.ID } }; } } config.width = width; config.height = height; config.layout = resizedLayout; }
private void EditMode_HandleInput() { if (Input.GetKeyDown(KeyCode.Mouse0)) { if (_editModeItemLayer) { // tap a grid item to cycle its type var gridItem = UserInput.PickObject <GridItemView>(Input.mousePosition); if (gridItem != null) { var selectedItemConfig = gridItem.GridItemConfig; // HACK: this only works because we set the MatchIndex values to sequential integers for each Category int nextItemIndex = selectedItemConfig.MatchIndex + 1; var nextItem = GameConfig.AllGridItems.FirstOrDefault(item => item.MatchIndex == nextItemIndex && item.Category == selectedItemConfig.Category); if (nextItem.ID == null) { nextItem = GameConfig.GetDefaultLayoutGridItem(selectedItemConfig.Category); // loop around } gridItem.EditMode_SetId(nextItem.ID); } } else { // tap a grid node to cycle its type var gridNode = UserInput.PickObject <GridNodeView>(Input.mousePosition); if (gridNode != null) { // HACK: this only works because we only have 2 nodes: Open and Closed var selectedNodeIsOpen = gridNode.GridNodeConfig.IsOpen; var nextNode = GameConfig.AllGridNodes.First(node => node.IsOpen != selectedNodeIsOpen); gridNode.EditMode_SetId(nextNode.ID); // sync the item var gridItem = TryGetGridItem(gridNode.Index); if (gridItem != null) { if (nextNode.IsOpen) { gridItem.EditMode_SetId(GameConfig.GetDefaultLayoutGridItem(_editModeTextCategory.text).ID); } else { gridItem.EditMode_SetId(null); } } } } } }
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); }
public LevelState(int levelIndex, LevelConfig config) { LevelIndex = levelIndex; Config = config; Grid = null; var includedItems = GameConfig.GetAllGridItemsInCategory(config.category, config.excludeItemIds); GridItemDrops = new GridItemDropDistribution(config.category, includedItems); if (config.width > 0 && config.height > 0) { var defaultGridItem = GameConfig.GetDefaultLayoutGridItem(config.category); // initialize the grid Grid = new GridNodeState[config.width, config.height]; for (int y = 0; y < config.height; y++) { for (int x = 0; x < config.width; x++) { var layout = config.GetNodeLayout(x, y); string itemId = null; if (!string.IsNullOrEmpty(layout.itemId)) { if (layout.itemId != defaultGridItem.ID) { itemId = layout.itemId; } else { itemId = GridItemDrops.Next(); } } Grid[x, y] = new GridNodeState(x, y, layout.nodeId, itemId); } } } }
public void OnClick_EditMode_NextCategory() { var allCategories = GameConfig.GetAllGridItemCategories().ToArray(); for (int i = 0; i < allCategories.Length; i++) { if (allCategories[i] == _editModeTextCategory.text) { int index = i + 1; if (index >= allCategories.Length) { index = 0; } string nextCategory = allCategories[index]; _editModeTextCategory.text = nextCategory; // sync max item types _editModeInputMaxItemTypes.text = "0"; // sync match rules _editModeTextMatchRules.text = GameConfig.AllMatchRules.First(rule => rule.Category == nextCategory).ID; // sync items var defaultGridItem = GameConfig.GetDefaultLayoutGridItem(nextCategory); foreach (var gridItem in _gridItemInstances) { if (!gridItem.IsEmpty) { gridItem.EditMode_SetId(defaultGridItem.ID); } } return; } } }