public void LoadLevel(string jsonText) { var levelData = JsonUtility.FromJson <LevelData>(jsonText); var placer = new PlaceBubbleAction(); randoms = new List <RandomBubbleDefinition>(levelData.Randoms ?? new RandomBubbleDefinition[0]); GlobalState.EventService.Dispatch(new RandomBubblesChangedEvent()); foreach (var bubble in levelData.Bubbles) { state.BubbleType = bubble.Type; placer.Perform(this, bubble.X, bubble.Y); bubbleFactory.ApplyEditorModifiers(views[BubbleData.GetKey(bubble.X, bubble.Y)], bubble); models[BubbleData.GetKey(bubble.X, bubble.Y)].modifiers = bubble.modifiers; } LevelProperties.FromLevelData(levelData); LevelProperties.StarValues = ScoreUtil.ComputeStarsForLevel(levelData, BubbleFactory); LevelProperties.NotifyListeners(); queue.CopyFrom(levelData.Queue); queue.ShotCount = levelData.ShotCount; queue.NotifyListeners(); Background = levelData.Background; GlobalState.EventService.Dispatch(new LevelModifiedEvent()); GlobalState.EventService.Dispatch(new LevelEditorLoadEvent()); }
private void RemoveRandomFromBoard(int removedIndex) { var deleter = new DeleteBubbleAction(); var placer = new PlaceBubbleAction(); var allRandomBubbles = GetAllRandomBubbles(); manipulator.PushState(); foreach (var bubble in allRandomBubbles) { var modifier = bubble.modifiers.First(m => m.type == BubbleModifierType.Random); var modifierIndex = int.Parse(modifier.data); if (modifierIndex == removedIndex) { // Delete randoms that were part of this group deleter.Perform(manipulator, bubble.X, bubble.Y); } else if (modifierIndex > removedIndex) { // Shift higher random groups down to fill the gap modifier.data = (modifierIndex - 1).ToString(); manipulator.SetBubbleType(bubble.Type); placer.Perform(manipulator, bubble.X, bubble.Y); } } manipulator.PopState(); }
private void ApplyTransformation(LevelManipulator manipulator, BubbleTransformation transformation) { var placer = new PlaceBubbleAction(); manipulator.PushState(); foreach (var bubble in savedState) { if (manipulator.Models.ContainsKey(bubble.Key)) { var replacement = transformation(bubble); manipulator.Models[replacement.Key] = replacement; manipulator.SetBubbleType(replacement.Type); placer.Perform(manipulator, replacement.X, replacement.Y); } } manipulator.PopState(); }