Skip to content

Commit

Permalink
Merge pull request #60 from CyberAgentGameEntertainment/feature/corru…
Browse files Browse the repository at this point in the history
…ption_notification

Feature/corruption notification
  • Loading branch information
Haruma-K authored Oct 7, 2024
2 parents 7ad4493 + e49610e commit 2686bed
Show file tree
Hide file tree
Showing 61 changed files with 1,239 additions and 225 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using SmartAddresser.Editor.Core.Models.Shared;
using SmartAddresser.Editor.Core.Models.Shared.AssetGroups;
using SmartAddresser.Editor.Core.Models.Shared.AssetGroups.ValidationError;
using SmartAddresser.Editor.Foundation.TinyRx.ObservableCollection;
using SmartAddresser.Editor.Foundation.TinyRx.ObservableProperty;
using UnityEditor.AddressableAssets.Settings;
Expand All @@ -19,9 +20,9 @@ public sealed class AddressRule : ISerializationCallbackReceiver
[SerializeField] private ObservableProperty<bool> _control = new ObservableProperty<bool>();
[SerializeField] private AssetGroupObservableList _assetGroups = new AssetGroupObservableList();

private ObservableProperty<string> _addressProviderDescription = new ObservableProperty<string>();

[SerializeReference] private IAddressProvider _addressProviderInternal;

private ObservableProperty<string> _addressProviderDescription = new ObservableProperty<string>();
private ObservableProperty<string> _assetGroupDescription = new ObservableProperty<string>();

// Define the default constructor for serialization.
Expand Down Expand Up @@ -76,6 +77,24 @@ public void Setup()
AddressProvider.Value.Setup();
}

public bool Validate(out AddressRuleValidationError error)
{
if (!_control.Value)
{
error = null;
return true;
}

if (_assetGroups.Validate(out var groupErrors))
{
error = null;
return true;
}

error = new AddressRuleValidationError(this, groupErrors);
return false;
}

