Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Godot project #1

Merged
merged 14 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 3 additions & 9 deletions Fauna-RPG/#Scenes/TestingScene.tscn
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
[gd_scene load_steps=13 format=3 uid="uid://87fedoq257xg"]
[gd_scene load_steps=11 format=3 uid="uid://87fedoq257xg"]

[ext_resource type="Script" path="res://Cards/CardContainer.gd" id="1_cwemj"]
[ext_resource type="PackedScene" uid="uid://caxbd2ppk3ans" path="res://Cards/Card.tscn" id="2_tx1h0"]
[ext_resource type="Script" path="res://Core/Battler.gd" id="2_w64qc"]
[ext_resource type="PackedScene" uid="uid://clmg3l3n28x38" path="res://Entity/Player/Player.tscn" id="3_4psp7"]
[ext_resource type="Resource" uid="uid://dxgoopi1roxu4" path="res://Cards/Resource/Card_Damage.tres" id="3_6uosf"]
[ext_resource type="PackedScene" uid="uid://85ove4xi0gf0" path="res://Entity/Enemy/Enemy_SaplingGreen.tscn" id="3_cr4lg"]
[ext_resource type="PackedScene" uid="uid://bxgvbltw03uda" path="res://Entity/Enemy/Enemy_SaplingRed.tscn" id="4_6j3pr"]
[ext_resource type="Resource" uid="uid://5yn4t13kwwoo" path="res://Cards/Resource/Card_DamageHealth.tres" id="4_nsiy1"]
[ext_resource type="Resource" uid="uid://d12g33rc6c3u5" path="res://Cards/Resource/Card_Heal.tres" id="5_4b2q2"]
[ext_resource type="Resource" uid="uid://ctx8jsvac84so" path="res://Cards/Resource/Card_Poison.tres" id="6_bferu"]
[ext_resource type="Resource" uid="uid://0x385c3nuq8f" path="res://Cards/Resource/Card_DamageAll.tres" id="7_7bwak"]
[ext_resource type="PackedScene" uid="uid://bcpmrmofcilbn" path="res://Core/Battler.tscn" id="8_qtw1k"]
[ext_resource type="Script" path="res://UI/EndTurnButton.gd" id="11_6xwul"]

[node name="TestingScene" type="Node2D"]
Expand All @@ -22,11 +20,7 @@ total_hand_width = 500.0
card_queued_offset = 200.0
default_hand = Array[Resource("res://Cards/CardBase.gd")]([ExtResource("3_6uosf"), ExtResource("4_nsiy1"), ExtResource("5_4b2q2"), ExtResource("6_bferu"), ExtResource("7_7bwak")])

[node name="Battler" type="Node2D" parent="."]
position = Vector2(596, 89)
script = ExtResource("2_w64qc")
enemies_to_summon = Array[PackedScene]([ExtResource("3_cr4lg"), ExtResource("4_6j3pr")])
enemy_spacing = 200.0
[node name="Battler" parent="." instance=ExtResource("8_qtw1k")]

[node name="Player" parent="." instance=ExtResource("3_4psp7")]
position = Vector2(595, 284)
Expand Down
45 changes: 45 additions & 0 deletions Fauna-RPG/.gut_editor_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"background_color": "262626ff",
"compact_mode": false,
"config_file": "res://.gutconfig.json",
"dirs": [
"res://Tests"
],
"disable_colors": false,
"double_strategy": 1,
"errors_do_not_cause_failure": false,
"font_color": "ccccccff",
"font_name": "CourierPrime",
"font_size": 16,
"gut_on_top": true,
"hide_orphans": false,
"ignore_pause": false,
"include_subdirs": false,
"inner_class": null,
"junit_xml_file": "",
"junit_xml_timestamp": false,
"log_level": 1,
"opacity": 100,
"paint_after": 0.1,
"panel_options": {
"font_name": "CourierPrime",
"font_size": 30,
"hide_output_text": false,
"hide_result_tree": false,
"hide_settings": false,
"output_font_name": "CourierPrime",
"output_font_size": 30,
"use_colors": false
},
"post_run_script": "",
"pre_run_script": "",
"prefix": "test_",
"selected": null,
"should_exit": false,
"should_exit_on_success": false,
"should_maximize": false,
"show_help": false,
"suffix": ".gd",
"tests": [],
"unit_test_name": null
}
11 changes: 11 additions & 0 deletions Fauna-RPG/Core/Battler.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[gd_scene load_steps=4 format=3 uid="uid://bcpmrmofcilbn"]

[ext_resource type="Script" path="res://Core/Battler.gd" id="1_7pmkk"]
[ext_resource type="PackedScene" uid="uid://85ove4xi0gf0" path="res://Entity/Enemy/Enemy_SaplingGreen.tscn" id="2_3w4is"]
[ext_resource type="PackedScene" uid="uid://bxgvbltw03uda" path="res://Entity/Enemy/Enemy_SaplingRed.tscn" id="3_s0fw5"]

