优化 sfx_config_panel

This commit is contained in:
cakipaul 2025-07-19 15:02:32 +08:00
parent 301ee98c0f
commit aaa7dc26bb
12 changed files with 194 additions and 121 deletions

View File

@ -4,7 +4,6 @@ extends CanvasLayer
func _ready() -> void:
AudioManager.process_mode = Node.PROCESS_MODE_PAUSABLE
SceneManager.toggle_pause_counter(true, "debugging")
layer = GlobalConfig.CANVAS_LAYER_SETTINGS
quit_debug_button.pressed.connect(_on_quit_debug_button_pressed)
@ -31,7 +30,6 @@ func _on_quit_debug_button_pressed() -> void:
func _exit_tree() -> void:
AudioManager.process_mode = Node.PROCESS_MODE_ALWAYS
SceneManager.toggle_pause_counter(false, "debugging")

View File

@ -236,7 +236,7 @@ func _load_manual_archive(_id: int, data: Dictionary) -> void:
ArchiveManager.archive = saving_archive
print("Loading archive from: ", data.path, " to: ", target_path)
# Reload current scene
get_tree().reload_current_scene()
SceneManager.enter_main_scene()
else:
_show_notification("加载存档失败:" + data.name)

View File

@ -6,6 +6,7 @@ extends Control
# 面板相关
@onready var scroll_container: ScrollContainer = %ScrollContainer
@onready var vbox_container: VBoxContainer = %VBoxContainer
@onready var reset_button: Button = %ResetButton
@onready var import_button: Button = %ImportButton
@onready var export_button: Button = %ExportButton
# 音频预览播放器
@ -21,6 +22,7 @@ var current_scene_name: String = ""
func _ready():
file_dialog.file_selected.connect(_on_file_selected)
reset_button.pressed.connect(_on_reset_pressed)
import_button.pressed.connect(_on_import_pressed)
export_button.pressed.connect(_on_export_pressed)
# 初始加载
@ -29,14 +31,12 @@ func _ready():
# 1. 检测 current_scene 下 Sfx 节点
func refresh_sfx_list(ground: Ground2D, headless := false):
if not headless:
clear_ui()
sfx_nodes.clear()
current_scene_name = GroundLoader.get_ground_scene_readable_name(ground.scene_name)
find_sfx_nodes(ground)
load_config()
if not headless:
create_ui_items()
refresh_ui()
var ignore_class_list = ["Portal2D", "Interactable2D", "Note2D", "Inspectable2D", "Pickable2D", "Npc2D", "Ambush2D"]
@ -62,6 +62,11 @@ func create_ui_items():
for sfx_node in sfx_nodes:
create_sfx_item(sfx_node)
func refresh_ui():
clear_ui()
create_ui_items()
func create_sfx_item(sfx_node: Node):
var item_container = VBoxContainer.new()
item_container.add_theme_constant_override("separation", 8)
@ -120,24 +125,29 @@ func create_sfx_item(sfx_node: Node):
stream_vbox.add_child(stream_hbox)
var stream_name_label = Label.new()
if sfx_node.stream:
stream_name_label.text = sfx_node.stream.resource_path.get_file()
else:
stream_name_label.text = "无音频文件"
stream_name_label.custom_minimum_size.x = 150
_set_stream_name_label(sfx_node, stream_name_label)
stream_hbox.add_child(stream_name_label)
# 预览播放按钮
var preview_button = Button.new()
preview_button.text = ""
preview_button.custom_minimum_size = Vector2(30, 30)
preview_button.pressed.connect(func(): preview_audio(sfx_node))
preview_button.pressed.connect(preview_audio.bind(sfx_node))
stream_hbox.add_child(preview_button)
# 恢复默认按钮
if sfx_node.stream_was_replaced():
var reset_button = Button.new()
reset_button.text = "🗑️"
reset_button.custom_minimum_size = Vector2(30, 30)
reset_button.pressed.connect(reset_audio.bind(sfx_node))
stream_hbox.add_child(reset_button)
# 3. 上传文件按钮
var upload_button = Button.new()
upload_button.text = "上传音频"
upload_button.pressed.connect(func(): open_file_dialog(sfx_node, stream_name_label))
upload_button.pressed.connect(open_file_dialog.bind(sfx_node, stream_name_label))
stream_hbox.add_child(upload_button)
# 分割线
@ -148,12 +158,28 @@ func create_sfx_item(sfx_node: Node):
item_container.set_meta("sfx_node", sfx_node)
item_container.set_meta("stream_label", stream_name_label)
func preview_audio(sfx_node: Node):
func _set_stream_name_label(sfx_node:Sfx, stream_name_label:Label) -> void:
if sfx_node.stream:
stream_name_label.text = sfx_node.stream.resource_path.get_file()
else:
stream_name_label.text = "无音频文件"
func preview_audio(sfx_node: Sfx):
if sfx_node.stream:
preview_player.stream = sfx_node.stream
preview_player.volume_db = sfx_node.volume_db
preview_player.play()
func reset_audio(sfx_node: Sfx):
sfx_node.reset_original_stream()
config_data.erase(sfx_node.name)
save_config()
refresh_ui()
var current_upload_node: Node
var current_stream_label: Label
@ -162,46 +188,44 @@ func open_file_dialog(sfx_node: Node, stream_label: Label):
current_stream_label = stream_label
file_dialog.popup_centered()
func _on_file_selected(path: String):
if not current_upload_node:
return
copy_and_load_audio_file(path, current_upload_node, current_stream_label)
# 3. 复制文件并加载
func copy_and_load_audio_file(source_path: String, sfx_node: Node, stream_label: Label):
var file_name = source_path.get_file()
var audio_dir = "user://audio/" + current_scene_name + "/"
var target_path = audio_dir + file_name
# 确保目录存在
DirAccess.open("user://").make_dir_recursive("audio/" + current_scene_name)
# 复制文件
var source_file = FileAccess.open(source_path, FileAccess.READ)
if not source_file:
push_error("无法读取源文件: " + source_path)
return
var target_file = FileAccess.open(target_path, FileAccess.WRITE)
if not target_file:
push_error("无法创建目标文件: " + target_path)
source_file.close()
return
target_file.store_buffer(source_file.get_buffer(source_file.get_length()))
source_file.close()
target_file.close()
# 加载新的音频流
var new_stream = AudioLoader.new().loadfile(target_path)
if new_stream:
sfx_node.stream = new_stream
sfx_node.replace_stream(new_stream)
stream_label.text = file_name
save_node_config(sfx_node.name, "stream", target_path)
print("音频文件已更新: ", sfx_node.name, " -> ", file_name)
else:
push_error("无法加载音频文件: " + target_path)
refresh_ui()
# 4. 配置保存与加载
func save_node_config(node_name: String, property: String, value):
@ -233,6 +257,7 @@ func load_config():
else:
config_data = {}
func apply_config():
for sfx_node in sfx_nodes:
if config_data.has(sfx_node.name):
@ -245,7 +270,17 @@ func apply_config():
var new_stream = AudioLoader.new().loadfile(stream_path)
# var new_stream = load(stream_path)
if new_stream:
sfx_node.stream = new_stream
sfx_node.replace_stream(new_stream)
func _on_reset_pressed() -> void:
for sfx_node in sfx_nodes:
sfx_node.reset_original_stream()
var config_file_path = "user://audio/" + current_scene_name + "/" + "/audio_config.dat"
if FileAccess.file_exists(config_file_path):
DirAccess.remove_absolute(config_file_path)
SceneManager.enter_main_scene()
# 5. Import/Export 功能
func _on_import_pressed():
@ -282,11 +317,9 @@ func _on_import_folder_selected(folder_path: String):
var source_path = folder_path + "/" + file_name
var target_path = target_dir + file_name
copy_file(source_path, target_path)
file_name = dir.get_next()
dir.list_dir_end()
# 重新加载配置
load_config()
refresh_sfx_list(SceneManager.get_ground())
print("配置和音频文件已导入")

