Insert / Delete Space
This commit is contained in:
parent
a99fbd283f
commit
ba3eb95ef3
|
@ -15,176 +15,42 @@ namespace HeavenStudio.Editor.Commands
|
||||||
public class MoveEntity : ICommand
|
public class MoveEntity : ICommand
|
||||||
{
|
{
|
||||||
private readonly List<Guid> entityIDs = new();
|
private readonly List<Guid> entityIDs = new();
|
||||||
private EntityMove newMove;
|
private List<double> newMoveBeat;
|
||||||
private EntityMove lastMove;
|
private List<double> lastMoveBeat;
|
||||||
|
|
||||||
private struct EntityMove
|
public MoveEntity(List<RiqEntity> originalEntities, List<double> newBeat)
|
||||||
{
|
|
||||||
public List<double> beat;
|
|
||||||
public List<int> layer;
|
|
||||||
|
|
||||||
public EntityMove(List<double> beat, List<int> layer)
|
|
||||||
{
|
|
||||||
this.beat = beat;
|
|
||||||
this.layer = layer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public MoveEntity(List<RiqEntity> originalEntities, List<double> newBeat, List<int> newLayer)
|
|
||||||
{
|
{
|
||||||
entityIDs = originalEntities.Select(c => c.guid).ToList();
|
entityIDs = originalEntities.Select(c => c.guid).ToList();
|
||||||
newMove = new EntityMove(newBeat, newLayer);
|
newMoveBeat = newBeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Execute()
|
public void Execute()
|
||||||
{
|
{
|
||||||
lastMove = new EntityMove();
|
lastMoveBeat = new();
|
||||||
lastMove.beat = new();
|
var beatmap = GameManager.instance.Beatmap;
|
||||||
lastMove.layer = new();
|
var entities = new[] { beatmap.Entities, beatmap.TempoChanges, beatmap.VolumeChanges, beatmap.SectionMarkers }
|
||||||
|
.SelectMany(list => list);
|
||||||
|
|
||||||
for (var i = 0; i < entityIDs.Count; i++)
|
for (var i = 0; i < entityIDs.Count; i++)
|
||||||
{
|
{
|
||||||
var entity = GameManager.instance.Beatmap.Entities.Find(c => c.guid == entityIDs[i]);
|
var movedEntity = entities.FirstOrDefault(c => c.guid == entityIDs[i]);
|
||||||
|
|
||||||
lastMove.beat.Add(entity.beat);
|
lastMoveBeat.Add(movedEntity.beat);
|
||||||
lastMove.layer.Add((int)entity["track"]);
|
movedEntity.beat = newMoveBeat[i];
|
||||||
|
|
||||||
entity.beat = newMove.beat[i];
|
|
||||||
entity["track"] = newMove.layer[i];
|
|
||||||
|
|
||||||
if (TimelineBlockManager.Instance.EntityMarkers.ContainsKey(entity.guid))
|
|
||||||
TimelineBlockManager.Instance.EntityMarkers[entity.guid].SetColor((int)entity["track"]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Undo()
|
public void Undo()
|
||||||
{
|
{
|
||||||
for (var i = 0; i < entityIDs.Count; i++)
|
var beatmap = GameManager.instance.Beatmap;
|
||||||
{
|
var entities = new[] { beatmap.Entities, beatmap.TempoChanges, beatmap.VolumeChanges, beatmap.SectionMarkers }
|
||||||
var entity = GameManager.instance.Beatmap.Entities.Find(c => c.guid == entityIDs[i]);
|
.SelectMany(list => list);
|
||||||
|
|
||||||
entity.beat = lastMove.beat[i];
|
|
||||||
entity["track"] = lastMove.layer[i];
|
|
||||||
|
|
||||||
if (TimelineBlockManager.Instance.EntityMarkers.ContainsKey(entity.guid))
|
|
||||||
TimelineBlockManager.Instance.EntityMarkers[entity.guid].SetColor((int)entity["track"]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class InsertSpace : ICommand
|
|
||||||
{
|
|
||||||
private Guid entityId;
|
|
||||||
private double newBeat, lastBeat;
|
|
||||||
private SpecialTimeline.HoveringTypes type;
|
|
||||||
|
|
||||||
public InsertSpace(Guid entityId, double newBeat, SpecialTimeline.HoveringTypes type)
|
|
||||||
{
|
|
||||||
this.entityId = entityId;
|
|
||||||
this.newBeat = newBeat;
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Execute()
|
|
||||||
{
|
|
||||||
RiqEntity movedEntity = null;
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case SpecialTimeline.HoveringTypes.TempoChange:
|
|
||||||
movedEntity = GameManager.instance.Beatmap.TempoChanges.Find(x => x.guid == entityId);
|
|
||||||
break;
|
|
||||||
case SpecialTimeline.HoveringTypes.VolumeChange:
|
|
||||||
movedEntity = GameManager.instance.Beatmap.VolumeChanges.Find(x => x.guid == entityId);
|
|
||||||
break;
|
|
||||||
case SpecialTimeline.HoveringTypes.SectionChange:
|
|
||||||
movedEntity = GameManager.instance.Beatmap.SectionMarkers.Find(x => x.guid == entityId);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (movedEntity != null)
|
|
||||||
{
|
|
||||||
lastBeat = movedEntity.beat;
|
|
||||||
movedEntity.beat = newBeat;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Undo()
|
|
||||||
{
|
|
||||||
RiqEntity movedEntity = null;
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case SpecialTimeline.HoveringTypes.TempoChange:
|
|
||||||
movedEntity = GameManager.instance.Beatmap.TempoChanges.Find(x => x.guid == entityId);
|
|
||||||
break;
|
|
||||||
case SpecialTimeline.HoveringTypes.VolumeChange:
|
|
||||||
movedEntity = GameManager.instance.Beatmap.VolumeChanges.Find(x => x.guid == entityId);
|
|
||||||
break;
|
|
||||||
case SpecialTimeline.HoveringTypes.SectionChange:
|
|
||||||
movedEntity = GameManager.instance.Beatmap.SectionMarkers.Find(x => x.guid == entityId);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (movedEntity != null)
|
|
||||||
{
|
|
||||||
movedEntity.beat = lastBeat;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DeleteSpace : ICommand
|
|
||||||
{
|
|
||||||
private readonly List<Guid> entityIDs = new();
|
|
||||||
private EntityMove newMove;
|
|
||||||
private EntityMove lastMove;
|
|
||||||
|
|
||||||
private struct EntityMove
|
|
||||||
{
|
|
||||||
public List<double> beat;
|
|
||||||
public List<int> layer;
|
|
||||||
|
|
||||||
public EntityMove(List<double> beat, List<int> layer)
|
|
||||||
{
|
|
||||||
this.beat = beat;
|
|
||||||
this.layer = layer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public DeleteSpace(List<RiqEntity> originalEntities, List<double> newBeat, List<int> newLayer)
|
|
||||||
{
|
|
||||||
entityIDs = originalEntities.Select(c => c.guid).ToList();
|
|
||||||
newMove = new EntityMove(newBeat, newLayer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Execute()
|
|
||||||
{
|
|
||||||
lastMove = new EntityMove();
|
|
||||||
lastMove.beat = new();
|
|
||||||
lastMove.layer = new();
|
|
||||||
|
|
||||||
for (var i = 0; i < entityIDs.Count; i++)
|
for (var i = 0; i < entityIDs.Count; i++)
|
||||||
{
|
{
|
||||||
var entity = GameManager.instance.Beatmap.Entities.Find(c => c.guid == entityIDs[i]);
|
var movedEntity = entities.FirstOrDefault(c => c.guid == entityIDs[i]);
|
||||||
|
|
||||||
lastMove.beat.Add(entity.beat);
|
movedEntity.beat = lastMoveBeat[i];
|
||||||
lastMove.layer.Add((int)entity["track"]);
|
|
||||||
|
|
||||||
entity.beat = newMove.beat[i];
|
|
||||||
entity["track"] = newMove.layer[i];
|
|
||||||
|
|
||||||
if (TimelineBlockManager.Instance.EntityMarkers.ContainsKey(entity.guid))
|
|
||||||
TimelineBlockManager.Instance.EntityMarkers[entity.guid].SetColor((int)entity["track"]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Undo()
|
|
||||||
{
|
|
||||||
for (var i = 0; i < entityIDs.Count; i++)
|
|
||||||
{
|
|
||||||
var entity = GameManager.instance.Beatmap.Entities.Find(c => c.guid == entityIDs[i]);
|
|
||||||
|
|
||||||
entity.beat = lastMove.beat[i];
|
|
||||||
entity["track"] = lastMove.layer[i];
|
|
||||||
|
|
||||||
if (TimelineBlockManager.Instance.EntityMarkers.ContainsKey(entity.guid))
|
|
||||||
TimelineBlockManager.Instance.EntityMarkers[entity.guid].SetColor((int)entity["track"]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -937,26 +937,64 @@ namespace HeavenStudio.Editor.Track
|
||||||
|
|
||||||
public void InsertSpace()
|
public void InsertSpace()
|
||||||
{
|
{
|
||||||
Debug.Log($"{snapInterval} {PlaybackBeat}");
|
List<RiqEntity> originalEntities = new();
|
||||||
|
List<double> newBeats = new();
|
||||||
|
|
||||||
// List<double> newBeats = new();
|
var beatmap = GameManager.instance.Beatmap;
|
||||||
// List<int> lastLayers = new();
|
var specialEntities = new[] { beatmap.TempoChanges, beatmap.VolumeChanges, beatmap.SectionMarkers }
|
||||||
// foreach (var marker in Selections.instance.eventsSelected)
|
.SelectMany(list => list);
|
||||||
// {
|
|
||||||
// var entity = marker.entity;
|
|
||||||
|
|
||||||
// lastBeats.Add(marker.entity.beat);
|
foreach (var entity in beatmap.Entities)
|
||||||
// lastLayers.Add((int)marker.entity["track"]);
|
{
|
||||||
|
var entityBeat = entity.beat;
|
||||||
|
if (entityBeat >= PlaybackBeat)
|
||||||
|
{
|
||||||
|
originalEntities.Add(entity);
|
||||||
|
newBeats.Add(entityBeat + snapInterval);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (var entity in specialEntities)
|
||||||
|
{
|
||||||
|
var entityBeat = entity.beat;
|
||||||
|
if (entityBeat >= PlaybackBeat && entityBeat > 0)
|
||||||
|
{
|
||||||
|
originalEntities.Add(entity);
|
||||||
|
newBeats.Add(entityBeat + snapInterval);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// entity.beat = marker.lastBeat;
|
if (originalEntities.Count > 0) CommandManager.Instance.AddCommand(new Commands.MoveEntity(originalEntities, newBeats));
|
||||||
// entity["track"] = marker.lastLayer;
|
|
||||||
// }
|
|
||||||
// CommandManager.Instance.AddCommand(new Commands.MoveEntity(Selections.instance.eventsSelected.Select(c => c.entity).ToList(), lastBeats, lastLayers));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteSpace()
|
public void DeleteSpace()
|
||||||
{
|
{
|
||||||
Debug.Log($"{snapInterval} {PlaybackBeat}");
|
List<RiqEntity> originalEntities = new();
|
||||||
|
List<double> newBeats = new();
|
||||||
|
|
||||||
|
var beatmap = GameManager.instance.Beatmap;
|
||||||
|
var specialEntities = new[] { beatmap.TempoChanges, beatmap.VolumeChanges, beatmap.SectionMarkers }
|
||||||
|
.SelectMany(list => list);
|
||||||
|
|
||||||
|
foreach (var entity in beatmap.Entities)
|
||||||
|
{
|
||||||
|
var entityBeat = entity.beat;
|
||||||
|
if (entityBeat - snapInterval >= PlaybackBeat)
|
||||||
|
{
|
||||||
|
originalEntities.Add(entity);
|
||||||
|
newBeats.Add(entityBeat - snapInterval);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (var entity in specialEntities)
|
||||||
|
{
|
||||||
|
var entityBeat = entity.beat;
|
||||||
|
if (entityBeat - snapInterval >= PlaybackBeat && entityBeat > 0)
|
||||||
|
{
|
||||||
|
originalEntities.Add(entity);
|
||||||
|
newBeats.Add(entityBeat - snapInterval);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (originalEntities.Count > 0) CommandManager.Instance.AddCommand(new Commands.MoveEntity(originalEntities, newBeats));
|
||||||
}
|
}
|
||||||
|
|
||||||
public float SnapToLayer(float y)
|
public float SnapToLayer(float y)
|
||||||
|
|
Loading…
Reference in a new issue