Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions entities/game/card_collider/scripts/CardCollider.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@ class_name CardCollider extends Node2D
signal set_shape(shape: RectangleShape2D)
signal mouse_enter(grid: Vector2i)
signal mouse_left(grid: Vector2i)
signal clicked(grid: Vector2i)
signal clicked(grid: Vector2i, card: MemoryCardResource)

var _grid_coordinate: Vector2i = Vector2i.ZERO
var _shape: CollisionShape2D = null

var _mouse_inside: bool = false
var _active_state: bool = false
var _card_id: int = -1
var _card_data: MemoryCardResource = null

func _ready() -> void:
_shape = get_node("%CollisionShape")

func set_card_id(id: int) -> void:
if _card_id != -1:
return
_card_id = id
func set_data(data: MemoryCardResource) -> void:

_card_data = data

func get_card_id() -> int:
return _card_id
return _card_data.id

func set_size(size: Vector2) -> void:
var shape: RectangleShape2D = RectangleShape2D.new()
Expand Down Expand Up @@ -63,6 +62,9 @@ func input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void:
return
if event is InputEventMouseButton:
if event.pressed and event.button_index == MouseButton.MOUSE_BUTTON_LEFT:
clicked.emit(_grid_coordinate)
disable_collider()
is_clicked()
activate()

func activate() -> void:
disable_collider()
is_clicked()
clicked.emit(_grid_coordinate, _card_data)
8 changes: 1 addition & 7 deletions entities/game/card_template/scenes/CardTemplate.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,13 @@ volume = -15.0
[connection signal="about_to_get_delete" from="." to="CardContentGroup" method="animate_destruction"]
[connection signal="about_to_get_delete" from="." to="CardBack" method="remove_from_board"]
[connection signal="about_to_get_delete" from="." to="MatchingFoundEffect" method="trigger"]
[connection signal="card_in_focus" from="." to="CardContentGroup/DropShadow" method="got_focus"]
[connection signal="card_in_focus" from="." to="CardBack" method="is_focused"]
[connection signal="card_in_focus" from="." to="FocusEffect" method="trigger_random_effect"]
[connection signal="card_lost_focus" from="." to="CardContentGroup/DropShadow" method="lost_focus"]
[connection signal="card_lost_focus" from="." to="CardBack" method="lost_focus"]
[connection signal="card_text_changed" from="." to="CardContentGroup/CardNameBackground/CardName" method="set_card_text"]
[connection signal="card_tooltip_changed" from="." to="CardContentGroup/CardNameBackground/CardName" method="set_tooltip"]
[connection signal="deck_changed" from="." to="CardContentGroup/DropShadow" method="deck_changed"]
[connection signal="deck_changed" from="." to="CardBack" method="deck_changed"]
[connection signal="focus_changed" from="." to="CardBack" method="focus_changed"]
[connection signal="hide_card" from="." to="CardContentGroup/CardNameBackground/CardName" method="card_hidden"]
[connection signal="hide_card" from="." to="CardBack" method="toggle_on"]
[connection signal="input_active" from="." to="CardBack" method="input_active"]
[connection signal="input_active" from="." to="FocusEffect" method="toggle_state"]
[connection signal="remove_requested" from="." to="CardBack" method="removal_planed"]
[connection signal="show_card" from="." to="CardContentGroup" method="show_card_content"]
[connection signal="show_card" from="." to="CardBack" method="toggle_off"]
Expand Down
64 changes: 27 additions & 37 deletions entities/game/card_template/scripts/CardTemplate.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,27 @@ signal show_card()
signal fully_hidden()
## The process of showing has ended, the card is fully visible now
signal fully_shown()
signal card_triggered(card: CardTemplate)
signal card_in_focus()
signal card_lost_focus()
signal mouse_was_used()

signal remove_requested()

signal animation_done()

## Signals to manage the visual card state

