Skip to content

Commit

Permalink
Gates: add Constant Value
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebual committed Jun 13, 2021
1 parent abafb42 commit a7d4164
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.vmdl_c
*.vpcf_c
*.vmat_c
*.vtex_c
3 changes: 0 additions & 3 deletions code/entities/ThrusterEntity.wire.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

public partial class ThrusterEntity : WireInputEntity
{
// todo: the vanilla ThrusterEntity is just on/off, so we'll probably want to just replace it entirely, rather than this extending...
[Net]
public float ForceMultiplier { get; set; } = 1.0f;
WirePortData IWireEntity.WirePorts { get; } = new WirePortData();
public void WireInitialize()
{
Expand Down
31 changes: 29 additions & 2 deletions code/entities/WireGateEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@
using System.Linq;

[Library( "ent_wiregate", Title = "Wire Gate" )]
public partial class WireGateEntity : Prop, WireInputEntity, WireOutputEntity
public partial class WireGateEntity : Prop, WireInputEntity, WireOutputEntity, IUse
{
[Net]
public string GateType { get; set; } = "Add";

private int constantValue = 3;

[Net]
public string DebugText { get; set; } = "";
WirePortData IWireEntity.WirePorts { get; } = new WirePortData();

public static IEnumerable<string> GetGates()
{
return new string[] { "Constant", "Add", "Subtract", "Negate", "Not", "And", "Or" };
}
public void WireInitialize()
{
var inputs = ((IWireEntity)this).WirePorts.inputs;
Expand Down Expand Up @@ -67,6 +77,10 @@ public void WireInitialize()
this.WireTriggerOutput( "Out", outValue );
}, new string[] { "A", "B", "C", "D", "E", "F", "G", "H" } );
}
else if ( GateType == "Constant" ) {
DebugText = $" value: {constantValue}";
this.WireTriggerOutput( "Out", constantValue );
}
}

protected void BulkRegisterInputHandlers( Action<float> handler, string[] inputNames )
Expand All @@ -88,6 +102,19 @@ public string[] WireGetOutputs()

string IWireEntity.GetOverlayText()
{
return $"Gate: {GateType}";
return $"Gate: {GateType}{DebugText}";
}

public bool OnUse( Entity user )
{
if ( GateType == "Constant" && Host.IsServer ) {
constantValue += Input.Down( InputButton.Run ) ? -1 : 1;
}
return false;
}

public bool IsUsable( Entity user )
{
return this.GateType == "Constant";
}
}
2 changes: 1 addition & 1 deletion code/tools/Wiring.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public partial class WireGatePanel : Panel
{
public WireGatePanel()
{
foreach ( var name in new string[] { "Add", "Subtract", "Negate", "Not", "And", "Or" } ) {
foreach ( var name in WireGateEntity.GetGates() ) {
Add.Button( name, () => {
ConsoleSystem.Run( "wire_spawn_gate", name );
} );
Expand Down
Binary file removed models/wirebox/katlatze/button.vmdl_c
Binary file not shown.
Binary file removed models/wirebox/katlatze/spoon.vmdl_c
Binary file not shown.

0 comments on commit a7d4164

Please sign in to comment.