2023-04-19 16:53:24 +00:00
|
|
|
@tool
|
2023-06-28 00:25:13 +00:00
|
|
|
extends Area2D
|
2023-04-19 16:53:24 +00:00
|
|
|
class_name Card
|
2023-10-12 16:25:21 +00:00
|
|
|
var compatible_sticky_notes: Array[StickyNote] = []
|
2025-02-24 15:14:08 +00:00
|
|
|
@export var evil_sticky_notes: Array[StickyNote] = []
|
2023-10-12 16:25:21 +00:00
|
|
|
var own_sticky_notes: Array[StickyNote] = []
|
|
|
|
|
var current_sticky_note: StickyNote = null
|
2023-06-29 15:35:30 +00:00
|
|
|
var wiggle_pos: float = 0
|
2023-06-28 09:44:55 +00:00
|
|
|
var wiggle_intensity: float = 0
|
|
|
|
|
var noise: Noise = FastNoiseLite.new()
|
|
|
|
|
var wiggle_tween
|
|
|
|
|
var scale_tween
|
2023-04-19 16:53:24 +00:00
|
|
|
|
2024-02-03 21:00:44 +00:00
|
|
|
var transfor_arr: Array[Transform2D] = [
|
2024-09-15 09:30:31 +00:00
|
|
|
Transform2D(0.9, Vector2(-125, -83)),
|
|
|
|
|
Transform2D(-0.3, Vector2(-126, -75)),
|
|
|
|
|
Transform2D(-0.3, Vector2(-126, -74)),
|
|
|
|
|
Transform2D(-0.3, Vector2(-126, -73)),
|
|
|
|
|
Transform2D(0.5, Vector2(-126, -77))
|
2024-02-03 21:00:44 +00:00
|
|
|
]
|
|
|
|
|
|
2023-04-19 16:53:24 +00:00
|
|
|
@export var text: String = "" :
|
2024-09-15 09:30:31 +00:00
|
|
|
set(value):
|
|
|
|
|
text = value
|
|
|
|
|
if get_children() != [] or Engine.is_editor_hint():
|
|
|
|
|
$Label.text = value
|
|
|
|
|
var curr_frame = text.hash() % $BackgroundSprite.sprite_frames.get_frame_count($BackgroundSprite.animation)
|
|
|
|
|
$BackgroundSprite.frame = text.hash() % $BackgroundSprite.sprite_frames.get_frame_count($BackgroundSprite.animation)
|
|
|
|
|
$Label.rotation = deg_to_rad(transfor_arr[curr_frame].get_rotation())
|
|
|
|
|
$Label.position = transfor_arr[curr_frame].origin
|
|
|
|
|
if !Engine.is_editor_hint():
|
|
|
|
|
wiggle_pos = float(text.hash() % 100)
|
|
|
|
|
_handle_wiggle(0)
|
2023-06-28 09:44:55 +00:00
|
|
|
@export var wiggle_strength: float = 0.2
|
|
|
|
|
@export var wiggle_speed: float = 5
|
|
|
|
|
@export_range(1, 2) var scale_bump: float = 1.05
|
2023-07-14 17:13:08 +00:00
|
|
|
@export_range(1.0, 10.0) var bounce_speed: float = 5
|
2023-06-28 09:44:55 +00:00
|
|
|
@export var highlighted: bool = false:
|
2024-09-15 09:30:31 +00:00
|
|
|
set(highlight):
|
|
|
|
|
if highlight != highlighted:
|
|
|
|
|
highlighted = highlight
|
|
|
|
|
|
|
|
|
|
if is_inside_tree() and is_node_ready():
|
|
|
|
|
if scale_tween: scale_tween.kill()
|
|
|
|
|
if wiggle_tween: wiggle_tween.kill()
|
|
|
|
|
if highlighted:
|
|
|
|
|
scale_tween = get_tree().create_tween()
|
|
|
|
|
scale_tween.tween_property(self, "scale", Vector2(scale_bump, scale_bump), 0.1)
|
|
|
|
|
wiggle_tween = get_tree().create_tween()
|
|
|
|
|
wiggle_tween.tween_property(self, "wiggle_intensity", 1, 0.2)
|
|
|
|
|
else:
|
|
|
|
|
scale_tween = get_tree().create_tween()
|
|
|
|
|
scale_tween.tween_property(self, "scale", Vector2(1, 1), 0.3)
|
|
|
|
|
wiggle_tween = get_tree().create_tween()
|
|
|
|
|
wiggle_tween.tween_property(self, "wiggle_intensity", 0, 0.5)
|
|
|
|
|
else:
|
|
|
|
|
if highlighted:
|
|
|
|
|
scale = Vector2(scale_bump, scale_bump)
|
|
|
|
|
wiggle_intensity = 1
|
|
|
|
|
else:
|
|
|
|
|
scale = Vector2(1,1)
|
|
|
|
|
wiggle_intensity = 0
|
|
|
|
|
|
2023-04-19 16:53:24 +00:00
|
|
|
@export var voice_line: AudioStream = null
|
2023-06-29 20:19:58 +00:00
|
|
|
@export var is_dragable: bool = false
|
2023-07-14 19:20:04 +00:00
|
|
|
@onready var diameter = $CollisionShape2D.shape.height
|
2025-02-24 15:14:08 +00:00
|
|
|
@onready var sticky_note_anchor: Node2D = %StickyNoteAncor
|
2023-07-14 17:13:08 +00:00
|
|
|
|
2023-07-14 19:20:04 +00:00
|
|
|
var is_dragged: bool = false:
|
2024-09-15 09:30:31 +00:00
|
|
|
set(dragged):
|
|
|
|
|
is_dragged = dragged
|
|
|
|
|
z_index = int(dragged)
|
2023-07-14 17:13:08 +00:00
|
|
|
|
2023-07-14 20:03:09 +00:00
|
|
|
var is_mouse_entered: bool = false
|
2023-07-14 19:20:04 +00:00
|
|
|
var mouse_offset: Vector2
|
2023-07-14 17:13:08 +00:00
|
|
|
|
2023-06-28 09:44:55 +00:00
|
|
|
func _ready():
|
2024-09-15 09:30:31 +00:00
|
|
|
|
2025-01-31 02:22:07 +00:00
|
|
|
input_event.connect(_on_input_event)
|
|
|
|
|
mouse_entered.connect(_on_mouse_entered)
|
|
|
|
|
mouse_exited.connect(_on_mouse_exited)
|
|
|
|
|
|
2024-09-15 09:30:31 +00:00
|
|
|
_handle_wiggle(0)
|
|
|
|
|
if not Engine.is_editor_hint() and is_inside_tree():
|
|
|
|
|
for sticky_note in self.get_children():
|
|
|
|
|
if sticky_note is StickyNote: self.own_sticky_notes.append(sticky_note as StickyNote)
|
|
|
|
|
|
|
|
|
|
for sticky_note in get_tree().get_nodes_in_group(name):
|
|
|
|
|
if sticky_note is StickyNote: self.compatible_sticky_notes.append(sticky_note as StickyNote)
|
|
|
|
|
|
|
|
|
|
compatible_sticky_notes.append_array(own_sticky_notes)
|
|
|
|
|
|
|
|
|
|
if own_sticky_notes.size() == 2:
|
|
|
|
|
own_sticky_notes[0].sibling = own_sticky_notes[1]
|
|
|
|
|
own_sticky_notes[1].sibling = own_sticky_notes[0]
|
|
|
|
|
|
2025-02-24 15:14:08 +00:00
|
|
|
%BackgroundSprite.frame = text.hash() % %BackgroundSprite.sprite_frames.get_frame_count(%BackgroundSprite.animation)
|
2024-09-15 09:30:31 +00:00
|
|
|
$Label.text = self.text
|
|
|
|
|
|
2025-04-04 17:27:57 +00:00
|
|
|
#$Label.theme = State.current_main_theme
|
|
|
|
|
#State.theme_changed.connect(func change_theme(new_theme): $Label.theme = new_theme)
|
2024-09-15 09:30:31 +00:00
|
|
|
|
|
|
|
|
wiggle_pos = float(text.hash() % 100)
|
|
|
|
|
if not Engine.is_editor_hint():
|
|
|
|
|
_handle_wiggle(0)
|
2025-04-04 21:17:31 +00:00
|
|
|
|
|
|
|
|
if text == "":
|
|
|
|
|
become_void()
|
|
|
|
|
|
|
|
|
|
func become_void():
|
|
|
|
|
%BackgroundSprite.add_child(load("res://logic-scenes/board/void_stuff.tscn").instantiate())
|
2023-04-19 16:53:24 +00:00
|
|
|
|
|
|
|
|
func _process(delta: float) -> void:
|
2024-09-15 09:30:31 +00:00
|
|
|
if highlighted:
|
|
|
|
|
_handle_wiggle(delta)
|
|
|
|
|
|
|
|
|
|
if get_overlapping_areas().size() > 0 and is_dragable:
|
|
|
|
|
for area in get_overlapping_areas():
|
|
|
|
|
if area is Card or area is CardCollider:
|
|
|
|
|
if area is CardCollider:
|
|
|
|
|
position += area.direction * delta
|
|
|
|
|
elif not (area.highlighted or self.highlighted) and area.is_dragable:
|
|
|
|
|
var diff:Vector2 = position - area.position
|
|
|
|
|
position -= diff.normalized() * ((diff.length()-diameter)/diameter) * bounce_speed * (delta/(1.0/60))
|
|
|
|
|
|
|
|
|
|
_move_card()
|
2023-06-28 09:44:55 +00:00
|
|
|
|
2023-08-01 08:59:24 +00:00
|
|
|
func get_text() -> String:
|
2024-09-15 09:30:31 +00:00
|
|
|
return $Label.text
|
2023-08-01 08:59:24 +00:00
|
|
|
|
2023-06-28 09:44:55 +00:00
|
|
|
func _handle_wiggle(delta):
|
2024-09-15 09:30:31 +00:00
|
|
|
wiggle_pos += delta * wiggle_speed * wiggle_intensity
|
|
|
|
|
|
|
|
|
|
rotation = noise.get_noise_1d(wiggle_pos)*wiggle_strength
|
2023-04-19 16:53:24 +00:00
|
|
|
|
2023-09-24 10:23:26 +00:00
|
|
|
## Deprecated
|
2023-05-28 13:21:19 +00:00
|
|
|
func replace_with(card: Card):
|
2024-09-15 09:30:31 +00:00
|
|
|
self.text = card.text
|
|
|
|
|
self.compatible_sticky_notes = card.compatible_sticky_notes
|
|
|
|
|
self.own_sticky_notes = card.own_sticky_notes
|
|
|
|
|
self.voice_line = card.voice_line
|
|
|
|
|
self.name = card.name
|
2025-01-31 02:22:07 +00:00
|
|
|
|
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
|
|
|
if event is InputEventMouseButton:
|
|
|
|
|
if event.button_index == MOUSE_BUTTON_LEFT and not event.pressed:
|
|
|
|
|
is_dragged = false
|
|
|
|
|
|
2023-04-19 16:53:24 +00:00
|
|
|
func _on_focus_entered():
|
2024-09-15 09:30:31 +00:00
|
|
|
print(self, "is focused")
|
2023-04-19 16:53:24 +00:00
|
|
|
|
|
|
|
|
func _on_focus_exited():
|
2024-09-15 09:30:31 +00:00
|
|
|
print(self, "is not focused")
|
2023-06-29 20:19:58 +00:00
|
|
|
|
|
|
|
|
func _on_mouse_entered():
|
2024-09-15 09:30:31 +00:00
|
|
|
is_mouse_entered = true
|
|
|
|
|
if not Input.is_action_pressed("mouse_left"):
|
|
|
|
|
# Do nothing if mouse hovers over sticky_note
|
|
|
|
|
if has_sticky_note_attached():
|
2025-01-31 02:22:07 +00:00
|
|
|
if current_sticky_note.highlighted:
|
2024-09-15 09:30:31 +00:00
|
|
|
return
|
|
|
|
|
highlighted = true
|
|
|
|
|
if "handle_hover" in owner:
|
|
|
|
|
owner.handle_hover(self)
|
2023-06-29 20:19:58 +00:00
|
|
|
|
|
|
|
|
func _on_mouse_exited():
|
2024-09-15 09:30:31 +00:00
|
|
|
highlighted = false
|
|
|
|
|
is_mouse_entered = false
|
2023-06-29 20:19:58 +00:00
|
|
|
|
2025-03-23 14:43:04 +00:00
|
|
|
func _on_input_event(_viewport, event, _shape_idx):
|
2024-09-15 09:30:31 +00:00
|
|
|
|
|
|
|
|
if event is InputEventMouseMotion:
|
|
|
|
|
_move_card()
|
|
|
|
|
|
|
|
|
|
if event is InputEventMouseButton:
|
2025-02-24 15:14:08 +00:00
|
|
|
# Mouse Button Left is being handled by card_board to prevent events being missed when mouse moves outside card
|
|
|
|
|
if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
2024-09-15 09:30:31 +00:00
|
|
|
if "handle_mouse_button" in owner:
|
|
|
|
|
mouse_offset = (get_viewport().get_mouse_position() - position)
|
|
|
|
|
if highlighted:
|
2025-01-31 02:22:07 +00:00
|
|
|
owner.handle_mouse_button(event, self)
|
2023-06-29 20:19:58 +00:00
|
|
|
|
2023-07-02 08:42:58 +00:00
|
|
|
func _move_card():
|
2024-09-15 09:30:31 +00:00
|
|
|
if is_dragged:
|
|
|
|
|
position += (get_viewport().get_mouse_position() - position) - mouse_offset
|
2023-07-02 09:50:19 +00:00
|
|
|
|
2023-10-12 16:25:21 +00:00
|
|
|
func has_sticky_note_attached() -> bool:
|
2025-02-24 15:14:08 +00:00
|
|
|
return sticky_note_anchor.get_child_count() > 0
|
2023-08-30 09:07:22 +00:00
|
|
|
|
2024-10-02 23:12:24 +00:00
|
|
|
func get_attached_sticky_note() -> StickyNote:
|
2025-02-24 15:14:08 +00:00
|
|
|
return null if not has_sticky_note_attached() else sticky_note_anchor.get_child(0)
|
2024-10-02 23:12:24 +00:00
|
|
|
|
2023-10-12 16:25:21 +00:00
|
|
|
func preview_sticky_note(sticky_note: StickyNote):
|
2024-09-15 09:30:31 +00:00
|
|
|
sticky_note.reparent(self.get_parent())
|
2025-02-24 15:14:08 +00:00
|
|
|
sticky_note.attached_to = self
|
2024-09-15 09:30:31 +00:00
|
|
|
sticky_note.tween_transform_to(Transform2D(0, sticky_note_anchor.global_position + 0 * Vector2(sticky_note.diameter, sticky_note.diameter)))
|
2023-08-30 09:07:22 +00:00
|
|
|
|
2023-10-12 16:25:21 +00:00
|
|
|
func attach_sticky_note(sticky_note: StickyNote) -> bool:
|
2024-09-15 09:30:31 +00:00
|
|
|
if has_sticky_note_attached():
|
|
|
|
|
return false
|
2025-02-24 15:14:08 +00:00
|
|
|
sticky_note.reparent(sticky_note_anchor)
|
|
|
|
|
sticky_note.position = Vector2.ZERO
|
2024-09-15 09:30:31 +00:00
|
|
|
sticky_note.on_board = false
|
|
|
|
|
current_sticky_note = sticky_note
|
|
|
|
|
sticky_note.attached_to = self
|
2025-02-24 15:14:08 +00:00
|
|
|
|
|
|
|
|
if name == "c_hit" and sticky_note.name == "p_effort":
|
2025-04-04 17:27:57 +00:00
|
|
|
#Steam.setAchievement("FIGHT_FOR_GOOD")
|
|
|
|
|
#Steam.storeStats()
|
|
|
|
|
pass
|
2025-02-24 15:14:08 +00:00
|
|
|
|
2024-09-15 09:30:31 +00:00
|
|
|
return true
|
2023-08-30 09:07:22 +00:00
|
|
|
|
2023-10-12 16:25:21 +00:00
|
|
|
func remove_sticky_note() -> StickyNote:
|
2024-09-15 09:30:31 +00:00
|
|
|
if not is_instance_valid(current_sticky_note): return null
|
|
|
|
|
var former_child:StickyNote = current_sticky_note
|
|
|
|
|
current_sticky_note = null
|
|
|
|
|
former_child.reparent(get_parent())
|
|
|
|
|
former_child.owner = self.owner
|
|
|
|
|
former_child.on_board = true
|
2025-03-31 19:31:09 +00:00
|
|
|
former_child.attached_to = owner
|
2024-09-15 09:30:31 +00:00
|
|
|
return former_child
|
2023-09-23 14:19:58 +00:00
|
|
|
|
2023-10-12 16:25:21 +00:00
|
|
|
func exchange_sticky_note_with(new_note: StickyNote) -> StickyNote:
|
2024-09-15 09:30:31 +00:00
|
|
|
var tmp = remove_sticky_note()
|
|
|
|
|
attach_sticky_note(new_note)
|
|
|
|
|
return tmp
|
2023-09-24 10:23:26 +00:00
|
|
|
|
2025-01-31 02:22:07 +00:00
|
|
|
# This makes sure this node highlights itself when focus has left the sticky note.
|
2023-07-14 20:03:09 +00:00
|
|
|
func check_hover():
|
2024-09-15 09:30:31 +00:00
|
|
|
if is_mouse_entered:
|
|
|
|
|
_on_mouse_entered()
|
2023-11-01 22:19:47 +00:00
|
|
|
|
|
|
|
|
func reclaim_sticky_note():
|
2024-09-15 09:30:31 +00:00
|
|
|
current_sticky_note.on_board = false
|
|
|
|
|
current_sticky_note.tween_transform_to(sticky_note_anchor.global_transform)
|
|
|
|
|
await current_sticky_note.transform_tween_finished
|
|
|
|
|
current_sticky_note.reparent(self)
|
|
|
|
|
current_sticky_note.owner = self.owner
|