Park/Buildings/PathSpeaker.cs
using System.Text.Json.Nodes;
namespace HC3;
public sealed class PathSpeaker : PathFurniture
{
[Property] public MusicPlayer MusicPlayer { get; set; }
[Inspectable]
public MusicTrack Track
{
get => MusicPlayer.Track;
set
{
MusicPlayer.Track = value;
}
}
//[Inspectable]
public bool BrokenDown
{
get => MusicPlayer.IsBrokenDown;
set => MusicPlayer.IsBrokenDown = value;
}
protected override void WriteMetadata( JsonObject json )
{
base.WriteMetadata( json );
json["Music"] = Track?.ResourcePath;
}
protected override void ReadMetadata( JsonObject json )
{
base.ReadMetadata( json );
if ( json.TryGetPropertyValue( "Music", out var textNode ) )
{
MusicPlayer.SetTrack( textNode?.GetValue<string>() );
}
}
[Button]
public void Play()
{
Sound.StopAll( 0 );
Sound.PlayFile( SoundFile.Load( "file_example_oog_5mg.ogg" ), 1, 1, 1 );
}
}