wip
This commit is contained in:
parent
4affbb6796
commit
a99fbd283f
191
Assets/Scripts/LevelEditor/Commands/Space.cs
Normal file
191
Assets/Scripts/LevelEditor/Commands/Space.cs
Normal file
|
@ -0,0 +1,191 @@
|
||||||
|
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<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 MoveEntity(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++)
|
||||||
|
{
|
||||||
|
var entity = GameManager.instance.Beatmap.Entities.Find(c => c.guid == entityIDs[i]);
|
||||||
|
|
||||||
|
lastMove.beat.Add(entity.beat);
|
||||||
|
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"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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++)
|
||||||
|
{
|
||||||
|
var entity = GameManager.instance.Beatmap.Entities.Find(c => c.guid == entityIDs[i]);
|
||||||
|
|
||||||
|
lastMove.beat.Add(entity.beat);
|
||||||
|
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"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/LevelEditor/Commands/Space.cs.meta
Normal file
11
Assets/Scripts/LevelEditor/Commands/Space.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6bb50347e9fcfa143aa79f3ef0f0b436
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -199,6 +199,18 @@ namespace HeavenStudio.Editor
|
||||||
{
|
{
|
||||||
Timeline.instance.Paste();
|
Timeline.instance.Paste();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Input.GetKey(KeyCode.LeftShift))
|
||||||
|
{
|
||||||
|
if (Input.GetKeyDown(KeyCode.I))
|
||||||
|
{
|
||||||
|
Timeline.instance.InsertSpace();
|
||||||
|
}
|
||||||
|
else if (Input.GetKeyDown(KeyCode.U))
|
||||||
|
{
|
||||||
|
Timeline.instance.DeleteSpace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input.GetKey(KeyCode.LeftControl))
|
if (Input.GetKey(KeyCode.LeftControl))
|
||||||
|
|
|
@ -935,6 +935,30 @@ namespace HeavenStudio.Editor.Track
|
||||||
return dup;
|
return dup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void InsertSpace()
|
||||||
|
{
|
||||||
|
Debug.Log($"{snapInterval} {PlaybackBeat}");
|
||||||
|
|
||||||
|
// List<double> newBeats = new();
|
||||||
|
// List<int> lastLayers = new();
|
||||||
|
// foreach (var marker in Selections.instance.eventsSelected)
|
||||||
|
// {
|
||||||
|
// var entity = marker.entity;
|
||||||
|
|
||||||
|
// lastBeats.Add(marker.entity.beat);
|
||||||
|
// lastLayers.Add((int)marker.entity["track"]);
|
||||||
|
|
||||||
|
// entity.beat = marker.lastBeat;
|
||||||
|
// entity["track"] = marker.lastLayer;
|
||||||
|
// }
|
||||||
|
// CommandManager.Instance.AddCommand(new Commands.MoveEntity(Selections.instance.eventsSelected.Select(c => c.entity).ToList(), lastBeats, lastLayers));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteSpace()
|
||||||
|
{
|
||||||
|
Debug.Log($"{snapInterval} {PlaybackBeat}");
|
||||||
|
}
|
||||||
|
|
||||||
public float SnapToLayer(float y)
|
public float SnapToLayer(float y)
|
||||||
{
|
{
|
||||||
float size = LayerHeight();
|
float size = LayerHeight();
|
||||||
|
|
|
@ -238,11 +238,10 @@ namespace HeavenStudio.Editor.Track
|
||||||
|
|
||||||
if (moving)
|
if (moving)
|
||||||
{
|
{
|
||||||
// Debug.Log($"{minBeat} {maxBeat} {minTrack} {maxTrack} {Timeline.instance.MousePos2BeatSnap}");
|
|
||||||
foreach (var marker in Selections.instance.eventsSelected)
|
foreach (var marker in Selections.instance.eventsSelected)
|
||||||
{
|
{
|
||||||
var nextBeat = System.Math.Max(Timeline.instance.MousePos2BeatSnap, 0 + selectedMaxInitMoveX) - marker.initMoveX;
|
var nextBeat = System.Math.Max(Timeline.instance.MousePos2BeatSnap, selectedMaxInitMoveX) - marker.initMoveX;
|
||||||
var nextTrack = Mathf.Clamp(Timeline.instance.MousePos2Layer, 0 + selectedMaxInitMoveY, Timeline.instance.LayerCount - 1 + selectedMinInitMoveY) - marker.initMoveY;
|
var nextTrack = Mathf.Clamp(Timeline.instance.MousePos2Layer, selectedMaxInitMoveY, Timeline.instance.LayerCount - 1 + selectedMinInitMoveY) - marker.initMoveY;
|
||||||
marker.entity.beat = System.Math.Max(nextBeat, 0);
|
marker.entity.beat = System.Math.Max(nextBeat, 0);
|
||||||
marker.entity["track"] = Mathf.Clamp(nextTrack, 0, Timeline.instance.LayerCount - 1);
|
marker.entity["track"] = Mathf.Clamp(nextTrack, 0, Timeline.instance.LayerCount - 1);
|
||||||
marker.SetColor((int)entity["track"]);
|
marker.SetColor((int)entity["track"]);
|
||||||
|
|
Loading…
Reference in a new issue