Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MultiValueArithmeticDriver<T> component enum and add my Resonite path to the csproj #7

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Xlinka marked this conversation as resolved.
Show resolved Hide resolved
{
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()
Xlinka marked this conversation as resolved.
Show resolved Hide resolved
{
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>
Xlinka marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>
<ItemGroup>
<Compile Remove="ProtoFlux\Bindings\Networking\**" />
Expand Down