创建新工程

This commit is contained in:
moyin
2025-12-05 19:00:14 +08:00
commit ff4fa5fffd
227 changed files with 32804 additions and 0 deletions

205
scripts/GameConfig.gd Normal file
View File

@@ -0,0 +1,205 @@
extends Node
## 游戏配置管理类
## 集中管理游戏的各种配置参数
# 网络配置
const NETWORK = {
"server_url": "ws://localhost:8080",
"connection_timeout": 10.0,
"max_reconnect_attempts": 3,
"reconnect_base_delay": 1.0,
"heartbeat_interval": 30.0
}
# 角色配置
const CHARACTER = {
"move_speed": 200.0,
"interaction_range": 80.0,
"name_min_length": 2,
"name_max_length": 20,
"position_sync_threshold": 1.0 # 位置同步的最小距离阈值
}
# UI配置
const UI = {
"notification_duration": 5.0,
"error_notification_duration": 8.0,
"loading_timeout": 15.0,
"font_sizes": {
"small": 12,
"normal": 16,
"large": 20,
"title": 24
},
"animations": {
"enable_animations": true,
"animation_speed": 1.0,
"reduce_motion": false
},
"accessibility": {
"high_contrast": false,
"large_text": false,
"screen_reader_support": false
},
"mobile_optimizations": {
"larger_touch_targets": true,
"haptic_feedback": true,
"auto_zoom_inputs": true
},
"performance": {
"reduce_transparency": false,
"disable_particles": false,
"low_quality_mode": false
}
}
# 场景配置
const SCENE = {
"world_size": Vector2(2000, 1500),
"spawn_position": Vector2(1000, 750),
"camera_follow_speed": 5.0,
"camera_zoom_speed": 2.0,
"camera_min_zoom": 0.5,
"camera_max_zoom": 2.0
}
# 输入配置
const INPUT = {
"virtual_joystick_size": 100,
"virtual_button_size": 80,
"touch_deadzone": 0.1
}
# 动画配置
const ANIMATION = {
"default_tween_duration": 0.3,
"position_smooth_duration": 0.2,
"ui_fade_duration": 0.25,
"camera_reset_duration": 0.5
}
# 调试配置
const DEBUG = {
"enable_debug_prints": true,
"show_collision_shapes": false,
"show_fps": false,
"log_network_messages": true
}
# 性能配置
const PERFORMANCE = {
"max_characters_visible": 50,
"update_frequency": 60, # FPS
"network_sync_rate": 20, # 网络同步频率
"physics_fps": 60
}
## 获取网络配置
static func get_network_config() -> Dictionary:
"""获取网络相关配置"""
return NETWORK
## 获取角色配置
static func get_character_config() -> Dictionary:
"""获取角色相关配置"""
return CHARACTER
## 获取UI配置
static func get_ui_config() -> Dictionary:
"""获取UI相关配置"""
return UI
## 获取场景配置
static func get_scene_config() -> Dictionary:
"""获取场景相关配置"""
return SCENE
## 获取输入配置
static func get_input_config() -> Dictionary:
"""获取输入相关配置"""
return INPUT
## 获取动画配置
static func get_animation_config() -> Dictionary:
"""获取动画相关配置"""
return ANIMATION
## 获取调试配置
static func get_debug_config() -> Dictionary:
"""获取调试相关配置"""
return DEBUG
## 获取性能配置
static func get_performance_config() -> Dictionary:
"""获取性能相关配置"""
return PERFORMANCE
## 是否启用调试模式
static func is_debug_enabled() -> bool:
"""检查是否启用调试模式"""
return DEBUG.enable_debug_prints
## 获取服务器URL
static func get_server_url() -> String:
"""获取服务器URL"""
return NETWORK.server_url
## 获取角色移动速度
static func get_character_move_speed() -> float:
"""获取角色移动速度"""
return CHARACTER.move_speed
## 获取交互范围
static func get_interaction_range() -> float:
"""获取角色交互范围"""
return CHARACTER.interaction_range
## 验证角色名称长度
static func is_valid_character_name_length(character_name: String) -> bool:
"""
验证角色名称长度是否有效
@param character_name: 角色名称
@return: 是否有效
"""
var length = character_name.length()
return length >= CHARACTER.name_min_length and length <= CHARACTER.name_max_length
## 获取默认生成位置
static func get_default_spawn_position() -> Vector2:
"""获取默认角色生成位置"""
return SCENE.spawn_position
## 获取世界大小
static func get_world_size() -> Vector2:
"""获取游戏世界大小"""
return SCENE.world_size
## 获取通知显示时长
static func get_notification_duration(is_error: bool = false) -> float:
"""
获取通知显示时长
@param is_error: 是否为错误通知
@return: 显示时长(秒)
"""
return UI.error_notification_duration if is_error else UI.notification_duration
## 获取相机配置
static func get_camera_config() -> Dictionary:
"""获取相机相关配置"""
return {
"follow_speed": SCENE.camera_follow_speed,
"zoom_speed": SCENE.camera_zoom_speed,
"min_zoom": SCENE.camera_min_zoom,
"max_zoom": SCENE.camera_max_zoom,
"reset_duration": ANIMATION.camera_reset_duration
}
## 获取网络同步配置
static func get_network_sync_config() -> Dictionary:
"""获取网络同步相关配置"""
return {
"sync_rate": PERFORMANCE.network_sync_rate,
"position_threshold": CHARACTER.position_sync_threshold,
"timeout": NETWORK.connection_timeout,
"max_reconnects": NETWORK.max_reconnect_attempts
}