Skip to content

Commit

Permalink
Fix MultiValueArithmeticDriver<T> component enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Nytra committed Nov 30, 2023
1 parent ee8744a commit c7b9a89
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 55 deletions.
109 changes: 54 additions & 55 deletions Components/Transform/Drivers/MultiValueArithmeticDriver.cs
Original file line number Diff line number Diff line change
@@ -1,70 +1,69 @@
using System.Linq;
using Elements.Assets;
using Elements.Core;
using FrooxEngine;

namespace Obsidian;

public enum ArithmeticMode
{
Addition,
Subtraction,
Multiplication,
Division
}

[Category(new string[] { "Obsidian/Transform/Drivers" })]
[GenericTypes(GenericTypesAttribute.Group.Primitives)]
public class MultiValueArithmeticDriver<T> : Component
{
public static bool IsValidGenericType => Coder<T>.SupportsAddSub;

public enum ArithmeticMode
{
Addition,
Subtraction,
Multiplication,
Division
}
public static bool IsValidGenericType => Coder<T>.SupportsAddSub;

public readonly FieldDrive<T> Target;
public readonly FieldDrive<T> Target;

public readonly Sync<ArithmeticMode> Mode;
public readonly Sync<ArithmeticMode> Mode;

public readonly SyncList<Sync<T>> Values;
public readonly SyncList<Sync<T>> Values;

protected override void OnChanges()
{
if (!Target.IsLinkValid || Values.Count == 0)
{
return;
}
if (Values.Contains(Target.Target))
{
// don't let the component drive itself, don't want a feedback loop
Target.ReleaseLink();
return;
}
T value = Values[0].Value;
switch (Mode.Value)
{
case ArithmeticMode.Addition:
foreach (Sync<T> sync in Values.Skip(1))
{
value = Coder<T>.Add(value, sync.Value);
}
break;
case ArithmeticMode.Subtraction:
foreach (Sync<T> sync in Values.Skip(1))
{
value = Coder<T>.Sub(value, sync.Value);
}
break;
case ArithmeticMode.Multiplication:
foreach (Sync<T> sync in Values.Skip(1))
{
value = Coder<T>.Mul(value, sync.Value);
}
break;
case ArithmeticMode.Division:
foreach (Sync<T> sync in Values.Skip(1))
{
value = Coder<T>.Div(value, sync.Value);
}
break;
}
Target.Target.Value = value;
}
protected override void OnChanges()
{
if (!Target.IsLinkValid || Values.Count == 0)
{
return;
}
if (Values.Contains(Target.Target))
{
// don't let the component drive itself, don't want a feedback loop
Target.ReleaseLink();
return;
}
T value = Values[0].Value;
switch (Mode.Value)
{
case ArithmeticMode.Addition:
foreach (Sync<T> sync in Values.Skip(1))
{
value = Coder<T>.Add(value, sync.Value);
}
break;
case ArithmeticMode.Subtraction:
foreach (Sync<T> sync in Values.Skip(1))
{
value = Coder<T>.Sub(value, sync.Value);
}
break;
case ArithmeticMode.Multiplication:
foreach (Sync<T> sync in Values.Skip(1))
{
value = Coder<T>.Mul(value, sync.Value);
}
break;
case ArithmeticMode.Division:
foreach (Sync<T> sync in Values.Skip(1))
{
value = Coder<T>.Div(value, sync.Value);
}
break;
}
Target.Target.Value = value;
}
}
1 change: 1 addition & 0 deletions ProjectObsidian.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<ResonitePath Condition="Exists('C:\Program Files (x86)\Steam\steamapps\common\Resonite\')">C:\Program Files (x86)\Steam\steamapps\common\Resonite\</ResonitePath>
<ResonitePath Condition="Exists('$(HOME)/.steam/steam/steamapps/common/Resonite/')">$(HOME)/.steam/steam/steamapps/common/Resonite/</ResonitePath>
<ResonitePath Condition="Exists('/mnt/LocalDisk2/SteamLibrary/steamapps/common/Resonite/')">/mnt/LocalDisk2/SteamLibrary/steamapps/common/Resonite/</ResonitePath>
<ResonitePath Condition="Exists('G:\SteamLibrary\steamapps\common\Resonite\')">G:\SteamLibrary\steamapps\common\Resonite\</ResonitePath>
</PropertyGroup>
<ItemGroup>
<Compile Remove="ProtoFlux\Bindings\Networking\**" />
Expand Down

0 comments on commit c7b9a89

Please sign in to comment.