mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2026-05-14 21:53:49 +08:00
R26_dev8 - First public commit
This commit is contained in:
@@ -0,0 +1,604 @@
|
||||
using CodeWalker.GameFiles;
|
||||
using CodeWalker.World;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
namespace CodeWalker.Project
|
||||
{
|
||||
public class ProjectFile
|
||||
{
|
||||
//fields stored in file
|
||||
public string Name { get; set; } //friendly name for this project
|
||||
public int Version { get; set; }
|
||||
public List<string> YmapFilenames { get; set; } = new List<string>();
|
||||
public List<string> YndFilenames { get; set; } = new List<string>();
|
||||
public List<string> YnvFilenames { get; set; } = new List<string>();
|
||||
public List<string> TrainsFilenames { get; set; } = new List<string>();
|
||||
public List<string> ScenarioFilenames { get; set; } = new List<string>();
|
||||
|
||||
//fields not stored
|
||||
public string Filename { get; set; } //filename without path
|
||||
public string Filepath { get; set; } //full path of the current file
|
||||
public bool HasChanged { get; set; } //flag for use by the UI
|
||||
|
||||
public List<YmapFile> YmapFiles { get; set; } = new List<YmapFile>();
|
||||
public List<YndFile> YndFiles { get; set; } = new List<YndFile>();
|
||||
public List<YnvFile> YnvFiles { get; set; } = new List<YnvFile>();
|
||||
public List<TrainTrack> TrainsFiles { get; set; } = new List<TrainTrack>();
|
||||
public List<YmtFile> ScenarioFiles { get; set; } = new List<YmtFile>();
|
||||
|
||||
|
||||
|
||||
public void Save()
|
||||
{
|
||||
XmlDocument doc = new XmlDocument();
|
||||
var projelem = doc.CreateElement("CodeWalkerProject");
|
||||
doc.AppendChild(projelem);
|
||||
|
||||
Xml.AddChildWithInnerText(doc, projelem, "Name", Name);
|
||||
Xml.AddChildWithAttribute(doc, projelem, "Version", "value", Version.ToString());
|
||||
|
||||
var ymapselem = Xml.AddChild(doc, projelem, "YmapFilenames");
|
||||
foreach (string ymapfilename in YmapFilenames)
|
||||
{
|
||||
Xml.AddChildWithInnerText(doc, ymapselem, "Item", ymapfilename);
|
||||
}
|
||||
|
||||
var yndselem = Xml.AddChild(doc, projelem, "YndFilenames");
|
||||
foreach (string yndfilename in YndFilenames)
|
||||
{
|
||||
Xml.AddChildWithInnerText(doc, yndselem, "Item", yndfilename);
|
||||
}
|
||||
|
||||
var ynvselem = Xml.AddChild(doc, projelem, "YnvFilenames");
|
||||
foreach (string ynvfilename in YnvFilenames)
|
||||
{
|
||||
Xml.AddChildWithInnerText(doc, ynvselem, "Item", ynvfilename);
|
||||
}
|
||||
|
||||
var trainselem = Xml.AddChild(doc, projelem, "TrainsFilenames");
|
||||
foreach (string trainsfile in TrainsFilenames)
|
||||
{
|
||||
Xml.AddChildWithInnerText(doc, trainselem, "Item", trainsfile);
|
||||
}
|
||||
|
||||
var scenarioselem = Xml.AddChild(doc, projelem, "ScenarioFilenames");
|
||||
foreach (string scenariofilename in ScenarioFilenames)
|
||||
{
|
||||
Xml.AddChildWithInnerText(doc, scenarioselem, "Item", scenariofilename);
|
||||
}
|
||||
|
||||
doc.Save(Filepath);
|
||||
}
|
||||
|
||||
public void Load(string filepath)
|
||||
{
|
||||
FileInfo fi = new FileInfo(filepath);
|
||||
Filename = fi.Name;
|
||||
Filepath = filepath;
|
||||
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.Load(filepath);
|
||||
|
||||
var projelem = doc.DocumentElement;
|
||||
|
||||
Name = Xml.GetChildInnerText(projelem, "Name");
|
||||
Version = Xml.GetChildIntAttribute(projelem, "Version", "value");
|
||||
|
||||
YmapFilenames.Clear();
|
||||
YmapFiles.Clear();
|
||||
var ymapselem = Xml.GetChild(projelem, "YmapFilenames");
|
||||
if (ymapselem != null)
|
||||
{
|
||||
foreach (var node in ymapselem.SelectNodes("Item"))
|
||||
{
|
||||
XmlElement ymapel = node as XmlElement;
|
||||
if (ymapel != null)
|
||||
{
|
||||
AddYmapFile(ymapel.InnerText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
YndFilenames.Clear();
|
||||
YndFiles.Clear();
|
||||
var yndselem = Xml.GetChild(projelem, "YndFilenames");
|
||||
if (yndselem != null)
|
||||
{
|
||||
foreach (var node in yndselem.SelectNodes("Item"))
|
||||
{
|
||||
XmlElement yndel = node as XmlElement;
|
||||
if (yndel != null)
|
||||
{
|
||||
AddYndFile(yndel.InnerText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
YnvFilenames.Clear();
|
||||
YnvFiles.Clear();
|
||||
var ynvselem = Xml.GetChild(projelem, "YnvFilenames");
|
||||
if (ynvselem != null)
|
||||
{
|
||||
foreach (var node in ynvselem.SelectNodes("Item"))
|
||||
{
|
||||
XmlElement ynvel = node as XmlElement;
|
||||
if (ynvel != null)
|
||||
{
|
||||
AddYnvFile(ynvel.InnerText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TrainsFilenames.Clear();
|
||||
TrainsFiles.Clear();
|
||||
var trainsselem = Xml.GetChild(projelem, "TrainsFilenames");
|
||||
if (trainsselem != null)
|
||||
{
|
||||
foreach (var node in trainsselem.SelectNodes("Item"))
|
||||
{
|
||||
XmlElement trainel = node as XmlElement;
|
||||
if (trainel != null)
|
||||
{
|
||||
AddTrainsFile(trainel.InnerText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
ScenarioFilenames.Clear();
|
||||
ScenarioFiles.Clear();
|
||||
var scenarioselem = Xml.GetChild(projelem, "ScenarioFilenames");
|
||||
if (scenarioselem != null)
|
||||
{
|
||||
foreach (var node in scenarioselem.SelectNodes("Item"))
|
||||
{
|
||||
XmlElement scenarioel = node as XmlElement;
|
||||
if (scenarioel != null)
|
||||
{
|
||||
AddScenarioFile(scenarioel.InnerText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void UpdateFilenames(string oldprojpath)
|
||||
{
|
||||
for (int i = 0; i < YmapFilenames.Count; i++)
|
||||
{
|
||||
YmapFilenames[i] = GetUpdatedFilePath(YmapFilenames[i], oldprojpath);
|
||||
}
|
||||
for (int i = 0; i < YndFilenames.Count; i++)
|
||||
{
|
||||
YndFilenames[i] = GetUpdatedFilePath(YndFilenames[i], oldprojpath);
|
||||
}
|
||||
for (int i = 0; i < YnvFilenames.Count; i++)
|
||||
{
|
||||
YnvFilenames[i] = GetUpdatedFilePath(YnvFilenames[i], oldprojpath);
|
||||
}
|
||||
for (int i = 0; i < TrainsFilenames.Count; i++)
|
||||
{
|
||||
TrainsFilenames[i] = GetUpdatedFilePath(TrainsFilenames[i], oldprojpath);
|
||||
}
|
||||
for (int i = 0; i < ScenarioFilenames.Count; i++)
|
||||
{
|
||||
ScenarioFilenames[i] = GetUpdatedFilePath(ScenarioFilenames[i], oldprojpath);
|
||||
}
|
||||
}
|
||||
|
||||
public string GetUpdatedFilePath(string oldpath, string oldprojpath)
|
||||
{
|
||||
string fullpath = GetFullFilePath(oldpath, oldprojpath);
|
||||
string newpath = GetRelativePath(fullpath);
|
||||
return newpath;
|
||||
}
|
||||
public string GetRelativePath(string filepath)
|
||||
{
|
||||
if (filepath == null) return string.Empty;
|
||||
if (Filepath == null) return filepath;
|
||||
|
||||
Uri fromUri;
|
||||
if (!Uri.TryCreate(Filepath, UriKind.RelativeOrAbsolute, out fromUri))
|
||||
{
|
||||
return filepath;
|
||||
}
|
||||
|
||||
Uri toUri;
|
||||
if (!Uri.TryCreate(filepath, UriKind.RelativeOrAbsolute, out toUri))
|
||||
{
|
||||
return filepath;
|
||||
}
|
||||
if (!toUri.IsAbsoluteUri)
|
||||
{
|
||||
return filepath;//already relative...
|
||||
}
|
||||
|
||||
//Uri fromUri = new Uri(Filepath);
|
||||
//Uri toUri = new Uri(filepath);
|
||||
if (fromUri.Scheme != toUri.Scheme)
|
||||
{
|
||||
return filepath.ToLower();
|
||||
}
|
||||
Uri relativeUri = fromUri.MakeRelativeUri(toUri);
|
||||
string relativePath = Uri.UnescapeDataString(relativeUri.ToString());
|
||||
if (string.Equals(toUri.Scheme, Uri.UriSchemeFile, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
relativePath = relativePath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
|
||||
}
|
||||
return relativePath.ToLower();
|
||||
}
|
||||
public string GetFullFilePath(string relpath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Filepath)) return relpath;
|
||||
string projfldr = new FileInfo(Filepath).DirectoryName + "\\";
|
||||
string cpath = Path.Combine(projfldr, relpath);
|
||||
string apath = Path.GetFullPath(cpath);
|
||||
return apath;
|
||||
}
|
||||
public string GetFullFilePath(string relpath, string basepath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(basepath)) return relpath;
|
||||
string basefldr = new FileInfo(basepath).DirectoryName + "\\";
|
||||
string cpath = Path.Combine(basefldr, relpath);
|
||||
string apath = Path.GetFullPath(cpath);
|
||||
return apath;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public YmapFile AddYmapFile(string filename)
|
||||
{
|
||||
YmapFile ymap = new YmapFile();
|
||||
ymap.RpfFileEntry = new RpfResourceFileEntry();
|
||||
ymap.RpfFileEntry.Name = new FileInfo(filename).Name;
|
||||
ymap.FilePath = GetFullFilePath(filename);
|
||||
ymap.Name = ymap.RpfFileEntry.Name;
|
||||
JenkIndex.Ensure(ymap.Name);
|
||||
JenkIndex.Ensure(Path.GetFileNameWithoutExtension(ymap.Name));
|
||||
JenkIndex.Ensure(filename);
|
||||
if (!AddYmapFile(ymap)) return null;
|
||||
return ymap;
|
||||
}
|
||||
public bool AddYmapFile(YmapFile ymap)
|
||||
{
|
||||
string relpath = GetRelativePath(ymap.FilePath);
|
||||
if (string.IsNullOrEmpty(relpath)) relpath = ymap.Name;
|
||||
if (YmapFilenames.Contains(relpath)) return false;
|
||||
YmapFilenames.Add(relpath);
|
||||
YmapFiles.Add(ymap);
|
||||
return true;
|
||||
}
|
||||
public void RemoveYmapFile(YmapFile ymap)
|
||||
{
|
||||
if (ymap == null) return;
|
||||
var relpath = GetRelativePath(ymap.FilePath);
|
||||
if (string.IsNullOrEmpty(relpath)) relpath = ymap.Name;
|
||||
YmapFiles.Remove(ymap);
|
||||
YmapFilenames.Remove(relpath);
|
||||
HasChanged = true;
|
||||
}
|
||||
public bool ContainsYmap(string filename)
|
||||
{
|
||||
bool found = false;
|
||||
filename = filename.ToLower();
|
||||
foreach (var ymapfn in YmapFilenames)
|
||||
{
|
||||
if (ymapfn == filename)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
public bool ContainsYmap(YmapFile ymap)
|
||||
{
|
||||
foreach (var f in YmapFiles)
|
||||
{
|
||||
if (f == ymap) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public bool RenameYmap(string oldfilename, string newfilename)
|
||||
{
|
||||
oldfilename = oldfilename.ToLower();
|
||||
newfilename = newfilename.ToLower();
|
||||
for (int i = 0; i < YmapFilenames.Count; i++)
|
||||
{
|
||||
if (YmapFilenames[i] == oldfilename)
|
||||
{
|
||||
YmapFilenames[i] = newfilename;
|
||||
HasChanged = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public YndFile AddYndFile(string filename)
|
||||
{
|
||||
YndFile ynd = new YndFile();
|
||||
ynd.RpfFileEntry = new RpfResourceFileEntry();
|
||||
ynd.RpfFileEntry.Name = new FileInfo(filename).Name;
|
||||
ynd.FilePath = GetFullFilePath(filename);
|
||||
ynd.Name = ynd.RpfFileEntry.Name;
|
||||
if (!AddYndFile(ynd)) return null;
|
||||
return ynd;
|
||||
}
|
||||
public bool AddYndFile(YndFile ynd)
|
||||
{
|
||||
string relpath = GetRelativePath(ynd.FilePath);
|
||||
if (string.IsNullOrEmpty(relpath)) relpath = ynd.Name;
|
||||
if (YndFilenames.Contains(relpath)) return false;
|
||||
YndFilenames.Add(relpath);
|
||||
YndFiles.Add(ynd);
|
||||
return true;
|
||||
}
|
||||
public void RemoveYndFile(YndFile ynd)
|
||||
{
|
||||
if (ynd == null) return;
|
||||
var relpath = GetRelativePath(ynd.FilePath);
|
||||
if (string.IsNullOrEmpty(relpath)) relpath = ynd.Name;
|
||||
YndFiles.Remove(ynd);
|
||||
YndFilenames.Remove(relpath);
|
||||
HasChanged = true;
|
||||
}
|
||||
public bool ContainsYnd(string filename)
|
||||
{
|
||||
bool found = false;
|
||||
filename = filename.ToLower();
|
||||
foreach (var yndfn in YndFilenames)
|
||||
{
|
||||
if (yndfn == filename)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
public bool ContainsYnd(YndFile ynd)
|
||||
{
|
||||
foreach (var f in YndFiles)
|
||||
{
|
||||
if (f == ynd) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public bool RenameYnd(string oldfilename, string newfilename)
|
||||
{
|
||||
oldfilename = oldfilename.ToLower();
|
||||
newfilename = newfilename.ToLower();
|
||||
for (int i = 0; i < YndFilenames.Count; i++)
|
||||
{
|
||||
if (YndFilenames[i] == oldfilename)
|
||||
{
|
||||
YndFilenames[i] = newfilename;
|
||||
HasChanged = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public YnvFile AddYnvFile(string filename)
|
||||
{
|
||||
YnvFile ynv = new YnvFile();
|
||||
ynv.RpfFileEntry = new RpfResourceFileEntry();
|
||||
ynv.RpfFileEntry.Name = new FileInfo(filename).Name;
|
||||
ynv.FilePath = GetFullFilePath(filename);
|
||||
ynv.Name = ynv.RpfFileEntry.Name;
|
||||
if (!AddYnvFile(ynv)) return null;
|
||||
return ynv;
|
||||
}
|
||||
public bool AddYnvFile(YnvFile ynv)
|
||||
{
|
||||
string relpath = GetRelativePath(ynv.FilePath);
|
||||
if (string.IsNullOrEmpty(relpath)) relpath = ynv.Name;
|
||||
if (YnvFilenames.Contains(relpath)) return false;
|
||||
YnvFilenames.Add(relpath);
|
||||
YnvFiles.Add(ynv);
|
||||
return true;
|
||||
}
|
||||
public void RemoveYnvFile(YnvFile ynv)
|
||||
{
|
||||
if (ynv == null) return;
|
||||
var relpath = GetRelativePath(ynv.FilePath);
|
||||
if (string.IsNullOrEmpty(relpath)) relpath = ynv.Name;
|
||||
YnvFiles.Remove(ynv);
|
||||
YnvFilenames.Remove(relpath);
|
||||
HasChanged = true;
|
||||
}
|
||||
public bool ContainsYnv(string filename)
|
||||
{
|
||||
bool found = false;
|
||||
filename = filename.ToLower();
|
||||
foreach (var ynvfn in YnvFilenames)
|
||||
{
|
||||
if (ynvfn == filename)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
public bool ContainsYnv(YnvFile ynv)
|
||||
{
|
||||
foreach (var f in YnvFiles)
|
||||
{
|
||||
if (f == ynv) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public bool RenameYnv(string oldfilename, string newfilename)
|
||||
{
|
||||
oldfilename = oldfilename.ToLower();
|
||||
newfilename = newfilename.ToLower();
|
||||
for (int i = 0; i < YnvFilenames.Count; i++)
|
||||
{
|
||||
if (YnvFilenames[i] == oldfilename)
|
||||
{
|
||||
YnvFilenames[i] = newfilename;
|
||||
HasChanged = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public TrainTrack AddTrainsFile(string filename)
|
||||
{
|
||||
TrainTrack track = new TrainTrack();
|
||||
track.RpfFileEntry = new RpfResourceFileEntry();
|
||||
track.RpfFileEntry.Name = new FileInfo(filename).Name;
|
||||
track.FilePath = GetFullFilePath(filename);
|
||||
track.Name = track.RpfFileEntry.Name;
|
||||
if (!AddTrainsFile(track)) return null;
|
||||
return track;
|
||||
}
|
||||
public bool AddTrainsFile(TrainTrack track)
|
||||
{
|
||||
string relpath = GetRelativePath(track.FilePath);
|
||||
if (string.IsNullOrEmpty(relpath)) relpath = track.Name;
|
||||
if (TrainsFilenames.Contains(relpath)) return false;
|
||||
TrainsFilenames.Add(relpath);
|
||||
TrainsFiles.Add(track);
|
||||
return true;
|
||||
}
|
||||
public void RemoveTrainsFile(TrainTrack track)
|
||||
{
|
||||
if (track == null) return;
|
||||
var relpath = GetRelativePath(track.FilePath);
|
||||
if (string.IsNullOrEmpty(relpath)) relpath = track.Name;
|
||||
TrainsFiles.Remove(track);
|
||||
TrainsFilenames.Remove(relpath);
|
||||
HasChanged = true;
|
||||
}
|
||||
public bool ContainsTrainTrack(string filename)
|
||||
{
|
||||
bool found = false;
|
||||
filename = filename.ToLower();
|
||||
foreach (var trainsfn in TrainsFilenames)
|
||||
{
|
||||
if (trainsfn == filename)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
public bool ContainsTrainTrack(TrainTrack track)
|
||||
{
|
||||
foreach (var f in TrainsFiles)
|
||||
{
|
||||
if (f == track) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public bool RenameTrainTrack(string oldfilename, string newfilename)
|
||||
{
|
||||
oldfilename = oldfilename.ToLower();
|
||||
newfilename = newfilename.ToLower();
|
||||
for (int i = 0; i < TrainsFilenames.Count; i++)
|
||||
{
|
||||
if (TrainsFilenames[i] == oldfilename)
|
||||
{
|
||||
TrainsFilenames[i] = newfilename;
|
||||
HasChanged = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public YmtFile AddScenarioFile(string filename)
|
||||
{
|
||||
YmtFile scenario = new YmtFile();
|
||||
scenario.RpfFileEntry = new RpfResourceFileEntry();
|
||||
scenario.RpfFileEntry.Name = new FileInfo(filename).Name;
|
||||
scenario.FilePath = GetFullFilePath(filename);
|
||||
scenario.Name = scenario.RpfFileEntry.Name;
|
||||
scenario.ContentType = YmtFileContentType.ScenarioPointRegion;
|
||||
scenario.FileFormat = YmtFileFormat.RSC;
|
||||
if (!AddScenarioFile(scenario)) return null;
|
||||
return scenario;
|
||||
}
|
||||
public bool AddScenarioFile(YmtFile ymt)
|
||||
{
|
||||
string relpath = GetRelativePath(ymt.FilePath);
|
||||
if (string.IsNullOrEmpty(relpath)) relpath = ymt.Name;
|
||||
if (ScenarioFilenames.Contains(relpath)) return false;
|
||||
ScenarioFilenames.Add(relpath);
|
||||
ScenarioFiles.Add(ymt);
|
||||
return true;
|
||||
}
|
||||
public void RemoveScenarioFile(YmtFile ymt)
|
||||
{
|
||||
if (ymt == null) return;
|
||||
var relpath = GetRelativePath(ymt.FilePath);
|
||||
if (string.IsNullOrEmpty(relpath)) relpath = ymt.Name;
|
||||
ScenarioFiles.Remove(ymt);
|
||||
ScenarioFilenames.Remove(relpath);
|
||||
HasChanged = true;
|
||||
}
|
||||
public bool ContainsScenario(string filename)
|
||||
{
|
||||
bool found = false;
|
||||
filename = filename.ToLower();
|
||||
foreach (var scenariofn in ScenarioFilenames)
|
||||
{
|
||||
if (scenariofn == filename)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
public bool ContainsScenario(YmtFile ymt)
|
||||
{
|
||||
foreach (var f in ScenarioFiles)
|
||||
{
|
||||
if (f == ymt) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public bool RenameScenario(string oldfilename, string newfilename)
|
||||
{
|
||||
oldfilename = oldfilename.ToLower();
|
||||
newfilename = newfilename.ToLower();
|
||||
for (int i = 0; i < ScenarioFilenames.Count; i++)
|
||||
{
|
||||
if (ScenarioFilenames[i] == oldfilename)
|
||||
{
|
||||
ScenarioFilenames[i] = newfilename;
|
||||
HasChanged = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,604 @@
|
||||
using CodeWalker.GameFiles;
|
||||
using CodeWalker.World;
|
||||
using SharpDX;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CodeWalker.Project
|
||||
{
|
||||
public abstract class UndoStep
|
||||
{
|
||||
|
||||
//revert the object to the state marked at the start of this step
|
||||
public abstract void Undo(WorldForm wf, ProjectForm pf, ref MapSelection sel);
|
||||
|
||||
//revert the object to the state marked at the end of this step
|
||||
public abstract void Redo(WorldForm wf, ProjectForm pf, ref MapSelection sel);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class EntityPositionUndoStep : UndoStep
|
||||
{
|
||||
public YmapEntityDef Entity { get; set; }
|
||||
public Vector3 StartPosition { get; set; }
|
||||
public Vector3 EndPosition { get; set; }
|
||||
|
||||
public EntityPositionUndoStep(YmapEntityDef ent, Vector3 startpos)
|
||||
{
|
||||
Entity = ent;
|
||||
StartPosition = startpos;
|
||||
EndPosition = ent?.WidgetPosition ?? Vector3.Zero;
|
||||
}
|
||||
|
||||
private void Update(WorldForm wf, ProjectForm pf, ref MapSelection sel, Vector3 p)
|
||||
{
|
||||
Entity?.SetPositionFromWidget(p);
|
||||
|
||||
if (Entity != sel.EntityDef) wf.SelectEntity(Entity);
|
||||
wf.SetWidgetPosition(Entity.WidgetPosition);
|
||||
if ((Entity != null) && (pf != null))
|
||||
{
|
||||
pf.OnWorldEntityModified(Entity);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Undo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, StartPosition);
|
||||
}
|
||||
|
||||
public override void Redo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, EndPosition);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return (Entity?._CEntityDef.archetypeName.ToString() ?? "") + ": Position";
|
||||
}
|
||||
}
|
||||
|
||||
public class EntityRotationUndoStep : UndoStep
|
||||
{
|
||||
public YmapEntityDef Entity { get; set; }
|
||||
public Quaternion StartRotation { get; set; }
|
||||
public Quaternion EndRotation { get; set; }
|
||||
|
||||
public EntityRotationUndoStep(YmapEntityDef ent, Quaternion startrot)
|
||||
{
|
||||
Entity = ent;
|
||||
StartRotation = startrot;
|
||||
EndRotation = ent?.WidgetOrientation ?? Quaternion.Identity;
|
||||
}
|
||||
|
||||
|
||||
private void Update(WorldForm wf, ProjectForm pf, ref MapSelection sel, Quaternion q)
|
||||
{
|
||||
Entity?.SetOrientationFromWidget(q);
|
||||
|
||||
if (Entity != sel.EntityDef) wf.SelectEntity(Entity);
|
||||
wf.SetWidgetRotation(q);
|
||||
if ((Entity != null) && (pf != null))
|
||||
{
|
||||
pf.OnWorldEntityModified(Entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void Undo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, StartRotation);
|
||||
}
|
||||
|
||||
public override void Redo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, EndRotation);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return (Entity?._CEntityDef.archetypeName.ToString() ?? "") + ": Rotation";
|
||||
}
|
||||
}
|
||||
|
||||
public class EntityScaleUndoStep : UndoStep
|
||||
{
|
||||
public YmapEntityDef Entity { get; set; }
|
||||
public Vector3 StartScale { get; set; }
|
||||
public Vector3 EndScale { get; set; }
|
||||
|
||||
public EntityScaleUndoStep(YmapEntityDef ent, Vector3 startscale)
|
||||
{
|
||||
Entity = ent;
|
||||
StartScale = startscale;
|
||||
EndScale = ent?.Scale ?? Vector3.One;
|
||||
}
|
||||
|
||||
|
||||
private void Update(WorldForm wf, ProjectForm pf, ref MapSelection sel, Vector3 s)
|
||||
{
|
||||
Entity?.SetScale(s);
|
||||
|
||||
if (Entity != sel.EntityDef) wf.SelectEntity(Entity);
|
||||
wf.SetWidgetScale(s);
|
||||
if ((Entity != null) && (pf != null))
|
||||
{
|
||||
pf.OnWorldEntityModified(Entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void Undo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, StartScale);
|
||||
}
|
||||
|
||||
public override void Redo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, EndScale);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return (Entity?._CEntityDef.archetypeName.ToString() ?? "") + ": Scale";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class EntityPivotPositionUndoStep : UndoStep
|
||||
{
|
||||
public YmapEntityDef Entity { get; set; }
|
||||
public Vector3 StartPosition { get; set; }
|
||||
public Vector3 EndPosition { get; set; }
|
||||
|
||||
public EntityPivotPositionUndoStep(YmapEntityDef ent, Vector3 startpos)
|
||||
{
|
||||
Entity = ent;
|
||||
StartPosition = startpos;
|
||||
EndPosition = ent?.WidgetPosition ?? Vector3.Zero;
|
||||
}
|
||||
|
||||
private void Update(WorldForm wf, ProjectForm pf, ref MapSelection sel, Vector3 p)
|
||||
{
|
||||
Entity?.SetPivotPositionFromWidget(p);
|
||||
|
||||
if (Entity != sel.EntityDef) wf.SelectEntity(Entity);
|
||||
wf.SetWidgetPosition(p);
|
||||
if ((Entity != null) && (pf != null))
|
||||
{
|
||||
pf.OnWorldEntityModified(Entity);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Undo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, StartPosition);
|
||||
}
|
||||
|
||||
public override void Redo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, EndPosition);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return (Entity?._CEntityDef.archetypeName.ToString() ?? "") + ": Pivot Position";
|
||||
}
|
||||
}
|
||||
|
||||
public class EntityPivotRotationUndoStep : UndoStep
|
||||
{
|
||||
public YmapEntityDef Entity { get; set; }
|
||||
public Quaternion StartRotation { get; set; }
|
||||
public Quaternion EndRotation { get; set; }
|
||||
|
||||
public EntityPivotRotationUndoStep(YmapEntityDef ent, Quaternion startrot)
|
||||
{
|
||||
Entity = ent;
|
||||
StartRotation = startrot;
|
||||
EndRotation = ent?.WidgetOrientation ?? Quaternion.Identity;
|
||||
}
|
||||
|
||||
|
||||
private void Update(WorldForm wf, ProjectForm pf, ref MapSelection sel, Quaternion q)
|
||||
{
|
||||
Entity?.SetPivotOrientationFromWidget(q);
|
||||
|
||||
if (Entity != sel.EntityDef) wf.SelectEntity(Entity);
|
||||
wf.SetWidgetRotation(q);
|
||||
if ((Entity != null) && (pf != null))
|
||||
{
|
||||
pf.OnWorldEntityModified(Entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void Undo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, StartRotation);
|
||||
}
|
||||
|
||||
public override void Redo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, EndRotation);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return (Entity?._CEntityDef.archetypeName.ToString() ?? "") + ": Pivot Rotation";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class CarGenPositionUndoStep : UndoStep
|
||||
{
|
||||
public YmapCarGen CarGen { get; set; }
|
||||
public Vector3 StartPosition { get; set; }
|
||||
public Vector3 EndPosition { get; set; }
|
||||
|
||||
public CarGenPositionUndoStep(YmapCarGen cargen, Vector3 startpos)
|
||||
{
|
||||
CarGen = cargen;
|
||||
StartPosition = startpos;
|
||||
EndPosition = cargen?.Position ?? Vector3.Zero;
|
||||
}
|
||||
|
||||
private void Update(WorldForm wf, ProjectForm pf, ref MapSelection sel, Vector3 p)
|
||||
{
|
||||
CarGen?.SetPosition(p);
|
||||
|
||||
if (CarGen != sel.CarGenerator) wf.SelectCarGen(CarGen);
|
||||
wf.SetWidgetPosition(p);
|
||||
if ((CarGen != null) && (pf != null))
|
||||
{
|
||||
pf.OnWorldCarGenModified(CarGen);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Undo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, StartPosition);
|
||||
}
|
||||
|
||||
public override void Redo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, EndPosition);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "CarGen " + (CarGen?._CCarGen.carModel.ToString() ?? "") + ": Position";
|
||||
}
|
||||
}
|
||||
|
||||
public class CarGenRotationUndoStep : UndoStep
|
||||
{
|
||||
public YmapCarGen CarGen { get; set; }
|
||||
public Quaternion StartRotation { get; set; }
|
||||
public Quaternion EndRotation { get; set; }
|
||||
|
||||
public CarGenRotationUndoStep(YmapCarGen cargen, Quaternion startrot)
|
||||
{
|
||||
CarGen = cargen;
|
||||
StartRotation = startrot;
|
||||
EndRotation = cargen?.Orientation ?? Quaternion.Identity;
|
||||
}
|
||||
|
||||
|
||||
private void Update(WorldForm wf, ProjectForm pf, ref MapSelection sel, Quaternion q)
|
||||
{
|
||||
CarGen?.SetOrientation(q);
|
||||
|
||||
if (CarGen != sel.CarGenerator) wf.SelectCarGen(CarGen);
|
||||
wf.SetWidgetRotation(q);
|
||||
if ((CarGen != null) && (pf != null))
|
||||
{
|
||||
pf.OnWorldCarGenModified(CarGen);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Undo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, StartRotation);
|
||||
}
|
||||
|
||||
public override void Redo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, EndRotation);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "CarGen " + (CarGen?._CCarGen.carModel.ToString() ?? "") + ": Rotation";
|
||||
}
|
||||
}
|
||||
|
||||
public class CarGenScaleUndoStep : UndoStep
|
||||
{
|
||||
public YmapCarGen CarGen { get; set; }
|
||||
public Vector3 StartScale { get; set; }
|
||||
public Vector3 EndScale { get; set; }
|
||||
|
||||
public CarGenScaleUndoStep(YmapCarGen cargen, Vector3 startscale)
|
||||
{
|
||||
CarGen = cargen;
|
||||
StartScale = startscale;
|
||||
EndScale = new Vector3(cargen?._CCarGen.perpendicularLength ?? 1.0f);
|
||||
}
|
||||
|
||||
private void Update(WorldForm wf, ProjectForm pf, ref MapSelection sel, Vector3 s)
|
||||
{
|
||||
CarGen?.SetScale(s);
|
||||
|
||||
if (CarGen != sel.CarGenerator) wf.SelectCarGen(CarGen);
|
||||
wf.SetWidgetScale(s);
|
||||
if ((CarGen != null) && (pf != null))
|
||||
{
|
||||
pf.OnWorldCarGenModified(CarGen);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void Undo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, StartScale);
|
||||
}
|
||||
|
||||
public override void Redo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, EndScale);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "CarGen " + (CarGen?._CCarGen.carModel.ToString() ?? "") + ": Scale";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class PathNodePositionUndoStep : UndoStep
|
||||
{
|
||||
public YndNode PathNode { get; set; }
|
||||
public Vector3 StartPosition { get; set; }
|
||||
public Vector3 EndPosition { get; set; }
|
||||
|
||||
public PathNodePositionUndoStep(YndNode pathnode, Vector3 startpos, WorldForm wf, ProjectForm pf)
|
||||
{
|
||||
PathNode = pathnode;
|
||||
StartPosition = startpos;
|
||||
EndPosition = pathnode?.Position ?? Vector3.Zero;
|
||||
|
||||
UpdateGraphics(wf, pf); //forces the update of the path graphics when it's moved...
|
||||
}
|
||||
|
||||
private void Update(WorldForm wf, ProjectForm pf, ref MapSelection sel, Vector3 p)
|
||||
{
|
||||
PathNode?.SetPosition(p);
|
||||
|
||||
if (PathNode != sel.PathNode)
|
||||
{
|
||||
if (sel.PathLink != null)
|
||||
{
|
||||
wf.SelectPathLink(sel.PathLink);
|
||||
}
|
||||
else
|
||||
{
|
||||
wf.SelectPathNode(PathNode);
|
||||
}
|
||||
}
|
||||
wf.SetWidgetPosition(p);
|
||||
|
||||
|
||||
UpdateGraphics(wf, pf);
|
||||
}
|
||||
|
||||
private void UpdateGraphics(WorldForm wf, ProjectForm pf)
|
||||
{
|
||||
if (PathNode != null)
|
||||
{
|
||||
//Ynd graphics needs to be updated.....
|
||||
wf.UpdatePathNodeGraphics(PathNode, false);
|
||||
if (pf != null) //make sure to update the project form UI..
|
||||
{
|
||||
pf.OnWorldPathNodeModified(PathNode, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void Undo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, StartPosition);
|
||||
}
|
||||
|
||||
public override void Redo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, EndPosition);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "PathNode " + (PathNode?._RawData.ToString() ?? "") + ": Position";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class TrainTrackNodePositionUndoStep : UndoStep
|
||||
{
|
||||
public TrainTrackNode Node { get; set; }
|
||||
public Vector3 StartPosition { get; set; }
|
||||
public Vector3 EndPosition { get; set; }
|
||||
|
||||
public TrainTrackNodePositionUndoStep(TrainTrackNode node, Vector3 startpos, WorldForm wf, ProjectForm pf)
|
||||
{
|
||||
Node = node;
|
||||
StartPosition = startpos;
|
||||
EndPosition = node?.Position ?? Vector3.Zero;
|
||||
|
||||
UpdateGraphics(wf, pf); //forces the update of the path graphics when it's moved...
|
||||
}
|
||||
|
||||
private void Update(WorldForm wf, ProjectForm pf, ref MapSelection sel, Vector3 p)
|
||||
{
|
||||
Node?.SetPosition(p);
|
||||
|
||||
if (Node != sel.TrainTrackNode)
|
||||
{
|
||||
wf.SelectTrainTrackNode(Node);
|
||||
}
|
||||
wf.SetWidgetPosition(p);
|
||||
|
||||
|
||||
UpdateGraphics(wf, pf);
|
||||
}
|
||||
|
||||
private void UpdateGraphics(WorldForm wf, ProjectForm pf)
|
||||
{
|
||||
if (Node != null)
|
||||
{
|
||||
//Ynd graphics needs to be updated.....
|
||||
wf.UpdateTrainTrackNodeGraphics(Node, false);
|
||||
if (pf != null) //make sure to update the project form UI..
|
||||
{
|
||||
pf.OnWorldTrainNodeModified(Node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void Undo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, StartPosition);
|
||||
}
|
||||
|
||||
public override void Redo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, EndPosition);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "TrainTrackNode " + (Node?.ToString() ?? "") + ": Position";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public class ScenarioNodePositionUndoStep : UndoStep
|
||||
{
|
||||
public ScenarioNode ScenarioNode { get; set; }
|
||||
public Vector3 StartPosition { get; set; }
|
||||
public Vector3 EndPosition { get; set; }
|
||||
|
||||
public ScenarioNodePositionUndoStep(ScenarioNode node, Vector3 startpos, WorldForm wf, ProjectForm pf)
|
||||
{
|
||||
ScenarioNode = node;
|
||||
StartPosition = startpos;
|
||||
EndPosition = node?.Position ?? Vector3.Zero;
|
||||
|
||||
UpdateGraphics(wf, pf); //forces the update of the path graphics when it's moved...
|
||||
}
|
||||
|
||||
private void Update(WorldForm wf, ProjectForm pf, ref MapSelection sel, Vector3 p)
|
||||
{
|
||||
ScenarioNode?.SetPosition(p);
|
||||
|
||||
if (ScenarioNode != sel.ScenarioNode) wf.SelectScenarioNode(ScenarioNode);
|
||||
wf.SetWidgetPosition(p);
|
||||
|
||||
UpdateGraphics(wf, pf);
|
||||
}
|
||||
|
||||
private void UpdateGraphics(WorldForm wf, ProjectForm pf)
|
||||
{
|
||||
if (ScenarioNode != null)
|
||||
{
|
||||
//Ymt graphics needs to be updated.....
|
||||
wf.UpdateScenarioGraphics(ScenarioNode.Ymt, false);
|
||||
if (pf != null) //make sure to update the project form UI..
|
||||
{
|
||||
pf.OnWorldScenarioNodeModified(ScenarioNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Undo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, StartPosition);
|
||||
}
|
||||
|
||||
public override void Redo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, EndPosition);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ScenarioNode.ToString() + ": Position";
|
||||
}
|
||||
}
|
||||
|
||||
public class ScenarioNodeRotationUndoStep : UndoStep
|
||||
{
|
||||
public ScenarioNode ScenarioNode { get; set; }
|
||||
public Quaternion StartRotation { get; set; }
|
||||
public Quaternion EndRotation { get; set; }
|
||||
|
||||
public ScenarioNodeRotationUndoStep(ScenarioNode node, Quaternion startrot, WorldForm wf, ProjectForm pf)
|
||||
{
|
||||
ScenarioNode = node;
|
||||
StartRotation = startrot;
|
||||
EndRotation = node?.Orientation ?? Quaternion.Identity;
|
||||
|
||||
//UpdateGraphics(wf, pf);
|
||||
}
|
||||
|
||||
|
||||
private void Update(WorldForm wf, ProjectForm pf, ref MapSelection sel, Quaternion q)
|
||||
{
|
||||
ScenarioNode?.SetOrientation(q);
|
||||
|
||||
if (ScenarioNode != sel.ScenarioNode) wf.SelectScenarioNode(ScenarioNode);
|
||||
wf.SetWidgetRotation(q);
|
||||
|
||||
//UpdateGraphics(wf, pf);
|
||||
}
|
||||
|
||||
private void UpdateGraphics(WorldForm wf, ProjectForm pf)
|
||||
{
|
||||
////this function shouldn't actually be needed for rotating...
|
||||
//if (ScenarioNode != null)
|
||||
//{
|
||||
// //Ymt graphics needs to be updated.....
|
||||
// wf.UpdateScenarioGraphics(ScenarioNode.Ymt, false);
|
||||
// if (pf != null) //make sure to update the project form UI..
|
||||
// {
|
||||
// pf.OnWorldScenarioNodeModified(ScenarioNode);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
public override void Undo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, StartRotation);
|
||||
}
|
||||
|
||||
public override void Redo(WorldForm wf, ProjectForm pf, ref MapSelection sel)
|
||||
{
|
||||
Update(wf, pf, ref sel, EndRotation);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ScenarioNode.ToString() + ": Rotation";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user