Skip to content

Commit

Permalink
Refactoring code ♻️
Browse files Browse the repository at this point in the history
Create terra_packed for changing current indicators
Indicators send terra_packed instead setting indicators value on its own

Change Natural Buttons sending action way

Change Pop up convention

File restructurization

Every planet have own terravarible resource

Normalize naming convenctions

Change indicator movement script to indicator background
Close solved issues: [closed #13], [closed #13], [closed #14], [closed #15]

Change balloon dialogue to Control
  • Loading branch information
wovri-github committed Sep 13, 2023
1 parent 8ab3eae commit 4862add
Show file tree
Hide file tree
Showing 44 changed files with 364 additions and 401 deletions.
18 changes: 18 additions & 0 deletions code/GUI/indicators/indicator_background.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
extends ColorRect


var planet_mechanic_res: TerraVaribleRes:
set(new):
planet_mechanic_res = new
max_value = planet_mechanic_res.max_value
min_value = planet_mechanic_res.min_value
planet_mechanic_res.value_changed.connect(_on_value_changed)
_on_value_changed(planet_mechanic_res.value)


var max_value: float
var min_value: float
@onready var indicator = $Indicator

func _on_value_changed(new_value: float):
indicator.position.x = remap(new_value, min_value, max_value, 0, self.size.x)
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
extends PanelContainer

@export var is_debug := false
var planet_mechanic_res: PlanetMechanic:
signal spike_action_made(terra_packed)

const DISPLAY_NAME = {
GlobalEnums.TERRA_VARIBLE_TYPE.ATMOSPHERE: "Atmosphere",
GlobalEnums.TERRA_VARIBLE_TYPE.OXYGEN: "Oxygen",
GlobalEnums.TERRA_VARIBLE_TYPE.HEAT: "Heat",
}


@export var is_debug := true:
set(new):
is_debug = new
if is_debug:
print_debug("Runned with debug mode:")
planet_mechanic_res = load("res://code/planet_mechanic/mock.tres")

var planet_mechanic_res: TerraVaribleRes:
set(new):
planet_mechanic_res = new
max_value = planet_mechanic_res.max_value
min_value = planet_mechanic_res.min_value
planet_mechanic_res.value_changed.connect(_on_value_changed)
if not self.is_inside_tree():
await(self.ready)
$Title.text = planet_mechanic_res.display_name
_on_value_changed(planet_mechanic_res.value)
var max_value: float
var min_value: float
$Background.planet_mechanic_res = planet_mechanic_res
$Title.text = DISPLAY_NAME[planet_mechanic_res.type]

@export_group("Buttons")
@export var total_value = 30
@export var duration_sec = 10
@export var cooldown_sec = 30
Expand All @@ -41,40 +50,42 @@ var value_per_sec: float

func _ready():
if is_debug:
planet_mechanic_res = load("res://code/planet_mechanic/mock.tres")
print_debug("Runned with debug mode:")
planet_mechanic_res = load("res://code/code_resources/terra_varible_resources/mock.tres")
cooldown_progress.max_value = cooldown_sec


func _process(delta):
if not duration_timer.is_stopped():
planet_mechanic_res.value += value_per_sec * delta
if not cooldown_timer.is_stopped():
cooldown_progress.value = cooldown_timer.time_left

func _on_value_changed(new_value: float):
if is_instance_valid(indicator):
indicator.position.x = remap(new_value, min_value, max_value, 0, $Background.size.x)

func create_terraforming_varibles(is_total_value_positive: bool):
assert(planet_mechanic_res, "Resource need to be assigned first!")
start_cooldown()
var terra_packed = TerraPack.new()
terra_packed.type = planet_mechanic_res.type
if is_total_value_positive:
terra_packed.total_value = total_value
else:
terra_packed.total_value = total_value * -1
terra_packed.duration_sec = duration_sec
emit_signal("spike_action_made", terra_packed)


func change_value_from_button(_total_value: float):
value_per_sec = _total_value / duration_sec
assert(cooldown_timer.is_stopped(), "Button should be disabled on cooldown!")
func start_cooldown():
$Increase.disabled = true
$Decrease.disabled = true
cooldown_timer.start(cooldown_sec)
duration_timer.start(duration_sec)


func _on_cooldown_timeout():
$Increase.disabled = false
$Decrease.disabled = false


func _on_increase_button_down():
change_value_from_button(total_value)
create_terraforming_varibles(true)


func _on_decrease_button_down():
change_value_from_button(total_value * -1)


func _on_cooldown_timeout():
$Increase.disabled = false
$Decrease.disabled = false
create_terraforming_varibles(false)
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[gd_scene load_steps=4 format=3 uid="uid://x1lh0re4n6wg"]
[gd_scene load_steps=5 format=3 uid="uid://x1lh0re4n6wg"]

[ext_resource type="Script" path="res://code/useful/planet_mechanic_indicator.gd" id="1_g3umh"]
[ext_resource type="PackedScene" uid="uid://bixuvnj0ukhsj" path="res://code/menus/menu_resources/button_sound.tscn" id="2_1mect"]
[ext_resource type="Script" path="res://code/GUI/indicators/indicator_bar.gd" id="1_qgvuk"]
[ext_resource type="Script" path="res://code/GUI/indicators/indicator_background.gd" id="2_1hemq"]
[ext_resource type="PackedScene" uid="uid://bixuvnj0ukhsj" path="res://code/code_resources/buttons/button_sound.tscn" id="2_qwyys"]

[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_76scr"]

Expand All @@ -10,14 +11,14 @@ custom_minimum_size = Vector2(160, 40)
offset_right = 171.0
offset_bottom = 40.0
theme_override_styles/panel = SubResource("StyleBoxEmpty_76scr")
script = ExtResource("1_g3umh")
is_debug = true
script = ExtResource("1_qgvuk")

[node name="Background" type="ColorRect" parent="."]
custom_minimum_size = Vector2(120, 12)
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 8
script = ExtResource("2_1hemq")

[node name="RedArea" type="MarginContainer" parent="Background"]
layout_mode = 1
Expand Down Expand Up @@ -91,13 +92,13 @@ size_flags_horizontal = 4
size_flags_vertical = 0
text = "Indicator name"

[node name="Increase" parent="." instance=ExtResource("2_1mect")]
[node name="Increase" parent="." instance=ExtResource("2_qwyys")]
custom_minimum_size = Vector2(20, 10)
layout_mode = 2
size_flags_horizontal = 8
text = "+"

[node name="Decrease" parent="." instance=ExtResource("2_1mect")]
[node name="Decrease" parent="." instance=ExtResource("2_qwyys")]
custom_minimum_size = Vector2(20, 10)
layout_mode = 2
size_flags_horizontal = 0
Expand Down
16 changes: 16 additions & 0 deletions code/GUI/indicators/indicators.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extends VBoxContainer

signal spike_action_made(terra_packed)

@export var is_debug := true
@onready var indicators = self.get_children()

func _ready():
if is_debug:
for indicator in indicators:
indicator.is_debug = true

func _on_spike_action_made(terra_packed):
for indicator in indicators:
indicator.start_cooldown()
emit_signal("spike_action_made", terra_packed)
25 changes: 25 additions & 0 deletions code/GUI/indicators/indicators.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[gd_scene load_steps=3 format=3 uid="uid://plfmfhlyals5"]

[ext_resource type="Script" path="res://code/GUI/indicators/indicators.gd" id="1_bu24p"]
[ext_resource type="PackedScene" uid="uid://x1lh0re4n6wg" path="res://code/GUI/indicators/indicator_bar.tscn" id="1_iw2oa"]

[node name="Indicators" type="VBoxContainer"]
size_flags_horizontal = 0
size_flags_vertical = 0
script = ExtResource("1_bu24p")

[node name="Atmo" parent="." instance=ExtResource("1_iw2oa")]
layout_mode = 2
is_debug = false

[node name="Oxygen" parent="." instance=ExtResource("1_iw2oa")]
layout_mode = 2
is_debug = false

[node name="Heat" parent="." instance=ExtResource("1_iw2oa")]
layout_mode = 2
is_debug = false

[connection signal="spike_action_made" from="Atmo" to="." method="_on_spike_action_made"]
[connection signal="spike_action_made" from="Oxygen" to="." method="_on_spike_action_made"]
[connection signal="spike_action_made" from="Heat" to="." method="_on_spike_action_made"]
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
@tool
extends ButtonSound

signal button_up_with_stats(stats)

@export var stats: TerraformingVaribles
@export var terra_packs: PackTerraPack



func _init():
self.button_up.connect(_on_button_up)

func _on_button_up():
emit_signal("button_up_with_stats", stats)
emit_signal("button_up_with_stats", terra_packs)
9 changes: 9 additions & 0 deletions code/GUI/nature_button_list/nature_button_list.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
extends PanelContainer

signal natural_action_made(pack_terra_pack: PackTerraPack)



func _on_button_up_with_stats(pack_terra_pack):
assert(pack_terra_pack, "This pack is empty!")
emit_signal("natural_action_made", pack_terra_pack)
Original file line number Diff line number Diff line change
@@ -1,56 +1,14 @@
[gd_scene load_steps=11 format=3 uid="uid://bvjjonej6wf7y"]

[ext_resource type="PackedScene" uid="uid://bixuvnj0ukhsj" path="res://code/menus/menu_resources/button_sound.tscn" id="1_anlb4"]
[ext_resource type="Script" path="res://code/useful/button_list.gd" id="1_tgrao"]
[ext_resource type="Script" path="res://code/useful/terraform_button.gd" id="3_ri8wo"]
[ext_resource type="Script" path="res://code/useful/mechanic_stats.gd" id="4_enbuo"]

[sub_resource type="Resource" id="Resource_wcmum"]
script = ExtResource("4_enbuo")
atmo = 10.0
oxygen = 10.0
heat = 10.0
duration = 20.0

[sub_resource type="Resource" id="Resource_w5c8v"]
script = ExtResource("4_enbuo")
atmo = -5.0
oxygen = 7.0
heat = 0.0
duration = 5.0

[sub_resource type="Resource" id="Resource_3en5a"]
script = ExtResource("4_enbuo")
atmo = -3.0
oxygen = 3.0
heat = 0.0
duration = 5.0

[sub_resource type="Resource" id="Resource_1h1oj"]
script = ExtResource("4_enbuo")
atmo = -11.0
oxygen = 10.0
heat = -1.0
duration = 13.0

[sub_resource type="Resource" id="Resource_63sdk"]
script = ExtResource("4_enbuo")
atmo = 2.0
oxygen = -4.0
heat = 3.0
duration = 16.0

[sub_resource type="Resource" id="Resource_vuye6"]
script = ExtResource("4_enbuo")
atmo = 20.0
oxygen = -12.0
heat = -7.0
duration = 19.0

[node name="ButtonList" type="PanelContainer"]
[gd_scene load_steps=5 format=3 uid="uid://bvjjonej6wf7y"]

[ext_resource type="Script" path="res://code/GUI/nature_button_list/nature_button_list.gd" id="1_8jm8o"]
[ext_resource type="PackedScene" uid="uid://bixuvnj0ukhsj" path="res://code/code_resources/buttons/button_sound.tscn" id="2_t42bp"]
[ext_resource type="Script" path="res://code/GUI/nature_button_list/nature_button.gd" id="3_l4sol"]
[ext_resource type="Resource" uid="uid://jaejalpclhid" path="res://resources/statistics/bacteria.tres" id="4_n1qd5"]

[node name="NatureButtonList" type="PanelContainer"]
size_flags_horizontal = 8
size_flags_vertical = 0
script = ExtResource("1_tgrao")
script = ExtResource("1_8jm8o")

[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 2
Expand All @@ -59,50 +17,50 @@ layout_mode = 2
layout_mode = 2
alignment = 1

[node name="BacteriaButton" parent="VBoxContainer/HBoxContainer" instance=ExtResource("1_anlb4")]
[node name="BacteriaButton" parent="VBoxContainer/HBoxContainer" instance=ExtResource("2_t42bp")]
layout_mode = 2
text = "Bacteria"
script = ExtResource("3_ri8wo")
stats = SubResource("Resource_wcmum")
script = ExtResource("3_l4sol")
terra_packs = ExtResource("4_n1qd5")

[node name="AlgaeButton" parent="VBoxContainer/HBoxContainer" instance=ExtResource("1_anlb4")]
[node name="AlgaeButton" parent="VBoxContainer/HBoxContainer" instance=ExtResource("2_t42bp")]
layout_mode = 2
text = "Algea"
script = ExtResource("3_ri8wo")
stats = SubResource("Resource_w5c8v")
script = ExtResource("3_l4sol")
terra_packs = null

[node name="HBoxContainer2" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2
alignment = 1

[node name="SmallPlantsButton" parent="VBoxContainer/HBoxContainer2" instance=ExtResource("1_anlb4")]
[node name="SmallPlantsButton" parent="VBoxContainer/HBoxContainer2" instance=ExtResource("2_t42bp")]
layout_mode = 2
text = "Small Plants"
script = ExtResource("3_ri8wo")
stats = SubResource("Resource_3en5a")
script = ExtResource("3_l4sol")
terra_packs = null

[node name="PlantTreesButton" parent="VBoxContainer/HBoxContainer2" instance=ExtResource("1_anlb4")]
[node name="PlantTreesButton" parent="VBoxContainer/HBoxContainer2" instance=ExtResource("2_t42bp")]
layout_mode = 2
text = "Plant Tree"
script = ExtResource("3_ri8wo")
stats = SubResource("Resource_1h1oj")
script = ExtResource("3_l4sol")
terra_packs = null

[node name="HBoxContainer3" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2
alignment = 1

[node name="LandAnimalsButton" parent="VBoxContainer/HBoxContainer3" instance=ExtResource("1_anlb4")]
[node name="LandAnimalsButton" parent="VBoxContainer/HBoxContainer3" instance=ExtResource("2_t42bp")]
layout_mode = 2
text = "Land Animals
"
script = ExtResource("3_ri8wo")
stats = SubResource("Resource_63sdk")
script = ExtResource("3_l4sol")
terra_packs = null

[node name="GoopButton" parent="VBoxContainer/HBoxContainer3" instance=ExtResource("1_anlb4")]
[node name="GoopButton" parent="VBoxContainer/HBoxContainer3" instance=ExtResource("2_t42bp")]
layout_mode = 2
text = "Goop"
script = ExtResource("3_ri8wo")
stats = SubResource("Resource_vuye6")
script = ExtResource("3_l4sol")
terra_packs = null

[node name="CooldownProgress" type="ProgressBar" parent="VBoxContainer"]
layout_mode = 2
Expand Down
Loading

0 comments on commit 4862add

Please sign in to comment.