Relay and delay components
This commit is contained in:
@@ -116,6 +116,8 @@
|
||||
<Compile Include="Source\Items\Components\Holdable\MeleeWeapon.cs" />
|
||||
<Compile Include="Source\Items\Components\Holdable\Propulsion.cs" />
|
||||
<Compile Include="Source\Items\Components\Machines\Deconstructor.cs" />
|
||||
<Compile Include="Source\Items\Components\Signal\DelayComponent.cs" />
|
||||
<Compile Include="Source\Items\Components\Signal\RelayComponent.cs" />
|
||||
<Compile Include="Source\Items\Components\Signal\WaterDetector.cs" />
|
||||
<Compile Include="Source\Items\Components\Signal\WifiComponent.cs" />
|
||||
<Compile Include="Source\Items\Components\Signal\SignalCheckComponent.cs" />
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 9.2 KiB |
@@ -202,7 +202,77 @@
|
||||
<input name="signal_in"/>
|
||||
<output name="signal_out"/>
|
||||
</ConnectionPanel>
|
||||
</Item>
|
||||
|
||||
<Item
|
||||
name="Relay Component"
|
||||
category="Electrical"
|
||||
Tags="smallitem"
|
||||
pickdistance="150"
|
||||
linkable="true"
|
||||
price="10"
|
||||
description="When switched on, forwards all received signals from the input connections to the outputs.">
|
||||
|
||||
<Deconstruct time="10">
|
||||
<Item name="Steel Bar"/>
|
||||
<Item name="FPGA Circuit"/>
|
||||
</Deconstruct>
|
||||
|
||||
<Sprite texture="signalcomp.png" depth="0.8" sourcerect="48,16,16,16"/>
|
||||
|
||||
<RelayComponent canbeselected = "true"/>
|
||||
|
||||
<Body width="16" height="16" density="30"/>
|
||||
|
||||
<Holdable selectkey="Action" slots="Any,RightHand,LeftHand" msg="Detach [Wrench]" PickingTime="5.0"
|
||||
aimpos="35,-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="power_in"/>
|
||||
<input name="signal_in1"/>
|
||||
<input name="signal_in2"/>
|
||||
<input name="toggle"/>
|
||||
<input name="set_state"/>
|
||||
|
||||
<output name="power_out"/>
|
||||
<output name="signal_out1"/>
|
||||
<output name="signal_out2"/>
|
||||
</ConnectionPanel>
|
||||
</Item>
|
||||
|
||||
<Item
|
||||
name="Delay Component"
|
||||
category="Electrical"
|
||||
Tags="smallitem"
|
||||
pickdistance="150"
|
||||
linkable="true"
|
||||
price="10"
|
||||
description="Delays all received signals for a specific amount of time.">
|
||||
|
||||
<Deconstruct time="10">
|
||||
<Item name="Steel Bar"/>
|
||||
<Item name="FPGA Circuit"/>
|
||||
</Deconstruct>
|
||||
|
||||
<Sprite texture="signalcomp.png" depth="0.8" sourcerect="16,32,16,8"/>
|
||||
|
||||
<DelayComponent canbeselected = "true"/>
|
||||
|
||||
<Body width="16" height="8" density="30"/>
|
||||
|
||||
<Holdable selectkey="Action" slots="Any,RightHand,LeftHand" msg="Detach [Wrench]" PickingTime="5.0"
|
||||
aimpos="35,-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_in"/>
|
||||
<output name="signal_out"/>
|
||||
</ConnectionPanel>
|
||||
</Item>
|
||||
|
||||
<Item
|
||||
|
||||
BIN
Subsurface/Content/watershader_opengl.xnb
Normal file
BIN
Subsurface/Content/watershader_opengl.xnb
Normal file
Binary file not shown.
57
Subsurface/Source/Items/Components/Signal/DelayComponent.cs
Normal file
57
Subsurface/Source/Items/Components/Signal/DelayComponent.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
class DelayComponent : ItemComponent
|
||||
{
|
||||
//the output is sent if both inputs have received a signal within the timeframe
|
||||
protected TimeSpan delay;
|
||||
|
||||
private Queue<Tuple<string, DateTime>> signalQueue;
|
||||
|
||||
[InGameEditable, HasDefaultValue(1.0f, true)]
|
||||
public float Delay
|
||||
{
|
||||
get { return (float)delay.TotalSeconds; }
|
||||
set
|
||||
{
|
||||
float seconds = MathHelper.Clamp(value, 0.0f, 60.0f);
|
||||
|
||||
delay = new TimeSpan(0,0,0,0, (int)(seconds*1000.0f));
|
||||
}
|
||||
}
|
||||
|
||||
public DelayComponent(Item item, XElement element)
|
||||
: base (item, element)
|
||||
{
|
||||
signalQueue = new Queue<Tuple<string, DateTime>>();
|
||||
|
||||
IsActive = true;
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
while (signalQueue.Any() && signalQueue.Peek().Item2 + delay <= DateTime.Now)
|
||||
{
|
||||
var signalOut = signalQueue.Dequeue();
|
||||
|
||||
item.SendSignal(signalOut.Item1, "signal_out");
|
||||
}
|
||||
}
|
||||
|
||||
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
|
||||
{
|
||||
switch (connection.Name)
|
||||
{
|
||||
case "signal_in":
|
||||
signalQueue.Enqueue(new Tuple<string, DateTime>(signal, DateTime.Now));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
43
Subsurface/Source/Items/Components/Signal/RelayComponent.cs
Normal file
43
Subsurface/Source/Items/Components/Signal/RelayComponent.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
class RelayComponent : ItemComponent
|
||||
{
|
||||
public RelayComponent(Item item, XElement element)
|
||||
: base (item, element)
|
||||
{
|
||||
IsActive = true;
|
||||
}
|
||||
|
||||
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
|
||||
{
|
||||
if (connection.Name.Contains("_in"))
|
||||
{
|
||||
if (!IsActive) return;
|
||||
|
||||
string outConnection = connection.Name.Contains("power_in") ? "power_out" : "signal_out";
|
||||
|
||||
int connectionNumber = -1;
|
||||
int.TryParse(connection.Name.Substring(connection.Name.Length - 1, 1), out connectionNumber);
|
||||
|
||||
if (connectionNumber > 0) outConnection += connectionNumber;
|
||||
|
||||
item.SendSignal(signal, outConnection, power);
|
||||
}
|
||||
else if (connection.Name == "toggle")
|
||||
{
|
||||
IsActive = !IsActive;
|
||||
}
|
||||
else if (connection.Name == "set_state")
|
||||
{
|
||||
IsActive = signal == "1";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user