Skip to content

Commit

Permalink
Merge pull request #5 from techno-dwarf-works/refactoring
Browse files Browse the repository at this point in the history
Version 0.0.4
  • Loading branch information
OpOpYaDev committed Sep 8, 2024
1 parent 340ffc2 commit 5a1796b
Show file tree
Hide file tree
Showing 42 changed files with 658 additions and 47 deletions.
16 changes: 14 additions & 2 deletions Runtime/Data/Overridable/ImplementationOverridable.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using Better.Attributes.Runtime.Select;
using Better.Commons.Runtime.Interfaces;
using UnityEngine;

namespace Better.Tweens.Runtime.Data
{
[Serializable]
public class ImplementationOverridable<TValue> : OverridableData<TValue>
public class ImplementationOverridable<TValue> : OverridableData<TValue>, ICloneable<ImplementationOverridable<TValue>>
where TValue : ICloneable<TValue>
{
[Select]
[SerializeReference] private TValue _overridenValue;
Expand All @@ -16,9 +18,19 @@ protected override TValue OverridenValue
set => _overridenValue = value;
}

public ImplementationOverridable(TValue overridenValue)
public ImplementationOverridable(TValue sourceValue, TValue overridenValue, bool overriden) : base(sourceValue, overriden)
{
_overridenValue = overridenValue;
}

public ImplementationOverridable(TValue overridenValue) : this(default, overridenValue, false)
{
}

public ImplementationOverridable<TValue> Clone()
{
var overridenClone = _overridenValue == null ? default : _overridenValue.Clone();
return new ImplementationOverridable<TValue>(overridenClone, SourceValue, Overriden);
}
}
}
19 changes: 14 additions & 5 deletions Runtime/Data/Overridable/OverridableData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,30 @@ namespace Better.Tweens.Runtime.Data
public abstract class OverridableData<TValue>
{
[SerializeField] private bool _overriden;

private TValue _sourceValue;

public TValue Value => Overriden ? OverridenValue : _sourceValue;

public TValue Value => Overriden ? OverridenValue : SourceValue;
protected abstract TValue OverridenValue { get; set; }
protected TValue SourceValue { get; private set; }

public bool Overriden
{
get => _overriden;
set => _overriden = value;
}

protected OverridableData()
{
}

protected OverridableData(TValue sourceValue, bool overriden)
{
SourceValue = sourceValue;
_overriden = overriden;
}

public void SetSource(TValue value)
{
_sourceValue = value;
SourceValue = value;
}

public void Override(TValue value)
Expand Down
3 changes: 0 additions & 3 deletions Runtime/Data/Overridable/Simples.meta

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System;
using Better.Attributes.Runtime.Select;
using UnityEngine;
using Better.Commons.Runtime.Interfaces;

namespace Better.Tweens.Runtime.Data
{
[Serializable]
public class SleepingDurationOverridable : SimpleOverridable<SleepingDuration>
public class SleepingDurationOverridable : ImplementationOverridable<SleepingDuration>, ICloneable<SleepingDurationOverridable>
{
public float Duration => Value.Value;
public bool Infinity => Value.Infinity;
Expand All @@ -14,6 +13,10 @@ public SleepingDurationOverridable(SleepingDuration overridenValue) : base(overr
{
}

public SleepingDurationOverridable(SleepingDuration overridenValue, SleepingDuration sourceValue, bool overriden) : base(overridenValue)
{
}

public void OverrideDuration(float value)
{
Overriden = true;
Expand All @@ -25,5 +28,11 @@ public void OverrideInfinity()
Overriden = true;
OverridenValue.MakeInfinity();
}

public new SleepingDurationOverridable Clone()
{
var overridenClone = OverridenValue?.Clone();
return new SleepingDurationOverridable(overridenClone, SourceValue, Overriden);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using Better.Attributes.Runtime.Select;
using Better.Commons.Runtime.Interfaces;
using UnityEngine;

namespace Better.Tweens.Runtime.Data
{
[Serializable]
public class SimpleOverridable<TValue> : OverridableData<TValue>
public class ValueOverridable<TValue> : OverridableData<TValue>, ICloneable<ValueOverridable<TValue>>
where TValue : struct
{
[SerializeField] private TValue _overridenValue;

Expand All @@ -15,9 +16,14 @@ protected override TValue OverridenValue
set => _overridenValue = value;
}

public SimpleOverridable(TValue overridenValue)
public ValueOverridable(TValue overridenValue)
{
_overridenValue = overridenValue;
}

public ValueOverridable<TValue> Clone()
{
return new ValueOverridable<TValue>(OverridenValue);
}
}
}
Loading

0 comments on commit 5a1796b

Please sign in to comment.