diff --git a/addons/com.brandonlamb.quest/domain/quest_system.gd b/addons/com.brandonlamb.quest/domain/quest_system.gd deleted file mode 100644 index b1a31ca..0000000 --- a/addons/com.brandonlamb.quest/domain/quest_system.gd +++ /dev/null @@ -1,7 +0,0 @@ -extends Reference - -const Goal = preload("res://addons/com.brandonlamb.quest/domain/goal.gd") -const Quest = preload("res://addons/com.brandonlamb.quest/domain/quest.gd") -const Requirement = preload("res://addons/com.brandonlamb.quest/domain/requirement.gd") -const RequirementProcessor = preload("res://addons/com.brandonlamb.quest/domain/requirement_processor.gd") -const Reward = preload("res://addons/com.brandonlamb.quest/domain/reward.gd") diff --git a/addons/com.brandonlamb.quest/memory/quest_repository.gd b/addons/com.brandonlamb.quest/memory/quest_repository.gd deleted file mode 100644 index 3030c37..0000000 --- a/addons/com.brandonlamb.quest/memory/quest_repository.gd +++ /dev/null @@ -1,26 +0,0 @@ -extends Reference - -const Quest = preload("res://addons/com.brandonlamb.quest/domain/quest.gd") - -const _quests = [] -const _questsMap = {} - -func _init(quests): - if typeof(quests) == TYPE_ARRAY: - _load_from_array(quests) - -func _load_from_array(quests): - for i in quests: - _quests.append(i) - _questsMap[i.id] = i - -func find_by_id(id): - if _questsMap.has(id): - return _questsMap[id] - return Quest.new() - -func find_all(): - return _quests - -func save(quest): - pass diff --git a/addons/com.brandonlamb.quest/domain/goal.gd b/addons/godot-quest-system/domain/goal.gd similarity index 100% rename from addons/com.brandonlamb.quest/domain/goal.gd rename to addons/godot-quest-system/domain/goal.gd diff --git a/addons/com.brandonlamb.quest/domain/quest.gd b/addons/godot-quest-system/domain/quest.gd similarity index 100% rename from addons/com.brandonlamb.quest/domain/quest.gd rename to addons/godot-quest-system/domain/quest.gd diff --git a/addons/godot-quest-system/domain/quest_repository.gd b/addons/godot-quest-system/domain/quest_repository.gd new file mode 100644 index 0000000..5769b65 --- /dev/null +++ b/addons/godot-quest-system/domain/quest_repository.gd @@ -0,0 +1,42 @@ +extends Reference + +signal quest_created(quest) +signal quest_deleted(quest) +signal quest_saved(quest) +signal quests_cleared() + +""" +Find quest by ID +@param int id +@return Quest +""" +func find_by_id(id): pass + +""" +Find all quests +@return Quest[] +""" +func find_all(): pass + +""" +Clear all quests +""" +func clear(): pass + +""" +Save quest +@param Quest quest +""" +func save(quest): pass + +""" +Delete quest +@param Quest quest +""" +func delete(quest): pass + +""" +Delete quest by ID +@param int id +""" +func delete_by_id(id): pass diff --git a/addons/godot-quest-system/domain/quest_system.gd b/addons/godot-quest-system/domain/quest_system.gd new file mode 100644 index 0000000..fef3db8 --- /dev/null +++ b/addons/godot-quest-system/domain/quest_system.gd @@ -0,0 +1,7 @@ +extends Reference + +const Goal = preload("res://addons/godot-quest-system/domain/goal.gd") +const Quest = preload("res://addons/godot-quest-system/domain/quest.gd") +const Requirement = preload("res://addons/godot-quest-system/domain/requirement.gd") +const RequirementProcessor = preload("res://addons/godot-quest-system/domain/requirement_processor.gd") +const Reward = preload("res://addons/godot-quest-system/domain/reward.gd") diff --git a/addons/com.brandonlamb.quest/domain/requirement.gd b/addons/godot-quest-system/domain/requirement.gd similarity index 100% rename from addons/com.brandonlamb.quest/domain/requirement.gd rename to addons/godot-quest-system/domain/requirement.gd diff --git a/addons/com.brandonlamb.quest/domain/requirement_processor.gd b/addons/godot-quest-system/domain/requirement_processor.gd similarity index 100% rename from addons/com.brandonlamb.quest/domain/requirement_processor.gd rename to addons/godot-quest-system/domain/requirement_processor.gd diff --git a/addons/com.brandonlamb.quest/domain/reward.gd b/addons/godot-quest-system/domain/reward.gd similarity index 100% rename from addons/com.brandonlamb.quest/domain/reward.gd rename to addons/godot-quest-system/domain/reward.gd diff --git a/addons/com.brandonlamb.quest/memory/quest_factory.gd b/addons/godot-quest-system/memory/quest_factory.gd similarity index 87% rename from addons/com.brandonlamb.quest/memory/quest_factory.gd rename to addons/godot-quest-system/memory/quest_factory.gd index f3f807d..2bc4aa9 100644 --- a/addons/com.brandonlamb.quest/memory/quest_factory.gd +++ b/addons/godot-quest-system/memory/quest_factory.gd @@ -1,6 +1,6 @@ extends Reference -const Quest = preload("res://addons/com.brandonlamb.quest/domain/quest.gd") +const Quest = preload("res://addons/godot-quest-system/domain/quest.gd") const QuestStatus = Quest.Status static func create_from_array(quests): @@ -24,4 +24,4 @@ static func create_from_static(): for q in data: quests.append(Quest.new(q[0], q[1], q[2])) - return quests \ No newline at end of file + return quests diff --git a/addons/godot-quest-system/memory/quest_repository.gd b/addons/godot-quest-system/memory/quest_repository.gd new file mode 100644 index 0000000..2d6513d --- /dev/null +++ b/addons/godot-quest-system/memory/quest_repository.gd @@ -0,0 +1,72 @@ +extends "res://addons/godot-quest-system/domain/quest_repository.gd" + +const Quest = preload("res://addons/godot-quest-system/domain/quest.gd") + +const _quests = [] +const _questsMap = {} + +""" +Constructor - accepts an array of quests to initialize the repository with +@param Quest[] quests +""" +func _init(quests): + if typeof(quests) == TYPE_ARRAY: + _load_from_array(quests) + +""" +Load quests from array of quests +@param Quest[] quests +""" +func _load_from_array(quests): + for i in quests: + _quests.append(i) + _questsMap[i.id] = i + +""" +@override +""" +func find_by_id(id): + if _questsMap.has(id): + return _questsMap[id] + return Quest.new() + +""" +@override +""" +func find_all(): + return _quests + +""" +@override +""" +func clear(): + _quests = [] + _questsMap = {} + +""" +@override +""" +func save(quest): + pass + +""" +@override +""" +func delete(quest): + for i in range(0, _quests.size()): + if _quests[i].id == quest.id: + _quests.remove(i) + + if _questsMap.has(quest.id): + _questsMap.erase(quest.id) + +""" +@override +""" +func delete_by_id(id): + for i in range(0, _quests.size()): + if _quests[i].id == id: + _quests.remove(i) + + if _questsMap.has(id): + _questsMap.erase(id) diff --git a/addons/com.brandonlamb.quest/sqlite/sqlite.gdns b/addons/godot-quest-system/sqlite/sqlite.gdns similarity index 100% rename from addons/com.brandonlamb.quest/sqlite/sqlite.gdns rename to addons/godot-quest-system/sqlite/sqlite.gdns diff --git a/addons/com.brandonlamb.quest/sqlite/test.gd b/addons/godot-quest-system/sqlite/test.gd similarity index 94% rename from addons/com.brandonlamb.quest/sqlite/test.gd rename to addons/godot-quest-system/sqlite/test.gd index 07dbb2d..eccae96 100644 --- a/addons/com.brandonlamb.quest/sqlite/test.gd +++ b/addons/godot-quest-system/sqlite/test.gd @@ -1,6 +1,6 @@ extends Node -var SQLite = preload("res://addons/com.brandonlamb.quest/sqlite/sqlite.gdns") +var SQLite = preload("res://addons/godot-quest-system/sqlite/sqlite.gdns") var db = SQLite.new() func _ready(): diff --git a/addons/com.brandonlamb.quest/sqlite/test.tscn b/addons/godot-quest-system/sqlite/test.tscn similarity index 94% rename from addons/com.brandonlamb.quest/sqlite/test.tscn rename to addons/godot-quest-system/sqlite/test.tscn index 3df53b7..99db409 100644 --- a/addons/com.brandonlamb.quest/sqlite/test.tscn +++ b/addons/godot-quest-system/sqlite/test.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=2 format=2] -[ext_resource path="res://addons/com.brandonlamb.quest/sqlite/test.gd" type="Script" id=1] +[ext_resource path="res://addons/godot-quest-system/sqlite/test.gd" type="Script" id=1] [node name="test" type="Control"] diff --git a/example/main.gd b/example/main.gd index 363a2b1..1287079 100644 --- a/example/main.gd +++ b/example/main.gd @@ -1,25 +1,26 @@ extends Node2D const Quest = preload("res://addons/com.brandonlamb.quest/domain/quest.gd") -const QuestStatus = Quest.Status const QuestRepo = preload("res://addons/com.brandonlamb.quest/memory/quest_repository.gd") const QuestFactory = preload("res://addons/com.brandonlamb.quest/memory/quest_factory.gd") func _ready(): var questRepo = QuestRepo.new(QuestFactory.create_from_static()) + var quests = questRepo.find_all() - for i in questRepo.find_all(): + for i in quests: i.connect("started", self, "_on_quest_started") i.start() - _debug_quest(i) var quest = questRepo.find_by_id(1) - quest.status = QuestStatus.FINISHED - _debug_quest(quest) + quest.status = "finished" + print(quest.to_string()) print("quest.to_string()=", quest.to_string()) + quests[2].status = "started" + + for i in quests: + print(i.to_string()) + func _on_quest_started(e): print("_on_quest_started: ", e.name) - -func _debug_quest(q): - print(q.to_string())