Skip to content

Commit

Permalink
features/patch 2 (#2)
Browse files Browse the repository at this point in the history
* add interface for quest repo

* add quest repo signals

* Move away from brandonlamb dir
  • Loading branch information
brandonlamb authored Dec 11, 2017
1 parent d9d0b27 commit e90b512
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 45 deletions.
7 changes: 0 additions & 7 deletions addons/com.brandonlamb.quest/domain/quest_system.gd

This file was deleted.

26 changes: 0 additions & 26 deletions addons/com.brandonlamb.quest/memory/quest_repository.gd

This file was deleted.

File renamed without changes.
File renamed without changes.
42 changes: 42 additions & 0 deletions addons/godot-quest-system/domain/quest_repository.gd
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions addons/godot-quest-system/domain/quest_system.gd
Original file line number Diff line number Diff line change
@@ -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")
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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
return quests
72 changes: 72 additions & 0 deletions addons/godot-quest-system/memory/quest_repository.gd
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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():
Expand Down
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down
17 changes: 9 additions & 8 deletions example/main.gd
Original file line number Diff line number Diff line change
@@ -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())

0 comments on commit e90b512

Please sign in to comment.