Skip to content

Commit

Permalink
refactor: move most scripts back to editor assembly
Browse files Browse the repository at this point in the history
  • Loading branch information
poi-vrc committed Aug 23, 2023
1 parent f581454 commit 79ac325
Show file tree
Hide file tree
Showing 180 changed files with 773 additions and 905 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
using System.Collections.Generic;
using Chocopoi.DressingTools.Cabinet;
using Chocopoi.DressingTools.Cabinet;
using Chocopoi.DressingTools.Dresser;
using Chocopoi.DressingTools.Lib.Cabinet;
using Chocopoi.DressingTools.Lib.Logging;
using Chocopoi.DressingTools.Lib.Wearable;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using UnityEngine;

namespace Chocopoi.DressingTools.Tests.Cabinet
{
public class CabinetApplierTest : DTTestBase
{
private static void ApplyCabinet(DTReport report, DTCabinet cabinet)
{
new CabinetApplier(report, cabinet).Execute();
}

[Test]
public void AvatarWithOneWearable_AppliesNormally()
{
var avatarRoot = InstantiateRuntimeTestPrefab("DTTest_PhysBoneAvatarWithWearable.prefab");
var avatarRoot = InstantiateEditorTestPrefab("DTTest_PhysBoneAvatarWithWearable.prefab");
var cabinet = avatarRoot.GetComponent<DTCabinet>();

var report = new DTReport();
cabinet.Apply(report);
ApplyCabinet(report, cabinet);

Assert.False(report.HasLogType(DTReportLogType.Error), "Should have no errors");
}
Expand All @@ -41,7 +41,7 @@ public void AvatarWithOneWearable_AppliesNormally()
// wearableComp.configJson = json.ToString(Formatting.None);

// var report = new DTReport();
// cabinet.Apply(report);
// ApplyCabinet(report, cabinet);

// Assert.True(report.HasLogCode(CabinetApplier.MessageCode.IncompatibleConfigVersion), "Should have incompatible config version error");
// }
Expand All @@ -51,7 +51,7 @@ public void AvatarWithOneWearable_AppliesNormally()
[Test]
public void ConfigDeserializationFailure_ReturnsCorrectErrorCodes()
{
var avatarRoot = InstantiateRuntimeTestPrefab("DTTest_PhysBoneAvatarWithWearable.prefab");
var avatarRoot = InstantiateEditorTestPrefab("DTTest_PhysBoneAvatarWithWearable.prefab");
var cabinet = avatarRoot.GetComponent<DTCabinet>();

// we simulate this by destroying the config json
Expand All @@ -60,21 +60,21 @@ public void ConfigDeserializationFailure_ReturnsCorrectErrorCodes()
wearableComp.configJson = "ababababababababa";

var report = new DTReport();
cabinet.Apply(report);
ApplyCabinet(report, cabinet);

Assert.True(report.HasLogCode(CabinetApplier.MessageCode.UnableToDeserializeConfig), "Should have deserialization error");
}

[Test]
public void GroupDynamicsToSeparateGameObjectsCorrectly()
{
var avatarRoot = InstantiateRuntimeTestPrefab("DTTest_PhysBoneAvatarWithWearableOtherDynamics.prefab");
var avatarRoot = InstantiateEditorTestPrefab("DTTest_PhysBoneAvatarWithWearableOtherDynamics.prefab");
var cabinet = avatarRoot.GetComponent<DTCabinet>();

var report = new DTReport();
cabinet.GroupDynamics = true;
cabinet.GroupDynamicsSeparateGameObjects = true;
cabinet.Apply(report);
cabinet.groupDynamics = true;
cabinet.groupDynamicsSeparateGameObjects = true;
ApplyCabinet(report, cabinet);

Assert.False(report.HasLogType(DTReportLogType.Error), "Should have no errors");

Expand All @@ -87,7 +87,7 @@ public void GroupDynamicsToSeparateGameObjectsCorrectly()
Assert.NotNull(dynamicsContainer);

// check dynamics
var wearableDynamicsList = DTRuntimeUtils.ScanDynamics(wearableRoot.gameObject);
var wearableDynamicsList = DTEditorUtils.ScanDynamics(wearableRoot.gameObject);
foreach (var wearableDynamics in wearableDynamicsList)
{
Assert.AreEqual(dynamicsContainer, wearableDynamics.Transform.parent);
Expand All @@ -97,13 +97,13 @@ public void GroupDynamicsToSeparateGameObjectsCorrectly()
[Test]
public void GroupDynamicsToSingleGameObjectCorrectly()
{
var avatarRoot = InstantiateRuntimeTestPrefab("DTTest_PhysBoneAvatarWithWearableOtherDynamics.prefab");
var avatarRoot = InstantiateEditorTestPrefab("DTTest_PhysBoneAvatarWithWearableOtherDynamics.prefab");
var cabinet = avatarRoot.GetComponent<DTCabinet>();

var report = new DTReport();
cabinet.GroupDynamics = true;
cabinet.GroupDynamicsSeparateGameObjects = false;
cabinet.Apply(report);
cabinet.groupDynamics = true;
cabinet.groupDynamicsSeparateGameObjects = false;
ApplyCabinet(report, cabinet);

Assert.False(report.HasLogType(DTReportLogType.Error), "Should have no errors");

Expand All @@ -116,7 +116,7 @@ public void GroupDynamicsToSingleGameObjectCorrectly()
Assert.NotNull(dynamicsContainer);

// check dynamics
var wearableDynamicsList = DTRuntimeUtils.ScanDynamics(wearableRoot.gameObject);
var wearableDynamicsList = DTEditorUtils.ScanDynamics(wearableRoot.gameObject);
foreach (var wearableDynamics in wearableDynamicsList)
{
Assert.AreEqual(dynamicsContainer, wearableDynamics.Transform);
Expand All @@ -126,11 +126,11 @@ public void GroupDynamicsToSingleGameObjectCorrectly()
[Test]
public void ApplyErrors_ReturnsCorrectErrorCodes()
{
var avatarRoot = InstantiateRuntimeTestPrefab("DTTest_PhysBoneAvatarWithWearableModuleError.prefab");
var avatarRoot = InstantiateEditorTestPrefab("DTTest_PhysBoneAvatarWithWearableModuleError.prefab");
var cabinet = avatarRoot.GetComponent<DTCabinet>();

var report = new DTReport();
cabinet.Apply(report);
ApplyCabinet(report, cabinet);

Assert.True(report.HasLogCode(DefaultDresser.MessageCode.NoArmatureInWearable), "Should have NoArmatureInWearable error");
Assert.True(report.HasLogCode(CabinetApplier.MessageCode.ApplyingModuleHasErrors), "Should have ApplyingModuleHasErrors error");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,61 +1,65 @@
using System.Collections;
using System.Collections.Generic;
using Chocopoi.DressingTools.Cabinet;
using Chocopoi.DressingTools.Lib.Cabinet;
using Chocopoi.DressingTools.Lib.Logging;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;

namespace Chocopoi.DressingTools.Tests.Cabinet
{
public class DTCabinetTest : DTTestBase
{
private static void ApplyCabinet(DTReport report, DTCabinet cabinet)
{
new CabinetApplier(report, cabinet).Execute();
}

[Test]
public void GetterSetterTest()
{
var cabinetGo = CreateGameObject("GetterSetterTestGameObject");
var cabinet = cabinetGo.AddComponent<DTCabinet>();

var obj = CreateGameObject("SomeGameObject");
cabinet.AvatarGameObject = obj;
Assert.AreEqual(obj, cabinet.AvatarGameObject);
cabinet.avatarGameObject = obj;
Assert.AreEqual(obj, cabinet.avatarGameObject);

var randomString = "SomeString";
cabinet.AvatarArmatureName = randomString;
Assert.AreEqual(randomString, cabinet.AvatarArmatureName);
cabinet.avatarArmatureName = randomString;
Assert.AreEqual(randomString, cabinet.avatarArmatureName);

var val = !cabinet.GroupDynamics;
cabinet.GroupDynamics = val;
Assert.AreEqual(val, cabinet.GroupDynamics);
var val = !cabinet.groupDynamics;
cabinet.groupDynamics = val;
Assert.AreEqual(val, cabinet.groupDynamics);

val = !cabinet.GroupDynamicsSeparateGameObjects;
cabinet.GroupDynamicsSeparateGameObjects = val;
Assert.AreEqual(val, cabinet.GroupDynamicsSeparateGameObjects);
val = !cabinet.groupDynamicsSeparateGameObjects;
cabinet.groupDynamicsSeparateGameObjects = val;
Assert.AreEqual(val, cabinet.groupDynamicsSeparateGameObjects);
}

[Test]
public void GetWearables_NoAvatarGameObject_ReturnsEmptyArray()
{
var cabinetGo = CreateGameObject("GetWearablesGameObject");
var cabinet = cabinetGo.AddComponent<DTCabinet>();
cabinet.AvatarGameObject = null;
cabinet.avatarGameObject = null;

Assert.IsNull(cabinet.AvatarGameObject);
Assert.IsNull(cabinet.avatarGameObject);

var wearables = cabinet.GetWearables();
var wearables = DTEditorUtils.GetCabinetWearables(cabinet);
Assert.NotNull(wearables);
Assert.AreEqual(0, wearables.Length);
}

[Test]
public void GetWearables_ReturnsOneWearable()
{
var avatarRoot = InstantiateRuntimeTestPrefab("DTTest_PhysBoneAvatarWithWearable.prefab");
var avatarRoot = InstantiateEditorTestPrefab("DTTest_PhysBoneAvatarWithWearable.prefab");

var cabinet = avatarRoot.GetComponent<DTCabinet>();
Assert.NotNull(cabinet);

var wearables = cabinet.GetWearables();
var wearables = DTEditorUtils.GetCabinetWearables(cabinet);
Assert.NotNull(wearables);
Assert.AreEqual(1, wearables.Length);

Expand All @@ -66,21 +70,21 @@ public void GetWearables_ReturnsOneWearable()
[Test]
public void ApplyInEditorMode_AppliesNormally()
{
var avatarRoot = InstantiateRuntimeTestPrefab("DTTest_PhysBoneAvatarWithWearable.prefab");
var avatarRoot = InstantiateEditorTestPrefab("DTTest_PhysBoneAvatarWithWearable.prefab");

var cabinet = avatarRoot.GetComponent<DTCabinet>();
Assert.NotNull(cabinet);

var report = new DTReport();
cabinet.Apply(report);
ApplyCabinet(report, cabinet);

Assert.False(report.HasLogType(DTReportLogType.Error), "Should have no errors");
}

[UnityTest]
public IEnumerator ApplyInPlayModeOnLoad_AppliesNormally()
{
var avatarRoot = InstantiateRuntimeTestPrefab("DTTest_PhysBoneAvatarWithWearable.prefab");
var avatarRoot = InstantiateEditorTestPrefab("DTTest_PhysBoneAvatarWithWearable.prefab");
yield return null;
// we are unable to check DTReport logs so we just check is the armature empty here
var wearableRoot = avatarRoot.transform.Find("DTTest_PhysBoneWearable");
Expand Down
Loading

0 comments on commit 79ac325

Please sign in to comment.