104 lines
2.9 KiB
GDScript
104 lines
2.9 KiB
GDScript
@tool
|
||
extends Node
|
||
|
||
static var config: GlobalConfig:
|
||
set = _set_config
|
||
|
||
var timer = Timer.new()
|
||
|
||
|
||
func _ready() -> void:
|
||
timer.wait_time = 5.0
|
||
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
|
||
# debug)
|
||
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
|
||
_on_timer_timeout_counter += 1
|
||
# 30s 打印一次,无需首次打印
|
||
# ArchiveManager 设置 archive 时会调用 print_global_info
|
||
if _on_timer_timeout_counter % 6 == 0:
|
||
print_global_info()
|
||
|
||
|
||
func print_global_info():
|
||
var archive := ArchiveManager.archive
|
||
if not archive or not config:
|
||
return
|
||
var hour := archive.game_seconds / 3600
|
||
var minute := (archive.game_seconds % 3600) / 60
|
||
var second := archive.game_seconds % 60
|
||
# 0:未开始游戏;1:序章;2-5:一~四章;6:结尾
|
||
var chapter := EventManager.get_chapter_stage()
|
||
var round_info = "r" + str(config.game_rounds) + "_c" + str(chapter)
|
||
var game_time_info = "game:" + str(hour) + ":" + str(minute) + ":" + str(second)
|
||
# get ticks since game app run
|
||
var ticks = Time.get_ticks_msec()
|
||
hour = ticks / 3600000
|
||
minute = (ticks % 3600000) / 60000
|
||
second = (ticks % 60000) / 1000
|
||
var msec = ticks % 1000
|
||
var tick_time_info = (
|
||
"tick:" + str(hour) + ":" + str(minute) + ":" + str(second) + "." + str(msec)
|
||
)
|
||
var time_info = game_time_info + " " + tick_time_info
|
||
var scene_info = archive.current_scene
|
||
prints("[timemark]", Time.get_datetime_string_from_system(), round_info, scene_info, time_info)
|