ajout des graines procédurales et des cinamatiques
This commit is contained in:
@@ -1,189 +1,105 @@
|
||||
extends Control
|
||||
class_name Tutorial
|
||||
|
||||
const INDICATOR_SCENE = preload("res://gui/game/tutorial/in_game_indicator/in_game_indicator.tscn")
|
||||
const STEP_SCENE = preload("res://gui/game/tutorial/step_gui/step_gui.tscn")
|
||||
|
||||
|
||||
var indicators : Array[InGameIndicator]
|
||||
@export var player : Player
|
||||
@export var region : Region
|
||||
|
||||
@onready var steps : Array[Step] = [
|
||||
DigSeedStep.new(),
|
||||
TakeSeedStep.new(),
|
||||
PlantSeedStep.new(),
|
||||
RechargeStep.new(),
|
||||
# WaitMaturePlant.new(),
|
||||
# HarvestMaturePlant.new(),
|
||||
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(
|
||||
"HARVEST_MATURE_PLANTS_WITH_SHOVEL",
|
||||
(func ():
|
||||
for e in region.entity_container.get_children():
|
||||
if e is Plant and e.harvested:
|
||||
return true
|
||||
return false)
|
||||
)
|
||||
]
|
||||
var actual_step : Step = null : set = pass_to_step
|
||||
|
||||
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.data.tutorial:
|
||||
if not actual_step and region.data.tutorial_step < len(steps):
|
||||
destroy_indicators()
|
||||
pass_to_step(steps[region.data.tutorial_step])
|
||||
|
||||
if player and actual_step and actual_step.is_step_over(player, region):
|
||||
destroy_indicators()
|
||||
region.data.tutorial_step += 1
|
||||
if region.data.tutorial_step < len(steps):
|
||||
pass_to_step(steps[region.data.tutorial_step])
|
||||
else:
|
||||
destroy_indicators()
|
||||
|
||||
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, region)
|
||||
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, _region : Region) -> Array[InGameIndicator]:
|
||||
return []
|
||||
|
||||
func is_step_over(_p : Player, _region : Region) -> bool:
|
||||
return true
|
||||
|
||||
class TakeShovelStep extends Step:
|
||||
func generate_indicators(_p: Player, region : Region) -> Array[InGameIndicator]:
|
||||
for entity in region.entity_container.get_children():
|
||||
if entity is ItemObject and entity.item is Shovel:
|
||||
var indicator = generate_indicator(tr("TAKE_THE_SHOVEL"))
|
||||
indicator.follow_entity(entity)
|
||||
return [
|
||||
indicator
|
||||
]
|
||||
printerr("No Shovel found...")
|
||||
return []
|
||||
|
||||
func is_step_over(p : Player, _region : Region) -> bool:
|
||||
for item in p.data.inventory.items:
|
||||
if item is Shovel:
|
||||
return true
|
||||
return false
|
||||
|
||||
class DigSeedStep extends Step:
|
||||
func generate_indicators(p: Player, region : Region) -> Array[InGameIndicator]:
|
||||
var closest_seed = null
|
||||
var limit_distance = 1000
|
||||
|
||||
var actual_distance = 100
|
||||
var player_tile = Math.get_tile_from_pos(p.global_position)
|
||||
|
||||
while closest_seed == null and actual_distance < limit_distance:
|
||||
for x in range(actual_distance):
|
||||
for y in range(actual_distance):
|
||||
var coord = Vector2i(x,y) - Vector2i.ONE * floori(actual_distance/2.) + player_tile
|
||||
if region.rock_layer.get_tile_type(coord) == RockLayer.TileType.CRISTAL:
|
||||
if closest_seed == null or player_tile.distance_to(coord) < player_tile.distance_to(closest_seed):
|
||||
closest_seed = coord
|
||||
if region and region.data and "tutorial" in region.data.flags:
|
||||
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
|
||||
|
||||
actual_distance += 100
|
||||
|
||||
if closest_seed:
|
||||
var indicator = generate_indicator(tr("DIG_UNDERGROUND_LOOT"))
|
||||
indicator.follow_game_position(closest_seed * Region.TILE_SIZE + Vector2i.ONE * floori(Region.TILE_SIZE/2.))
|
||||
return [indicator]
|
||||
return []
|
||||
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 is_step_over(_p : Player, region : Region) -> bool:
|
||||
for entity in region.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, region : Region) -> Array[InGameIndicator]:
|
||||
var indicators : Array[InGameIndicator] = []
|
||||
for entity in region.entity_container.get_children():
|
||||
if entity is ItemObject and entity.item is Seed:
|
||||
var indicator = generate_indicator(tr("TAKE_A_SEED"))
|
||||
indicator.follow_entity(entity)
|
||||
indicators.append(
|
||||
indicator
|
||||
)
|
||||
return indicators
|
||||
|
||||
func is_step_over(p : Player, _region : Region) -> 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, _region : Region) -> Array[InGameIndicator]:
|
||||
var indicator = generate_indicator(tr("PLANT_THE_SEED_IN_DECONTAMINED_ZONE"))
|
||||
indicator.follow_game_position(Region.CHUNK_TILE_SIZE/2. * Region.TILE_SIZE * Vector2.ONE)
|
||||
return [indicator]
|
||||
|
||||
func is_step_over(_p : Player, region : Region) -> bool:
|
||||
for entity in region.entity_container.get_children():
|
||||
if entity is Plant:
|
||||
return true
|
||||
return false
|
||||
|
||||
class RechargeStep extends Step:
|
||||
func generate_indicators(_p: Player, region : Region) -> Array[InGameIndicator]:
|
||||
for entity in region.entity_container.get_children():
|
||||
var indicator = generate_indicator(tr("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, region : Region) -> bool:
|
||||
if region == null :
|
||||
return false
|
||||
return region.data.day > 1
|
||||
|
||||
class WaitMaturePlant extends Step:
|
||||
func generate_indicators(_p: Player, _region : Region) -> Array[InGameIndicator]:
|
||||
return []
|
||||
|
||||
func is_step_over(_p : Player, region : Region) -> bool:
|
||||
if region == null :
|
||||
return false
|
||||
for entity in region.entity_container.get_children():
|
||||
if entity is Plant and entity.data.get_state() == PlantData.State.MATURE:
|
||||
return true
|
||||
return false
|
||||
|
||||
class HarvestMaturePlant extends Step:
|
||||
|
||||
var mature_plant_number : int = 0
|
||||
|
||||
func generate_indicators(_p: Player, region : Region) -> Array[InGameIndicator]:
|
||||
var indicators : Array[InGameIndicator] = []
|
||||
for entity in region.entity_container.get_children():
|
||||
if entity is Plant and entity.data.get_state() == PlantData.State.MATURE:
|
||||
var indicator = generate_indicator(tr("HARVEST_MATURE_PLANTS_WITH_SHOVEL"))
|
||||
indicator.follow_entity(entity)
|
||||
indicators.append(
|
||||
indicator
|
||||
)
|
||||
mature_plant_number += 1
|
||||
return indicators
|
||||
|
||||
func is_step_over(_p : Player, region : Region) -> bool:
|
||||
if region == null :
|
||||
return false
|
||||
var actual_mature_plant_number = 0
|
||||
for entity in region.entity_container.get_children():
|
||||
if entity is Plant and entity.data.get_state() == PlantData.State.MATURE:
|
||||
actual_mature_plant_number += 1
|
||||
return mature_plant_number != actual_mature_plant_number
|
||||
func update_succeeded() -> bool:
|
||||
if not succeeded:
|
||||
succeeded = is_step_over_callable.call()
|
||||
return succeeded
|
||||
|
||||
Reference in New Issue
Block a user