Refactor game scripts and update vault scene structure. Enhanced organization of game logic by separating data and rendering responsibilities across multiple scripts. Removed unused background assets and updated vault scene to include new game clock and weather system functionalities.
This commit is contained in:
@@ -27,7 +27,15 @@ enum Mode { SELECT, BUILD, DEMOLISH }
|
||||
@onready var _saves: SaveManagerService = get_node("/root/SaveManager")
|
||||
@onready var _vault: VaultView = $View
|
||||
@onready var _camera: VaultCamera = $Camera
|
||||
@onready var _clock: GameClock = $Clock
|
||||
@onready var _weather: WeatherSystem = $Weather
|
||||
@onready var _sky: SkyView = $Sky
|
||||
@onready var _surface: SurfaceView = $Surface
|
||||
@onready var _weather_label: Label = $Hud/Root/TopRight/Row/ClockBar/Body/Moment/WeatherLabel
|
||||
@onready var _stats: HBoxContainer = $Hud/Root/TopBar/Stats
|
||||
@onready var _date_label: Label = $Hud/Root/TopRight/Row/ClockBar/Body/Moment/DateLabel
|
||||
@onready var _time_label: Label = $Hud/Root/TopRight/Row/ClockBar/Body/Moment/TimeLabel
|
||||
@onready var _flow_controls: HBoxContainer = $Hud/Root/TopRight/Row/ClockBar/Body/Controls
|
||||
@onready var _tools: HBoxContainer = $Hud/Root/BottomAnchor/Row/BuildBar/Panel/Tools
|
||||
@onready var _status: Label = $Hud/Root/BottomAnchor/Row/BuildBar/Panel/Status
|
||||
|
||||
@@ -41,6 +49,11 @@ var _stat_labels := {}
|
||||
var _tool_group := ButtonGroup.new()
|
||||
var _right_pressed := false
|
||||
var _right_press_position := Vector2.ZERO
|
||||
var _flow_group := ButtonGroup.new()
|
||||
var _speed_group := ButtonGroup.new()
|
||||
var _play_button: Button
|
||||
var _pause_button: Button
|
||||
var _speed_buttons := {}
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -52,7 +65,18 @@ func _ready() -> void:
|
||||
|
||||
_build_stats()
|
||||
_build_tools()
|
||||
_build_flow_controls()
|
||||
_refresh_stats()
|
||||
|
||||
_weather.attach_clock(_clock)
|
||||
_weather.changed.connect(_on_weather_changed)
|
||||
|
||||
_clock.minute_passed.connect(_on_minute_passed)
|
||||
_clock.flow_changed.connect(_refresh_flow)
|
||||
_refresh_moment()
|
||||
_refresh_flow()
|
||||
_on_weather_changed(_weather.kind)
|
||||
|
||||
_status.text = HINT
|
||||
|
||||
|
||||
@@ -167,6 +191,93 @@ func _describe(room: Dictionary) -> String:
|
||||
return " · ".join(parts)
|
||||
|
||||
|
||||
# --- Ход времени ------------------------------------------------------------
|
||||
|
||||
func _build_flow_controls() -> void:
|
||||
# Тема рассчитана на крупные кнопки меню; для панели времени нужен свой,
|
||||
# компактный набор стилей. Ресурсы общие на все кнопки — их всего четыре.
|
||||
var styles := {
|
||||
"normal": _flow_style("#ffffff0d", "#ffffff1f"),
|
||||
"hover": _flow_style("#2ee6c51f", "#2ee6c566"),
|
||||
"pressed": _flow_style("#2ee6c52e", "#2ee6c5cc"),
|
||||
"focus": _flow_style("#2ee6c51a", "#2ee6c599"),
|
||||
}
|
||||
|
||||
_play_button = _add_flow_button("▶", _flow_group, styles)
|
||||
_play_button.pressed.connect(_clock.play)
|
||||
|
||||
_pause_button = _add_flow_button("❚❚", _flow_group, styles)
|
||||
_pause_button.pressed.connect(_clock.pause)
|
||||
|
||||
var gap := Control.new()
|
||||
gap.custom_minimum_size.x = 8
|
||||
_flow_controls.add_child(gap)
|
||||
|
||||
for multiplier: int in GameClock.SPEEDS:
|
||||
# Выбор скорости заодно снимает паузу — отдельно жать «play» не нужно.
|
||||
var button := _add_flow_button("x%d" % multiplier, _speed_group, styles)
|
||||
button.pressed.connect(_clock.set_speed.bind(multiplier))
|
||||
_speed_buttons[multiplier] = button
|
||||
|
||||
|
||||
func _add_flow_button(label: String, group: ButtonGroup, styles: Dictionary) -> Button:
|
||||
var button := Button.new()
|
||||
button.text = label
|
||||
button.toggle_mode = true
|
||||
button.button_group = group
|
||||
button.custom_minimum_size.x = 34
|
||||
button.add_theme_font_size_override("font_size", 13)
|
||||
for state: String in styles:
|
||||
button.add_theme_stylebox_override(state, styles[state])
|
||||
_flow_controls.add_child(button)
|
||||
return button
|
||||
|
||||
|
||||
func _flow_style(background: String, border: String) -> StyleBoxFlat:
|
||||
var style := StyleBoxFlat.new()
|
||||
style.bg_color = Color(background)
|
||||
style.border_color = Color(border)
|
||||
style.set_border_width_all(1)
|
||||
style.set_corner_radius_all(5)
|
||||
style.content_margin_left = 9.0
|
||||
style.content_margin_right = 9.0
|
||||
style.content_margin_top = 4.0
|
||||
style.content_margin_bottom = 4.0
|
||||
return style
|
||||
|
||||
|
||||
func _on_minute_passed(_total_minutes: int) -> void:
|
||||
_refresh_moment()
|
||||
_refresh_environment()
|
||||
|
||||
|
||||
func _on_weather_changed(_kind: int) -> void:
|
||||
_weather_label.text = _weather.label()
|
||||
|
||||
|
||||
func _refresh_moment() -> void:
|
||||
_date_label.text = _clock.date_text()
|
||||
_time_label.text = _clock.time_text()
|
||||
|
||||
|
||||
## Небо и поверхность зависят от одних и тех же двух вещей — часа и погоды.
|
||||
func _refresh_environment() -> void:
|
||||
var hour := SkyCycle.hour_of(_clock.now())
|
||||
_sky.set_conditions(hour, _weather.clouds)
|
||||
_surface.set_conditions(hour, _weather)
|
||||
|
||||
|
||||
## Кнопки только отражают состояние часов — источник правды там.
|
||||
func _refresh_flow() -> void:
|
||||
# Облака и осадки идут в такт игре: на паузе они замирают.
|
||||
_surface.time_scale = float(_clock.speed) if _clock.running else 0.0
|
||||
_play_button.set_pressed_no_signal(_clock.running)
|
||||
_pause_button.set_pressed_no_signal(not _clock.running)
|
||||
for multiplier: int in _speed_buttons:
|
||||
var button: Button = _speed_buttons[multiplier]
|
||||
button.set_pressed_no_signal(multiplier == _clock.speed)
|
||||
|
||||
|
||||
# --- HUD --------------------------------------------------------------------
|
||||
|
||||
func _build_stats() -> void:
|
||||
@@ -274,6 +385,8 @@ func _on_demolish_toggled(is_on: bool) -> void:
|
||||
func save_data() -> Dictionary:
|
||||
return {
|
||||
"rooms": _grid.to_array(),
|
||||
"clock": _clock.save_data(),
|
||||
"weather": _weather.save_data(),
|
||||
"camera": {
|
||||
"x": _camera.position.x,
|
||||
"y": _camera.position.y,
|
||||
@@ -284,6 +397,9 @@ func save_data() -> Dictionary:
|
||||
|
||||
func load_data(data: Dictionary) -> void:
|
||||
_grid.from_array(data.get("rooms", []))
|
||||
_clock.load_data(data.get("clock", {}))
|
||||
_weather.load_data(data.get("weather", {}))
|
||||
_refresh_environment()
|
||||
|
||||
var camera_state: Dictionary = data.get("camera", {})
|
||||
if not camera_state.is_empty():
|
||||
|
||||
Reference in New Issue
Block a user