* Changement de l'UI, ajouts de l'inspecteur par carte et changement de police * Ajout d'un semblant d'exploration * Ajout de la sauvegarde des entités * Restructuration mineure de l'arborescence * Fix divers et réécriture des textes
185 lines
5.6 KiB
GDScript
185 lines
5.6 KiB
GDScript
extends Control
|
|
class_name Tutorial
|
|
|
|
const INDICATOR_SCENE = preload("res://gui/game/tutorial/in_game_indicator/in_game_indicator.tscn")
|
|
|
|
var indicators : Array[InGameIndicator]
|
|
@export var player : Player
|
|
@export var planet : Planet
|
|
|
|
@onready var steps : Array[Step] = [
|
|
TakeShovelStep.new(),
|
|
DigLootStep.new(),
|
|
TakeSeedStep.new(),
|
|
PlantSeedStep.new(),
|
|
RechargeStep.new(),
|
|
WaitMaturePlant.new(),
|
|
HarvestMaturePlant.new(),
|
|
]
|
|
var actual_step : Step = null : set = pass_to_step
|
|
|
|
func _process(_d):
|
|
if not GameInfo.game_data.tutorial_done:
|
|
if not actual_step and planet.data.tutorial_step < len(steps):
|
|
destroy_indicators()
|
|
pass_to_step(steps[planet.data.tutorial_step])
|
|
|
|
if player and actual_step and actual_step.is_step_over(player, planet):
|
|
destroy_indicators()
|
|
planet.data.tutorial_step += 1
|
|
if planet.data.tutorial_step < len(steps):
|
|
pass_to_step(steps[planet.data.tutorial_step])
|
|
else :
|
|
GameInfo.game_data.tutorial_done = true
|
|
|
|
func destroy_indicators():
|
|
for i in indicators:
|
|
i.queue_free()
|
|
indicators = []
|
|
|
|
func pass_to_step(new_step : Step):
|
|
actual_step = new_step
|
|
indicators = new_step.generate_indicators(player, planet)
|
|
for i in indicators:
|
|
add_child(i)
|
|
|
|
class Step:
|
|
func generate_indicator(text : String) -> InGameIndicator:
|
|
var new_indicator : InGameIndicator = INDICATOR_SCENE.instantiate()
|
|
new_indicator.setup(
|
|
text
|
|
)
|
|
return new_indicator
|
|
|
|
func generate_indicators(_player : Player, _planet : Planet) -> Array[InGameIndicator]:
|
|
return []
|
|
|
|
func is_step_over(_p : Player, _planet : Planet) -> bool:
|
|
return true
|
|
|
|
class TakeShovelStep extends Step:
|
|
func generate_indicators(_p: Player, planet : Planet) -> Array[InGameIndicator]:
|
|
for entity in planet.entity_container.get_children():
|
|
if entity is ItemObject and entity.item is Shovel:
|
|
var indicator = generate_indicator("Take the Shovel")
|
|
indicator.follow_entity(entity)
|
|
return [
|
|
indicator
|
|
]
|
|
printerr("No Shovel found...")
|
|
return []
|
|
|
|
func is_step_over(p : Player, _planet : Planet) -> bool:
|
|
for item in p.data.inventory.items:
|
|
if item is Shovel:
|
|
return true
|
|
return false
|
|
|
|
class DigLootStep extends Step:
|
|
func generate_indicators(p: Player, planet : Planet) -> Array[InGameIndicator]:
|
|
var closest_loot : UndergroundLoot
|
|
var closest_distance = 10000000
|
|
|
|
for entity in planet.entity_container.get_children():
|
|
if entity is UndergroundLoot:
|
|
var distance = entity.global_position.distance_to(p.global_position)
|
|
if distance < closest_distance:
|
|
closest_distance = distance
|
|
closest_loot = entity
|
|
|
|
if closest_loot:
|
|
var indicator = generate_indicator("Dig Underground Loot")
|
|
indicator.follow_entity(closest_loot)
|
|
return [indicator]
|
|
return []
|
|
|
|
func is_step_over(_p : Player, planet : Planet) -> bool:
|
|
for entity in planet.entity_container.get_children():
|
|
if entity is ItemObject and entity.item is Seed:
|
|
return true
|
|
return false
|
|
|
|
class TakeSeedStep extends Step:
|
|
func generate_indicators(_p: Player, planet : Planet) -> Array[InGameIndicator]:
|
|
var indicators : Array[InGameIndicator] = []
|
|
for entity in planet.entity_container.get_children():
|
|
if entity is ItemObject and entity.item is Seed:
|
|
var indicator = generate_indicator("Take a seed")
|
|
indicator.follow_entity(entity)
|
|
indicators.append(
|
|
indicator
|
|
)
|
|
return indicators
|
|
|
|
func is_step_over(p : Player, _planet : Planet) -> bool:
|
|
for item in p.data.inventory.items:
|
|
if item is Seed:
|
|
return true
|
|
return false
|
|
|
|
class PlantSeedStep extends Step:
|
|
func generate_indicators(_p: Player, planet : Planet) -> Array[InGameIndicator]:
|
|
var indicator = generate_indicator("Plant the seed in decontamined zone")
|
|
indicator.follow_game_position(Vector2(0,0) + planet.entity_container.global_position)
|
|
return [indicator]
|
|
|
|
func is_step_over(_p : Player, planet : Planet) -> bool:
|
|
for entity in planet.entity_container.get_children():
|
|
if entity is Plant:
|
|
return true
|
|
return false
|
|
|
|
class RechargeStep extends Step:
|
|
func generate_indicators(_p: Player, planet : Planet) -> Array[InGameIndicator]:
|
|
for entity in planet.entity_container.get_children():
|
|
var indicator = generate_indicator("Recharge to pass days")
|
|
indicator.follow_entity(entity)
|
|
if entity is TruckRecharge:
|
|
return [
|
|
indicator
|
|
]
|
|
printerr("No Recharge Station found...")
|
|
return []
|
|
|
|
func is_step_over(_p : Player, planet : Planet) -> bool:
|
|
if planet == null :
|
|
return false
|
|
return planet.data.day > 1
|
|
|
|
class WaitMaturePlant extends Step:
|
|
func generate_indicators(_p: Player, _planet : Planet) -> Array[InGameIndicator]:
|
|
return []
|
|
|
|
func is_step_over(_p : Player, planet : Planet) -> bool:
|
|
if planet == null :
|
|
return false
|
|
for entity in planet.entity_container.get_children():
|
|
if entity is Plant and entity.state == Plant.State.MATURE:
|
|
return true
|
|
return false
|
|
|
|
class HarvestMaturePlant extends Step:
|
|
|
|
var mature_plant_number : int = 0
|
|
|
|
func generate_indicators(_p: Player, planet : Planet) -> Array[InGameIndicator]:
|
|
var indicators : Array[InGameIndicator] = []
|
|
for entity in planet.entity_container.get_children():
|
|
if entity is Plant and entity.state == Plant.State.MATURE:
|
|
var indicator = generate_indicator("Harvest mature plants with shovel")
|
|
indicator.follow_entity(entity)
|
|
indicators.append(
|
|
indicator
|
|
)
|
|
mature_plant_number += 1
|
|
return indicators
|
|
|
|
func is_step_over(_p : Player, planet : Planet) -> bool:
|
|
if planet == null :
|
|
return false
|
|
var actual_mature_plant_number = 0
|
|
for entity in planet.entity_container.get_children():
|
|
if entity is Plant and entity.state == Plant.State.MATURE:
|
|
actual_mature_plant_number += 1
|
|
return mature_plant_number != actual_mature_plant_number
|