-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Button tool into BaseWireTool
- Loading branch information
Showing
6 changed files
with
86 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
namespace Sandbox.Tools | ||
{ | ||
public abstract partial class BaseWireTool : BaseTool | ||
{ | ||
PreviewEntity previewModel; | ||
|
||
abstract protected Type GetEntityType(); | ||
abstract protected string GetModel(); | ||
abstract protected ModelEntity SpawnEntity( TraceResult tr ); | ||
|
||
protected override bool IsPreviewTraceValid( TraceResult tr ) | ||
{ | ||
if ( !base.IsPreviewTraceValid( tr ) ) { | ||
return false; | ||
} | ||
if ( tr.Entity.GetType().IsSubclassOf( GetEntityType() ) ) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public override void CreatePreviews() | ||
{ | ||
if ( TryCreatePreview( ref previewModel, GetModel() ) ) { | ||
previewModel.RelativeToNormal = false; | ||
} | ||
} | ||
|
||
public override void Simulate() | ||
{ | ||
if ( !Host.IsServer ) { | ||
return; | ||
} | ||
|
||
using ( Prediction.Off() ) { | ||
var input = Owner.Input; | ||
|
||
if ( !input.Pressed( InputButton.Attack1 ) ) | ||
return; | ||
|
||
var startPos = Owner.EyePos; | ||
var dir = Owner.EyeRot.Forward; | ||
|
||
var tr = Trace.Ray( startPos, startPos + dir * MaxTraceDistance ) | ||
.Ignore( Owner ) | ||
.Run(); | ||
|
||
if ( !tr.Hit || !tr.Entity.IsValid() ) { | ||
return; | ||
} | ||
|
||
CreateHitEffects( tr.EndPos ); | ||
|
||
if ( tr.Entity.GetType().IsSubclassOf( GetEntityType() ) ) { | ||
return; | ||
} | ||
|
||
var ent = SpawnEntity( tr ); | ||
ent.SetModel( GetModel() ); | ||
|
||
var attachEnt = tr.Body.IsValid() ? tr.Body.Entity : tr.Entity; | ||
|
||
if ( attachEnt.IsValid() ) { | ||
ent.SetParent( tr.Body.Entity, tr.Body.PhysicsGroup.GetBodyBoneName( tr.Body ) ); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
xcopy /E models\wirebox\ ..\..\..\models\wirebox\ | ||
xcopy /E /Y models\wirebox\ ..\..\..\models\wirebox\ |