Created
June 15, 2021 13:21
-
-
Save handsomematt/c7298951511d6e82201c1195e2a47bd9 to your computer and use it in GitHub Desktop.
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
using Sandbox; | |
using System; | |
using System.Text; | |
namespace Hammer | |
{ | |
/// <summary> | |
/// Change the color of the wireframe box in the Hammer 2D views. | |
/// </summary> | |
[AttributeUsage( AttributeTargets.Class )] | |
public class ColorAttribute : MetaDataAttribute | |
{ | |
internal byte ColorR; | |
internal byte ColorG; | |
internal byte ColorB; | |
public ColorAttribute( byte r, byte g, byte b ) | |
{ | |
ColorR = r; | |
ColorG = g; | |
ColorB = b; | |
} | |
public override void AddHeader( StringBuilder sb ) | |
{ | |
sb.Append( $" color( {ColorR} {ColorG} {ColorB} )" ); | |
} | |
} | |
} |
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
using Sandbox; | |
using System; | |
using System.Text; | |
namespace Hammer | |
{ | |
/// <summary> | |
/// Draw the entity's transform angle or specific angles property in Hammer. | |
/// </summary> | |
[AttributeUsage( AttributeTargets.Class )] | |
public class DrawAnglesAttribute : MetaDataAttribute | |
{ | |
internal string AngleProperty; | |
internal string LocalProperty; | |
public DrawAnglesAttribute() { } | |
public DrawAnglesAttribute( string property ) | |
{ | |
AngleProperty = property; | |
} | |
public DrawAnglesAttribute( string property, string local ) | |
{ | |
AngleProperty = property; | |
LocalProperty = local; | |
} | |
public override void AddHeader( StringBuilder sb ) | |
{ | |
// drawangles() | |
// drawangles(angle) | |
// drawangles(angle, local) | |
sb.Append( " drawangles( " ); | |
if ( !string.IsNullOrEmpty( AngleProperty ) ) | |
{ | |
sb.Append( $"{StringX.QuoteSafe( AngleProperty )}" ); | |
if ( !string.IsNullOrEmpty( LocalProperty ) ) | |
sb.Append( $", {StringX.QuoteSafe( LocalProperty )}" ); | |
} | |
sb.Append( " ) " ); | |
} | |
} | |
} |
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
using Sandbox; | |
using System; | |
using System.Text; | |
namespace Hammer | |
{ | |
/// <summary> | |
/// Use this to indicate to the map builder that any meshes associated with this entity should have a different default physics type. | |
/// </summary> | |
/// <remarks> | |
/// Adds the base class PhysicsTypeOverride_* that the map builder is hard coded to use. | |
/// </remarks> | |
[AttributeUsage( AttributeTargets.Class )] | |
public class PhysicsTypeOverrideAttribute : MetaDataAttribute | |
{ | |
public enum PhysicsTypeOverride | |
{ | |
Mesh, | |
SingleConvex, | |
MultiConvex | |
}; | |
internal PhysicsTypeOverride PhysTypeOverride; | |
public PhysicsTypeOverrideAttribute( PhysicsTypeOverride type ) => PhysTypeOverride = type; | |
public override void AddHeader( StringBuilder sb ) | |
{ | |
// Seems a bit saner then relying on Enum.ToString() in the string builder.. | |
var name = PhysTypeOverride switch { | |
PhysicsTypeOverride.Mesh => "Mesh", | |
PhysicsTypeOverride.SingleConvex => "SingleConvex", | |
PhysicsTypeOverride.MultiConvex => "MultiConvex", | |
_ => throw new NotSupportedException() | |
}; | |
// todo: multiple bases | |
sb.Append( $" base( PhysicsTypeOverride_{PhysTypeOverride} ) " ); | |
} | |
} | |
} |
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
using Sandbox; | |
using System; | |
using System.Text; | |
namespace Hammer | |
{ | |
/// <summary> | |
/// Use this to add Render Properties to the entity, these are used by the map builder. | |
/// </summary> | |
[AttributeUsage( AttributeTargets.Class )] | |
public class RenderPropertiesAttribute : MetaDataAttribute | |
{ | |
public override void AddHeader( StringBuilder sb ) | |
{ | |
// todo: multiple bases | |
sb.Append( $" base( RenderFields ) " ); | |
} | |
public override void AddBody( StringBuilder sb ) | |
{ | |
// vrad_brush_cast_shadows is used internally by the map builder on brushes | |
sb.AppendLine( "\tvrad_brush_cast_shadows( boolean )[ group=\"Render Properties\" ] : \"Shadows\" : 0 : \"Set this if this brush casts lightmap shadows.\"" ); | |
// equally not covered in RenderFields base but still used by the map builder | |
sb.AppendLine( "\tdisableshadows( boolean )[group = \"Render Properties\"] : \"Disable shadows\" : 0" ); | |
} | |
} | |
} |
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
using Sandbox; | |
using System; | |
using System.Text; | |
namespace Hammer | |
{ | |
/// <summary> | |
/// Display a sphere of the specified property's radius in Hammer. | |
/// </summary> | |
[AttributeUsage( AttributeTargets.Class )] | |
public class SphereAttribute : MetaDataAttribute | |
{ | |
internal string Property; | |
public SphereAttribute( string property ) => Property = property; | |
public override void AddHeader( StringBuilder sb ) | |
{ | |
sb.Append( $" sphere( {StringX.QuoteSafe(Property)} )" ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment