Files
seeding-planets/gui/game/tutorial/scripts/tutorial.gd

133 lines
3.6 KiB
GDScript

extends Control
class_name Tutorial
const STEP_SCENE = preload("res://gui/game/tutorial/step_gui/step_gui.tscn")
signal succeded
var indicators : Array[InGameIndicator]
@export var player : Player
@export var region : Region
@onready var steps : Array[Step] = [
Step.new(
"USE_YOUR_DETECTOR_TO_FIND_THE_BATTERY",
(func ():
return player.position.distance_to(Vector2.ZERO) < 600)
),
Step.new(
"DIG_A_TALION_VEIN_WITH_SHOVEL",
(func ():
for e in region.entity_container.get_children():
if e is ItemObject and e.item is Seed:
return true
return false)
),
Step.new(
"TAKE_A_SEED",
(func ():
return player.data.inventory.items.find_custom(
func(i:Item): return i is Seed
) != -1)
),
Step.new(
"PLANT_SEED_IN_FERTILE_ZONE",
(func ():
for e in region.entity_container.get_children():
if e is Plant:
return true
return false)
),
Step.new(
"RECHARGE_TO_PASS_DAYS",
(func ():
return region and region.data and region.data.charges != 10)
),
Step.new(
"GAIN_FIRST_PLANT_POINT",
(func ():
return region.data.get_score() != 0)
),
Step.new(
"DISCOVER_A_SEED_WITH_A_MUTATION",
(func ():
for e in region.entity_container.get_children():
if e is ItemObject and e.item is Seed and len(e.item.plant_mutations):
return true
return false)
),
Step.new(
"PLANT_A_SEED_WITH_A_MUTATION",
(func ():
for e in region.entity_container.get_children():
if e is Plant and len(e.data.mutations):
return true
return false)
),
Step.new(
"HARVEST_A_MATURE_PLANT_WITH_A_MUTATION",
(func ():
for e in region.entity_container.get_children():
if e is Plant and e.harvested and len(e.data.mutations):
return true
return false)
),
]
func _ready():
if region and region.data and "tutorial" in region.data.flags:
setup_gui()
show()
else:
hide()
func setup_gui():
for s in %Steps.get_children():
s.queue_free()
for s in steps:
var new_step = STEP_SCENE.instantiate() as TutorialStepGui
new_step.suceeded = false
new_step.text = s.get_text()
%Steps.add_child(new_step)
func _process(_d):
if region and region.data and "tutorial" in region.data.flags and not GameInfo.game_data.tutorial_done:
var success = true
for i in len(steps):
var step := steps[i]
var step_gui := %Steps.get_children()[i] as TutorialStepGui
step.update_succeeded()
step_gui.suceeded = step.succeeded
if not step.succeeded:
success = false
if success:
finish_tutorial()
func finish_tutorial():
GameInfo.game_data.tutorial_done = true
succeded.emit()
class Step:
var text : String : get = get_text
var is_step_over_callable : Callable
var succeeded = false
func _init(
_text : String = "",
_is_step_over_callable : Callable = (func():return false)
):
text = _text
is_step_over_callable = _is_step_over_callable
func get_text() -> String:
return text
func update_succeeded() -> bool:
if not succeeded:
succeeded = is_step_over_callable.call()
return succeeded