69 lines
2.3 KiB
GDScript
69 lines
2.3 KiB
GDScript
extends CanvasLayer
|
|
|
|
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
|
@onready var wood_count_label_2: Label = $UI/Background/Control3/WoodCountLabel2
|
|
@onready var restart: Control = $Restart
|
|
@onready var color_rect_2: ColorRect = $Restart/ColorRect2
|
|
|
|
var available_tween
|
|
var restart_tween
|
|
|
|
func _ready() -> void:
|
|
Persister.persist_data("wood", 50)
|
|
Persister.persist_data("stone", 50)
|
|
Persister.persist_data("population", 3)
|
|
Persister.persist_data("avail_population", 3)
|
|
Persister.persist_data("food", 10)
|
|
Persister.persist_data("water", 10)
|
|
Persister.persist_data("max_population", 3)
|
|
Triggerer.listen("show_info", _on_show_info)
|
|
Triggerer.listen("hide_info", _on_hide_info)
|
|
|
|
func _process(delta: float) -> void:
|
|
if Input.is_action_just_pressed("lclick") and not Persister.get_value("game_started"):
|
|
Persister.persist_data("game_started", true)
|
|
animation_player.play("start")
|
|
|
|
wood_count_label_2.text = "%d available" % [Persister.get_value("avail_population")]
|
|
|
|
if Input.is_action_just_pressed("restart"):
|
|
if restart_tween:
|
|
restart_tween.kill()
|
|
|
|
restart_tween = create_tween()
|
|
restart_tween.set_parallel()
|
|
restart_tween.tween_property(restart, "modulate", Color.WHITE, 0.5)
|
|
restart_tween.tween_property(color_rect_2, "scale:x", 1, 1).set_delay(0.1)
|
|
restart_tween.chain()
|
|
restart_tween.tween_callback(func():
|
|
Persister.clear_category(PersisterEnums.Scope.RUN)
|
|
get_tree().change_scene_to_packed(preload("res://Main.tscn"))
|
|
)
|
|
|
|
if Input.is_action_just_released("restart"):
|
|
if restart_tween:
|
|
restart_tween.kill()
|
|
|
|
restart_tween = create_tween()
|
|
restart_tween.set_parallel()
|
|
restart_tween.tween_property(color_rect_2, "scale:x", 0, 1)
|
|
restart_tween.tween_property(restart, "modulate", Color.TRANSPARENT, 0.5)
|
|
|
|
func _on_show_info(_data):
|
|
if available_tween:
|
|
available_tween.kill()
|
|
|
|
available_tween = create_tween()
|
|
available_tween.set_ease(Tween.EASE_OUT)
|
|
available_tween.set_trans(Tween.TRANS_BACK)
|
|
available_tween.tween_property(wood_count_label_2, "scale", Vector2.ONE, 0.5)
|
|
|
|
|
|
func _on_hide_info(_data):
|
|
if available_tween:
|
|
available_tween.kill()
|
|
|
|
available_tween = create_tween()
|
|
available_tween.set_ease(Tween.EASE_OUT)
|
|
available_tween.set_trans(Tween.TRANS_QUAD)
|
|
available_tween.tween_property(wood_count_label_2, "scale", Vector2.ZERO, 0.5)
|