rimworld-animation-studio/Assets/Scripts/Workspace/Workspace.cs

150 lines
6.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace RimWorldAnimationStudio
{
public class Workspace : Singleton<Workspace>
{
public static AnimationDef animationDef;
public static int stageID = 0;
public static int keyframeID = 0;
public static List<string> defNames = new List<string>() { "Human" };
public static List<string> bodyParts = new List<string>() { "Any appendage", "Any orifice", "Penis", "Vagina", "Anus", "Breasts", "Mouth" };
public static List<string> bodyDefTypes = new List<string>() { "Human", "Bird", "BeetleLike", "BeetleLikeWithClaw", "MechanicalCentipede", "MechanicalTermite", "Lancer", "Pikeman", "Monkey", "QuadrupedAnimalWithClawsTailAndJowl", "QuadrupedAnimalWithHooves", "QuadrupedAnimalWithHoovesAndHorn", "QuadrupedAnimalWithHoovesAndHump", "QuadrupedAnimalWithHoovesAndTusks", "QuadrupedAnimalWithHoovesTusksAndTrunk", "QuadrupedAnimalWithPaws", "QuadrupedAnimalWithPawsAndTail", "Scyther", "Snake", "TurtleLike" };
public static List<string> sexTypes = new List<string>() { "None", "Vaginal", "Anal", "Oral", "Masturbation", "DoublePenetration", "Boobjob", "Handjob", "Footjob", "Fingering", "Scissoring", "MutualMasturbation", "Fisting", "MechImplant", "Rimming", "Fellatio", "Cunnilingus", "Sixtynine" };
public static List<string> interactionDefTypes = new List<string>();
public static List<string> soundDefs = new List<string>() { "None", "Sex", "Fuck", "Slimy", "Suck", "Cum" };
public static List<string> actorLayers = new List<string>() { "Building", "BuildingOnTop", "MoteBelowThings", "Item", "ItemImportant", "LayingPawn", "PawnRope", "Projectile", "Pawn", "PawnUnused", "PawnState" };
[SerializeField] private List<HistoricRecord> workspaceHistory = new List<HistoricRecord>();
[SerializeField] private int historyIndex = 0;
[SerializeField] private int maxHistoryDepth = 100;
private bool isDirty = false;
public static ActorManipulationMode actorManipulationMode = ActorManipulationMode.Pan;
public static ActorBodyPart selectedBodyPart;
static int _actorID = 0;
public static int actorID { get { return Mathf.Clamp(_actorID, 0, animationDef.actors.Count - 1); } set { _actorID = value; } }
public static int StageWindowSize
{
get
{
if (animationDef == null)
{ return -1; }
if (animationDef.animationStages[stageID].stageWindowSize < 0)
{ return animationDef.animationStages[stageID].animationClips.Select(x => x.duration).Max(); }
return animationDef.animationStages[stageID].stageWindowSize;
}
}
public void Update()
{
//if (isDirty)
//{ TrackChanges(); }
}
public PawnKeyframe GetCurrentPawnKeyframe(bool makeKeyframe = false)
{
int stageTick = AnimationController.Instance.stageTick;
PawnKeyframe keyframe = animationDef?.animationStages[stageID]?.animationClips[actorID]?.keyframes.FirstOrDefault(x => x.atTick == stageTick);
if (keyframe != null || makeKeyframe == false)
{ return keyframe; }
AnimationController.Instance.AddPawnKeyframe();
return animationDef?.animationStages[stageID]?.animationClips[actorID]?.keyframes.FirstOrDefault(x => x.atTick == stageTick);
}
public PawnAnimationClip GetCurrentPawnAnimationClip()
{
return animationDef.animationStages[stageID].animationClips[actorID];
}
public PawnAnimationClip GetPawnAnimationClip(int actorID)
{
return animationDef.animationStages[stageID].animationClips[actorID];
}
public PawnKeyframe GetPawnKeyframe(int actorID, int keyframeID)
{
return animationDef.animationStages[stageID].animationClips[actorID].keyframes.FirstOrDefault(x => x.keyframeID == keyframeID);
}
[SerializeField]
public LinkedList<HistoricRecord> pastSnapshots = new LinkedList<HistoricRecord>();
public LinkedList<HistoricRecord> futureSnapshots = new LinkedList<HistoricRecord>();
public void MakeHistoricRecord(string eventDesc)
{
HistoricRecord record = new HistoricRecord();
record.recordID = pastSnapshots.Count;
record.eventDesc = eventDesc;
record.animationDef = animationDef.Copy();
record.stageID = stageID;
futureSnapshots.Clear();
pastSnapshots.AddLast(record);
if (pastSnapshots.Count > maxHistoryDepth)
{ pastSnapshots.RemoveFirst(); }
}
public void RestoreToHistoricRecord(HistoricRecord record)
{
animationDef = record.animationDef.Copy();
stageID = record.stageID;
AnimationController.Instance.MakeDirty();
}
public void Undo()
{
HistoricRecord recordToRead = pastSnapshots.Last?.Previous?.Value;
HistoricRecord recordToStore = pastSnapshots.Last?.Value;
if (recordToRead == null || recordToStore == null) return;
pastSnapshots.RemoveLast();
futureSnapshots.AddLast(recordToStore);
RestoreToHistoricRecord(recordToRead);
Debug.Log("Undo : " + recordToStore.eventDesc + " (record ID: " + recordToStore.recordID + ")");
}
public void Redo()
{
HistoricRecord recordToReadAndStore = futureSnapshots.Last?.Value;
if (recordToReadAndStore == null) return;
futureSnapshots.RemoveLast();
pastSnapshots.AddLast(recordToReadAndStore);
RestoreToHistoricRecord(recordToReadAndStore);
Debug.Log("Redo : " + recordToReadAndStore.eventDesc + " (record ID: " + recordToReadAndStore.recordID + ")");
}
public void ClearHistory()
{
pastSnapshots.Clear();
futureSnapshots.Clear();
}
public void RecordEvent(string eventDesc)
{
Debug.Log("Recording event: " + eventDesc + " (record ID: " + pastSnapshots.Count + ")");
MakeHistoricRecord(eventDesc);
}
}
}