From 4246e3585fa844d086bf5142c2f829c06822da46 Mon Sep 17 00:00:00 2001 From: tynutsathitya Date: Mon, 18 Dec 2023 11:52:08 -0800 Subject: [PATCH 1/6] Create Event Parent and Event Child Classes --- Event/Event.gd | 11 +++++++++++ Event/Event_Heal.gd | 8 ++++++++ Event/Event_Mob.gd | 8 ++++++++ Event/Event_Random.gd | 8 ++++++++ Event/Event_Shop.gd | 8 ++++++++ 5 files changed, 43 insertions(+) create mode 100644 Event/Event.gd create mode 100644 Event/Event_Heal.gd create mode 100644 Event/Event_Mob.gd create mode 100644 Event/Event_Random.gd create mode 100644 Event/Event_Shop.gd diff --git a/Event/Event.gd b/Event/Event.gd new file mode 100644 index 00000000..aa070288 --- /dev/null +++ b/Event/Event.gd @@ -0,0 +1,11 @@ +extends Resource +class_name Event + +var EVENTS_CLASSIFICATION = [Event_Mob, Event_Random, Event_Shop, Event_Heal] + +# Initialize Event +func _init(): + print("Initialize Event") + +func _update(): + print("Update") diff --git a/Event/Event_Heal.gd b/Event/Event_Heal.gd new file mode 100644 index 00000000..88f76337 --- /dev/null +++ b/Event/Event_Heal.gd @@ -0,0 +1,8 @@ +extends Event +class_name Event_Heal + +func _init(): + print("Initializing Heal Event") + +func _update(): + print("Updating Heal Event") diff --git a/Event/Event_Mob.gd b/Event/Event_Mob.gd new file mode 100644 index 00000000..610033dd --- /dev/null +++ b/Event/Event_Mob.gd @@ -0,0 +1,8 @@ +extends Event +class_name Event_Mob + +func _init(): + print("Initialize Mob") + +func _update(): + print("Update Mob") diff --git a/Event/Event_Random.gd b/Event/Event_Random.gd new file mode 100644 index 00000000..d69402a6 --- /dev/null +++ b/Event/Event_Random.gd @@ -0,0 +1,8 @@ +extends Event +class_name Event_Random + +func _init(): + print("Initializing Random Event") + +func _update(): + print("Updating Random Event") diff --git a/Event/Event_Shop.gd b/Event/Event_Shop.gd new file mode 100644 index 00000000..bc652e8e --- /dev/null +++ b/Event/Event_Shop.gd @@ -0,0 +1,8 @@ +extends Event +class_name Event_Shop + +func _init(): + print("Initializing Shop") + +func _update(): + print("Updating shop") From 5ed8cdfd60af7a88773b1e4d6b5dbd5c3f8557bf Mon Sep 17 00:00:00 2001 From: tynutsathitya Date: Mon, 18 Dec 2023 20:19:18 -0800 Subject: [PATCH 2/6] Issue 20: Update Event Children with scene string instantiation, Create Events Classification script to hold enums for different events and added it to AutoLoader --- Event/Event.gd | 17 ++++++++++++----- Event/Event_Heal.gd | 8 +++++--- Event/Event_Mob.gd | 10 ++++++---- Event/Event_Random.gd | 8 +++++--- Event/Event_Shop.gd | 8 +++++--- Event/EventsClassification.gd | 16 ++++++++++++++++ project.godot | 1 + 7 files changed, 50 insertions(+), 18 deletions(-) create mode 100644 Event/EventsClassification.gd diff --git a/Event/Event.gd b/Event/Event.gd index aa070288..8dbfd331 100644 --- a/Event/Event.gd +++ b/Event/Event.gd @@ -1,11 +1,18 @@ extends Resource class_name Event -var EVENTS_CLASSIFICATION = [Event_Mob, Event_Random, Event_Shop, Event_Heal] +#const EVENTS_CLASSIFICATION = [Event_Mob, Event_Random, Event_Shop, Event_Heal] + +var packedScene: String = "" # Initialize Event -func _init(): - print("Initialize Event") +func _init(scene: String) -> void: + packedScene = scene + +func _update_event() -> void: + pass + +func _load_scene() -> Node: + var loadScene: PackedScene = load(packedScene) + return loadScene.instantiate() -func _update(): - print("Update") diff --git a/Event/Event_Heal.gd b/Event/Event_Heal.gd index 88f76337..386f7015 100644 --- a/Event/Event_Heal.gd +++ b/Event/Event_Heal.gd @@ -1,8 +1,10 @@ extends Event class_name Event_Heal -func _init(): - print("Initializing Heal Event") +# @Override +func _init(scene: String) -> void: + super(scene) -func _update(): +# @Override +func _update_event() -> void: print("Updating Heal Event") diff --git a/Event/Event_Mob.gd b/Event/Event_Mob.gd index 610033dd..e26a61c2 100644 --- a/Event/Event_Mob.gd +++ b/Event/Event_Mob.gd @@ -1,8 +1,10 @@ extends Event class_name Event_Mob -func _init(): - print("Initialize Mob") - -func _update(): +# @Override +func _init(scene: String) -> void: + super(scene) + +# @Override +func _update_event() -> void: print("Update Mob") diff --git a/Event/Event_Random.gd b/Event/Event_Random.gd index d69402a6..37f9ed25 100644 --- a/Event/Event_Random.gd +++ b/Event/Event_Random.gd @@ -1,8 +1,10 @@ extends Event class_name Event_Random -func _init(): - print("Initializing Random Event") +# @Override +func _init(scene: String) -> void: + super(scene) -func _update(): +# @Override +func _update_event() -> void: print("Updating Random Event") diff --git a/Event/Event_Shop.gd b/Event/Event_Shop.gd index bc652e8e..bdafa405 100644 --- a/Event/Event_Shop.gd +++ b/Event/Event_Shop.gd @@ -1,8 +1,10 @@ extends Event class_name Event_Shop -func _init(): - print("Initializing Shop") +# @Override +func _init(scene: String) -> void: + super(scene) -func _update(): +# @Override +func _update_event() -> void: print("Updating shop") diff --git a/Event/EventsClassification.gd b/Event/EventsClassification.gd new file mode 100644 index 00000000..dd505ddd --- /dev/null +++ b/Event/EventsClassification.gd @@ -0,0 +1,16 @@ +extends Node + +enum EventsClassification { EVENT_MOB, EVENT_RANDOM, EVENT_SHOP, EVENT_HEAL } + +func createEvent(index: int) -> Event: + var event = null + match index: + EventsClassification.EVENT_MOB: + event = Event_Mob.new("res://Event/EventTest.tscn") + EventsClassification.EVENT_RANDOM: + event = Event_Random.new("res://Event/EventTest.tscn") + EventsClassification.EVENT_SHOP: + event = Event_Shop.new("res://Event/EventTest.tscn") + EventsClassification.EVENT_HEAL: + event = Event_Heal.new("res://Event/EventTest.tscn") + return event diff --git a/project.godot b/project.godot index f7782fc3..476ad19b 100644 --- a/project.godot +++ b/project.godot @@ -21,6 +21,7 @@ PlayerManager="*res://Managers/PlayerManager.gd" CardManager="*res://Managers/CardManager.gd" PhaseManager="*res://Managers/PhaseManager.gd" RandomGenerator="*res://Managers/RandomGenerator.gd" +EventsClassification="*res://Event/EventsClassification.gd" [display] From dce24320c4cf2395613f77e14bc01385f590a4da Mon Sep 17 00:00:00 2001 From: tynutsathitya Date: Mon, 18 Dec 2023 20:20:34 -0800 Subject: [PATCH 3/6] Issue 20: Add comment for test function --- Event/EventsClassification.gd | 1 + 1 file changed, 1 insertion(+) diff --git a/Event/EventsClassification.gd b/Event/EventsClassification.gd index dd505ddd..e217cf83 100644 --- a/Event/EventsClassification.gd +++ b/Event/EventsClassification.gd @@ -2,6 +2,7 @@ extends Node enum EventsClassification { EVENT_MOB, EVENT_RANDOM, EVENT_SHOP, EVENT_HEAL } +# Test function for creating event, will remove later func createEvent(index: int) -> Event: var event = null match index: From 4f23054d5ddb0f6801971a0eed86685e15281092 Mon Sep 17 00:00:00 2001 From: tynutsathitya Date: Tue, 19 Dec 2023 11:44:47 -0800 Subject: [PATCH 4/6] Issue-20: Rename Event classes, remove EventsClassification enum --- Event/{Event.gd => EventBase.gd} | 4 ++-- Event/{Event_Heal.gd => EventHeal.gd} | 4 ++-- Event/{Event_Mob.gd => EventMob.gd} | 4 ++-- Event/{Event_Random.gd => EventRandom.gd} | 4 ++-- Event/{Event_Shop.gd => EventShop.gd} | 4 ++-- Event/EventsClassification.gd | 17 ----------------- project.godot | 1 - 7 files changed, 10 insertions(+), 28 deletions(-) rename Event/{Event.gd => EventBase.gd} (65%) rename Event/{Event_Heal.gd => EventHeal.gd} (77%) rename Event/{Event_Mob.gd => EventMob.gd} (76%) rename Event/{Event_Random.gd => EventRandom.gd} (77%) rename Event/{Event_Shop.gd => EventShop.gd} (76%) delete mode 100644 Event/EventsClassification.gd diff --git a/Event/Event.gd b/Event/EventBase.gd similarity index 65% rename from Event/Event.gd rename to Event/EventBase.gd index 8dbfd331..0102d72d 100644 --- a/Event/Event.gd +++ b/Event/EventBase.gd @@ -1,7 +1,7 @@ extends Resource -class_name Event +class_name EventBase -#const EVENTS_CLASSIFICATION = [Event_Mob, Event_Random, Event_Shop, Event_Heal] +const EVENTS_CLASSIFICATION: Array[EventBase] = [EventMob.new(""), EventRandom.new(""), EventShop.new(""), EventHeal.new("")] var packedScene: String = "" diff --git a/Event/Event_Heal.gd b/Event/EventHeal.gd similarity index 77% rename from Event/Event_Heal.gd rename to Event/EventHeal.gd index 386f7015..91b8b1b3 100644 --- a/Event/Event_Heal.gd +++ b/Event/EventHeal.gd @@ -1,5 +1,5 @@ -extends Event -class_name Event_Heal +extends EventBase +class_name EventHeal # @Override func _init(scene: String) -> void: diff --git a/Event/Event_Mob.gd b/Event/EventMob.gd similarity index 76% rename from Event/Event_Mob.gd rename to Event/EventMob.gd index e26a61c2..5f79ea88 100644 --- a/Event/Event_Mob.gd +++ b/Event/EventMob.gd @@ -1,5 +1,5 @@ -extends Event -class_name Event_Mob +extends EventBase +class_name EventMob # @Override func _init(scene: String) -> void: diff --git a/Event/Event_Random.gd b/Event/EventRandom.gd similarity index 77% rename from Event/Event_Random.gd rename to Event/EventRandom.gd index 37f9ed25..1d3bf66f 100644 --- a/Event/Event_Random.gd +++ b/Event/EventRandom.gd @@ -1,5 +1,5 @@ -extends Event -class_name Event_Random +extends EventBase +class_name EventRandom # @Override func _init(scene: String) -> void: diff --git a/Event/Event_Shop.gd b/Event/EventShop.gd similarity index 76% rename from Event/Event_Shop.gd rename to Event/EventShop.gd index bdafa405..0456b4ed 100644 --- a/Event/Event_Shop.gd +++ b/Event/EventShop.gd @@ -1,5 +1,5 @@ -extends Event -class_name Event_Shop +extends EventBase +class_name EventShop # @Override func _init(scene: String) -> void: diff --git a/Event/EventsClassification.gd b/Event/EventsClassification.gd deleted file mode 100644 index e217cf83..00000000 --- a/Event/EventsClassification.gd +++ /dev/null @@ -1,17 +0,0 @@ -extends Node - -enum EventsClassification { EVENT_MOB, EVENT_RANDOM, EVENT_SHOP, EVENT_HEAL } - -# Test function for creating event, will remove later -func createEvent(index: int) -> Event: - var event = null - match index: - EventsClassification.EVENT_MOB: - event = Event_Mob.new("res://Event/EventTest.tscn") - EventsClassification.EVENT_RANDOM: - event = Event_Random.new("res://Event/EventTest.tscn") - EventsClassification.EVENT_SHOP: - event = Event_Shop.new("res://Event/EventTest.tscn") - EventsClassification.EVENT_HEAL: - event = Event_Heal.new("res://Event/EventTest.tscn") - return event diff --git a/project.godot b/project.godot index 476ad19b..f7782fc3 100644 --- a/project.godot +++ b/project.godot @@ -21,7 +21,6 @@ PlayerManager="*res://Managers/PlayerManager.gd" CardManager="*res://Managers/CardManager.gd" PhaseManager="*res://Managers/PhaseManager.gd" RandomGenerator="*res://Managers/RandomGenerator.gd" -EventsClassification="*res://Event/EventsClassification.gd" [display] From c4861d85248b78a2187a2a911966feee0d9ccd26 Mon Sep 17 00:00:00 2001 From: tynutsathitya Date: Tue, 19 Dec 2023 17:26:55 -0800 Subject: [PATCH 5/6] Issue-20: Update EventBase to have array of different types of events. Update init() as well. --- Event/EventBase.gd | 6 +++--- Event/EventHeal.gd | 4 ++-- Event/EventMob.gd | 4 ++-- Event/EventRandom.gd | 4 ++-- Event/EventShop.gd | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Event/EventBase.gd b/Event/EventBase.gd index 0102d72d..623fd4e2 100644 --- a/Event/EventBase.gd +++ b/Event/EventBase.gd @@ -1,13 +1,13 @@ extends Resource class_name EventBase -const EVENTS_CLASSIFICATION: Array[EventBase] = [EventMob.new(""), EventRandom.new(""), EventShop.new(""), EventHeal.new("")] +var EVENTS_CLASSIFICATION: Array[EventBase] = [EventMob.new(), EventRandom.new(), EventShop.new(), EventHeal.new()] var packedScene: String = "" # Initialize Event -func _init(scene: String) -> void: - packedScene = scene +func _init() -> void: + pass func _update_event() -> void: pass diff --git a/Event/EventHeal.gd b/Event/EventHeal.gd index 91b8b1b3..5c9c9d63 100644 --- a/Event/EventHeal.gd +++ b/Event/EventHeal.gd @@ -2,8 +2,8 @@ extends EventBase class_name EventHeal # @Override -func _init(scene: String) -> void: - super(scene) +func _init() -> void: + pass # @Override func _update_event() -> void: diff --git a/Event/EventMob.gd b/Event/EventMob.gd index 5f79ea88..22039df8 100644 --- a/Event/EventMob.gd +++ b/Event/EventMob.gd @@ -2,8 +2,8 @@ extends EventBase class_name EventMob # @Override -func _init(scene: String) -> void: - super(scene) +func _init() -> void: + pass # @Override func _update_event() -> void: diff --git a/Event/EventRandom.gd b/Event/EventRandom.gd index 1d3bf66f..9dc71de4 100644 --- a/Event/EventRandom.gd +++ b/Event/EventRandom.gd @@ -2,8 +2,8 @@ extends EventBase class_name EventRandom # @Override -func _init(scene: String) -> void: - super(scene) +func _init() -> void: + pass # @Override func _update_event() -> void: diff --git a/Event/EventShop.gd b/Event/EventShop.gd index 0456b4ed..c1bb4b57 100644 --- a/Event/EventShop.gd +++ b/Event/EventShop.gd @@ -2,8 +2,8 @@ extends EventBase class_name EventShop # @Override -func _init(scene: String) -> void: - super(scene) +func _init() -> void: + pass # @Override func _update_event() -> void: From d9270d31ce501899e1311acf32e14d48651cd4a9 Mon Sep 17 00:00:00 2001 From: tynutsathitya Date: Tue, 19 Dec 2023 17:51:30 -0800 Subject: [PATCH 6/6] Issue-20: Update EventBase Array holding all Events, Add Unit Test for EventBase --- Event/EventBase.gd | 2 +- Tests/test_eventbase.gd | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 Tests/test_eventbase.gd diff --git a/Event/EventBase.gd b/Event/EventBase.gd index 623fd4e2..47c59e8d 100644 --- a/Event/EventBase.gd +++ b/Event/EventBase.gd @@ -1,7 +1,7 @@ extends Resource class_name EventBase -var EVENTS_CLASSIFICATION: Array[EventBase] = [EventMob.new(), EventRandom.new(), EventShop.new(), EventHeal.new()] +var EVENTS_CLASSIFICATION: Array[Resource] = [EventMob, EventRandom, EventShop, EventHeal] var packedScene: String = "" diff --git a/Tests/test_eventbase.gd b/Tests/test_eventbase.gd new file mode 100644 index 00000000..e4c6ded5 --- /dev/null +++ b/Tests/test_eventbase.gd @@ -0,0 +1,21 @@ +extends GutTest +## Test for Event Base and Events + +var eventBase: EventBase = null + +func before_each(): + eventBase = EventBase.new() + +func test_event_base_array_all_types(): + var event0 = eventBase.EVENTS_CLASSIFICATION[0] + assert_eq(event0, EventMob) + + var event1 = eventBase.EVENTS_CLASSIFICATION[1] + assert_eq(event1, EventRandom) + + var event2 = eventBase.EVENTS_CLASSIFICATION[2] + assert_eq(event2, EventShop) + + var event3 = eventBase.EVENTS_CLASSIFICATION[3] + assert_eq(event3, EventHeal) +