## The card is now queued to be freed
signal about_to_get_delete()
signal input_active(is_active: bool)

## The card text was changed
signal card_text_changed(new_text: String)

## The card tooltip was changed
signal card_tooltip_changed(new_tooltip: String)

## The card deck was changed
signal deck_changed(deck: MemoryDeckResource)

signal remove_requested()
signal focus_changed(new_state: bool)


@export var is_ghost: bool = false

Expand Down Expand Up @@ -103,25 +111,23 @@ func _setup_timer() -> void:
_timer_for_hide_delay.timeout.connect(hide_card_now)
add_child(_timer_for_hide_delay)

func _enter_tree() -> void:
if is_ghost:
return
var parent_node: MemoryGame = get_parent().get_node("%World").get_parent() as MemoryGame
if parent_node == null:
printerr("No parent node was found!")
func change_focus(new_state: bool) -> void:
focus_changed.emit(new_state)

func toggle_card_on() -> void:
var time_range: float = card_flip_animation_max_time_delay - card_flip_animation_min_time_delay
var delay: float = randf() * time_range + card_flip_animation_min_time_delay
_timer_for_hide_delay.wait_time = delay
_timer_for_hide_delay.start()
await get_tree().create_timer(delay).timeout
hide_card_now()
#_timer_for_hide_delay.wait_time = delay
#_timer_for_hide_delay.start()

func hide_card_now() -> void:
if back_side == null or back_side.is_hidden():
return
_was_clicked = false
hide_card.emit()
lost_focus()
_playing_animation = true
play_card_turn_sound()

func get_height() -> float:
Expand All @@ -131,7 +137,6 @@ func freeze_card() -> void:
if back_side == null:
return
_card_frozen = true
lost_focus()

func unfreeze_card() -> void:
if back_side == null:
Expand All @@ -154,14 +159,13 @@ func force_reveal_card() -> void:
if _was_clicked or not _valid_game_state:
return
_was_clicked = true
_playing_animation = true
freeze_card()
play_card_turn_sound()
if back_side == null or back_side.is_queued_for_deletion():
return
back_side.toggle_off()
show_card.emit()

card_triggered.emit(self)

func play_card_turn_sound() -> void:
GlobalSoundManager.play_sound_effect(flip_effects.pick_random())
Expand Down Expand Up @@ -237,6 +241,7 @@ func _trigger_remove() -> void:
for group: String in get_groups():
remove_from_group(group)
_playing_animation = false
animation_done.emit()
about_to_get_delete.emit()

func is_playing_animation() -> bool:
Expand All @@ -245,9 +250,6 @@ func is_playing_animation() -> bool:
func is_getting_removed() -> bool:
return _getting_removed

func destory_now() -> void:
queue_free()

func card_is_hidden() -> bool:
if back_side == null:
return true
Expand All @@ -263,31 +265,19 @@ func card_is_focused() -> bool:
return true
return back_side.is_currently_in_focus()

func got_focus() -> void:
if _was_clicked or _card_frozen:
return
card_in_focus.emit()

func lost_focus() -> void:
if _was_clicked:
return
card_lost_focus.emit()

func selected_by_mouse() -> void:
mouse_was_used.emit()

func play_sound(audio: AudioStream) -> void:
if audio == null:
return
GlobalSoundManager.play_sound_effect(audio)

func input_allowed(allowed: bool) -> void:
input_active.emit(allowed)

func signal_repeater_fully_shown() -> void:
_playing_animation = false
animation_done.emit()
fully_shown.emit()

func signal_repeater_fully_hidden() -> void:
_playing_animation = false
animation_done.emit()
fully_hidden.emit()

func game_state_changed(new_state: GameEnum.State) -> void:
Expand Down
30 changes: 15 additions & 15 deletions entities/game/card_template/scripts/ToggleCardVisibility.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ enum VisibilityEnum
var _internal_toggle_material: ShaderMaterial
var _internal_focus_material: ShaderMaterial

