From 5ad4c1f09da67700b2f96d935341b8429750e67c Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Fri, 18 Oct 2024 12:44:26 +0800 Subject: [PATCH] =?UTF-8?q?Add=20audio=20logs.=20=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E9=9F=B3=E9=A2=91=E7=9A=84=E6=97=A5=E5=BF=97=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locals/Log.csv | 5 ++++- scripts/pickable/PickAbleTemplate.cs | 8 ++++---- scripts/weapon/WeaponTemplate.cs | 27 +++++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/locals/Log.csv b/locals/Log.csv index 1edc100..e7c71f1 100644 --- a/locals/Log.csv +++ b/locals/Log.csv @@ -126,4 +126,7 @@ log_parameter_inconsistency,参数不齐。,Parameter inconsistency.,パラメ log_room_slot_position_is_empty,房间位置描述为空。,Room location is described as empty.,部屋の位置は空です。 log_room_overlap,房间重叠。,The rooms overlap.,部屋が重なります。 log_game_over_event_is_empty,游戏结束事件为空。,End of game event is empty.,ゲームオーバーでイベントは空です。 -log_cannot_resurrect_non_existent_player,不能复活不存在的玩家。,Cannot resurrect non-existent players.,存在しないプレイヤーを復活させることはできません。 \ No newline at end of file +log_cannot_resurrect_non_existent_player,不能复活不存在的玩家。,Cannot resurrect non-existent players.,存在しないプレイヤーを復活させることはできません。 +log_no_audio_stream_player,没有音频播放器组件。,No audio player component.,オーディオプレーヤーキットはありません。 +log_audio_stream_player_is_playing,音频播放器正在播放中。,The audio player is playing.,オーディオプレーヤーが再生中です。 +log_play_audio,播放音频BUS为{0}Stream为{1}.,BUS is {0} and Stream is {1}.,再生オーディオはBUSが{0}Streamが{1}です。 \ No newline at end of file diff --git a/scripts/pickable/PickAbleTemplate.cs b/scripts/pickable/PickAbleTemplate.cs index 6b28f33..27d677e 100644 --- a/scripts/pickable/PickAbleTemplate.cs +++ b/scripts/pickable/PickAbleTemplate.cs @@ -168,18 +168,18 @@ public partial class PickAbleTemplate : RigidBody2D, IItem } private CollisionShape2D? _collisionShape2D; - + /// /// Whether the resource has been loaded /// 是否已加载过资源了 /// private bool _loadedResource; - public sealed override void _Ready() + public override void _Ready() { LoadResource(); } - + public virtual void LoadResource() { @@ -196,7 +196,7 @@ public partial class PickAbleTemplate : RigidBody2D, IItem SetCollisionMaskValue(Config.LayerNumber.Barrier, true); _loadedResource = true; } - + public override void _MouseEnter() { if (Picked) diff --git a/scripts/weapon/WeaponTemplate.cs b/scripts/weapon/WeaponTemplate.cs index 0843e65..250c619 100644 --- a/scripts/weapon/WeaponTemplate.cs +++ b/scripts/weapon/WeaponTemplate.cs @@ -1,5 +1,6 @@ using System; using ColdMint.scripts.character; +using ColdMint.scripts.debug; using ColdMint.scripts.pickable; using Godot; @@ -22,7 +23,10 @@ public abstract partial class WeaponTemplate : PickAbleTemplate public override void LoadResource() { base.LoadResource(); - _audioStreamPlayer2D = GetNode("Marker2D/AudioStreamPlayer2D"); + if (_audioStreamPlayer2D == null) + { + _audioStreamPlayer2D = GetNode("Marker2D/AudioStreamPlayer2D"); + } } public override bool Use(Node2D? owner, Vector2 targetGlobalPosition) @@ -97,7 +101,26 @@ public abstract partial class WeaponTemplate : PickAbleTemplate characterTemplate.AddForce(enemyGlobalPosition.DirectionTo(characterTemplate.GlobalPosition) * _recoilStrength * Config.CellSize); } } - _audioStreamPlayer2D?.Play(); + if (_audioStreamPlayer2D == null) + { + //No audio player + //没有音频播放器 + LogCat.Log("no_audio_stream_player"); + return true; + } + + if (_audioStreamPlayer2D.IsPlaying()) + { + //The audio is playing + //音频正在播放中 + LogCat.Log("audio_stream_player_is_playing"); + return true; + } + + //Play audio + //播放音频 + LogCat.LogWithFormat("play_audio", LogCat.LogLabel.Default, _audioStreamPlayer2D.Bus, _audioStreamPlayer2D.Stream); + _audioStreamPlayer2D.Play(); } return result; }