Release v0.15.12.0
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
using Barotrauma.Extensions;
|
||||
using Barotrauma.Networking;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
partial class ButtonTerminal : ItemComponent
|
||||
{
|
||||
[Editable, Serialize(new string[0], true, description: "Signals sent when the corresponding buttons are pressed.", alwaysUseInstanceValues: true)]
|
||||
public string[] Signals { get; set; }
|
||||
[Editable, Serialize("", true, description: "Identifiers or tags of items that, when contained, allow the terminal buttons to be used. Multiple ones should be separated by commas.", alwaysUseInstanceValues: true)]
|
||||
public string ActivatingItems { get; set; }
|
||||
|
||||
private int RequiredSignalCount { get; set; }
|
||||
private ItemContainer Container { get; set; }
|
||||
private HashSet<ItemPrefab> ActivatingItemPrefabs { get; set; } = new HashSet<ItemPrefab>();
|
||||
|
||||
|
||||
private bool AllowUsingButtons => ActivatingItemPrefabs.None() || Container.Inventory.AllItems.Any(i => i != null && ActivatingItemPrefabs.Any(p => p == i.Prefab));
|
||||
|
||||
public ButtonTerminal(Item item, XElement element) : base(item, element)
|
||||
{
|
||||
IsActive = true;
|
||||
RequiredSignalCount = element.GetChildElements("TerminalButton").Count(c => c.GetAttribute("style") != null);
|
||||
if (RequiredSignalCount < 1)
|
||||
{
|
||||
DebugConsole.ThrowError($"Error in item \"{item.Name}\": no TerminalButton elements defined for the ButtonTerminal component!");
|
||||
}
|
||||
InitProjSpecific(element);
|
||||
}
|
||||
|
||||
partial void InitProjSpecific(XElement element);
|
||||
|
||||
public override void OnItemLoaded()
|
||||
{
|
||||
base.OnItemLoaded();
|
||||
|
||||
if (Signals == null)
|
||||
{
|
||||
Signals = new string[RequiredSignalCount];
|
||||
for (int i = 0; i < RequiredSignalCount; i++)
|
||||
{
|
||||
Signals[i] = string.Empty;
|
||||
}
|
||||
}
|
||||
else if (Signals.Length != RequiredSignalCount)
|
||||
{
|
||||
string[] newSignals = new string[RequiredSignalCount];
|
||||
if (Signals.Length < RequiredSignalCount)
|
||||
{
|
||||
Signals.CopyTo(newSignals, 0);
|
||||
for (int i = Signals.Length; i < RequiredSignalCount; i++)
|
||||
{
|
||||
newSignals[i] = string.Empty;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < RequiredSignalCount; i++)
|
||||
{
|
||||
newSignals[i] = Signals[i];
|
||||
}
|
||||
}
|
||||
Signals = newSignals;
|
||||
}
|
||||
|
||||
ActivatingItemPrefabs.Clear();
|
||||
if (!string.IsNullOrEmpty(ActivatingItems))
|
||||
{
|
||||
foreach (var activatingItem in ActivatingItems.Split(','))
|
||||
{
|
||||
if (MapEntityPrefab.Find(null, identifier: activatingItem, showErrorMessages: false) is ItemPrefab prefab)
|
||||
{
|
||||
ActivatingItemPrefabs.Add(prefab);
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemPrefab.Prefabs.Where(p => p.Tags.Any(t => t.Equals(activatingItem, StringComparison.OrdinalIgnoreCase)))
|
||||
.ForEach(p => ActivatingItemPrefabs.Add(p));
|
||||
}
|
||||
}
|
||||
if (ActivatingItemPrefabs.None())
|
||||
{
|
||||
DebugConsole.ThrowError($"Error in item \"{item.Name}\": no activating item prefabs found with identifiers or tags \"{ActivatingItems}\"");
|
||||
}
|
||||
}
|
||||
|
||||
var containers = item.GetComponents<ItemContainer>().ToList();
|
||||
if (containers.Count != 1)
|
||||
{
|
||||
DebugConsole.ThrowError($"Error in item \"{item.Name}\": the ButtonTerminal component requires exactly one ItemContainer component!");
|
||||
return;
|
||||
}
|
||||
Container = containers[0];
|
||||
|
||||
OnItemLoadedProjSpecific();
|
||||
}
|
||||
|
||||
partial void OnItemLoadedProjSpecific();
|
||||
|
||||
private bool SendSignal(int signalIndex, bool isServerMessage = false)
|
||||
{
|
||||
if (!isServerMessage && !AllowUsingButtons) { return false; }
|
||||
string signal = Signals[signalIndex];
|
||||
string connectionName = $"signal_out{signalIndex + 1}";
|
||||
item.SendSignal(signal, connectionName);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void Write(IWriteMessage msg, object[] extraData)
|
||||
{
|
||||
if (extraData == null || extraData.Length < 3) { return; }
|
||||
msg.WriteRangedInteger((int)extraData[2], 0, Signals.Length - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
foreach (XElement connectionElement in subElement.Elements())
|
||||
{
|
||||
string prefabConnectionName = element.GetAttributeString("name", null);
|
||||
string prefabConnectionName = connectionElement.GetAttributeString("name", null);
|
||||
if (prefabConnectionName == Name)
|
||||
{
|
||||
displayNameTag = connectionElement.GetAttributeString("displayname", "");
|
||||
|
||||
+24
-13
@@ -134,20 +134,30 @@ namespace Barotrauma.Items.Components
|
||||
foreach (Wire wire in c.Wires)
|
||||
{
|
||||
if (wire == null) { continue; }
|
||||
#if CLIENT
|
||||
if (wire.Item.IsSelected) { continue; }
|
||||
#endif
|
||||
var wireNodes = wire.GetNodes();
|
||||
if (wireNodes.Count == 0) { continue; }
|
||||
TryMoveWire(wire);
|
||||
}
|
||||
}
|
||||
|
||||
if (Submarine.RectContains(item.Rect, wireNodes[0] + wireNodeOffset))
|
||||
{
|
||||
wire.MoveNode(0, amount);
|
||||
}
|
||||
else if (Submarine.RectContains(item.Rect, wireNodes[wireNodes.Count - 1] + wireNodeOffset))
|
||||
{
|
||||
wire.MoveNode(wireNodes.Count - 1, amount);
|
||||
}
|
||||
foreach (var wire in DisconnectedWires)
|
||||
{
|
||||
TryMoveWire(wire);
|
||||
}
|
||||
|
||||
void TryMoveWire(Wire wire)
|
||||
{
|
||||
#if CLIENT
|
||||
if (wire.Item.IsSelected) { return; }
|
||||
#endif
|
||||
var wireNodes = wire.GetNodes();
|
||||
if (wireNodes.Count == 0) { return; }
|
||||
|
||||
if (Submarine.RectContains(item.Rect, wireNodes[0] + wireNodeOffset))
|
||||
{
|
||||
wire.MoveNode(0, amount);
|
||||
}
|
||||
else if (Submarine.RectContains(item.Rect, wireNodes[wireNodes.Count - 1] + wireNodeOffset))
|
||||
{
|
||||
wire.MoveNode(wireNodes.Count - 1, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -350,6 +360,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
}
|
||||
Connections.Clear();
|
||||
|
||||
#if CLIENT
|
||||
rewireSoundChannel?.FadeOutAndDispose();
|
||||
|
||||
@@ -159,7 +159,10 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
lightColor = value;
|
||||
#if CLIENT
|
||||
if (Light != null) Light.Color = IsActive ? lightColor : Color.Transparent;
|
||||
if (Light != null)
|
||||
{
|
||||
Light.Color = IsActive ? lightColor : Color.Transparent;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -233,6 +236,8 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
UpdateOnActiveEffects(deltaTime);
|
||||
|
||||
if (powerIn == null && powerConsumption > 0.0f) { Voltage -= deltaTime; }
|
||||
|
||||
#if CLIENT
|
||||
Light.ParentSub = item.Submarine;
|
||||
#endif
|
||||
@@ -293,8 +298,6 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
SetLightSourceState(true, lightBrightness);
|
||||
|
||||
if (powerIn == null && powerConsumption > 0.0f) { Voltage -= deltaTime; }
|
||||
}
|
||||
|
||||
public override void UpdateBroken(float deltaTime, Camera cam)
|
||||
|
||||
+15
-1
@@ -12,8 +12,10 @@ namespace Barotrauma.Items.Components
|
||||
public enum WaveType
|
||||
{
|
||||
Pulse,
|
||||
Sawtooth,
|
||||
Sine,
|
||||
Square,
|
||||
Triangle,
|
||||
}
|
||||
|
||||
private float frequency;
|
||||
@@ -22,8 +24,11 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
[InGameEditable, Serialize(WaveType.Pulse, true, description: "What kind of a signal the item outputs." +
|
||||
" Pulse: periodically sends out a signal of 1." +
|
||||
" Sawtooth: sends out a periodic wave that increases linearly from 0 to 1." +
|
||||
" Sine: sends out a sine wave oscillating between -1 and 1." +
|
||||
" Square: sends out a signal that alternates between 0 and 1.", alwaysUseInstanceValues: true)]
|
||||
" Square: sends out a signal that alternates between 0 and 1." +
|
||||
" Triangle: sends out a wave that alternates between increasing linearly from -1 to 1 and decreasing from 1 to -1.",
|
||||
alwaysUseInstanceValues: true)]
|
||||
public WaveType OutputType
|
||||
{
|
||||
get;
|
||||
@@ -63,6 +68,10 @@ namespace Barotrauma.Items.Components
|
||||
phase -= pulseInterval;
|
||||
}
|
||||
break;
|
||||
case WaveType.Sawtooth:
|
||||
phase = (phase + deltaTime * frequency) % 1.0f;
|
||||
item.SendSignal(phase.ToString(CultureInfo.InvariantCulture), "signal_out");
|
||||
break;
|
||||
case WaveType.Square:
|
||||
phase = (phase + deltaTime * frequency) % 1.0f;
|
||||
item.SendSignal(phase < 0.5f ? "0" : "1", "signal_out");
|
||||
@@ -71,6 +80,11 @@ namespace Barotrauma.Items.Components
|
||||
phase = (phase + deltaTime * frequency) % 1.0f;
|
||||
item.SendSignal(Math.Sin(phase * MathHelper.TwoPi).ToString(CultureInfo.InvariantCulture), "signal_out");
|
||||
break;
|
||||
case WaveType.Triangle:
|
||||
phase = (phase + deltaTime * frequency) % 1.0f;
|
||||
float output = 4.0f * MathF.Abs(MathUtils.PositiveModulo(phase - 0.25f, 1.0f) - 0.5f) - 1.0f;
|
||||
item.SendSignal(output.ToString(CultureInfo.InvariantCulture), "signal_out");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -80,19 +80,21 @@ namespace Barotrauma.Items.Components
|
||||
public RegExFindComponent(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
nonContinuousOutputSent = true;
|
||||
IsActive = true;
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(expression) || regex == null) return;
|
||||
if (string.IsNullOrWhiteSpace(expression) || regex == null) { return; }
|
||||
if (!ContinuousOutput && nonContinuousOutputSent) { return; }
|
||||
|
||||
if (receivedSignal != previousReceivedSignal && receivedSignal != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Match match = regex.Match(receivedSignal);
|
||||
previousResult = match.Success;
|
||||
previousResult = match.Success;
|
||||
previousGroups = UseCaptureGroup && previousResult ? match.Groups : null;
|
||||
previousReceivedSignal = receivedSignal;
|
||||
|
||||
@@ -133,7 +135,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (!string.IsNullOrEmpty(signalOut)) { item.SendSignal(signalOut, "signal_out"); }
|
||||
}
|
||||
else if (!nonContinuousOutputSent)
|
||||
else
|
||||
{
|
||||
if (!string.IsNullOrEmpty(signalOut)) { item.SendSignal(signalOut, "signal_out"); }
|
||||
nonContinuousOutputSent = true;
|
||||
|
||||
@@ -41,10 +41,13 @@ namespace Barotrauma.Items.Components
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrEmpty(value)) { return; }
|
||||
ShowOnDisplay(value);
|
||||
ShowOnDisplay(value, addToHistory: true);
|
||||
}
|
||||
}
|
||||
|
||||
[Editable, Serialize(false, true, description: "The terminal will use a monospace font if this box is ticked.", alwaysUseInstanceValues: true)]
|
||||
public bool UseMonospaceFont { get; set; }
|
||||
|
||||
private string OutputValue { get; set; }
|
||||
|
||||
public Terminal(Item item, XElement element)
|
||||
@@ -56,7 +59,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
partial void InitProjSpecific(XElement element);
|
||||
|
||||
partial void ShowOnDisplay(string input, bool addToHistory = true);
|
||||
partial void ShowOnDisplay(string input, bool addToHistory);
|
||||
|
||||
public override void ReceiveSignal(Signal signal, Connection connection)
|
||||
{
|
||||
@@ -67,14 +70,14 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
string inputSignal = signal.value.Replace("\\n", "\n");
|
||||
ShowOnDisplay(inputSignal);
|
||||
ShowOnDisplay(inputSignal, addToHistory: true);
|
||||
}
|
||||
|
||||
public override void OnItemLoaded()
|
||||
{
|
||||
bool isSubEditor = false;
|
||||
#if CLIENT
|
||||
isSubEditor = Screen.Selected != GameMain.SubEditorScreen || GameMain.GameSession?.GameMode is TestGameMode;
|
||||
isSubEditor = Screen.Selected == GameMain.SubEditorScreen || GameMain.GameSession?.GameMode is TestGameMode;
|
||||
#endif
|
||||
|
||||
base.OnItemLoaded();
|
||||
@@ -107,7 +110,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
string msg = componentElement.GetAttributeString("msg" + i, null);
|
||||
if (msg == null) { break; }
|
||||
ShowOnDisplay(msg);
|
||||
ShowOnDisplay(msg, addToHistory: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,9 +100,11 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (item.CurrentHull != null)
|
||||
{
|
||||
int waterPercentage = MathHelper.Clamp((int)Math.Round(item.CurrentHull.WaterPercentage), 0, 100);
|
||||
int waterPercentage = MathHelper.Clamp((int)Math.Ceiling(item.CurrentHull.WaterPercentage), 0, 100);
|
||||
item.SendSignal(waterPercentage.ToString(), "water_%");
|
||||
}
|
||||
string highPressureOut = (item.CurrentHull == null || item.CurrentHull.LethalPressure > 5.0f) ? "1" : "0";
|
||||
item.SendSignal(highPressureOut, "high_pressure");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ namespace Barotrauma.Items.Components
|
||||
//signal strength diminishes by distance
|
||||
float sentSignalStrength = signal.strength *
|
||||
MathHelper.Clamp(1.0f - (Vector2.Distance(item.WorldPosition, wifiComp.item.WorldPosition) / wifiComp.range), 0.0f, 1.0f);
|
||||
Signal s = new Signal(signal.value, ++signal.stepsTaken, sender: signal.sender, source: signal.source,
|
||||
Signal s = new Signal(signal.value, signal.stepsTaken + 1, sender: signal.sender, source: signal.source,
|
||||
power: 0.0f, strength: sentSignalStrength);
|
||||
|
||||
if (wifiComp.signalOutConnection != null)
|
||||
|
||||
@@ -133,15 +133,15 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public bool IsConnectedTo(Item item)
|
||||
{
|
||||
if (connections[0] != null && connections[0].Item == item) return true;
|
||||
return (connections[1] != null && connections[1].Item == item);
|
||||
if (connections[0] != null && connections[0].Item == item) { return true; }
|
||||
return connections[1] != null && connections[1].Item == item;
|
||||
}
|
||||
|
||||
public void RemoveConnection(Item item)
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (connections[i] == null || connections[i].Item != item) continue;
|
||||
if (connections[i] == null || connections[i].Item != item) { continue; }
|
||||
|
||||
foreach (Wire wire in connections[i].Wires)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user