Skip to content

Commit

Permalink
feat: verify and migrate config version in DTCabinetApplier
Browse files Browse the repository at this point in the history
  • Loading branch information
poi-vrc committed Aug 17, 2023
1 parent d3cb029 commit 464a69d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public static class MessageCode
public const string UnableToDeserializeConfig = "appliers.default.msgCode.error.unableToDeserializeConfig";
public const string ApplyingModuleHasErrors = "appliers.default.msgCode.error.applyingModuleHasErrors";
public const string ApplyingWearableHasErrors = "appliers.default.msgCode.error.applyingWearableHasErrors";
public const string IncompatibleConfigVersion = "appliers.default.msgCode.error.incompatibleConfigVersion";
public const string ConfigMigrationFailed = "appliers.default.msgCode.error.configMigrationFailed";
}

private DTReport _report;
Expand Down Expand Up @@ -116,20 +118,9 @@ private void RollbackTransform(Transform lastAvatarParent, Vector3 lastAvatarSca

private bool ApplyWearable(DTWearableConfig config, GameObject wearableGameObject)
{
// TODO: check config version and do migration here

// TODO: do avatar GUID check?

// TODO: is this check still necessary now?
GameObject wearableObj;
if (DTRuntimeUtils.IsGrandParent(_cabinet.avatarGameObject.transform, wearableGameObject.transform))
{
//// check if it's a prefab
//if (PrefabUtility.IsPartOfAnyPrefab(wearable.wearableGameObject))
//{
// // unpack completely the prefab
// PrefabUtility.UnpackPrefabInstance(wearable.wearableGameObject, PrefabUnpackMode.Completely, InteractionMode.AutomatedAction);
//}
wearableObj = wearableGameObject;
}
else
Expand Down Expand Up @@ -174,6 +165,24 @@ public void Execute()
// deserialize the config
var config = JsonConvert.DeserializeObject<DTWearableConfig>(wearable.configJson);

// Migration
if (config.configVersion > DTWearableConfig.CurrentConfigVersion)
{
_report.LogErrorLocalized(LogLabel, MessageCode.IncompatibleConfigVersion);
break;
}
else if (config.configVersion < DTWearableConfig.CurrentConfigVersion)
{
var result = DTWearableConfigMigrator.Migrate(wearable.configJson, out var migratedJson);
if (!result)
{
_report.LogErrorLocalized(LogLabel, MessageCode.ConfigMigrationFailed);
break;
}
wearable.configJson = migratedJson;
config = JsonConvert.DeserializeObject<DTWearableConfig>(migratedJson);
}

if (config == null)
{
_report.LogErrorLocalized(LogLabel, MessageCode.UnableToDeserializeConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@

namespace Chocopoi.DressingTools.Wearable
{
public class DTWearableConfigMigrator
{
public static bool Migrate(string inputJson, out string outputJson)
{
// TODO: do migration if necessary
outputJson = inputJson;
return false;
}
}

// serialization is handled by newtonsoft json
public class DTWearableConfig
{
Expand Down

0 comments on commit 464a69d

Please sign in to comment.