Code/GolfCourseInfo.cs

A scene component that holds metadata for a golf course scene: course name, ambience sound, shadow cascade distance, and which wall kit style to use. It also includes a static helper to find the component in a Scene.

using Sandbox;
using System.Linq;

/// <summary>
/// What a course scene says about itself, on one object at the scene root. The game reads it:
/// the name, the ambience loop played while the scene is loaded, how far the sun's shadows reach
/// (0 leaves the engine's own distance), and which wall set the Kit Wall Builder picks.
/// </summary>
[Title( "Golf Course Info" ), Category( "Golf" ), Icon( "flag" )]
public sealed class GolfCourseInfo : Component
{
	/// <summary>The models the Kit Wall Builder tool places: the Blender kit (wall_100 and post_10) or the Minigolf hedge set.</summary>
	public enum KitWallStyle
	{
		Kit,
		Minigolf,
	}

	/// <summary>The course's name, as shown to the players.</summary>
	[Property, Title( "Course Name" )]
	public string CourseName { get; set; } = "";

	/// <summary>A 2D loop every machine plays while this scene is loaded. None for a silent course.</summary>
	[Property]
	public SoundEvent Ambience { get; set; }

	/// <summary>
	/// How far from the camera the sun's shadow cascades reach, in units, while this course is
	/// loaded. A small course gets crisp shadows from a short distance; 0 keeps the engine default.
	/// </summary>
	[Property, Title( "Shadow Distance" ), Range( 0f, 20000f )]
	public float ShadowDistance { get; set; } = 0f;

	/// <summary>Which wall models the Kit Wall Builder places on this course.</summary>
	[Property, Title( "Wall Style" )]
	public KitWallStyle WallStyle { get; set; } = KitWallStyle.Kit;

	/// <summary>The course info in a scene, or null when it has none.</summary>
	public static GolfCourseInfo Find( Scene scene )
	{
		return scene?.GetAllComponents<GolfCourseInfo>().FirstOrDefault();
	}
}