Adder Signal Component
Added a Adder signal component, which adds values inputted together and outputs a sum.
This commit is contained in:
@@ -1475,6 +1475,7 @@
|
|||||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Characters\CharacterNetworking.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Source\Characters\CharacterNetworking.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Characters\DamageModifier.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Source\Characters\DamageModifier.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Events\Missions\MissionPrefab.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Source\Events\Missions\MissionPrefab.cs" />
|
||||||
|
<Compile Include="$(MSBuildThisFileDirectory)Source\Items\Components\Signal\AdderComponent.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Source\StatusEffects\DelayedEffect.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Source\StatusEffects\DelayedEffect.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Characters\HuskInfection.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Source\Characters\HuskInfection.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Characters\Jobs\Job.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Source\Characters\Jobs\Job.cs" />
|
||||||
|
|||||||
@@ -146,6 +146,40 @@
|
|||||||
</ConnectionPanel>
|
</ConnectionPanel>
|
||||||
</Item>
|
</Item>
|
||||||
|
|
||||||
|
<Item
|
||||||
|
name="Adder Component"
|
||||||
|
category="Electrical"
|
||||||
|
Tags="smallitem"
|
||||||
|
linkable="false"
|
||||||
|
cargocontainername="Metal Crate"
|
||||||
|
price="10"
|
||||||
|
description="Sends a signal when both inputs receive a signal within a set period of each other.">
|
||||||
|
|
||||||
|
<Deconstruct time="10">
|
||||||
|
<Item name="Steel Bar"/>
|
||||||
|
<Item name="FPGA Circuit"/>
|
||||||
|
</Deconstruct>
|
||||||
|
|
||||||
|
<Sprite texture="signalcomp.png" depth="0.8" sourcerect="0,0,16,16"/>
|
||||||
|
|
||||||
|
<AdderComponent canbeselected = "true"/>
|
||||||
|
|
||||||
|
<Body width="16" height="16" density="30"/>
|
||||||
|
|
||||||
|
<Holdable selectkey="Select" pickkey="Use" slots="Any,RightHand,LeftHand" msg="Detach [Wrench]" PickingTime="5.0"
|
||||||
|
aimpos="65,-10" handle1="0,0" attachable="true" aimable="true">
|
||||||
|
<requireditem name="Wrench" type="Equipped"/>
|
||||||
|
</Holdable>
|
||||||
|
|
||||||
|
|
||||||
|
<ConnectionPanel selectkey="Action" canbeselected = "true" msg="Rewire [Screwdriver]">
|
||||||
|
<requireditem name="Screwdriver,Wire" type="Equipped"/>
|
||||||
|
<input name="signal_in1"/>
|
||||||
|
<input name="signal_in2"/>
|
||||||
|
<output name="signal_out"/>
|
||||||
|
</ConnectionPanel>
|
||||||
|
</Item>
|
||||||
|
|
||||||
<Item
|
<Item
|
||||||
name="Or Component"
|
name="Or Component"
|
||||||
category="Electrical"
|
category="Electrical"
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
using System;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace Barotrauma.Items.Components
|
||||||
|
{
|
||||||
|
class AdderComponent : ItemComponent
|
||||||
|
{
|
||||||
|
//an array to keep track of how long ago a signal was received on both inputs
|
||||||
|
protected float[] timeSinceReceived;
|
||||||
|
|
||||||
|
protected float[] receivedSignal;
|
||||||
|
|
||||||
|
|
||||||
|
//the output is sent if both inputs have received a signal within the timeframe
|
||||||
|
protected float timeFrame;
|
||||||
|
|
||||||
|
[InGameEditable, Serialize(0.0f, true)]
|
||||||
|
public float TimeFrame
|
||||||
|
{
|
||||||
|
get { return timeFrame; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
timeFrame = Math.Max(0.0f, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public AdderComponent(Item item, XElement element)
|
||||||
|
: base(item, element)
|
||||||
|
{
|
||||||
|
timeSinceReceived = new float[] { Math.Max(timeFrame * 2.0f, 0.1f), Math.Max(timeFrame * 2.0f, 0.1f) };
|
||||||
|
receivedSignal = new float[2];
|
||||||
|
IsActive = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(float deltaTime, Camera cam)
|
||||||
|
{
|
||||||
|
bool sendOutput = true;
|
||||||
|
for (int i = 0; i < timeSinceReceived.Length; i++)
|
||||||
|
{
|
||||||
|
if (timeSinceReceived[i] > timeFrame) sendOutput = false;
|
||||||
|
timeSinceReceived[i] += deltaTime;
|
||||||
|
}
|
||||||
|
if (sendOutput)
|
||||||
|
{
|
||||||
|
item.SendSignal(0, (receivedSignal[0] + receivedSignal[1]).ToString(), "signal_out", null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power=0.0f)
|
||||||
|
{
|
||||||
|
switch (connection.Name)
|
||||||
|
{
|
||||||
|
case "signal_in1":
|
||||||
|
float.TryParse(signal, out receivedSignal[0]);
|
||||||
|
timeSinceReceived[0] = 0.0f;
|
||||||
|
break;
|
||||||
|
case "signal_in2":
|
||||||
|
float.TryParse(signal, out receivedSignal[1]);
|
||||||
|
timeSinceReceived[1] = 0.0f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user