Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full MVVM refactor #56

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

1 change: 0 additions & 1 deletion GLWpfControl
Submodule GLWpfControl deleted from 2fae25
10 changes: 0 additions & 10 deletions TT Lab.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TT Lab", "TT Lab\TT Lab.csp
{14348117-4503-49CD-94F9-1852069543E3} = {14348117-4503-49CD-94F9-1852069543E3}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GLWpfControl", "GLWpfControl\src\GLWpfControl\GLWpfControl.csproj", "{FA7C1291-E0F8-4C2F-8964-DE992B00E568}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -45,14 +43,6 @@ Global
{640EEAEC-CB84-4499-B5A9-E084CAB68D91}.Release|Any CPU.Build.0 = Release|Any CPU
{640EEAEC-CB84-4499-B5A9-E084CAB68D91}.Release|x64.ActiveCfg = Release|x64
{640EEAEC-CB84-4499-B5A9-E084CAB68D91}.Release|x64.Build.0 = Release|x64
{FA7C1291-E0F8-4C2F-8964-DE992B00E568}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA7C1291-E0F8-4C2F-8964-DE992B00E568}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA7C1291-E0F8-4C2F-8964-DE992B00E568}.Debug|x64.ActiveCfg = Debug|Any CPU
{FA7C1291-E0F8-4C2F-8964-DE992B00E568}.Debug|x64.Build.0 = Debug|Any CPU
{FA7C1291-E0F8-4C2F-8964-DE992B00E568}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA7C1291-E0F8-4C2F-8964-DE992B00E568}.Release|Any CPU.Build.0 = Release|Any CPU
{FA7C1291-E0F8-4C2F-8964-DE992B00E568}.Release|x64.ActiveCfg = Release|Any CPU
{FA7C1291-E0F8-4C2F-8964-DE992B00E568}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
45 changes: 0 additions & 45 deletions TT Lab/About.xaml

This file was deleted.

6 changes: 4 additions & 2 deletions TT Lab/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TT_Lab"
xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI"
xmlns:adonisControls="clr-namespace:AdonisUI.Controls;assembly=AdonisUI"
StartupUri="MainWindow.xaml">
xmlns:adonisControls="clr-namespace:AdonisUI.Controls;assembly=AdonisUI">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/AdonisUI;component/ColorSchemes/Dark.xaml"/>
<ResourceDictionary Source="pack://application:,,,/AdonisUI.ClassicTheme;component/Resources.xaml"/>
<ResourceDictionary Source="LabStyles.xaml"/>
<ResourceDictionary>
<local:Bootstrapper x:Key="Bootstrapper"/>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Expand Down
21 changes: 18 additions & 3 deletions TT Lab/AssetData/AbstractAssetData.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Newtonsoft.Json;
using Caliburn.Micro;
using Newtonsoft.Json;
using System;
using System.Diagnostics;
using TT_Lab.Assets;
using TT_Lab.Assets.Factory;
using TT_Lab.Project;
using Twinsanity.TwinsanityInterchange.Interfaces;

namespace TT_Lab.AssetData
Expand All @@ -19,7 +21,7 @@ public abstract class AbstractAssetData : IDisposable
public void Load(String dataPath, JsonSerializerSettings? settings = null)
{
var workingDirectory = System.IO.Directory.GetCurrentDirectory();
System.IO.Directory.SetCurrentDirectory(Project.ProjectManagerSingleton.PM.OpenedProject!.ProjectPath);
System.IO.Directory.SetCurrentDirectory(IoC.Get<ProjectManager>().OpenedProject!.ProjectPath);
LoadInternal(dataPath, settings);
System.IO.Directory.SetCurrentDirectory(workingDirectory);
}
Expand All @@ -32,7 +34,20 @@ protected virtual void LoadInternal(String dataPath, JsonSerializerSettings? set
disposedValue = false;
}

public virtual void Save(String dataPath, JsonSerializerSettings? settings = null)
public void Save(String dataPath, JsonSerializerSettings? settings = null)
{
var workingDirectory = System.IO.Directory.GetCurrentDirectory();
System.IO.Directory.SetCurrentDirectory($"{IoC.Get<ProjectManager>().OpenedProject!.ProjectPath}\\assets");
SaveInternal(dataPath, settings);
System.IO.Directory.SetCurrentDirectory(workingDirectory);
}

public void SaveInCurrentDirectory(String dataPath, JsonSerializerSettings? settings = null)
{
SaveInternal(dataPath, settings);
}

