mirror of
https://github.com/celisej567/gm_construct_port.git
synced 2026-01-01 09:48:13 +03:00
55 lines
1.4 KiB
C#
55 lines
1.4 KiB
C#
using System;
|
|
|
|
namespace Sandbox.Tools
|
|
{
|
|
[Library( "tool_resizer", Title = "Resizer", Description = "Change the scale of things", Group = "construction" )]
|
|
public partial class ResizerTool : BaseTool
|
|
{
|
|
public override void Simulate()
|
|
{
|
|
if ( !Host.IsServer )
|
|
return;
|
|
|
|
using ( Prediction.Off() )
|
|
{
|
|
var startPos = Owner.EyePos;
|
|
var dir = Owner.EyeRot.Forward;
|
|
int resizeDir = 0;
|
|
var reset = false;
|
|
|
|
if ( Input.Down( InputButton.Attack1 ) ) resizeDir = 1;
|
|
else if ( Input.Down( InputButton.Attack2 ) ) resizeDir = -1;
|
|
else if ( Input.Pressed( InputButton.Reload ) ) reset = true;
|
|
else return;
|
|
|
|
var tr = Trace.Ray( startPos, startPos + dir * MaxTraceDistance )
|
|
.Ignore( Owner )
|
|
.UseHitboxes()
|
|
.HitLayer( CollisionLayer.Debris )
|
|
.Run();
|
|
|
|
if ( !tr.Hit || !tr.Entity.IsValid() || tr.Entity.PhysicsGroup == null )
|
|
return;
|
|
|
|
// Disable resizing lights for now
|
|
if ( tr.Entity is LightEntity || tr.Entity is LampEntity )
|
|
return;
|
|
|
|
var scale = reset ? 1.0f : Math.Clamp( tr.Entity.Scale + ((0.5f * Time.Delta) * resizeDir), 0.4f, 4.0f );
|
|
|
|
if ( tr.Entity.Scale != scale )
|
|
{
|
|
tr.Entity.Scale = scale;
|
|
tr.Entity.PhysicsGroup.RebuildMass();
|
|
tr.Entity.PhysicsGroup.Wake();
|
|
}
|
|
|
|
if ( Input.Pressed( InputButton.Attack1 ) || Input.Pressed( InputButton.Attack2 ) || reset )
|
|
{
|
|
CreateHitEffects( tr.EndPos );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|