View File

@ -22,6 +22,12 @@ theme_override_font_sizes/font_size = 18
text = "音效配置面板"
horizontal_alignment = 1
[node name="ResetButton" type="Button" parent="MainVBox/HeaderHBox"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 8
text = "重置所有配置"
[node name="ImportButton" type="Button" parent="MainVBox/HeaderHBox"]
unique_name_in_owner = true
layout_mode = 2

View File

@ -1,4 +1,4 @@
[gd_resource type="Resource" script_class="VibeGroupCollection" load_steps=22 format=3 uid="uid://bfhwn1v0c2io7"]
[gd_resource type="Resource" script_class="VibeGroupCollection" load_steps=18 format=3 uid="uid://bfhwn1v0c2io7"]
[ext_resource type="Script" uid="uid://cy1ngx5no67v" path="res://manager/audio_manager/vibe_group.gd" id="1_0bbao"]
[ext_resource type="Script" uid="uid://bo8gxwe8hfs01" path="res://manager/audio_manager/vibe_group_collection.gd" id="2_h4hph"]
@ -10,8 +10,6 @@
[ext_resource type="AudioStream" uid="uid://6oc0cgc3mbqb" path="res://asset/audio/sfx/环境音/白噪音/白噪声楼道2.ogg" id="7_lca37"]
[ext_resource type="AudioStream" uid="uid://c6ehv3lgway26" path="res://asset/audio/sfx/环境音/白噪音/白噪声诡异室外.ogg" id="8_646q0"]
[ext_resource type="AudioStream" uid="uid://s7uigovfp5g3" path="res://asset/audio/sfx/环境音/第一章/火灾演出.ogg" id="9_wuwx1"]
[ext_resource type="AudioStream" uid="uid://d0ef0felylt8d" path="res://asset/audio/sfx/环境音/第一章/氛围不受欢迎的存在.ogg" id="10_uwtc1"]
[ext_resource type="AudioStream" uid="uid://bal423qlb3jp2" path="res://asset/audio/sfx/环境音/点缀音/sfx_夜晚虫鸣.ogg" id="11_scrw7"]
[sub_resource type="Resource" id="Resource_bjndi"]
script = ExtResource("1_0bbao")
@ -76,25 +74,7 @@ base_sound_db = 0.0
embellishments = Array[ExtResource("3_scrw7")]([])
metadata/_custom_type_script = "uid://cy1ngx5no67v"
[sub_resource type="Resource" id="Resource_f75a1"]
script = ExtResource("1_0bbao")
group_name = &"氛围_不受欢迎的存在"
group_db = 0.0
base_sound = ExtResource("10_uwtc1")
base_sound_db = -12.0
embellishments = Array[ExtResource("3_scrw7")]([])
metadata/_custom_type_script = "uid://cy1ngx5no67v"
[sub_resource type="Resource" id="Resource_scrw7"]
script = ExtResource("1_0bbao")
group_name = &"夜晚虫鸣"
group_db = 0.0
base_sound = ExtResource("11_scrw7")
base_sound_db = -10.0
embellishments = Array[ExtResource("3_scrw7")]([])
metadata/_custom_type_script = "uid://cy1ngx5no67v"
[resource]
script = ExtResource("2_h4hph")
groups = Array[ExtResource("1_0bbao")]([SubResource("Resource_bjndi"), SubResource("Resource_chrc1"), SubResource("Resource_7c7wx"), SubResource("Resource_an5bn"), SubResource("Resource_egnaw"), SubResource("Resource_e3r3f"), SubResource("Resource_j0xlt"), SubResource("Resource_f75a1"), SubResource("Resource_scrw7")])
groups = Array[ExtResource("1_0bbao")]([SubResource("Resource_bjndi"), SubResource("Resource_chrc1"), SubResource("Resource_7c7wx"), SubResource("Resource_an5bn"), SubResource("Resource_egnaw"), SubResource("Resource_e3r3f"), SubResource("Resource_j0xlt")])
metadata/_custom_type_script = "uid://bo8gxwe8hfs01"

View File

@ -7,6 +7,8 @@ enum VIBE {
TOUCHING,
}
signal pause_counter_updated
# 从 ground loader 控制该信号
# 建议使用 CONNECT_ONE_SHOT 来连接 ground ready 与 start 等信号
@warning_ignore("unused_signal")
@ -354,14 +356,14 @@ var main_scene = preload("uid://dygvcmykn02n8")
func enter_main_scene() -> void:
# 防止撕裂帧
await get_tree().process_frame
get_tree().change_scene_to_packed.call_deferred(main_scene)
# get_tree().change_scene_to_file.call_deferred("uid://dygvcmykn02n8")
if pause_counter_arr.size() > 0:
printerr("enter_main_scene: pause_counter_arr is not empty, resetting pause counter")
pause_counter_arr.clear()
get_tree().paused = false
# 防止撕裂帧
await get_tree().process_frame
get_tree().change_scene_to_packed.call_deferred(main_scene)
#### debugging
@ -426,6 +428,8 @@ func toggle_pause_counter(plus := true, from := "") -> void:
print("SceneTree pause_counter_arr: ", pause_counter_arr)
get_tree().paused = len(pause_counter_arr) > 0
pause_counter_mutex.unlock()
# 增删结束后再发射信号
pause_counter_updated.emit()
func quit_game() -> void:

View File

@ -1,8 +1,11 @@
@tool
class_name Sfx extends AudioStreamPlayer
const META_ORIGINAL_STREAM = &"original_stream"
@export_enum("交互与效果音", "BGM", "场景背景音") var mode := "交互与效果音":
set(value):
_set_up_process_mode_by_mode()
mode = value
notify_property_list_changed()
@ -13,19 +16,36 @@ var default_db := 0.0
# 只有 场景背景音 生效
var scene_loop := true
var scene_autostart := true
var scene_sense_player_mov := false
func _ready() -> void:
bus = &"game_sfx"
default_db = volume_db
process_mode = Node.PROCESS_MODE_INHERIT
if Engine.is_editor_hint():
return
# 记录原 stream
if stream:
set_meta(META_ORIGINAL_STREAM, stream)
else:
set_meta(META_ORIGINAL_STREAM, null)
_set_up_process_mode_by_mode()
finished.connect(_on_finished)
# ground 退出时process mode 切换为 alwaysease out
SceneManager.ground_transition_pre_paused.connect(_on_ground_transition_pre_paused)
SceneManager.pause_counter_updated.connect(_on_pause_counter_updated)
func _on_pause_counter_updated() -> void:
_set_up_process_mode_by_mode()
func _set_up_process_mode_by_mode():
# 如果是 debug panel则 pause
if mode == "场景背景音" and not SceneManager.pause_counter_arr.has("debugging"):
process_mode = Node.PROCESS_MODE_ALWAYS
else:
process_mode = Node.PROCESS_MODE_PAUSABLE
func _on_ground_transition_pre_paused():
@ -40,6 +60,25 @@ func _on_finished() -> void:
play()
func reset_original_stream(ignore_null := true):
var original_stream = get_meta(META_ORIGINAL_STREAM)
if original_stream != null:
replace_stream(original_stream)
elif not ignore_null:
stream = null
func replace_stream(new_stream: AudioStream) -> void:
stop()
stream = new_stream
if autoplay and is_node_ready():
play()
func stream_was_replaced() -> bool:
return get_meta(META_ORIGINAL_STREAM) != stream
func resart(ease_duration := 1.0):
easing_kill(ease_duration).tween_callback(play)
@ -75,18 +114,17 @@ func _get_property_list() -> Array[Dictionary]:
"type": TYPE_NIL,
"usage": PROPERTY_USAGE_GROUP,
},
{"name": "自动开始", "type": TYPE_BOOL},
{"name": "循环播放", "type": TYPE_BOOL},
{"name": "感应玩家操作", "type": TYPE_BOOL}
]
func _property_can_revert(property: StringName) -> bool:
return property == "自动开始" or property == "循环播放" or property == "感应玩家操作"
return property == "循环播放" or property == "感应玩家操作"
func _property_get_revert(property: StringName) -> Variant:
if property == "自动开始" or property == "循环播放":
if property == "循环播放":
return true
elif property == "感应玩家操作":
return false
@ -96,11 +134,6 @@ func _property_get_revert(property: StringName) -> Variant:
func _set(property: StringName, value: Variant) -> bool:
if mode != "场景背景音":
return false
if property == "自动开始":
if value != null:
autoplay = value
scene_autostart = value
return true
elif property == "循环播放":
scene_loop = value
return true
@ -113,8 +146,6 @@ func _set(property: StringName, value: Variant) -> bool:
func _get(property: StringName) -> Variant:
if mode != "场景背景音":
return null
if property == "自动开始":
return scene_autostart
elif property == "循环播放":
return scene_loop
elif property == "感应玩家操作":

