mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-01-19 19:44:46 +00:00
126 lines
4.6 KiB
GDScript
126 lines
4.6 KiB
GDScript
# This file is part of open-fpsz.
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
extends GutTest
|
|
|
|
var FLAG : PackedScene = preload("res://entities/flag/flag.tscn")
|
|
var PLAYER : PackedScene = preload("res://entities/player/player.tscn")
|
|
|
|
var _subject : Flag
|
|
|
|
func before_each() -> void:
|
|
_subject = FLAG.instantiate()
|
|
watch_signals(_subject)
|
|
add_child_autofree(_subject)
|
|
|
|
func _is_mesh_visible() -> bool:
|
|
var mesh : Node3D = _subject.find_child("Mesh")
|
|
return mesh.is_visible()
|
|
|
|
func test_that_flag_is_on_stand_by_default() -> void:
|
|
assert_eq(_subject.flag_state, Flag.FlagState.FLAG_STATE_ON_STAND)
|
|
|
|
func test_that_mesh_is_visible_by_default() -> void:
|
|
assert_true(_is_mesh_visible())
|
|
|
|
func test_that_flag_on_stand_can_be_grabbed() -> void:
|
|
_subject.flag_state = Flag.FlagState.FLAG_STATE_ON_STAND
|
|
assert_true(_subject.can_be_grabbed())
|
|
|
|
func test_that_dropped_flag_can_be_grabbed() -> void:
|
|
_subject.flag_state = Flag.FlagState.FLAG_STATE_DROPPED
|
|
assert_true(_subject.can_be_grabbed())
|
|
|
|
func test_that_taken_flag_cannot_be_grabbed() -> void:
|
|
_subject.flag_state = Flag.FlagState.FLAG_STATE_TAKEN
|
|
assert_false(_subject.can_be_grabbed())
|
|
|
|
func test_that_on_stand_flag_grab_emits_grab_signal_and_changes_state() -> void:
|
|
_subject.flag_state = Flag.FlagState.FLAG_STATE_ON_STAND
|
|
var player : Player = PLAYER.instantiate()
|
|
_subject.grab(player)
|
|
assert_signal_emitted_with_parameters(_subject, 'grabbed', [player])
|
|
assert_eq(_subject.flag_state, Flag.FlagState.FLAG_STATE_TAKEN)
|
|
assert_eq(_subject.last_carrier, player)
|
|
player.free()
|
|
|
|
func test_that_dropped_flag_grab_emits_grab_signal_and_changes_state() -> void:
|
|
_subject.flag_state = Flag.FlagState.FLAG_STATE_DROPPED
|
|
var player : Player = PLAYER.instantiate()
|
|
_subject.grab(player)
|
|
assert_signal_emitted_with_parameters(_subject, 'grabbed', [player])
|
|
assert_eq(_subject.flag_state, Flag.FlagState.FLAG_STATE_TAKEN)
|
|
assert_eq(_subject.last_carrier, player)
|
|
player.free()
|
|
|
|
func test_that_taken_flag_grab_does_not_emit_grab_signal_and_keeps_state() -> void:
|
|
_subject.flag_state = Flag.FlagState.FLAG_STATE_TAKEN
|
|
_subject.grab(null) # doesn't matter that it's null in this case
|
|
assert_signal_not_emitted(_subject, 'grabbed')
|
|
assert_eq(_subject.flag_state, Flag.FlagState.FLAG_STATE_TAKEN)
|
|
assert_null(_subject.last_carrier)
|
|
|
|
func test_that_flag_grab_hides_mesh() -> void:
|
|
var player : Player = PLAYER.instantiate()
|
|
_subject.grab(player)
|
|
assert_false(_is_mesh_visible())
|
|
player.free()
|
|
|
|
func test_that_taken_flag_drop_emits_signal_and_changes_state() -> void:
|
|
var player : Player = PLAYER.instantiate()
|
|
_subject.grab(player)
|
|
_subject.drop(player)
|
|
assert_signal_emitted_with_parameters(_subject, 'dropped', [player])
|
|
assert_eq(_subject.flag_state, Flag.FlagState.FLAG_STATE_DROPPED)
|
|
player.free()
|
|
|
|
func test_that_on_stand_flag_drop_does_not_emit_signals_and_keeps_state() -> void:
|
|
var player : Player = PLAYER.instantiate()
|
|
_subject.drop(player)
|
|
assert_signal_not_emitted(_subject, 'dropped')
|
|
assert_eq(_subject.flag_state, Flag.FlagState.FLAG_STATE_ON_STAND)
|
|
player.free()
|
|
|
|
func test_that_flag_drop_shows_mesh() -> void:
|
|
var player : Player = PLAYER.instantiate()
|
|
_subject.grab(player)
|
|
_subject.drop(player)
|
|
assert_true(_is_mesh_visible())
|
|
player.free()
|
|
|
|
func test_that_impossible_regrab_does_not_emit_regrabbed_signal() -> void:
|
|
var player : Player = PLAYER.instantiate()
|
|
_subject.grab(player)
|
|
_subject.grab(player)
|
|
assert_signal_not_emitted(_subject, 'regrabbed')
|
|
player.free()
|
|
|
|
func test_that_regrab_by_same_player_emits_regrabbed_signal() -> void:
|
|
var player : Player = PLAYER.instantiate()
|
|
_subject.grab(player)
|
|
_subject.drop(player)
|
|
_subject.grab(player)
|
|
assert_signal_emitted_with_parameters(_subject, 'regrabbed', [player])
|
|
player.free()
|
|
|
|
func test_that_regrab_by_different_player_does_not_emit_regrabbed_signal() -> void:
|
|
var player : Player = PLAYER.instantiate()
|
|
var different_player : Player = PLAYER.instantiate()
|
|
_subject.grab(player)
|
|
_subject.drop(player)
|
|
_subject.grab(different_player)
|
|
assert_signal_not_emitted(_subject, 'regrabbed')
|
|
player.free()
|
|
different_player.free()
|