@tool extends Node2D class_name PaintingDisplay const PAINTING_SIZE := Vector2(310, 200) @export var custom_paintings: Array[Texture2D] @export_tool_button('Next Custom') var next_custom_action = func next_custom(): configure_painting(absi(%Painting.painting_id + 1) % custom_paintings.size()) animate_show_painting() @export_tool_button('Random Procedual') var random_procedual_action = func random_procedual(): configure_painting(-absi(randi())) animate_show_painting() @export var shake_distance := 12.0 @export var shake_duration := 0.3 @export var shake_step_count := 5 @export_tool_button('damage_deal') var damage_deal_action = damage_deal @export_tool_button('damage_undo') var damage_undo_action = damage_undo func get_n_unique_custom_paintings(count: int) -> Array[int]: var list: Array[int] = [] for idx in custom_paintings.size(): list.push_back(idx) list.shuffle() list.resize(count) return list var _shake_tween: Tween func animate_shake(): if _shake_tween: _shake_tween.kill() var shake_step := shake_duration / shake_step_count _shake_tween = create_tween() for i in shake_step_count: var pos := Vector2(randf_range(-shake_distance, shake_distance), randf_range(-shake_distance, shake_distance)) _shake_tween.set_ease(Tween.EASE_OUT_IN) _shake_tween.set_trans(Tween.TRANS_ELASTIC) _shake_tween.tween_property(%Shaker, ^'position', pos, shake_step) _shake_tween.set_ease(Tween.EASE_OUT) _shake_tween.set_trans(Tween.TRANS_ELASTIC) _shake_tween.tween_property(%Shaker, ^'position', Vector2.ZERO, shake_duration) _shake_tween.tween_callback(func(): _shake_tween = null) func damage_deal() -> bool: animate_shake() %Painting.damage += 1 if %Painting.damage > 3: $AnimationPlayer.play(&'broke') return true else: return false func damage_undo(): %Painting.damage = 0 $AnimationPlayer.play_backwards(&'broke') #var _has_loaded_painting := false #var _loaded_painting_id: int #func animate_prev_painting() -> void: #if _has_loaded_painting: #$AnimationPlayer.play_backwards(&'slide') #await $AnimationPlayer.animation_finished #$AnimationPlayer.play_backwards(&'broke') #await $AnimationPlayer.animation_finished #_has_loaded_painting = false #func animate_next_painting(id: int) -> void: #_has_loaded_painting = true #_loaded_painting_id = id #%Painting.damage = 0 #%Painting.painting_id = id #%Painting.overwrite_texture = custom_paintings[id] if id >= 0 and id < custom_paintings.size() else null #$AnimationPlayer.play(&'slide') #await $AnimationPlayer.animation_finished func configure_painting(id: int) -> void: %Painting.damage = 0 %Painting.painting_id = id %Painting.overwrite_texture = custom_paintings[id] if id >= 0 and id < custom_paintings.size() else null $AnimationPlayer.play(&'RESET') func animate_show_painting() -> void: $AnimationPlayer.play(&'slide') await $AnimationPlayer.animation_finished var _painting_pile: PaintingPile var _pile_tween: Tween func move_painting_to_pile(pile: PaintingPile) -> void: assert(not _painting_pile) _painting_pile = pile animate_move(pile.push_tracking(self)) func animate_move(rect: Rect2) -> void: if _pile_tween: _pile_tween.kill() _pile_tween = create_tween() _pile_tween.parallel().tween_property($Root, ^'global_position', rect.get_center(), 1.2) _pile_tween.parallel().tween_property($Root, ^'scale', rect.size / PAINTING_SIZE, 1.2) _pile_tween.tween_callback(func(): _pile_tween = null)