View File

@ -232,12 +232,13 @@ func _add_ground() -> void:
if not Engine.is_editor_hint():
_setup_player_position()
# debug 模式在 ground add 之前加载音频
add_child(ground)
# debug 模式在 ground add 之后加载音频
# 防止影响 Sfx 的 META 设置 ORIGINAL_STREAM
if GlobalConfig.DEBUG:
# headless 模式
SfxConfigPanel.new().refresh_sfx_list(ground, true)
add_child(ground)
print(
"GroundLoader add_ground finished:",

View File

@ -1,10 +1,12 @@
[gd_scene load_steps=12 format=3 uid="uid://bbs7yy5aofw1v"]
[gd_scene load_steps=14 format=3 uid="uid://bbs7yy5aofw1v"]
[ext_resource type="PackedScene" uid="uid://dayyx4jerj7io" path="res://scene/ground/ground.tscn" id="1_c4tdi"]
[ext_resource type="Script" uid="uid://jkselt4d5q4r" path="res://scene/ground/scene/c02/s01_公寓门口.gd" id="2_jfumy"]
[ext_resource type="Script" uid="uid://cpejxlfni6n52" path="res://manager/audio_manager/vibe_sfx.gd" id="3_bhi7l"]
[ext_resource type="AudioStream" uid="uid://dvc2emnfcmabx" path="res://asset/audio/sfx/环境音/白噪音/白噪声楼道1.ogg" id="4_ev3cr"]
[ext_resource type="Script" uid="uid://rq6w1vuhuq1m" path="res://scene/entity/audio/sfx.gd" id="5_ev3cr"]
[ext_resource type="Texture2D" uid="uid://d05pqud4yoxx3" path="res://asset/art/scene/c02/s01_公寓门口/bg_公寓门口.png" id="5_j2ctx"]
[ext_resource type="PackedScene" uid="uid://jr1yd46wm5je" path="res://scene/entity/note.tscn" id="6_bhi7l"]
[ext_resource type="AudioStream" uid="uid://bal423qlb3jp2" path="res://asset/audio/sfx/环境音/点缀音/sfx_夜晚虫鸣.ogg" id="6_ev3cr"]
[ext_resource type="PackedScene" uid="uid://ci5anaxsa1apl" path="res://scene/entity/inspectable.tscn" id="7_vc2dw"]
[ext_resource type="Texture2D" uid="uid://qls0yc054048" path="res://asset/art/scene/c02/小蝉寻人启事/e_寻人启事残破.png" id="8_j2ctx"]
[ext_resource type="Texture2D" uid="uid://cuyfloebe2mht" path="res://asset/art/scene/c02/小蝉寻人启事/ux_寻人启事残破.png" id="9_bhi7l"]
@ -21,15 +23,27 @@ player_y = 60
[node name="AnimationPlayer" parent="Ground" index="0"]
script = ExtResource("2_jfumy")
[node name="VibeSfx" type="Node" parent="Ground/AnimationPlayer" index="0"]
script = ExtResource("3_bhi7l")
autoplay_group = &"c02_楼道1"
metadata/_custom_type_script = "uid://cpejxlfni6n52"
[node name="Sfx背景音" type="AudioStreamPlayer" parent="Ground/AnimationPlayer" index="0"]
stream = ExtResource("4_ev3cr")
volume_db = -5.0
autoplay = true
bus = &"game_sfx"
script = ExtResource("5_ev3cr")
mode = "场景背景音"
"循环播放" = true
"感应玩家操作" = false
metadata/_custom_type_script = "uid://rq6w1vuhuq1m"
[node name="VibeSfx虫鸣" type="Node" parent="Ground/AnimationPlayer" index="1"]
script = ExtResource("3_bhi7l")
autoplay_group = &"夜晚虫鸣"
metadata/_custom_type_script = "uid://cpejxlfni6n52"
[node name="Sfx背景虫鸣" type="AudioStreamPlayer" parent="Ground/AnimationPlayer" index="1"]
stream = ExtResource("6_ev3cr")
volume_db = -10.0
autoplay = true
bus = &"game_sfx"
script = ExtResource("5_ev3cr")
mode = "场景背景音"
"循环播放" = true
"感应玩家操作" = false
metadata/_custom_type_script = "uid://rq6w1vuhuq1m"
[node name="BGSprite2D" parent="Ground" index="2"]
texture = ExtResource("5_j2ctx")

View File

@ -2,6 +2,7 @@
[ext_resource type="PackedScene" uid="uid://dayyx4jerj7io" path="res://scene/ground/ground.tscn" id="1_0dylx"]
[ext_resource type="Script" uid="uid://dsp5plrdkrsd7" path="res://scene/ground/scene/c02/s03_院子.gd" id="2_dt5aj"]
[ext_resource type="AudioStream" uid="uid://d0ef0felylt8d" path="res://asset/audio/sfx/环境音/第一章/氛围不受欢迎的存在.ogg" id="3_2b6vx"]
[ext_resource type="Texture2D" uid="uid://b3odt4ojsvu5n" path="res://asset/art/scene/c02/s03_公寓一楼院子/bg_一楼.png" id="3_sqv8l"]
[ext_resource type="SpriteFrames" uid="uid://3nas025c2c5u" path="res://asset/art/gif/c02_杂项/c02_杂项_frames.tres" id="4_gd6xp"]
[ext_resource type="Script" uid="uid://rq6w1vuhuq1m" path="res://scene/entity/audio/sfx.gd" id="4_ygnci"]
@ -10,7 +11,6 @@
[ext_resource type="Texture2D" uid="uid://f8yjp5ggr8qw" path="res://asset/art/scene/c02/s03_公寓一楼院子/算卦布.png" id="6_1tart"]
[ext_resource type="Texture2D" uid="uid://0uh6qaalhqju" path="res://asset/art/scene/c02/s11_一楼火灾/总背景/bg_院子1楼火灾.png" id="6_d7h4s"]
[ext_resource type="AudioStream" uid="uid://bhaws2ungqaf5" path="res://asset/audio/sfx/交互/角色/sfx_哼歌.ogg" id="6_jhod7"]
[ext_resource type="Script" uid="uid://cpejxlfni6n52" path="res://manager/audio_manager/vibe_sfx.gd" id="6_lq23y"]
[ext_resource type="PackedScene" uid="uid://jr1yd46wm5je" path="res://scene/entity/note.tscn" id="6_t48d1"]
[ext_resource type="AudioStream" uid="uid://civuwccn6v6yk" path="res://asset/audio/sfx/交互/第一章/sfx_闷雷声.ogg" id="6_vddfx"]
[ext_resource type="Texture2D" uid="uid://bxqetnlx0bpv4" path="res://asset/art/scene/c02/门_贴图/1012保卫科.png" id="6_ygnci"]
@ -285,37 +285,43 @@ libraries = {
}
script = ExtResource("2_dt5aj")
[node name="Sfx闷雷" type="AudioStreamPlayer" parent="Ground/AnimationPlayer" index="0"]
[node name="Sfx背景音" type="AudioStreamPlayer" parent="Ground/AnimationPlayer" index="0"]
stream = ExtResource("3_2b6vx")
volume_db = -12.0
autoplay = true
bus = &"game_sfx"
script = ExtResource("4_ygnci")
mode = "场景背景音"
"循环播放" = true
"感应玩家操作" = false
metadata/_custom_type_script = "uid://rq6w1vuhuq1m"
[node name="Sfx闷雷" type="AudioStreamPlayer" parent="Ground/AnimationPlayer" index="1"]
stream = ExtResource("6_vddfx")
bus = &"game_sfx"
script = ExtResource("4_ygnci")
metadata/_custom_type_script = "uid://rq6w1vuhuq1m"
[node name="Sfx打开铁门后" type="AudioStreamPlayer" parent="Ground/AnimationPlayer" index="1"]
[node name="Sfx打开铁门后" type="AudioStreamPlayer" parent="Ground/AnimationPlayer" index="2"]
stream = ExtResource("5_qt2qg")
volume_db = -20.0
bus = &"game_sfx"
script = ExtResource("4_ygnci")
metadata/_custom_type_script = "uid://rq6w1vuhuq1m"
[node name="Sfx小鞋落地" type="AudioStreamPlayer" parent="Ground/AnimationPlayer" index="2"]
[node name="Sfx小鞋落地" type="AudioStreamPlayer" parent="Ground/AnimationPlayer" index="3"]
stream = ExtResource("7_df1yo")
bus = &"game_sfx"
script = ExtResource("4_ygnci")
metadata/_custom_type_script = "uid://rq6w1vuhuq1m"
[node name="Sfx小蝉哼歌" type="AudioStreamPlayer" parent="Ground/AnimationPlayer" index="3"]
[node name="Sfx小蝉哼歌" type="AudioStreamPlayer" parent="Ground/AnimationPlayer" index="4"]
stream = ExtResource("6_jhod7")
volume_db = 16.0
bus = &"game_sfx"
script = ExtResource("4_ygnci")
metadata/_custom_type_script = "uid://rq6w1vuhuq1m"
[node name="VibeSfx氛围" type="Node" parent="Ground/AnimationPlayer" index="4"]
script = ExtResource("6_lq23y")
autoplay_group = &"氛围_不受欢迎的存在"
metadata/_custom_type_script = "uid://cpejxlfni6n52"
[node name="Sfx牵手演出氛围音" type="AudioStreamPlayer" parent="Ground/AnimationPlayer" index="5"]
stream = ExtResource("9_2b6vx")
bus = &"game_sfx"

View File

@ -200,7 +200,7 @@ position = Vector2(34, 8)
[node name="portal_right" parent="Ground/DeployLayer" index="1"]
position = Vector2(697, 18)
target_scene = "c02_s06"
target_portal = "right"
target_portal = "3"
[node name="互动公告" type="Sprite2D" parent="Ground/DeployLayer" index="2"]
position = Vector2(377, 30)

View File

@ -170,44 +170,44 @@ func loadfile(filepath):
else:
print ("ERROR: Wrong filetype or format")
# Converts .wav data from 24 or 32 bits to 16
#
# These conversions are SLOW in GDScript
# on my one test song, 32 -> 16 was around 3x slower than 24 -> 16
#
# I couldn't get threads to help very much
# They made the 24bit case about 2x faster in my test file
# And the 32bit case abour 50% slower
# I don't wanna risk it always being slower on other files
# And really, the solution would be to handle it in a low-level language
func convert_to_16bit(data: PackedByteArray, from: int) -> PackedByteArray:
print("converting to 16-bit from %d" % from)
var time = Time.get_ticks_msec()
# 24 bit .wav's are typically stored as integers
# so we just grab the 2 most significant bytes and ignore the other
if from == 24:
var j = 0
for i in range(0, data.size(), 3):
data[j] = data[i+1]
data[j+1] = data[i+2]
j += 2
data.resize(data.size() * 2 / 3)
# 32 bit .wav's are typically stored as floating point numbers
# so we need to grab all 4 bytes and interpret them as a float first
if from == 32:
var spb := StreamPeerBuffer.new()
var single_float: float
var value: int
for i in range(0, data.size(), 4):
# spb.data_array = data.subarray(i, i+3)
spb.data_array = data.slice(i, i+4)
single_float = spb.get_float()
value = single_float * 32768
data[i/2] = value
data[i/2+1] = value >> 8
data.resize(data.size() / 2)
print("Took %f seconds for slow conversion" % ((Time.get_ticks_msec() - time) / 1000.0))
return data
# # Converts .wav data from 24 or 32 bits to 16
# #
# # These conversions are SLOW in GDScript
# # on my one test song, 32 -> 16 was around 3x slower than 24 -> 16
# #
# # I couldn't get threads to help very much
# # They made the 24bit case about 2x faster in my test file
# # And the 32bit case abour 50% slower
# # I don't wanna risk it always being slower on other files
# # And really, the solution would be to handle it in a low-level language
# func convert_to_16bit(data: PackedByteArray, from: int) -> PackedByteArray:
# print("converting to 16-bit from %d" % from)
# var time = Time.get_ticks_msec()
# # 24 bit .wav's are typically stored as integers
# # so we just grab the 2 most significant bytes and ignore the other
# if from == 24:
# var j = 0
# for i in range(0, data.size(), 3):
# data[j] = data[i+1]
# data[j+1] = data[i+2]
# j += 2
# data.resize(data.size() * 2 / 3)
# # 32 bit .wav's are typically stored as floating point numbers
# # so we need to grab all 4 bytes and interpret them as a float first
# if from == 32:
# var spb := StreamPeerBuffer.new()
# var single_float: float
# var value: int
# for i in range(0, data.size(), 4):
# # spb.data_array = data.subarray(i, i+3)
# spb.data_array = data.slice(i, i+4)
# single_float = spb.get_float()
# value = single_float * 32768
# data[i/2] = value
# data[i/2+1] = value >> 8
# data.resize(data.size() / 2)
# print("Took %f seconds for slow conversion" % ((Time.get_ticks_msec() - time) / 1000.0))
# return data
# ---------- REFERENCE ---------------