Skip to content

Commit

Permalink
Change ISavable.Parent to ISavable.SvParent
Browse files Browse the repository at this point in the history
  • Loading branch information
SNAKE committed Oct 15, 2024
1 parent a6e2383 commit 9bd12b9
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Salvavida.Generator.Debug/UserModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public partial class UserModel : ISavable<UserModel>
{
public event PropertyChangeEventHandler<UserModel> PropertyChanged;

public ISavable Parent { get; private set; }
public ISavable SvParent { get; private set; }

public string SvId { get; set; }

Expand Down Expand Up @@ -66,7 +66,7 @@ public void SetDirty(bool dirty, bool recursively)

public void SetParent(ISavable parent)
{
Parent = parent;
SvParent = parent;
}
}

Expand Down
4 changes: 2 additions & 2 deletions Salvavida.Generator/BasicCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ protected virtual void WriteImplementationsHead(ScriptBuilder sb, CodeGeneration
sb.WriteLine($"public event PropertyChangeEventHandler<{_infoStore!.className}> PropertyChanged;");
sb.WriteLine();
AddAttributePreventSerialize(sb, true);
sb.WriteLine("public ISavable Parent { get; private set; }");
sb.WriteLine("public ISavable SvParent { get; private set; }");
sb.WriteLine();
AddAttributePreventSerialize(sb, false);
sb.WriteLine("private string _svId;");
Expand Down Expand Up @@ -449,7 +449,7 @@ protected virtual void WriteImplementationsFoot(ScriptBuilder sb, CodeGeneration
{
using (sb.CurlyBracketsScope())
{
sb.WriteLine("Parent = parent;");
sb.WriteLine("SvParent = parent;");
}
}
sb.WriteLine();
Expand Down
Binary file modified Salvavida/Package/CodeGen/Salvavida.Generator.dll
Binary file not shown.
Binary file modified Salvavida/Package/CodeGen/Salvavida.Generator.pdb
Binary file not shown.
3 changes: 2 additions & 1 deletion Salvavida/Package/Runtime/IBackupService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if USE_UNITASK && !SV_FORCE_TASK
using System.Threading;

#if USE_UNITASK && !SV_FORCE_TASK
using Task = Cysharp.Threading.Tasks.UniTask;
#else
using Task = System.Threading.Tasks.Task;
Expand Down
2 changes: 1 addition & 1 deletion Salvavida/Package/Runtime/ISavable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Salvavida
{
public interface ISavable
{
ISavable? Parent { get; }
ISavable? SvParent { get; }

string? SvId { get; set; }
bool IsDirty { get; }
Expand Down
12 changes: 6 additions & 6 deletions Salvavida/Package/Runtime/ObservableCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public ObservableCollection(string svid, bool saveSeparately)
private readonly string _svid;
protected bool _isDirty = true;

public ISavable? Parent { get; protected set; }
public ISavable? SvParent { get; protected set; }
bool ISavable.IsDirty => _isDirty;

public abstract bool IsSavableCollection { get; }
Expand All @@ -36,9 +36,9 @@ void ISavable.SetDirty(bool dirty, bool _)

public void TrySave(Serializer? serializer, PathBuilder pathBuilder)
{
if (Parent == null || string.IsNullOrEmpty(SvId) || !_isDirty)
if (SvParent == null || string.IsNullOrEmpty(SvId) || !_isDirty)
return;
serializer ??= Parent.GetSerializer();
serializer ??= SvParent.GetSerializer();
if (serializer == null)
return;
pathBuilder.Push(SvId, SvHelper.GetPathType(this));
Expand Down Expand Up @@ -67,7 +67,7 @@ void ISavable.SetParent(ISavable? parent)

protected void SetParent(ISavable? parent)
{
Parent = parent;
SvParent = parent;
}

public virtual void BeforeSerialize(Serializer serializer)
Expand Down Expand Up @@ -125,7 +125,7 @@ protected void TryUnWatch(TElem? obj)
protected void OnCollectionChange(CollectionChangeInfo<TElem?> e)
{
_isDirty = true;
var serializer = Parent?.GetSerializer();
var serializer = SvParent?.GetSerializer();
if (serializer != null)
{
if (SaveSeparately)
Expand Down Expand Up @@ -159,7 +159,7 @@ protected void TrySaveSeparatelyByEvent(Serializer serializer, PathBuilder pathB

protected virtual void TrySaveItems(Serializer serializer, PathBuilder pathBuilder, CollectionChangeInfo<TElem?> e)
{
if (string.IsNullOrEmpty(SvId) || Parent == null)
if (string.IsNullOrEmpty(SvId) || SvParent == null)
return;
switch (e.Action)
{
Expand Down
10 changes: 5 additions & 5 deletions Salvavida/Package/Runtime/SvHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void SetChild<T>(this ISavable parent, T child)

public static ReadOnlySpan<char> GetParentPathAsSpan(this ISavable? savable, PathBuilder pathBuilder)
{
return GetSavePathAsSpan(savable?.Parent, pathBuilder);
return GetSavePathAsSpan(savable?.SvParent, pathBuilder);
}

public static ReadOnlySpan<char> GetSavePathAsSpan(this ISavable? savable, PathBuilder pathBuilder)
Expand All @@ -47,7 +47,7 @@ public static ReadOnlySpan<char> GetSavePathAsSpan(this ISavable? savable, PathB
{
TryThrowOnSvIdEmpty(savable);
_tempPathBuilder.Push(savable.SvId!, GetPathType(savable));
savable = savable.Parent;
savable = savable.SvParent;
}
while (!_tempPathBuilder.IsEmpty)
{
Expand All @@ -72,7 +72,7 @@ public static PathBuilder.Type GetPathType<T>(T sv) where T : ISavable
{
if (savable is ISerializeRoot root)
return root.Serializer;
savable = savable.Parent;
savable = savable.SvParent;
}
if (x > 100)
throw new StackOverflowException();
Expand Down Expand Up @@ -105,7 +105,7 @@ public static void TrySave<TParent, T>(this TParent savable, string propName, T
}

// if savable's parent is not null, then the save action will perform by it's parent, not it self.
var parent = savable.Parent;
var parent = savable.SvParent;
if (parent != null)
return;

Expand Down Expand Up @@ -138,7 +138,7 @@ public static void TryThrowOnSvIdEmpty<T>(T sv) where T : ISavable
throw new NullReferenceException(nameof(sv));
if (string.IsNullOrEmpty(sv.SvId))
{
if (sv.Parent != null)
if (sv.SvParent != null)
throw new ArgumentNullException($"The child object of {sv.GetSavePathAsSpan(new PathBuilder()).ToString()} has a empty SvId");
else
throw new ArgumentException(nameof(sv.SvId));
Expand Down

0 comments on commit 9bd12b9

Please sign in to comment.