[node name="Battler" type="Node2D"]
position = Vector2(596, 89)
script = ExtResource("1_7pmkk")
enemies_to_summon = Array[PackedScene]([ExtResource("2_3w4is"), ExtResource("3_s0fw5")])
enemy_spacing = 200.0
6 changes: 1 addition & 5 deletions Fauna-RPG/Entity/Components/StatComponent.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,4 @@ class_name StatComponent
## have different stats based on the Entity type.


var stats: EntityStats


func _ready() -> void:
stats = EntityStats.new()
var stats: EntityStats = EntityStats.new()
Turtyo marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions Fauna-RPG/Managers/PhaseManager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extends Node
## be kept to as little calls as we can to reduce confusion with game phase changes.


signal on_game_start
signal on_phase_changed(new_phase: Enums.Phase, old_phase: Enums.Phase)
var current_phase: Enums.Phase = Enums.Phase.NONE

Expand All @@ -20,6 +21,7 @@ func _ready() -> void:

func _start_game() -> void:
set_phase(Enums.Phase.PLAYER_ATTACKING)
on_game_start.emit()


func set_phase(phase: Enums.Phase) -> void:
Expand Down
154 changes: 154 additions & 0 deletions Fauna-RPG/Tests/test_health.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
extends GutTest
## Tests for health related things


var _player_scene: PackedScene = load("res://Entity/Player/Player.tscn")
var _enemy_scene: PackedScene = load("res://Entity/Enemy/Enemy.tscn")
var _battler_scene: PackedScene = load("res://Core/Battler.tscn")
var _player: Entity = null
var _enemy: Entity = null
var _battler: Battler = null
var _player_health_component: HealthComponent = null
var _enemy_health_component: HealthComponent = null

func before_all():
await PhaseManager.on_game_start


func before_each():
_player = _player_scene.instantiate()
_enemy = _enemy_scene.instantiate()
_battler = _battler_scene.instantiate()

get_tree().root.add_child(_player)
get_tree().root.add_child(_enemy)
get_tree().root.add_child(_battler)

_player_health_component = _player.get_health_component()
_enemy_health_component = _enemy.get_health_component()


func after_each():
_player.queue_free()
_enemy.queue_free()
_battler.queue_free()


func test_take_damage():
var deal_damage_data = DealDamageData.new()
deal_damage_data.damage = 5.0
deal_damage_data.attacker = _player

_player_health_component.deal_damage(deal_damage_data)
assert_eq(_player_health_component.current_health, 95.0)


func test_take_lots_of_damage():
var deal_damage_data = DealDamageData.new()
deal_damage_data.damage = 999999.0
deal_damage_data.attacker = _player

_player_health_component.deal_damage(deal_damage_data)
assert_eq(_player_health_component.current_health, 0.0)


func test_null_attacker():
var deal_damage_data = DealDamageData.new()
deal_damage_data.damage = 50.0
deal_damage_data.attacker = null

_player_health_component.deal_damage(deal_damage_data)
assert_eq(_player_health_component.current_health, 50.0)


func test_heal():
var deal_damage_data = DealDamageData.new()
deal_damage_data.damage = -50.0
deal_damage_data.attacker = _player

_player_health_component._set_health(50.0)
_player_health_component.deal_damage(deal_damage_data)
assert_eq(_player_health_component.current_health, 100.0)


func test_attack_enemy():
var deal_damage_data = DealDamageData.new()
deal_damage_data.damage = 50.0
deal_damage_data.attacker = _player

_enemy_health_component.deal_damage(deal_damage_data)
assert_eq(_enemy_health_component.current_health, 50.0)


# apply strength to player and damage enemy
func test_strength_buff():
var deal_damage_data = DealDamageData.new()
deal_damage_data.damage = 50.0
deal_damage_data.attacker = _player

var strength_buff = Buff_Strength.new()
strength_buff.buff_power = 1.0
_player.get_buff_component().add_buff(strength_buff, _player)

_enemy_health_component.deal_damage(deal_damage_data)
assert_eq(_enemy_health_component.current_health, 49.0)


# apply weakness to player and damage enemy
func test_weakness_buff():
var deal_damage_data = DealDamageData.new()
deal_damage_data.damage = 50.0
deal_damage_data.attacker = _player

var weakness_buff = Buff_Weakness.new()
weakness_buff.buff_power = 1.0
_player.get_buff_component().add_buff(weakness_buff, _player)

_enemy_health_component.deal_damage(deal_damage_data)
assert_eq(_enemy_health_component.current_health, 51.0)


# apply vulnerability to enemy and damage enemy
func test_vulnerability_buff():
var deal_damage_data = DealDamageData.new()
deal_damage_data.damage = 50.0
deal_damage_data.attacker = _player

var vulnerability_buff = Buff_Vulnerability.new()
vulnerability_buff.buff_power = 1.0
_enemy.get_buff_component().add_buff(vulnerability_buff, _player)

