using System; using System.Collections.Generic; using System.Linq; using UnityEngine; using Jukebox; using HeavenStudio.Editor.Track; using Newtonsoft.Json; using UnityEditor; using UnityEngine.Timeline; namespace HeavenStudio.Editor.Commands { // Insert / Delete Space public class MoveEntity : ICommand { private readonly List entityIDs = new(); private List newMoveBeat; private List lastMoveBeat; public MoveEntity(List originalEntities, List newBeat) { entityIDs = originalEntities.Select(c => c.guid).ToList(); newMoveBeat = newBeat; } public void Execute() { lastMoveBeat = new(); var beatmap = GameManager.instance.Beatmap; var entities = new[] { beatmap.Entities, beatmap.TempoChanges, beatmap.VolumeChanges, beatmap.SectionMarkers } .SelectMany(list => list); for (var i = 0; i < entityIDs.Count; i++) { var movedEntity = entities.FirstOrDefault(c => c.guid == entityIDs[i]); lastMoveBeat.Add(movedEntity.beat); movedEntity.beat = newMoveBeat[i]; } } public void Undo() { var beatmap = GameManager.instance.Beatmap; var entities = new[] { beatmap.Entities, beatmap.TempoChanges, beatmap.VolumeChanges, beatmap.SectionMarkers } .SelectMany(list => list); for (var i = 0; i < entityIDs.Count; i++) { var movedEntity = entities.FirstOrDefault(c => c.guid == entityIDs[i]); movedEntity.beat = lastMoveBeat[i]; } } } }