protected virtual void SaveInternal(String dataPath, JsonSerializerSettings? settings = null)
{
using System.IO.FileStream fs = new(dataPath, System.IO.FileMode.Create, System.IO.FileAccess.Write);
using System.IO.BinaryWriter writer = new(fs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public BehaviourCommandsSequenceData(ITwinBehaviourCommandsSequence codeModel) :
public String Code { get; set; }
public List<UInt32> BehaviourGraphIds { get; set; }

public override void Save(string dataPath, JsonSerializerSettings? settings = null)
protected override void SaveInternal(string dataPath, JsonSerializerSettings? settings = null)
{
using FileStream fs = new(dataPath, FileMode.Create, FileAccess.Write);
using BinaryWriter writer = new(fs);
Expand Down
2 changes: 1 addition & 1 deletion TT Lab/AssetData/Code/Behaviour/BehaviourGraphData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected override void Dispose(Boolean disposing)
Graph = "";
}

public override void Save(string dataPath, JsonSerializerSettings? settings = null)
protected override void SaveInternal(string dataPath, JsonSerializerSettings? settings = null)
{
using var fs = new FileStream(dataPath, FileMode.Create, FileAccess.Write);
using var writer = new BinaryWriter(fs);
Expand Down
2 changes: 1 addition & 1 deletion TT Lab/AssetData/Code/SoundEffectData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected override void Dispose(Boolean disposing)
return;
}

public override void Save(string dataPath, JsonSerializerSettings? settings = null)
protected override void SaveInternal(string dataPath, JsonSerializerSettings? settings = null)
{
using FileStream fs = new(dataPath, FileMode.Create, FileAccess.Write);
using BinaryWriter writer = new(fs);
Expand Down
4 changes: 2 additions & 2 deletions TT Lab/AssetData/Global/PTCData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public override void Import(LabURI package, String? variant, Int32? layoutId)
{
var assetManager = AssetManager.Get();
var ptc = GetTwinItem<ITwinPTC>();
var texture = new Texture(package, true, $"{ptc.GetName()}_Texture_{variant}", ptc.TexID, $"{ptc.GetName()}_Texture", ptc.Texture);
var texture = new Texture(package, true, $"{ptc.GetName()}_{variant}", ptc.TexID, $"{ptc.GetName()}_Texture", ptc.Texture);
assetManager.AddAssetToImport(texture);
var material = new Material(package, true, $"{ptc.GetName()}_Material_{variant}", ptc.MatID, $"{ptc.GetName()}_Material", ptc.Material);
var material = new Material(package, true, $"{ptc.GetName()}_{variant}", ptc.MatID, $"{ptc.GetName()}_Material", ptc.Material);
assetManager.AddAssetToImport(material);

TextureID = texture.URI;
Expand Down
2 changes: 1 addition & 1 deletion TT Lab/AssetData/Global/SaveIconData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public override void Import(LabURI package, String? variant, Int32? layoutId)
return;
}

public override void Save(String dataPath, JsonSerializerSettings? settings = null)
protected override void SaveInternal(String dataPath, JsonSerializerSettings? settings = null)
{
using var fs = new FileStream(dataPath, FileMode.Create, FileAccess.Write);
using var writer = new BinaryWriter(fs);
Expand Down
2 changes: 1 addition & 1 deletion TT Lab/AssetData/Global/TextFileData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public override void Import(LabURI package, String? variant, Int32? layoutId)
return;
}

public override void Save(String dataPath, JsonSerializerSettings? settings = null)
protected override void SaveInternal(String dataPath, JsonSerializerSettings? settings = null)
{
using var fs = new FileStream(dataPath, FileMode.Create, FileAccess.Write);
using var writer = new BinaryWriter(fs);
Expand Down
4 changes: 2 additions & 2 deletions TT Lab/AssetData/Graphics/BlendSkinData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected override void Dispose(Boolean disposing)
Blends.Clear();
}

public override void Save(String dataPath, JsonSerializerSettings? settings = null)
protected override void SaveInternal(String dataPath, JsonSerializerSettings? settings = null)
{
var scene = new SharpGLTF.Scenes.SceneBuilder("TwinsanityBlendSkin");
var root = new SharpGLTF.Scenes.NodeBuilder("blend_skin_root");
Expand Down Expand Up @@ -122,7 +122,7 @@ static VERTEX_BUILDER generateVertexFromTwinVertex(Vertex vertex)
{
var mesh = new MeshBuilder<VERTEX, COLOR_UV, JOINT_WEIGHT>($"blend_subskin_{index++}");
var blendShapeInfo = System.Text.Json.JsonSerializer.Serialize(blendModel.BlendShape);
mesh.Extras = SharpGLTF.IO.JsonContent.Serialize(blendModel.BlendShape);
mesh.Extras = System.Text.Json.Nodes.JsonNode.Parse(System.Text.Json.JsonSerializer.Serialize(blendModel.BlendShape));

foreach (var face in blendModel.Faces)
{
Expand Down
3 changes: 1 addition & 2 deletions TT Lab/AssetData/Graphics/ModelData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected override void Dispose(Boolean disposing)
Meshes.Clear();
}

public override void Save(string dataPath, JsonSerializerSettings? settings = null)
protected override void SaveInternal(string dataPath, JsonSerializerSettings? settings = null)
{
var material = new SharpGLTF.Materials.MaterialBuilder()
.WithDoubleSide(true)
Expand Down Expand Up @@ -246,7 +246,6 @@ protected override void LoadInternal(String dataPath, JsonSerializerSettings? se
if (vertexes.Colors1 != null)
{
ver.EmitColor = vertexes.Colors1[i].ToTwin();
ver.EmitColor = new Vector4(ver.EmitColor.X * 255, ver.EmitColor.Y * 255, ver.EmitColor.Z * 255, ver.EmitColor.W * 255);
}
submodel.Add(ver);
}
Expand Down
4 changes: 2 additions & 2 deletions TT Lab/AssetData/Graphics/Shaders/LabShader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using TT_Lab.Assets;
using TT_Lab.Assets.Graphics;
using TT_Lab.Util;
using TT_Lab.ViewModels.Graphics;
using TT_Lab.ViewModels.Editors.Graphics;
using Twinsanity.TwinsanityInterchange.Common;
using Twinsanity.TwinsanityInterchange.Common.ShaderAnimation;
using static Twinsanity.TwinsanityInterchange.Common.TwinShader;
Expand Down Expand Up @@ -54,7 +54,7 @@ public class LabShader

public LabShader() { }

public LabShader(LabShaderViewModel vm)
public LabShader(ShaderViewModel vm)
{
ShaderType = vm.Type;
IntParam = vm.IntParam;
Expand Down
4 changes: 2 additions & 2 deletions TT Lab/AssetData/Graphics/SkinData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected override void Dispose(Boolean disposing)
SubSkins.Clear();
}

public override void Save(string dataPath, JsonSerializerSettings? settings = null)
protected override void SaveInternal(string dataPath, JsonSerializerSettings? settings = null)
{
var scene = new SharpGLTF.Scenes.SceneBuilder("TwinsanitySkin");
var root = new SharpGLTF.Scenes.NodeBuilder("skin_root");
Expand Down Expand Up @@ -151,7 +151,7 @@ protected override void LoadInternal(String dataPath, JsonSerializerSettings? se
vertexes.Positions[i].ToTwin(),
vertexes.Colors0[i].ToTwin(),
vertexes.TexCoords0[i].ToTwin());
ver.Color = new Twinsanity.TwinsanityInterchange.Common.Vector4(ver.Color.X * 255, ver.Color.Y * 255, ver.Color.Z * 255, ver.Color.W * 255);
ver.Color = new Twinsanity.TwinsanityInterchange.Common.Vector4(ver.Color.X, ver.Color.Y, ver.Color.Z, ver.Color.W);
ver.JointInfo.JointIndex1 = (Int32)vertexes.Joints0[i].X;
ver.JointInfo.JointIndex2 = (Int32)vertexes.Joints0[i].Y;
ver.JointInfo.JointIndex3 = (Int32)vertexes.Joints0[i].Z;
Expand Down
4 changes: 2 additions & 2 deletions TT Lab/AssetData/Graphics/SubModels/SubBlendData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public SubBlendData(LabURI material, IEnumerable<SharpGLTF.Schema2.Mesh> meshes,
var allVertexes = new List<Vertex>();
var allIndices = new List<IndexedFace>();
var indiceAccessor = 0;
var blendShape = (Vector3)mesh.Extras.Deserialize(typeof(Vector3));
var blendShape = mesh.Extras.AsValue().GetValue<Vector3>();
var primitive = mesh.Primitives[0];
var vertexes = primitive.GetVertexColumns();
var indices = primitive.GetTriangleIndices();
Expand All @@ -57,7 +57,7 @@ public SubBlendData(LabURI material, IEnumerable<SharpGLTF.Schema2.Mesh> meshes,
vertexes.Positions[i].ToTwin(),
vertexes.Colors0[i].ToTwin(),
vertexes.TexCoords0[i].ToTwin());
ver.Color = new Vector4(ver.Color.X * 255, ver.Color.Y * 255, ver.Color.Z * 255, ver.Color.W * 255);
ver.Color = new Vector4(ver.Color.X, ver.Color.Y, ver.Color.Z, ver.Color.W);
ver.JointInfo.JointIndex1 = (Int32)vertexes.Joints0[i].X;
ver.JointInfo.JointIndex2 = (Int32)vertexes.Joints0[i].Y;
ver.JointInfo.JointIndex3 = (Int32)vertexes.Joints0[i].Z;
Expand Down
2 changes: 1 addition & 1 deletion TT Lab/AssetData/Graphics/TextureData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected override void Dispose(Boolean disposing)
Bitmap.Dispose();
}
}
public override void Save(string dataPath, JsonSerializerSettings? settings = null)
protected override void SaveInternal(string dataPath, JsonSerializerSettings? settings = null)
{
if (Bitmap != null && !Disposed)
{
Expand Down
2 changes: 1 addition & 1 deletion TT Lab/AssetData/Instance/Scenery/SceneryBaseData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using TT_Lab.Assets.Factory;
using TT_Lab.Assets.Graphics;
using TT_Lab.Util;
using TT_Lab.ViewModels.Instance.Scenery;
using TT_Lab.ViewModels.Editors.Instance.Scenery;
using Twinsanity.TwinsanityInterchange.Common;
using Twinsanity.TwinsanityInterchange.Common.ScenerySubtypes;
using Twinsanity.TwinsanityInterchange.Enumerations;
Expand Down
2 changes: 1 addition & 1 deletion TT Lab/AssetData/Instance/Scenery/SceneryLeafData.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using TT_Lab.Assets;
using TT_Lab.ViewModels.Instance.Scenery;
using TT_Lab.ViewModels.Editors.Instance.Scenery;
using Twinsanity.TwinsanityInterchange.Common.ScenerySubtypes;

namespace TT_Lab.AssetData.Instance.Scenery
Expand Down
2 changes: 1 addition & 1 deletion TT Lab/AssetData/Instance/Scenery/SceneryNodeData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.IO;
using TT_Lab.Assets;
using TT_Lab.Util;
using TT_Lab.ViewModels.Instance.Scenery;
using TT_Lab.ViewModels.Editors.Instance.Scenery;
using Twinsanity.TwinsanityInterchange.Common.ScenerySubtypes;
using Twinsanity.TwinsanityInterchange.Interfaces.Items.SM;

Expand Down
2 changes: 1 addition & 1 deletion TT Lab/AssetData/Instance/Scenery/SceneryRootData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System;
using System.IO;
using TT_Lab.Assets;
using TT_Lab.ViewModels.Instance.Scenery;
using TT_Lab.ViewModels.Editors.Instance.Scenery;
using Twinsanity.TwinsanityInterchange.Common.ScenerySubtypes;
using Twinsanity.TwinsanityInterchange.Interfaces.Items.SM;

Expand Down
4 changes: 2 additions & 2 deletions TT Lab/AssetData/Instance/SceneryData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ protected override void Dispose(Boolean disposing)
Sceneries.Clear();
}

public override void Save(String dataPath, JsonSerializerSettings? settings = null)
protected override void SaveInternal(String dataPath, JsonSerializerSettings? settings = null)
{
settings = new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.All
};
base.Save(dataPath, settings);
base.SaveInternal(dataPath, settings);
}

protected override void LoadInternal(String dataPath, JsonSerializerSettings? settings = null)
Expand Down
8 changes: 6 additions & 2 deletions TT Lab/Assets/AssetManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Caliburn.Micro;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
Expand All @@ -15,6 +16,9 @@ public class AssetManager
private AssetStorage _assets = new();
private AssetStorage _importAssets = new();

// TODO: Check if locks are required to access assets for thread-safety
//private object assetAccessLock = new object();

public AssetManager() { }

public AssetManager(Dictionary<LabURI, IAsset> assets)
Expand Down Expand Up @@ -105,7 +109,7 @@ public void RemoveAsset(LabURI uri)
/// <returns>AssetManager for the currently opened project</returns>
public static AssetManager Get()
{
return ProjectManagerSingleton.PM.OpenedProject!.AssetManager;
return IoC.Get<ProjectManager>().OpenedProject!.AssetManager;
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions TT Lab/Assets/ChunkFolder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using TT_Lab.AssetData;
using TT_Lab.Editors;
using TT_Lab.ViewModels.Editors;

namespace TT_Lab.Assets
{
Expand Down Expand Up @@ -34,7 +34,7 @@ public override AbstractAssetData GetData()

public override Type GetEditorType()
{
return typeof(ChunkEditor);
return typeof(ChunkEditorViewModel);
}
}
}
Loading