From 6ac064d16d41bd9e334491ccdc4d311fb108fe0d Mon Sep 17 00:00:00 2001 From: PersonGuyGit Date: Sun, 17 Dec 2023 12:34:25 -0700 Subject: [PATCH] Refactored Special Abilities Object to be used as a middleware function for UI and other classes --- .../specialabliities/SpecialAbility.gd | 56 +++++-------------- .../middleware/specialabliities/testblank.gd | 8 --- .../Main/screens/TestScreen/test_scene.gd | 13 +++++ .../Main/screens/TestScreen/test_scene.tscn | 6 ++ 4 files changed, 34 insertions(+), 49 deletions(-) delete mode 100644 Phase2/Godot_Toolset/Main/middleware/specialabliities/testblank.gd create mode 100644 Phase2/Godot_Toolset/Main/screens/TestScreen/test_scene.gd create mode 100644 Phase2/Godot_Toolset/Main/screens/TestScreen/test_scene.tscn diff --git a/Phase2/Godot_Toolset/Main/middleware/specialabliities/SpecialAbility.gd b/Phase2/Godot_Toolset/Main/middleware/specialabliities/SpecialAbility.gd index ef322b6..e4d4e94 100644 --- a/Phase2/Godot_Toolset/Main/middleware/specialabliities/SpecialAbility.gd +++ b/Phase2/Godot_Toolset/Main/middleware/specialabliities/SpecialAbility.gd @@ -1,48 +1,22 @@ -extends Object +extends Node #This class, is used to define special ability data. Such as for attacks like shooting fireballs. #This is the middle ware, to define the structure of the data, before it is accesable by the character sheet. #This class is also used to define the structure, as to make it normalized for the database / XML layers. # Luke, 12/10/2023, Godot 3.5+ - - -var Name: String -var Attribute: Array - -var Cost: int - -var Damage: int - -var LevelRequirement: int - -var Duration: float - -var AffectedAttribute: String - -var DiceRules: Vector3 - -func _init(initName: String, initAttribute: Array, initCost: int, initDamage: int, -initLevelRequirement: int, initDuration: float, initAffectedAttribute: String, -initDiceRules: Vector3): - - Name = initName -# Attribute = initAttribute - Cost = initCost - Damage = initDamage - LevelRequirement = initLevelRequirement - Duration = initDuration - AffectedAttribute = initAffectedAttribute - DiceRules = initDiceRules - - Attribute = [] - for element in initAttribute: - if typeof(element) == TYPE_STRING: - Attribute.append(element) - else: - print("Warning: Ignoring non-string element in StringArray.") - -# Custom method to convert the object to a string -func to_string() -> String: - return "SpecialAbility(Name: {Name}, Attribute: {Attribute}, Cost: {Cost}, Damage: {Damage}, LevelRequirement: {LevelRequirement}, Duration: {Duration}, AffectedAttribute: {AffectedAttribute}, DiceRules: {DiceRules})" +func create_ability(AbilityName: String, Attribute: Array, Cost: int, Damage: int, +LevelRequirement: int, Duration: float, AffectedAttribute: String, +DiceRules: Vector3) -> Dictionary: + var data = { + "AbilityName": AbilityName, + "Attribute": Attribute, + "Cost": Cost, + "Damage": Damage, + "LevelRequirement": LevelRequirement, + "Duration": Duration, + "AffectedAttribute": AffectedAttribute, + "DiceRules": DiceRules, + } + return data diff --git a/Phase2/Godot_Toolset/Main/middleware/specialabliities/testblank.gd b/Phase2/Godot_Toolset/Main/middleware/specialabliities/testblank.gd deleted file mode 100644 index 2c02799..0000000 --- a/Phase2/Godot_Toolset/Main/middleware/specialabliities/testblank.gd +++ /dev/null @@ -1,8 +0,0 @@ - - -extends Node - -func _ready(): - var SpecialAbility = preload("res://middleware/specialabliities/SpecialAbility.gd") - var special_ability = SpecialAbility.new("Fireball", ["Fire Type", "Projectile"], 1, 10, 0, 5.0, "strength", Vector3(1, 1, 1)) - print(special_ability.to_string()) diff --git a/Phase2/Godot_Toolset/Main/screens/TestScreen/test_scene.gd b/Phase2/Godot_Toolset/Main/screens/TestScreen/test_scene.gd new file mode 100644 index 0000000..3e15811 --- /dev/null +++ b/Phase2/Godot_Toolset/Main/screens/TestScreen/test_scene.gd @@ -0,0 +1,13 @@ +extends Node + + +func _ready(): + print(SpecialAbility.create_ability("Fireball", + ["Fire Type", "Projectile"], + 1, + 10, + 5, + 3.0, + "strength", + Vector3(1, 2, 3) +)) diff --git a/Phase2/Godot_Toolset/Main/screens/TestScreen/test_scene.tscn b/Phase2/Godot_Toolset/Main/screens/TestScreen/test_scene.tscn new file mode 100644 index 0000000..1d5aca7 --- /dev/null +++ b/Phase2/Godot_Toolset/Main/screens/TestScreen/test_scene.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://screens/TestScreen/test_scene.gd" type="Script" id=1] + +[node name="Node2D" type="Node2D"] +script = ExtResource( 1 )