_enemy_health_component.deal_damage(deal_damage_data)
assert_eq(_enemy_health_component.current_health, 49.0)


func test_vulnerability_weakness_strength():
var deal_damage_data = DealDamageData.new()
deal_damage_data.damage = 50.0
deal_damage_data.attacker = _player

var vulnerability_buff = Buff_Vulnerability.new()
vulnerability_buff.buff_power = 1.0
_enemy.get_buff_component().add_buff(vulnerability_buff, _player)

var weakness_buff = Buff_Weakness.new()
weakness_buff.buff_power = 2.0
_player.get_buff_component().add_buff(weakness_buff, _player)

var strength_buff = Buff_Strength.new()
strength_buff.buff_power = 1.0
_player.get_buff_component().add_buff(strength_buff, _player)

_enemy_health_component.deal_damage(deal_damage_data)
assert_eq(_enemy_health_component.current_health, 50.0)


func test_poison_buff():
var poison_buff = Buff_Poison.new()
poison_buff.buff_power = 1.0
poison_buff.buff_turn_duration = 3.0
poison_buff.buff_owner = _enemy
_enemy.get_buff_component().add_buff(poison_buff, _player)

poison_buff.on_turn_start()
assert_eq(_enemy_health_component.current_health, 99.0)
127 changes: 127 additions & 0 deletions Fauna-RPG/addons/gut/GutScene.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
extends Node2D
# ##############################################################################
# This is a wrapper around the normal and compact gui controls and serves as
# the interface between gut.gd and the gui. The GutRunner creates an instance
# of this and then this takes care of managing the different GUI controls.
# ##############################################################################
@onready var _normal_gui = $Normal
@onready var _compact_gui = $Compact

var gut = null :
set(val):
gut = val
_set_gut(val)


func _ready():
_normal_gui.switch_modes.connect(use_compact_mode.bind(true))
_compact_gui.switch_modes.connect(use_compact_mode.bind(false))

_normal_gui.set_title("GUT")
_compact_gui.set_title("GUT")

_normal_gui.align_right()
_compact_gui.to_bottom_right()

use_compact_mode(false)

if(get_parent() == get_tree().root):
_test_running_setup()

func _test_running_setup():
set_font_size(100)
_normal_gui.get_textbox().text = "hello world, how are you doing?"

# ------------------------
# Private
# ------------------------
func _set_gut(val):
if(_normal_gui.get_gut() == val):
return
_normal_gui.set_gut(val)
_compact_gui.set_gut(val)

val.start_run.connect(_on_gut_start_run)
val.end_run.connect(_on_gut_end_run)
val.start_pause_before_teardown.connect(_on_gut_pause)
val.end_pause_before_teardown.connect(_on_pause_end)

func _set_both_titles(text):
_normal_gui.set_title(text)
_compact_gui.set_title(text)


# ------------------------
# Events
# ------------------------
func _on_gut_start_run():
_set_both_titles('Running')

func _on_gut_end_run():
_set_both_titles('Finished')

func _on_gut_pause():
_set_both_titles('-- Paused --')

func _on_pause_end():
_set_both_titles('Running')


# ------------------------
# Public
# ------------------------
func get_textbox():
return _normal_gui.get_textbox()


func set_font_size(new_size):
var rtl = _normal_gui.get_textbox()

rtl.set('theme_override_font_sizes/bold_italics_font_size', new_size)
rtl.set('theme_override_font_sizes/bold_font_size', new_size)
rtl.set('theme_override_font_sizes/italics_font_size', new_size)
rtl.set('theme_override_font_sizes/normal_font_size', new_size)


func set_font(font_name):
_set_all_fonts_in_rtl(_normal_gui.get_textbox(), font_name)


func _set_font(rtl, font_name, custom_name):
if(font_name == null):
rtl.add_theme_font_override(custom_name, null)
else:
var dyn_font = FontFile.new()
dyn_font.load_dynamic_font('res://addons/gut/fonts/' + font_name + '.ttf')
rtl.add_theme_font_override(custom_name, dyn_font)


func _set_all_fonts_in_rtl(rtl, base_name):
if(base_name == 'Default'):
_set_font(rtl, null, 'normal_font')
_set_font(rtl, null, 'bold_font')
_set_font(rtl, null, 'italics_font')
_set_font(rtl, null, 'bold_italics_font')
else:
_set_font(rtl, base_name + '-Regular', 'normal_font')
_set_font(rtl, base_name + '-Bold', 'bold_font')
_set_font(rtl, base_name + '-Italic', 'italics_font')
_set_font(rtl, base_name + '-BoldItalic', 'bold_italics_font')


func set_default_font_color(color):
_normal_gui.get_textbox().set('custom_colors/default_color', color)


func set_background_color(color):
_normal_gui.set_bg_color(color)


func use_compact_mode(should=true):
_compact_gui.visible = should
_normal_gui.visible = !should


func set_opacity(val):
_normal_gui.modulate.a = val
_compact_gui.modulate.a = val
Loading