Add boss, first version
This commit is contained in:
@@ -13,6 +13,7 @@ enum Status{
|
||||
@export var unlocks: Dictionary[int, Dictionary] = {}:
|
||||
set(value):
|
||||
unlocks = ensure_data_integrity(value)
|
||||
@export var boss_statuses: Array[int] = []
|
||||
@export var last_modified: String
|
||||
|
||||
|
||||
@@ -24,6 +25,7 @@ func _init() -> void:
|
||||
func init_unlocks() -> void:
|
||||
if not unlocks:
|
||||
unlocks = {} # Triggers ensure_data_integrity(), that will fill the default values
|
||||
_sanitize_boss_statuses()
|
||||
|
||||
# Verify the lessons
|
||||
var number_of_lessons: int = Database.get_lessons_count()
|
||||
@@ -45,6 +47,7 @@ func init_unlocks() -> void:
|
||||
if unlocks.has(1):
|
||||
if unlocks[1]["look_and_learn"] == Status.Locked:
|
||||
unlocks[1]["look_and_learn"] = Status.Unlocked
|
||||
_sanitize_boss_statuses()
|
||||
|
||||
|
||||
func ensure_data_integrity(data: Dictionary[int, Dictionary]) -> Dictionary:
|
||||
@@ -139,12 +142,69 @@ func ensure_data_integrity(data: Dictionary[int, Dictionary]) -> Dictionary:
|
||||
if not is_init:
|
||||
Log.warn("StudentProgression: Garden %d: lesson unlocked because previous garden is completed" % index)
|
||||
|
||||
_sanitize_boss_statuses()
|
||||
return result
|
||||
|
||||
|
||||
static func get_boss_gate_lessons() -> Array[int]:
|
||||
var gates: Array[int] = []
|
||||
var total_lessons: int = Database.get_lessons_count()
|
||||
if total_lessons <= 0:
|
||||
return gates
|
||||
var boundary_lessons: Array[int] = _get_garden_boundary_lessons(total_lessons)
|
||||
var last_boss_pseudowords: int = 0
|
||||
for lesson_number: int in range(1, total_lessons + 1):
|
||||
var total_pseudowords: int = Database.get_pseudowords_for_lesson(lesson_number).size()
|
||||
var new_pseudowords: int = total_pseudowords - last_boss_pseudowords
|
||||
if new_pseudowords >= 40 and boundary_lessons.has(lesson_number):
|
||||
gates.append(lesson_number)
|
||||
last_boss_pseudowords = total_pseudowords
|
||||
return gates
|
||||
|
||||
|
||||
static func _get_garden_boundary_lessons(total_lessons: int) -> Array[int]:
|
||||
var boundaries: Array[int] = []
|
||||
var layout: GardensLayout = Gardens.get_session_layout(total_lessons)
|
||||
var distribution: Array[int] = Gardens.get_lessons_distribution(total_lessons, layout.gardens)
|
||||
var lesson_index: int = 0
|
||||
for count: int in distribution:
|
||||
if count <= 0:
|
||||
continue
|
||||
lesson_index += count
|
||||
if lesson_index < total_lessons:
|
||||
boundaries.append(lesson_index)
|
||||
return boundaries
|
||||
|
||||
|
||||
func _sanitize_boss_statuses() -> void:
|
||||
if typeof(boss_statuses) != TYPE_ARRAY:
|
||||
boss_statuses = []
|
||||
var gate_lessons: Array[int] = get_boss_gate_lessons()
|
||||
var sanitized: Array[int] = []
|
||||
for gate_lesson: int in boss_statuses:
|
||||
if gate_lessons.has(gate_lesson):
|
||||
sanitized.append(gate_lesson)
|
||||
boss_statuses = sanitized
|
||||
|
||||
|
||||
func is_boss_completed(gate_lesson: int) -> bool:
|
||||
return boss_statuses.has(gate_lesson)
|
||||
|
||||
|
||||
func is_lesson_blocked_by_boss(lesson_number: int) -> bool:
|
||||
var gate_lessons: Array[int] = get_boss_gate_lessons()
|
||||
gate_lessons.sort()
|
||||
for gate: int in gate_lessons:
|
||||
if gate < lesson_number and not boss_statuses.has(gate):
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func get_max_unlocked_lesson_index() -> int:
|
||||
var max_unlocked_level: int = 1
|
||||
for index: int in range(unlocks.size()):
|
||||
if is_lesson_blocked_by_boss(index + 1):
|
||||
break
|
||||
if unlocks[index + 1]["look_and_learn"] >= Status.Unlocked:
|
||||
max_unlocked_level = index
|
||||
else:
|
||||
@@ -184,14 +244,26 @@ func game_completed(lesson_number: int, game_number: int) -> bool:
|
||||
for index: int in range(3):
|
||||
all_completed = all_completed and unlocks[lesson_number]["games"][index] == Status.Completed
|
||||
|
||||
if all_completed and unlocks.has(lesson_number + 1):
|
||||
unlocks[lesson_number + 1]["look_and_learn"] = Status.Unlocked
|
||||
if all_completed:
|
||||
if unlocks.has(lesson_number + 1):
|
||||
unlocks[lesson_number + 1]["look_and_learn"] = Status.Unlocked
|
||||
|
||||
last_modified = Time.get_datetime_string_from_system(true)
|
||||
progression_changed.emit()
|
||||
return true
|
||||
|
||||
|
||||
func boss_completed(lesson_number: int) -> bool:
|
||||
if not get_boss_gate_lessons().has(lesson_number):
|
||||
return false
|
||||
if boss_statuses.has(lesson_number):
|
||||
return false
|
||||
boss_statuses.append(lesson_number)
|
||||
last_modified = Time.get_datetime_string_from_system(true)
|
||||
progression_changed.emit()
|
||||
return true
|
||||
|
||||
|
||||
func add_level_time(lesson_number: int, game_number: int, time_spent: int) -> void:
|
||||
Log.trace("StudentProgression: Add time to level %d, minigame %d. Time added: %s" % [lesson_number, game_number, time_spent])
|
||||
if game_number > 2:
|
||||
|
||||
Reference in New Issue
Block a user