/// <summary>
/// Provide an address from asset information.
/// </summary>
Expand All @@ -88,8 +107,13 @@ public void Setup()
/// You can pass false if it is guaranteed to be valid.
/// </param>
/// <returns>Return true if successful.</returns>
public bool TryProvideAddress(string assetPath, Type assetType, bool isFolder, out string address,
bool checkIsPathValidForEntry = true)
public bool TryProvideAddress(
string assetPath,
Type assetType,
bool isFolder,
out string address,
bool checkIsPathValidForEntry = true
)
{
// If this addressable group is not the control target, do nothing.
if (!Control.Value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using SmartAddresser.Editor.Core.Models.Shared;
using SmartAddresser.Editor.Core.Models.Shared.AssetGroups;
using SmartAddresser.Editor.Core.Models.Shared.AssetGroups.ValidationError;
using SmartAddresser.Editor.Foundation.TinyRx.ObservableCollection;
using SmartAddresser.Editor.Foundation.TinyRx.ObservableProperty;
using UnityEngine;
Expand All @@ -17,11 +18,11 @@ public sealed class LabelRule : ISerializationCallbackReceiver
[SerializeField] private ObservableProperty<string> _name = new ObservableProperty<string>("New Label Rule");
[SerializeField] private AssetGroupObservableList _assetGroups = new AssetGroupObservableList();

[SerializeReference] private ILabelProvider _labelProviderInternal;

private ObservableProperty<string> _assetGroupDescription = new ObservableProperty<string>();
private ObservableProperty<string> _labelProviderDescription = new ObservableProperty<string>();

[SerializeReference] private ILabelProvider _labelProviderInternal;

public LabelRule()
{
_id = IdentifierFactory.Create();
Expand Down Expand Up @@ -65,6 +66,18 @@ public void Setup()
LabelProvider.Value.Setup();
}

public bool Validate(out LabelRuleValidationError error)
{
if (_assetGroups.Validate(out var groupErrors))
{
error = null;
return true;
}

error = new LabelRuleValidationError(this, groupErrors);
return false;
}

/// <summary>
/// Create a label from asset information.
/// </summary>
Expand All @@ -77,8 +90,13 @@ public void Setup()
/// You can pass false if it is guaranteed to be valid.
/// </param>
/// <returns>Return true if successful.</returns>
public bool TryProvideLabel(string assetPath, Type assetType, bool isFolder, out string label,
bool checkIsPathValidForEntry = true)
public bool TryProvideLabel(
string assetPath,
Type assetType,
bool isFolder,
out string label,
bool checkIsPathValidForEntry = true
)
{
if (!_assetGroups.Contains(assetPath, assetType, isFolder))
{
Expand Down
84 changes: 57 additions & 27 deletions Assets/SmartAddresser/Editor/Core/Models/LayoutRules/LayoutRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using SmartAddresser.Editor.Core.Models.LayoutRules.LabelRules;
using SmartAddresser.Editor.Core.Models.LayoutRules.Settings;
using SmartAddresser.Editor.Core.Models.LayoutRules.VersionRules;
using SmartAddresser.Editor.Core.Models.Shared.AssetGroups.ValidationError;
using SmartAddresser.Editor.Foundation.TinyRx.ObservableCollection;
using UnityEditor.AddressableAssets.Settings;
using UnityEngine;
Expand All @@ -24,6 +25,16 @@ public sealed class LayoutRule
public IObservableList<LabelRule> LabelRules => _labelRules;
public IObservableList<VersionRule> VersionRules => _versionRules;

public void Setup()
{
foreach (var addressRule in _addressRules)
addressRule.Setup();
foreach (var labelRule in _labelRules)
labelRule.Setup();
foreach (var versionRule in _versionRules)
versionRule.Setup();
}

/// <summary>
/// <para>* If there is no address group that hold the addressable group, add it.</para>
/// <para>* Remove address rules that hold addressable groups that no longer exists.</para>
Expand All @@ -35,11 +46,8 @@ public bool SyncAddressRulesWithAddressableAssetGroups(List<AddressableAssetGrou
{
var isDirty = false;
if (addressableGroups.Count != _addressRules.Count)
{
isDirty = true;
}
else
{
for (var i = 0; i < addressableGroups.Count; i++)
{
var addressableGroup = addressableGroups[i];
Expand All @@ -50,11 +58,10 @@ public bool SyncAddressRulesWithAddressableAssetGroups(List<AddressableAssetGrou
break;
}
}
}

if (!isDirty)
return false;

var newList = new List<AddressRule>();
foreach (var addressableGroup in addressableGroups)
{
Expand All @@ -70,14 +77,14 @@ public bool SyncAddressRulesWithAddressableAssetGroups(List<AddressableAssetGrou
return true;
}

public void SetupForAddress()
{
foreach (var addressRule in _addressRules)
addressRule.Setup();
}

public bool TryProvideAddressAndAddressableGroup(string assetPath, Type assetType, bool isFolder, bool doSetup,
out string address, out AddressableAssetGroup addressableGroup)
public bool TryProvideAddressAndAddressableGroup(
string assetPath,
Type assetType,
bool isFolder,
bool doSetup,
out string address,
out AddressableAssetGroup addressableGroup
)
{
foreach (var addressRule in _addressRules)
{
Expand All @@ -97,12 +104,6 @@ public bool TryProvideAddressAndAddressableGroup(string assetPath, Type assetTyp
return false;
}

public void SetupForLabels()
{
foreach (var labelRule in _labelRules)
labelRule.Setup();
}

/// <summary>
/// Provide the labels.
/// </summary>
Expand All @@ -115,8 +116,13 @@ public void SetupForLabels()
/// You can pass false if it is guaranteed to be valid.
/// </param>
/// <returns></returns>
public IReadOnlyCollection<string> ProvideLabels(string assetPath, Type assetType, bool isFolder, bool doSetup,
bool checkIsPathValidForEntry = true)
public IReadOnlyCollection<string> ProvideLabels(
string assetPath,
Type assetType,
bool isFolder,
bool doSetup,
bool checkIsPathValidForEntry = true
)
{
var labels = new HashSet<string>();
for (int i = 0, count = _labelRules.Count; i < count; i++)
Expand All @@ -133,12 +139,6 @@ public IReadOnlyCollection<string> ProvideLabels(string assetPath, Type assetTyp
return labels;
}

public void SetupForVersion()
{
foreach (var versionRule in _versionRules)
versionRule.Setup();
}

public string ProvideVersion(string assetPath, Type assetType, bool isFolder, bool doSetup)
{
foreach (var versionRule in _versionRules)
Expand All @@ -153,5 +153,35 @@ public string ProvideVersion(string assetPath, Type assetType, bool isFolder, bo

return null;
}

public bool Validate(out LayoutRuleValidationError error)
{
var versionRuleErrors = new List<VersionRuleValidationError>();
foreach (var versionRule in _versionRules)
if (!versionRule.Validate(out var versionRuleError))
versionRuleErrors.Add(versionRuleError);

var labelRuleErrors = new List<LabelRuleValidationError>();
foreach (var labelRule in _labelRules)
if (!labelRule.Validate(out var labelRuleError))
labelRuleErrors.Add(labelRuleError);

var addressRuleErrors = new List<AddressRuleValidationError>();
foreach (var addressRule in _addressRules)
if (!addressRule.Validate(out var addressRuleError))
addressRuleErrors.Add(addressRuleError);

if (versionRuleErrors.Count == 0 && labelRuleErrors.Count == 0 && addressRuleErrors.Count == 0)
{
error = null;
return true;
}

error = new LayoutRuleValidationError(
addressRuleErrors.ToArray(),
labelRuleErrors.ToArray(),
versionRuleErrors.ToArray());
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// --------------------------------------------------------------
// Copyright 2024 CyberAgent, Inc.
// --------------------------------------------------------------

namespace SmartAddresser.Editor.Core.Models.LayoutRules
{
public enum LayoutRuleErrorHandleType
{
Ignore,
LogError,
ThrowException,
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using SmartAddresser.Editor.Core.Models.Shared;
using SmartAddresser.Editor.Core.Models.Shared.AssetGroups;
using SmartAddresser.Editor.Core.Models.Shared.AssetGroups.ValidationError;
using SmartAddresser.Editor.Foundation.TinyRx.ObservableCollection;
using SmartAddresser.Editor.Foundation.TinyRx.ObservableProperty;
using UnityEngine;
Expand All @@ -16,10 +17,10 @@ public sealed class VersionRule : ISerializationCallbackReceiver
[SerializeField] private string _id;
[SerializeField] private ObservableProperty<string> _name = new ObservableProperty<string>("New Version Rule");
[SerializeField] private AssetGroupObservableList _assetGroups = new AssetGroupObservableList();
private ObservableProperty<string> _assetGroupDescription = new ObservableProperty<string>();
private ObservableProperty<string> _versionProviderDescription = new ObservableProperty<string>();

[SerializeReference] private IVersionProvider _versionProviderInternal;
private ObservableProperty<string> _assetGroupDescription = new ObservableProperty<string>();
private ObservableProperty<string> _versionProviderDescription = new ObservableProperty<string>();

public VersionRule()
{
Expand Down Expand Up @@ -64,6 +65,18 @@ public void Setup()
VersionProvider.Value.Setup();
}

public bool Validate(out VersionRuleValidationError error)
{
if (_assetGroups.Validate(out var groupErrors))
{
error = null;
return true;
}

error = new VersionRuleValidationError(this, groupErrors);
return false;
}

/// <summary>
/// Create a version from asset information.
/// </summary>
Expand All @@ -76,8 +89,13 @@ public void Setup()
/// You can pass false if it is guaranteed to be valid.
/// </param>
/// <returns>Return true if successful.</returns>
public bool TryProvideVersion(string assetPath, Type assetType, bool isFolder, out string version,
bool checkIsPathValidForEntry = true)
public bool TryProvideVersion(
string assetPath,
Type assetType,
bool isFolder,
out string version,
bool checkIsPathValidForEntry = true
)
{
if (!_assetGroups.Contains(assetPath, assetType, isFolder))
{
Expand All @@ -92,12 +110,13 @@ public bool TryProvideVersion(string assetPath, Type assetType, bool isFolder, o
}

version = VersionProvider.Value.Provide(assetPath, assetType, isFolder);

if (string.IsNullOrEmpty(version))
{
version = null;
return false;
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using SmartAddresser.Editor.Foundation.AssetDatabaseAdapter;
using SmartAddresser.Editor.Foundation.SemanticVersioning;
using UnityEditor.AddressableAssets.Settings;
using Version = SmartAddresser.Editor.Foundation.SemanticVersioning.Version;

namespace SmartAddresser.Editor.Core.Models.Services
{
Expand All @@ -28,25 +29,13 @@ IAssetDatabaseAdapter assetDatabaseAdapter
_assetDatabaseAdapter = assetDatabaseAdapter;
}

/// <summary>
/// If you want to process multiple asset by this instance, you should call this method before you call
/// <see cref="TryAddEntry" /> and set <c>false</c> to the <c>doSetup</c> argument of the <see cref="TryAddEntry" />.
/// If you want to process single asset by this instance, you should not call this method and set <c>true</c> to the
/// <c>doSetup</c> argument of the <see cref="TryAddEntry" />.
/// </summary>
public void Setup()
{
_layoutRule.SetupForAddress();
_layoutRule.SetupForLabels();
_layoutRule.SetupForVersion();
}

/// <summary>
/// Apply the layout rule to the addressable settings for all assets.
/// </summary>
public void ApplyAll()
public void ApplyAll(bool doSetup)
{
Setup();
if (doSetup)
_layoutRule.Setup();

// Add all entries to the addressable asset system.
var removeTargetAssetGuids = new List<string>();
Expand Down
Loading

0 comments on commit 2686bed

Please sign in to comment.