var currently_in_focus: bool = false
## The card is the current focus of the player
var _current_focus: bool = false

var removal_requested: bool = false
var can_remove: bool = false
Expand All @@ -51,9 +52,8 @@ func deck_changed(deck: MemoryDeckResource) -> void:
texture = real_texture
return

# This method will hide a fully shown card
## This method will hide a fully shown card
func toggle_on() -> void:
print("toggle on")
can_remove = false
if is_hidden():
return
Expand All @@ -68,23 +68,20 @@ func toggle_on() -> void:
visibility = VisibilityEnum.TRANSITION
animation_tween.tween_method(update_toggle_material, 1.0, 0.0, animation_time)
animation_tween.finished.connect(func() -> void: _animation_finished(true))
if currently_in_focus:
if _current_focus:
set_shader_material(_internal_toggle_material)

func _animation_finished(should_hide: bool) -> void:
if should_hide:
fully_hidden.emit()
visibility = VisibilityEnum.HIDDEN
print("hidden")
if not should_hide:
fully_shown.emit()
visibility = VisibilityEnum.SHOWN
can_remove = true
print("shown")

# This method will show a fully hidden card
## This method will show a fully hidden card
func toggle_off() -> void:
print("toggle off")
if animation_tween != null:
animation_tween.kill()
if material is ShaderMaterial:
Expand All @@ -93,28 +90,31 @@ func toggle_off() -> void:
visibility = VisibilityEnum.TRANSITION
animation_tween.tween_method(update_toggle_material, 0.0, 1.0, animation_time)
animation_tween.finished.connect(func() -> void: _animation_finished(false))
if currently_in_focus:
if _current_focus:
set_shader_material(_internal_toggle_material)

func update_toggle_material(progress: float) -> void:
if material is ShaderMaterial:
material.set_shader_parameter("threshold", progress)

func focus_changed(new_focus: bool) -> void:
if new_focus:
is_focused()
else:
lost_focus()

func is_focused() -> void:
if animation_tween != null && animation_tween.is_running():
return
if visibility == VisibilityEnum.TRANSITION:
return
for card: Node in get_tree().get_nodes_in_group("game_card"):
if card is CardTemplate and card.card_is_focused():
card.lost_focus()

currently_in_focus = true
_current_focus = true
set_shader_material(_internal_focus_material)
_animate_focus(focus_scale)

func lost_focus() -> void:
currently_in_focus = false
_current_focus = false
set_shader_material(_internal_toggle_material)

_animate_focus(1.0)
Expand All @@ -133,7 +133,7 @@ func is_fully_shown() -> bool:
return visibility == VisibilityEnum.SHOWN

func is_currently_in_focus() -> bool:
return currently_in_focus
return _current_focus

