ajout des graines procédurales et des cinamatiques
This commit is contained in:
@@ -11,7 +11,6 @@ func _ready():
|
||||
set_max_energy()
|
||||
|
||||
func set_max_energy(_max_energy : int = max_energy):
|
||||
var old = max_energy
|
||||
max_energy = _max_energy
|
||||
if is_node_ready() and max_energy != len(%Batteries.get_children()):
|
||||
for c in %Batteries.get_children():
|
||||
|
||||
@@ -3,6 +3,8 @@ class_name GameGui
|
||||
|
||||
const SCORE_ICON : Texture = preload("res://common/icons/growth.svg")
|
||||
|
||||
var score_by_plant : Dictionary[String, int] = {}
|
||||
|
||||
var score_mirror :
|
||||
set(v):
|
||||
score_mirror = v
|
||||
@@ -10,17 +12,20 @@ var score_mirror :
|
||||
|
||||
func _ready():
|
||||
GameInfo.game_data.current_region_data.updated.connect(_on_region_updated)
|
||||
GameInfo.game_data.current_region_data.plant_changing_score.connect(_on_plant_changing_score)
|
||||
GameInfo.game_data.player_data.updated.connect(_on_player_updated)
|
||||
GameInfo.game_data.current_region_data.pass_day_ended.connect(_on_region_pass_day_ended)
|
||||
|
||||
score_mirror = GameInfo.game_data.current_region_data.get_score()
|
||||
|
||||
charge_update(GameInfo.game_data.current_region_data)
|
||||
player_update(GameInfo.game_data.player_data, false)
|
||||
%EnergyInfo.reset_size()
|
||||
%GiveUpButton.pressed.connect(_on_give_up_pressed)
|
||||
|
||||
score_mirror = GameInfo.game_data.current_region_data.get_score()
|
||||
print(score_mirror)
|
||||
for p : PlantData in GameInfo.game_data.current_region_data.plants:
|
||||
score_by_plant[str(p.random_seed)] = p.get_score()
|
||||
|
||||
func _on_player_updated(player_data : PlayerData):
|
||||
player_update(player_data)
|
||||
|
||||
@@ -32,6 +37,28 @@ func player_update(player_data : PlayerData, with_animation = true):
|
||||
)
|
||||
|
||||
func _on_region_updated(region_data : RegionData):
|
||||
await get_tree().create_timer(0.1).timeout
|
||||
if score_mirror != region_data.get_score():
|
||||
for p in region_data.plants:
|
||||
var score = p.get_score()
|
||||
if not str(p.random_seed) in score_by_plant:
|
||||
score_by_plant[str(p.random_seed)] = 0
|
||||
if score > score_by_plant[str(p.random_seed)]:
|
||||
print("emit particles for %s" % p.plant_name)
|
||||
plant_changing_score(p, score - score_by_plant[str(p.random_seed)])
|
||||
elif score < score_by_plant[str(p.random_seed)]:
|
||||
print("reduce score for %s" % p.plant_name)
|
||||
score_mirror -= score_by_plant[str(p.random_seed)] - score
|
||||
score_by_plant[str(p.random_seed)] = score
|
||||
# Check for removed plants
|
||||
for key in score_by_plant:
|
||||
if region_data.plants.find_custom(
|
||||
func (p): return str(p.random_seed) == key
|
||||
) == -1:
|
||||
print("remove plant")
|
||||
score_mirror -= score_by_plant[key]
|
||||
score_by_plant.erase(key)
|
||||
|
||||
charge_update(region_data)
|
||||
|
||||
func _on_give_up_pressed():
|
||||
@@ -67,7 +94,7 @@ func score_update(with_animation = true):
|
||||
else:
|
||||
%ObjectiveProgressBar.set_progress(objective_progression)
|
||||
|
||||
func _on_plant_changing_score(plant_data: PlantData, amount : int):
|
||||
func plant_changing_score(plant_data: PlantData, amount : int):
|
||||
if GameInfo.game_data.current_region_data.in_passing_day_animation:
|
||||
await GameInfo.game_data.current_region_data.pass_day_ended
|
||||
if amount <= 0:
|
||||
|
||||
@@ -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
|
||||
|
||||
30
gui/game/tutorial/step_gui/scripts/step_gui.gd
Normal file
30
gui/game/tutorial/step_gui/scripts/step_gui.gd
Normal file
@@ -0,0 +1,30 @@
|
||||
@tool
|
||||
extends HBoxContainer
|
||||
class_name TutorialStepGui
|
||||
|
||||
const DEFAULT_ICON = preload("res://common/icons/circle-dotted.svg")
|
||||
const SUCEEDED_ICON = preload("res://common/icons/circle-check.svg")
|
||||
const SUCEEDED_OPACITY = 0.5
|
||||
|
||||
@export var suceeded := false : set = set_suceeded
|
||||
@export var text := "" : set = set_text
|
||||
|
||||
func _ready():
|
||||
update()
|
||||
|
||||
|
||||
func set_suceeded(v := suceeded):
|
||||
suceeded = v
|
||||
if is_node_ready():
|
||||
update()
|
||||
|
||||
|
||||
func set_text(v := text):
|
||||
text = v
|
||||
if is_node_ready():
|
||||
update()
|
||||
|
||||
func update():
|
||||
%Icon.texture = SUCEEDED_ICON if suceeded else DEFAULT_ICON
|
||||
%Label.text = tr(text)
|
||||
modulate.a = SUCEEDED_OPACITY if suceeded else 1.
|
||||
1
gui/game/tutorial/step_gui/scripts/step_gui.gd.uid
Normal file
1
gui/game/tutorial/step_gui/scripts/step_gui.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://c2w7h0x2blimk
|
||||
40
gui/game/tutorial/step_gui/step_gui.tscn
Normal file
40
gui/game/tutorial/step_gui/step_gui.tscn
Normal file
@@ -0,0 +1,40 @@
|
||||
[gd_scene format=3 uid="uid://cnh1uof0w06f4"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c2w7h0x2blimk" path="res://gui/game/tutorial/step_gui/scripts/step_gui.gd" id="1_8qp12"]
|
||||
[ext_resource type="Texture2D" uid="uid://dk7j4cmn2avor" path="res://common/icons/circle-check.svg" id="2_8qp12"]
|
||||
|
||||
[node name="Step" type="HBoxContainer" unique_id=595946430]
|
||||
modulate = Color(1, 1, 1, 0.5)
|
||||
custom_minimum_size = Vector2(400, 0)
|
||||
offset_right = 24.0
|
||||
offset_bottom = 20.0
|
||||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 0
|
||||
alignment = 1
|
||||
script = ExtResource("1_8qp12")
|
||||
suceeded = true
|
||||
text = "Hello"
|
||||
|
||||
[node name="Icon" type="TextureRect" parent="." unique_id=1345441660]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(20, 20)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 4
|
||||
texture = ExtResource("2_8qp12")
|
||||
expand_mode = 1
|
||||
stretch_mode = 5
|
||||
|
||||
[node name="Label" type="RichTextLabel" parent="." unique_id=1116828300]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 0
|
||||
theme_override_font_sizes/normal_font_size = 15
|
||||
theme_override_font_sizes/bold_font_size = 15
|
||||
theme_override_font_sizes/bold_italics_font_size = 15
|
||||
theme_override_font_sizes/italics_font_size = 15
|
||||
theme_override_font_sizes/mono_font_size = 15
|
||||
bbcode_enabled = true
|
||||
text = "Lorem Ipsum dolor sit amet and again and again and again and again"
|
||||
fit_content = true
|
||||
@@ -1,10 +1,70 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dt6mptqg80dew"]
|
||||
[gd_scene format=3 uid="uid://dt6mptqg80dew"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://beg7favg2ukbi" path="res://gui/game/tutorial/scripts/tutorial.gd" id="1_ie1q8"]
|
||||
[ext_resource type="Theme" uid="uid://bgcmd213j6gk1" path="res://gui/ressources/hud.tres" id="2_1wikm"]
|
||||
[ext_resource type="Texture2D" uid="uid://1ynlp05wj0hm" path="res://common/icons/rocket.svg" id="3_8kuag"]
|
||||
[ext_resource type="FontFile" uid="uid://qt80w6o01q5s" path="res://gui/ressources/fonts/TitanOne-Regular.ttf" id="4_1wikm"]
|
||||
|
||||
[node name="Tutorial" type="Control"]
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_x7cwm"]
|
||||
bg_color = Color(0.18, 0.18, 0.18, 0.48235294)
|
||||
corner_radius_top_left = 20
|
||||
corner_radius_top_right = 20
|
||||
corner_radius_bottom_right = 20
|
||||
corner_radius_bottom_left = 20
|
||||
|
||||
[sub_resource type="LabelSettings" id="LabelSettings_8kuag"]
|
||||
font = ExtResource("4_1wikm")
|
||||
font_size = 20
|
||||
|
||||
[node name="Tutorial" type="Control" unique_id=1210916048]
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
script = ExtResource("1_ie1q8")
|
||||
metadata/_edit_horizontal_guides_ = [369.0]
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="." unique_id=502187513]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("2_1wikm")
|
||||
|
||||
[node name="PanelContainer" type="PanelContainer" parent="MarginContainer" unique_id=913156548]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 8
|
||||
mouse_filter = 2
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_x7cwm")
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="MarginContainer/PanelContainer" unique_id=332993244]
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/PanelContainer/MarginContainer" unique_id=1196958295]
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer" unique_id=1140176018]
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer" unique_id=527978183]
|
||||
layout_mode = 2
|
||||
texture = ExtResource("3_8kuag")
|
||||
|
||||
[node name="Label" type="Label" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer" unique_id=592987672]
|
||||
layout_mode = 2
|
||||
text = "TUTORIAL"
|
||||
label_settings = SubResource("LabelSettings_8kuag")
|
||||
|
||||
[node name="Steps" type="VBoxContainer" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer" unique_id=125170550]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
@@ -237,7 +237,7 @@ theme_override_fonts/bold_font = ExtResource("4_apjlw")
|
||||
theme_override_font_sizes/normal_font_size = 15
|
||||
theme_override_font_sizes/bold_font_size = 18
|
||||
bbcode_enabled = true
|
||||
text = "DECONTAMINED_LAND_TEXT"
|
||||
text = "FERTILE_LAND_TEXT"
|
||||
fit_content = true
|
||||
vertical_alignment = 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user