Skip to content

Commit d9d0b27

Browse files
authored
Features/patch 3 (#1)
* initial files * add sqlite files * apply ddd * add some QoL * add to_string() methods
1 parent 58a3c3a commit d9d0b27

21 files changed

+695
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
.#*
3+
*~
Binary file not shown.
Binary file not shown.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
extends Reference
2+
3+
var type = Type.UNKNOWN setget set_type
4+
var goal_int
5+
var goal_float
6+
var goal_vector
7+
8+
func _init(
9+
type = Type.UNKNOWN,
10+
goal_int = 0,
11+
goal_float = 0.0,
12+
goal_vector = null
13+
):
14+
set_type(type)
15+
self.goal_int = goal_int
16+
self.goal_float = goal_float
17+
self.goal_vector = goal_vector
18+
19+
func _get_type():
20+
if type == Type.UNKNOWN:
21+
return "unknown"
22+
elif type == Type.ITEMS_HELD:
23+
return "items_held"
24+
elif type == Type.GOLD:
25+
return "gold"
26+
elif type == Type.ENEMIES_KILLED:
27+
return "enemies_killed"
28+
elif type == Type.DESTINATION_REACHED:
29+
return "destination_reached"
30+
elif type == Type.TRIGGER_ENABLED:
31+
return "trigger_enabled"
32+
33+
func to_string():
34+
return str(
35+
"type=", _get_type(),
36+
", goal_int=", goal_int,
37+
", goal_float=", goal_float,
38+
", goal_vector=", goal_vector
39+
)
40+
41+
func set_type(value):
42+
# Support passing a Type enum
43+
if typeof(value) != TYPE_STRING:
44+
type = value
45+
return
46+
47+
# Support passing a string, parse into a Type enum
48+
if typeof(value) == TYPE_STRING:
49+
value = value.to_lower()
50+
51+
if value.match("unknown"):
52+
type = Type.UNKNOWN
53+
elif value.match("items_held"):
54+
type = Type.ITEMS_HELD
55+
elif value.match("gold"):
56+
type = Type.GOLD
57+
elif value.match("enemies_killed"):
58+
type = Type.ENEMIES_KILLED
59+
elif value.match("destination_reached"):
60+
type = Type.DESTINATION_REACHED
61+
elif value.match("trigger_enabled"):
62+
type = Type.TRIGGER_ENABLED
63+
else:
64+
print("Invalid goal type: ", value)
65+
66+
enum Type {
67+
UNKNOWN
68+
ITEMS_HELD
69+
GOLD
70+
ENEMIES_KILLED
71+
DESTINATION_REACHED
72+
TRIGGER_ENABLED
73+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
extends Reference
2+
3+
var id
4+
var name
5+
var description
6+
var status = Status.UNKNOWN setget set_status
7+
var rewards
8+
var requirements
9+
var goals
10+
11+
signal started(event_target)
12+
signal progressed(event_target)
13+
signal goals_completed(event_target)
14+
signal finished(event_target)
15+
16+
func _init(
17+
id = 0, name = "Default name",
18+
description = "Default description",
19+
status = Status.UNKNOWN,
20+
rewards = [],
21+
requirements = [],
22+
goals = []
23+
):
24+
self.id = id
25+
self.name = name
26+
self.description = description
27+
set_status(status)
28+
self.rewards = rewards
29+
self.requirements = requirements
30+
self.goals = goals
31+
32+
func _get_status():
33+
if status == Status.UNKNOWN:
34+
return "unknown"
35+
elif status == Status.STARTED:
36+
return "started"
37+
elif status == Status.FAILED:
38+
return "failed"
39+
elif status == Status.FINISHED:
40+
return "finished"
41+
42+
func to_string():
43+
return str(
44+
"id=", id,
45+
", name=", name,
46+
", description=", description,
47+
", status=", _get_status()
48+
)
49+
50+
func start():
51+
emit_signal("on_started", self)
52+
53+
func set_status(value):
54+
# Support passing a Status enum
55+
if typeof(value) != TYPE_STRING:
56+
status = value
57+
return
58+
59+
# Support passing a string, parse into a Status enum
60+
if typeof(value) == TYPE_STRING:
61+
value = value.to_lower()
62+
63+
if value.match("unknown"):
64+
status = Status.UNKNOWN
65+
elif value.match("started"):
66+
status = Status.STARTED
67+
elif value.match("finished"):
68+
status = Status.FINISHED
69+
elif value.match("failed"):
70+
status = Status.FAILED
71+
else:
72+
print("Invalid quest status: ", value)
73+
74+
enum Status {
75+
UNKNOWN
76+
STARTED
77+
FINISHED
78+
FAILED
79+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extends Reference
2+
3+
const Goal = preload("res://addons/com.brandonlamb.quest/domain/goal.gd")
4+
const Quest = preload("res://addons/com.brandonlamb.quest/domain/quest.gd")
5+
const Requirement = preload("res://addons/com.brandonlamb.quest/domain/requirement.gd")
6+
const RequirementProcessor = preload("res://addons/com.brandonlamb.quest/domain/requirement_processor.gd")
7+
const Reward = preload("res://addons/com.brandonlamb.quest/domain/reward.gd")
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
extends Reference
2+
3+
"""
4+
Requirement
5+
"""
6+
var type = Type.UNKNOWN setget set_type
7+
var required_number
8+
var required_string
9+
10+
func _init(type = Type.UNKNOWN, required_number = 0, required_string = ""):
11+
set_type(type)
12+
self.required_number = required_number
13+
self.required_string = required_string
14+
15+
func _get_type():
16+
if type == Type.UNKNOWN:
17+
return "unknown"
18+
elif type == Type.LEVEL:
19+
return "level"
20+
elif type == Type.CLASS:
21+
return "class"
22+
elif type == Type.RACE:
23+
return "race"
24+
elif type == Type.FACTION_SCORE:
25+
return "faction_score"
26+
elif type == Type.TRIGGER_ACTIVE:
27+
return "trigger_active"
28+
elif type == Type.TRIGGER_DEACTIVE:
29+
return "trigger_deactive"
30+
elif type == Type.ITEM_HELD:
31+
return "item_held"
32+
33+
func to_string():
34+
return str(
35+
"type=", _get_type(),
36+
", required_number=", required_number,
37+
", required_string=", required_string
38+
)
39+
40+
func set_type(value):
41+
# Support passing a Type enum
42+
if typeof(value) != TYPE_STRING:
43+
type = value
44+
return
45+
46+
# Support passing a string, parse into a Type enum
47+
if typeof(value) == TYPE_STRING:
48+
value = value.to_lower()
49+
50+
if value.match("unknown"):
51+
type = Type.UNKNOWN
52+
elif value.match("level"):
53+
type = Type.LEVEL
54+
elif value.match("class"):
55+
type = Type.CLASS
56+
elif value.match("race"):
57+
type = Type.RACE
58+
elif value.match("faction_score"):
59+
type = Type.FACTION_SCORE
60+
elif value.match("trigger_active"):
61+
type = Type.TRIGGER_ACTIVE
62+
elif value.match("trigger_deactive"):
63+
type = Type.TRIGGER_DEACTIVE
64+
elif value.match("item_held"):
65+
type = Type.ITEM_HELD
66+
else:
67+
print("Invalid goal type: ", value)
68+
69+
enum Type {
70+
UNKNOWN
71+
LEVEL
72+
CLASS
73+
RACE
74+
FACTION_SCORE
75+
TRIGGER_ACTIVE
76+
TRIGGER_DEACTIVE
77+
ITEM_HELD
78+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extends Reference
2+
3+
var character_repo
4+
var trigger_repo
5+
var faction_repo
6+
7+
func requirements_are_met(quest):
8+
for r in quest.requirements:
9+
if !r.is_met():
10+
return false
11+
return true
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
extends Reference
2+
3+
var type = Type.UNKNOWN setget set_type
4+
var reward_float
5+
var reward_int
6+
7+
func _init(type = Type.UNKNOWN, reward_float = 0.0, reward_int = 0):
8+
set_type(type)
9+
self.reward_float = reward_float
10+
self.reward_int = reward_int
11+
12+
func _get_type():
13+
if type == Type.UNKNOWN:
14+
return "unknown"
15+
elif type == Type.EXPERIENCE:
16+
return "experience"
17+
elif type == Type.ITEM:
18+
return "item"
19+
elif type == Type.TRIGGER_ACTIVE:
20+
return "trigger_active"
21+
elif type == Type.TRIGGER_DEACTIVE:
22+
return "trigger_deactive"
23+
elif type == Type.FACTION_SCORE:
24+
return "faction_score"
25+
elif type == Type.GOLD:
26+
return "gold"
27+
28+
func to_string():
29+
return str(
30+
"type=", _get_type(),
31+
", reward_float=", reward_float,
32+
", reward_int=", reward_int
33+
)
34+
35+
func set_type(value):
36+
# Support passing a Type enum
37+
if typeof(value) != TYPE_STRING:
38+
type = value
39+
return
40+
41+
# Support passing a string, parse into a Type enum
42+
if typeof(value) == TYPE_STRING:
43+
value = value.to_lower()
44+
45+
if value.match("unknown"):
46+
type = Type.UNKNOWN
47+
elif value.match("experience"):
48+
type = Type.EXPERIENCE
49+
elif value.match("item"):
50+
type = Type.ITEM
51+
elif value.match("trigger_active"):
52+
type = Type.TRIGGER_ACTIVE
53+
elif value.match("trigger_deactive"):
54+
type = Type.TRIGGER_DEACTIVE
55+
elif value.match("faction_score"):
56+
type = Type.FACTION_SCORE
57+
elif value.match("gold"):
58+
type = Type.GOLD
59+
else:
60+
print("Invalid goal type: ", value)
61+
62+
enum Type {
63+
UNKNOWN
64+
EXPERIENCE
65+
ITEM
66+
TRIGGER_ACTIVATED
67+
TRIGGER_DEACTIVATED
68+
FACTION_SCORE
69+
GOLD
70+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
extends Reference
2+
3+
const Quest = preload("res://addons/com.brandonlamb.quest/domain/quest.gd")
4+
const QuestStatus = Quest.Status
5+
6+
static func create_from_array(quests):
7+
# Take in array of data and convert into array of Quest
8+
pass
9+
10+
static func create_from_file(file):
11+
# Read file and parse as json, convert into array of Quest
12+
pass
13+
14+
static func create_from_static():
15+
var data = [
16+
[1, "Quest 1", "Description for quest 1", QuestStatus.STARTED],
17+
[2, "Quest 2", "Description for quest 2", QuestStatus.STARTED],
18+
[3, "Quest 3", "Description for quest 3", QuestStatus.STARTED],
19+
[4, "Quest 4", "Description for quest 4", QuestStatus.STARTED]
20+
]
21+
22+
var quests = []
23+
24+
for q in data:
25+
quests.append(Quest.new(q[0], q[1], q[2]))
26+
27+
return quests
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
extends Reference
2+
3+
const Quest = preload("res://addons/com.brandonlamb.quest/domain/quest.gd")
4+
5+
const _quests = []
6+
const _questsMap = {}
7+
8+
func _init(quests):
9+
if typeof(quests) == TYPE_ARRAY:
10+
_load_from_array(quests)
11+
12+
func _load_from_array(quests):
13+
for i in quests:
14+
_quests.append(i)
15+
_questsMap[i.id] = i
16+
17+
func find_by_id(id):
18+
if _questsMap.has(id):
19+
return _questsMap[id]
20+
return Quest.new()
21+
22+
func find_all():
23+
return _quests
24+
25+
func save(quest):
26+
pass

0 commit comments

Comments
 (0)