func remove_from_board() -> void:
removal_requested = true
Expand Down
20 changes: 10 additions & 10 deletions entities/game/memory_game/scenes/MemoryGame.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -281,26 +281,26 @@ debug_functions = Array[ExtResource("34_4hsit")]([SubResource("Resource_8rpam")]
[connection signal="player_has_changed" from="Systems/NetworkHandlerSystem" to="Systems/PlayerSystem" method="set_player_by_id"]
[connection signal="player_has_scored" from="Systems/NetworkHandlerSystem" to="Systems/PlayerSystem" method="set_player_score"]
[connection signal="remove_card" from="Systems/NetworkHandlerSystem" to="World/CardBoard" method="remove_card_from_board"]
[connection signal="all_matching_cards_removed" from="World/CardBoard" to="." method="all_cards_removed"]
[connection signal="all_matching_cards_removed" from="World/CardBoard" to="Systems/GameStateSystem" method="matches_found"]
[connection signal="all_matching_cards_removed" from="World/CardBoard" to="Systems/TutorialStateSystem" method="matching_card_found"]
[connection signal="all_matching_cards_removed" from="World/CardBoard" to="Systems/PlayerSystem" method="player_scored"]
[connection signal="animations_finished" from="World/CardBoard" to="Systems/GameStateSystem" method="animation_cleared"]
[connection signal="animations_finished" from="World/CardBoard" to="Systems/PlayerSystem" method="card_animations_completed"]
[connection signal="board_ready" from="World/CardBoard" to="Systems/GameStateSystem" method="board_ready"]
[connection signal="card_activated" from="World/CardBoard" to="Systems/GameStateSystem" method="card_was_clicked"]
[connection signal="card_activated" from="World/CardBoard" to="Systems/TutorialStateSystem" method="card_triggered"]
[connection signal="card_removed" from="World/CardBoard" to="World/CardBoard/CardInteractionField" method="remove_card"]
[connection signal="card_triggered" from="World/CardBoard" to="Systems/AiAgentSystem" method="card_was_triggered"]
[connection signal="identical_cards" from="World/CardBoard" to="Systems/AiAgentSystem" method="card_was_identically"]
[connection signal="no_matches_found" from="World/CardBoard" to="Systems/GameStateSystem" method="no_matches"]
[connection signal="ai_information_card_clicked" from="World/CardBoard/CardInteractionField" to="Systems/AiAgentSystem" method="card_was_triggered"]
[connection signal="board_area" from="World/CardBoard/CardInteractionField" to="World/Camera2D" method="adjust_zoom_and_position_to_play_area"]
[connection signal="board_build" from="World/CardBoard/CardInteractionField" to="Systems/GameStateSystem" method="game_field_ready"]
[connection signal="board_build" from="World/CardBoard/CardInteractionField" to="UI/PauseMenuButton" method="show_button_if_valid"]
[connection signal="board_build" from="World/CardBoard/CardInteractionField" to="UI/PlayersOverlay" method="show"]
[connection signal="board_build" from="World/CardBoard/CardInteractionField" to="UI/ZoomButtons/ZoomIn" method="show_button_if_valid"]
[connection signal="board_build" from="World/CardBoard/CardInteractionField" to="UI/ZoomButtons/ZoomOut" method="show_button_if_valid"]
[connection signal="board_empty" from="World/CardBoard/CardInteractionField" to="Systems/GameStateSystem" method="board_empty"]
[connection signal="card_activated" from="World/CardBoard/CardInteractionField" to="Systems/TutorialStateSystem" method="card_triggered"]
[connection signal="clicked" from="World/CardBoard/CardInteractionField" to="World/CardBoard" method="trigger_card_at_position"]
[connection signal="match_found" from="World/CardBoard/CardInteractionField" to="Systems/GameStateSystem" method="matches_found"]
[connection signal="match_found" from="World/CardBoard/CardInteractionField" to="Systems/TutorialStateSystem" method="matching_card_found"]
[connection signal="match_found" from="World/CardBoard/CardInteractionField" to="Systems/PlayerSystem" method="player_scored"]
[connection signal="mouse_enter" from="World/CardBoard/CardInteractionField" to="World/CardBoard" method="select_card_at_position"]
[connection signal="place_card" from="World/CardBoard/CardInteractionField" to="World/CardBoard" method="place_card"]
[connection signal="remove_card_at" from="World/CardBoard/CardInteractionField" to="Systems/AiAgentSystem" method="remove_card_to_all_ais"]
[connection signal="remove_cards_at" from="World/CardBoard/CardInteractionField" to="World/CardBoard" method="remove_cards_from_board"]
[connection signal="turn_ended" from="World/CardBoard/CardInteractionField" to="Systems/GameStateSystem" method="no_matches"]
[connection signal="touch_used" from="World/Camera2D" to="World/CardBoard" method="disable_card_effects"]
[connection signal="pressed" from="UI/PauseMenuButton" to="." method="show_game_menu"]
Loading
Loading