xiandie/manager/config_manager/global_config_manager.gd

97 lines
2.3 KiB
GDScript

@tool
extends Node
static var config: GlobalConfig:
set = _set_config
var timer = Timer.new()
func _ready() -> void:
timer.wait_time = 5
timer.one_shot = false
timer.timeout.connect(_on_timer_timeout)
add_child(timer)
timer.start()
func _set_config(val: GlobalConfig) -> void:
config = val
if Engine.is_editor_hint():
return
if config.debug_mode:
GlobalConfig.DEBUG = true
print_rich("[color=orange]Debug mode enabled[/color]")
# set up window
if config.window_fullscreen:
get_window().mode = Window.MODE_FULLSCREEN
else:
get_window().mode = Window.MODE_WINDOWED
get_window().always_on_top = config.window_top
# set up sound
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), config.db_master)
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("game_sfx"), config.db_game_sfx)
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("dialog"), config.db_dialog)
prints(
"config load volume_db settings (master, sfx, dialog): ",
config.db_master,
config.db_game_sfx,
config.db_dialog
)
# set locale
update_locale(config.language, config.caption)
func update_locale(lang_id: int, caption_id: int):
# -1 null; 0 zh; 2 en
# var lang_id = language_options.selected
# zh: 0 _SH, 1 _CN; en: [null];
# var caption_id = caption_options.selected
var lang = ""
match lang_id:
0:
if caption_id == 0:
lang = "zh_SH"
elif caption_id == 1:
lang = "zh_CN"
1:
lang = "en"
GlobalConfigManager.config.language = lang_id
GlobalConfigManager.config.caption = caption_id
print("set language to: ", lang)
TranslationServer.set_locale(lang)
var _on_timer_timeout_counter := 0
func _on_timer_timeout():
var archive = ArchiveManager.archive
if archive and config:
archive.game_seconds += 5
config.game_total_seconds += 5
# 30s 打印一次
if _on_timer_timeout_counter % 6 == 0:
var time = get_concise_timemark(archive)
prints("[timemark]", Time.get_datetime_string_from_system(), time)
_on_timer_timeout_counter += 1
# for log use
func get_concise_timemark(archive) -> String:
var hour = archive.game_seconds / 3600 as int
var minute = (archive.game_seconds % 3600) / 60 as int
var second = archive.game_seconds % 60
return (
"r"
+ str(config.game_rounds)
+ "_c"
+ str(archive.current_chapter)
+ " "
+ str(hour)
+ ":"
+ str(minute)
+ ":"
+ str(second)
)