- invisible entities (items inside cabinets, hulls/gaps when they've been hidden) can't be highlighted or selected in the editor - fixed And Components always sending a signal out during the first frame if timeframe is set to 0.0 - fixed moloch not appearing in the tutorial
77 lines
2.2 KiB
C#
77 lines
2.2 KiB
C#
using System;
|
|
using System.Xml.Linq;
|
|
|
|
namespace Barotrauma.Items.Components
|
|
{
|
|
class AndComponent : ItemComponent
|
|
{
|
|
protected string output;
|
|
|
|
//an array to keep track of how long ago a non-zero signal was received on both inputs
|
|
protected float[] timeSinceReceived;
|
|
|
|
//the output is sent if both inputs have received a signal within the timeframe
|
|
protected float timeFrame;
|
|
|
|
[InGameEditable, HasDefaultValue(0.0f, true)]
|
|
public float TimeFrame
|
|
{
|
|
get { return timeFrame; }
|
|
set
|
|
{
|
|
timeFrame = Math.Max(0.0f, value);
|
|
}
|
|
}
|
|
|
|
[InGameEditable, HasDefaultValue("1", true)]
|
|
public string Output
|
|
{
|
|
get { return output; }
|
|
set { output = value; }
|
|
}
|
|
|
|
public AndComponent(Item item, XElement element)
|
|
: base (item, element)
|
|
{
|
|
timeSinceReceived = new float[] { Math.Max(timeFrame*2.0f,0.1f), Math.Max(timeFrame*2.0f, 0.1f) };
|
|
|
|
//output = "1";
|
|
}
|
|
|
|
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(output, "signal_out");
|
|
}
|
|
}
|
|
|
|
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
|
|
{
|
|
switch (connection.Name)
|
|
{
|
|
case "signal_in1":
|
|
if (signal == "0") return;
|
|
timeSinceReceived[0] = 0.0f;
|
|
IsActive = true;
|
|
break;
|
|
case "signal_in2":
|
|
if (signal == "0") return;
|
|
timeSinceReceived[1] = 0.0f;
|
|
IsActive = true;
|
|
break;
|
|
case "set_output":
|
|
output = signal;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|