完成部分服务器数据向MongoDB数据库迁移
This commit is contained in:
59
GameManager/DayNightSystem.gd
Normal file
59
GameManager/DayNightSystem.gd
Normal file
@@ -0,0 +1,59 @@
|
||||
extends Node2D
|
||||
#昼夜循环系统
|
||||
#时间直接获取现实世界时间
|
||||
#内容就是直接调节背景图片modulate的亮度HEX 白天最亮为c3c3c3 晚上最暗为131313 然后在这之间变化
|
||||
|
||||
# 背景节点引用
|
||||
@onready var background_node=$'../BackgroundUI/BackgroundSwitcher'
|
||||
|
||||
# 白天和夜晚的颜色值
|
||||
var day_color = Color("#c3c3c3")
|
||||
var night_color = Color("#131313")
|
||||
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if background_node == null:
|
||||
return
|
||||
|
||||
# 获取当前时间
|
||||
var current_time = Time.get_datetime_dict_from_system()
|
||||
var hour = current_time.hour
|
||||
var minute = current_time.minute
|
||||
|
||||
# 将时间转换为小数形式(0-24)
|
||||
var time_decimal = hour + minute / 60.0
|
||||
|
||||
# 计算亮度插值因子
|
||||
var brightness_factor = calculate_brightness_factor(time_decimal)
|
||||
|
||||
# 在白天和夜晚颜色之间插值
|
||||
var current_color = night_color.lerp(day_color, brightness_factor)
|
||||
|
||||
# 应用到背景节点
|
||||
background_node.modulate = current_color
|
||||
|
||||
# 计算亮度因子(0为夜晚,1为白天)
|
||||
func calculate_brightness_factor(time: float) -> float:
|
||||
# 定义关键时间点
|
||||
var sunrise = 6.0 # 日出时间 6:00
|
||||
var noon = 12.0 # 正午时间 12:00
|
||||
var sunset = 18.0 # 日落时间 18:00
|
||||
var midnight = 0.0 # 午夜时间 0:00
|
||||
|
||||
if time >= sunrise and time <= noon:
|
||||
# 日出到正午:从0.2逐渐变亮到1.0
|
||||
return 0.2 + 0.8 * (time - sunrise) / (noon - sunrise)
|
||||
elif time > noon and time <= sunset:
|
||||
# 正午到日落:从1.0逐渐变暗到0.2
|
||||
return 1.0 - 0.8 * (time - noon) / (sunset - noon)
|
||||
else:
|
||||
# 夜晚时间:保持较暗状态(0.0-0.2之间)
|
||||
if time > sunset:
|
||||
# 日落后到午夜
|
||||
var night_progress = (time - sunset) / (24.0 - sunset)
|
||||
return 0.2 - 0.2 * night_progress
|
||||
else:
|
||||
# 午夜到日出
|
||||
var dawn_progress = time / sunrise
|
||||
return 0.0 + 0.2 * dawn_progress
|
||||
1
GameManager/DayNightSystem.gd.uid
Normal file
1
GameManager/DayNightSystem.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://di8wjflimodb0
|
||||
@@ -9,8 +9,16 @@ extends Node2D
|
||||
# 天气系统
|
||||
# 要显示哪种天气直接调用相应天气的show()然后一并隐藏其他天气hide()
|
||||
|
||||
# 动态天气显示控制(可以覆盖全局设置)
|
||||
var weather_display_enabled: bool = true
|
||||
|
||||
# 设置天气的统一方法
|
||||
func set_weather(weather_type: String):
|
||||
# 检查全局设置和动态设置
|
||||
if GlobalVariables.DisableWeatherDisplay or not weather_display_enabled:
|
||||
hide_all_weather()
|
||||
return
|
||||
|
||||
# 先隐藏所有天气效果
|
||||
hide_all_weather()
|
||||
|
||||
@@ -37,6 +45,19 @@ func set_weather(weather_type: String):
|
||||
_:
|
||||
print("未知的天气类型: ", weather_type)
|
||||
|
||||
# 动态设置天气显示状态
|
||||
func set_weather_display_enabled(enabled: bool):
|
||||
"""动态设置天气显示是否启用"""
|
||||
weather_display_enabled = enabled
|
||||
if not enabled:
|
||||
hide_all_weather()
|
||||
print("天气显示已", "启用" if enabled else "禁用")
|
||||
|
||||
# 获取当前天气显示状态
|
||||
func is_weather_display_enabled() -> bool:
|
||||
"""获取当前天气显示状态"""
|
||||
return weather_display_enabled and not GlobalVariables.DisableWeatherDisplay
|
||||
|
||||
# 隐藏所有天气效果
|
||||
func hide_all_weather():
|
||||
if cherry_blossom_rain:
|
||||
|
||||
Reference in New Issue
Block a user