Audio system and rich text
This commit is contained in:
parent
a6f817efbc
commit
68cafff083
161 changed files with 1605 additions and 255 deletions
85
scripts/audio/AudioSequencer.cs
Normal file
85
scripts/audio/AudioSequencer.cs
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
public partial class AudioSequencer : Node
|
||||
{
|
||||
private static AudioSequencer instance;
|
||||
private Dictionary<string, AudioStreamPlayer> channels = [];
|
||||
private Dictionary<string, bool> channelProcess = [];
|
||||
private Dictionary<string, ChannelSettings> channelSettings = [];
|
||||
|
||||
[Export]
|
||||
private ChannelSettings standardSettings;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public static bool IsChannelPlaying(string id)
|
||||
{
|
||||
if (instance.channels.ContainsKey(id) == false)
|
||||
{
|
||||
instance.InitiateChannel(id);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (instance.channelSettings[id].restartTreshold == 0)
|
||||
return false;
|
||||
if (instance.channelSettings[id].restartTreshold < 0)
|
||||
return instance.channelProcess[id];
|
||||
|
||||
return instance.channelProcess[id] && instance.channels[id].GetPlaybackPosition() < instance.channelSettings[id].restartTreshold / Engine.TimeScale;
|
||||
}
|
||||
|
||||
public static void Play(string id, AudioStream what)
|
||||
{
|
||||
if (IsChannelPlaying(id)) return;
|
||||
instance.PlayAtChannel(id, what);
|
||||
}
|
||||
|
||||
public static void ChangeSettings(string id, ChannelSettings settings)
|
||||
{
|
||||
if (instance.channels.ContainsKey(id) == false)
|
||||
{
|
||||
instance.InitiateChannel(id, settings);
|
||||
return;
|
||||
}
|
||||
instance.channelSettings[id] = settings;
|
||||
}
|
||||
|
||||
private AudioStreamPlayer InitiateChannel(string id, ChannelSettings settings = null)
|
||||
{
|
||||
AudioStreamPlayer player = new();
|
||||
|
||||
AddChild(player);
|
||||
channels.Add(id, player);
|
||||
channelProcess.Add(id, false);
|
||||
player.Name = id;
|
||||
|
||||
player.Finished += () => { MarkChannel(id, false); };
|
||||
|
||||
if (settings != null)
|
||||
{
|
||||
channelSettings.Add(id, settings);
|
||||
}
|
||||
else
|
||||
{
|
||||
channelSettings.Add(id, standardSettings);
|
||||
}
|
||||
|
||||
return player;
|
||||
}
|
||||
|
||||
private void PlayAtChannel(string id, AudioStream what)
|
||||
{
|
||||
channels[id].Stream = what;
|
||||
channels[id].Play();
|
||||
MarkChannel(id, true);
|
||||
}
|
||||
|
||||
private void MarkChannel(string id, bool how)
|
||||
{
|
||||
channelProcess[id] = how;
|
||||
}
|
||||
}
|
||||
1
scripts/audio/AudioSequencer.cs.uid
Normal file
1
scripts/audio/AudioSequencer.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cauc1ieq84fwg
|
||||
43
scripts/audio/AudioSlider.cs
Normal file
43
scripts/audio/AudioSlider.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using Godot;
|
||||
using Newlon;
|
||||
|
||||
public partial class AudioSlider : HSlider
|
||||
{
|
||||
enum TYPE
|
||||
{
|
||||
SFX,
|
||||
MUSIC
|
||||
}
|
||||
|
||||
[Export] private TYPE affects;
|
||||
public override void _Ready()
|
||||
{
|
||||
DragEnded += OnDragEnded;
|
||||
if (affects == TYPE.SFX)
|
||||
{
|
||||
SetValueNoSignal(Utility.SFX);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetValueNoSignal(Utility.Music);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDragEnded(bool hasChanged)
|
||||
{
|
||||
if (hasChanged)
|
||||
{
|
||||
if (affects == TYPE.SFX)
|
||||
{
|
||||
Utility.SFX = Value;
|
||||
AudioServer.SetBusVolumeDb(0, Mathf.LinearToDb((float)Value));
|
||||
}
|
||||
else
|
||||
{
|
||||
Utility.Music = Value;
|
||||
AudioServer.SetBusVolumeDb(1, Mathf.LinearToDb((float)Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
1
scripts/audio/AudioSlider.cs.uid
Normal file
1
scripts/audio/AudioSlider.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://ciccaxqo70s13
|
||||
16
scripts/audio/ChannelPlayer.cs
Normal file
16
scripts/audio/ChannelPlayer.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using Godot;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class ChannelPlayer : Node
|
||||
{
|
||||
[Export] private ChannelSettings settings;
|
||||
[Export] private AudioStream audioStream;
|
||||
[Export] private string channel;
|
||||
|
||||
public void Play()
|
||||
{
|
||||
AudioSequencer.Play(channel, audioStream);
|
||||
if (settings != null)
|
||||
AudioSequencer.ChangeSettings(channel, settings);
|
||||
}
|
||||
}
|
||||
1
scripts/audio/ChannelPlayer.cs.uid
Normal file
1
scripts/audio/ChannelPlayer.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c36bj8u7jghc7
|
||||
35
scripts/audio/ChannelPlaylist.cs
Normal file
35
scripts/audio/ChannelPlaylist.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class ChannelPlaylist : Node
|
||||
{
|
||||
[Export] private Array<AudioStream> playlist;
|
||||
[Export] private Array<string> channels;
|
||||
[Export] private ChannelSettings channelSettings;
|
||||
private int internal_index = 0;
|
||||
|
||||
public void Play()
|
||||
{
|
||||
AudioSequencer.Play(channels[internal_index], playlist[internal_index]);
|
||||
}
|
||||
|
||||
public void SetIndex(int index)
|
||||
{
|
||||
internal_index = index;
|
||||
if (internal_index >= playlist.Count)
|
||||
{
|
||||
internal_index = 0;
|
||||
}
|
||||
else if (internal_index < 0)
|
||||
{
|
||||
internal_index = playlist.Count - 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void Next()
|
||||
{
|
||||
SetIndex(internal_index + 1);
|
||||
}
|
||||
|
||||
}
|
||||
1
scripts/audio/ChannelPlaylist.cs.uid
Normal file
1
scripts/audio/ChannelPlaylist.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cnn0ymuhypdff
|
||||
7
scripts/audio/ChannelSettings.cs
Normal file
7
scripts/audio/ChannelSettings.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
using Godot;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class ChannelSettings : Resource
|
||||
{
|
||||
[Export] public float restartTreshold;
|
||||
}
|
||||
1
scripts/audio/ChannelSettings.cs.uid
Normal file
1
scripts/audio/ChannelSettings.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c1x4n4nqyq72f
|
||||
Loading…
Add table
Add a link
Reference in a new issue