Skip to content

Commit

Permalink
Issue 20: Events Structure (#29)
Browse files Browse the repository at this point in the history
* Create Event Parent and Event Child Classes

* Issue 20: Update Event Children with scene string instantiation, Create Events Classification script to hold enums for different events and added it to AutoLoader

* Issue 20: Add comment for test function

* Issue-20: Rename Event classes, remove EventsClassification enum

* Issue-20: Update EventBase to have array of different types of events. Update init() as well.

* Issue-20: Update EventBase Array holding all Events, Add Unit Test for EventBase
  • Loading branch information
Tysterman74 authored Dec 22, 2023
1 parent dfe1838 commit c384093
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Event/EventBase.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
extends Resource
class_name EventBase

var EVENTS_CLASSIFICATION: Array[Resource] = [EventMob, EventRandom, EventShop, EventHeal]

var packedScene: String = ""

# Initialize Event
func _init() -> void:
pass

func _update_event() -> void:
pass

func _load_scene() -> Node:
var loadScene: PackedScene = load(packedScene)
return loadScene.instantiate()

10 changes: 10 additions & 0 deletions Event/EventHeal.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extends EventBase
class_name EventHeal

# @Override
func _init() -> void:
pass

# @Override
func _update_event() -> void:
print("Updating Heal Event")
10 changes: 10 additions & 0 deletions Event/EventMob.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extends EventBase
class_name EventMob

# @Override
func _init() -> void:
pass

# @Override
func _update_event() -> void:
print("Update Mob")
10 changes: 10 additions & 0 deletions Event/EventRandom.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extends EventBase
class_name EventRandom

# @Override
func _init() -> void:
pass

# @Override
func _update_event() -> void:
print("Updating Random Event")
10 changes: 10 additions & 0 deletions Event/EventShop.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extends EventBase
class_name EventShop

# @Override
func _init() -> void:
pass

# @Override
func _update_event() -> void:
print("Updating shop")
21 changes: 21 additions & 0 deletions Tests/test_eventbase.gd
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit c384093

Please sign in to comment.