Compare commits

..

2 commits

21 changed files with 349 additions and 30 deletions

View file

@ -0,0 +1,13 @@
[gd_resource type="Resource" script_class="FilamentData" format=3 uid="uid://dvu3hbx3tn0nx"]
[ext_resource type="Script" uid="uid://cim8peoxip2si" path="res://Resources/filament_data.gd" id="1_7duty"]
[resource]
script = ExtResource("1_7duty")
material = "PLA"
reward_multiplier = 1.0
xp_multiplier = 1.0
amount = 200.0
price = 4.18
description = "Filament with reduced plastic content"
metadata/_custom_type_script = "uid://cim8peoxip2si"

View file

@ -0,0 +1,10 @@
class_name FilamentData
extends Resource
@export var material: String
@export var reward_multiplier: float
@export var xp_multiplier: float
@export var amount: float
@export var price: float
@export var description: String = ""
@export var level_req: int = 1

View file

@ -0,0 +1 @@
uid://cim8peoxip2si

View file

@ -4,13 +4,22 @@ extends Node
signal job_generated(job: Node)
signal job_interact
signal printer_bought(printer: Node)
signal filament_bought
@warning_ignore("unused_signal")
signal refresh_printer_dropdown
signal notification_requested(message: String, color: String)
# - Variables - Code managed
var job_spawn_timer: Timer
var jobs_array: Array[JobData]
var current_job_count: int = 0
var filaments_array: Array[FilamentData]
# - Text colors
var hex_white: String = '#ffffff'
var hex_green: String = '#4ade80'
var hex_blue: String = '#60a5fa'
var hex_red: String = '#f87171'
# - Scenes
const JOB_CARD = preload("uid://dvfcie8hqcb0")
@ -33,6 +42,10 @@ func _ready() -> void:
job_spawn_timer.timeout.connect(_on_job_spawn_timer_timeout)
job_spawn_timer.start()
func display_msg(message: String, color: String) -> void:
notification_requested.emit(message,color)
#region Shop buy interactions
func _on_shop_printer_purchase_req(printer_data: PrinterData) -> void:
if PlayerData.try_purchase(printer_data.printer_price):
var new_printer = PRINTER.instantiate()
@ -40,6 +53,11 @@ func _on_shop_printer_purchase_req(printer_data: PrinterData) -> void:
new_printer.initialize_printer(printer_data)
PlayerData.owned_printers += 1
func _on_shop_filament_purchase_req(filament_data: FilamentData) -> void:
if PlayerData.try_purchase(filament_data.price):
filaments_array.append(filament_data)
filament_bought.emit()
#endregion
#region Job generation
func _on_job_spawn_timer_timeout() -> void:

View file

@ -29,7 +29,7 @@ var sell_multiplier: float = 0.5:
set(value):
sell_multiplier = value
var failure_chance: float = 0.4:
var failure_chance: float = 0.2:
set(value):
failure_chance = value

View file

@ -4,12 +4,11 @@ extends PanelContainer
@onready var printer_model_label: Label = $MarginContainer/MainArea/PrinterModelLabel
@onready var progress_bar: ProgressBar = $MarginContainer/MainArea/PrintInfo/ProgressBar
@onready var select_job: OptionButton = $MarginContainer/MainArea/SelectJob
@onready var status_label: Label = $MarginContainer/MainArea/TopInfo/StatusLabel
@onready var status_label: RichTextLabel = $MarginContainer/MainArea/TopInfo/StatusLabel
@onready var time_left_label: Label = $MarginContainer/MainArea/PrintInfo/InfoRow2/TimeLeftLabel
@onready var start_button: Button = $MarginContainer/MainArea/Buttons/StartButton
@onready var reward_label: Label = $MarginContainer/MainArea/PrintInfo/InfoRow2/RewardLabel
@onready var quality_label: Label = $MarginContainer/MainArea/PrintInfo/InfoRow1/QualityLabel
@onready var reward_label: RichTextLabel = $MarginContainer/MainArea/PrintInfo/InfoRow2/RewardLabel
@onready var quality_label: RichTextLabel = $MarginContainer/MainArea/PrintInfo/InfoRow1/QualityLabel
var printer_data: PrinterData
var selected_job: JobData
@ -32,9 +31,10 @@ func initialize_printer(data: PrinterData) -> void:
reward_label.visible = false
time_left_label.visible = false
time_left = 0
set_status()
status_label.text = 'Status: [color=%s]%s[/color]' % [GameData.hex_white, "Free"]
progress_bar.visible = false
progress_bar.value = 0
GameData.display_msg('%s printer bought!' % printer_data.printer_manufacturer, GameData.hex_green)
_on_select_job_pressed()
func _process(delta) -> void:
@ -46,8 +46,8 @@ func _process(delta) -> void:
reward_label.visible = true
set_status()
quality_label.text = 'Quality: %.0f %%' % (print_quality * 100)
reward_label.text = 'Reward: %.2f' % (selected_job.job_reward * print_quality)
quality_label.text = 'Quality: [color=%s]%.0f%%[/color]' % [GameData.hex_green, (print_quality * 100)]
reward_label.text = 'Reward: [color=%s]%.2f[/color]' % [GameData.hex_green, (selected_job.job_reward * print_quality)]
var total_time = selected_job.job_time / printer_data.printer_speed
var progress = (total_time - time_left) / total_time
@ -64,16 +64,10 @@ func _process(delta) -> void:
if failure_points.has(roundf(progress_bar.value * 100)):
if failure_points[0] == roundf(progress_bar.value * 100):
if check_failure(roundf(progress_bar.value * 100)):
print('Print failed')
print_failed = true
reset_status()
else:
if check_failure(roundf(progress_bar.value * 100)):
elif check_failure(roundf(progress_bar.value * 100)):
print_quality -= 0.1
print('Fail check, new print quality: %.2f' % print_quality)
print('Failure points: ', failure_points)
else:
print('Passed check')
func reset_status() -> void:
is_printing = false
@ -93,14 +87,21 @@ func reset_status() -> void:
_on_select_job_pressed()
func set_status() -> void:
var color_hex: String = GameData.hex_white
var status: String
if print_failed:
status_label.text = 'Status: Failed'
return
if is_printing:
status_label.text = 'Status: Printing'
status = 'Failed'
color_hex = GameData.hex_red
GameData.display_msg('Print failed!',color_hex)
elif is_printing:
status = 'Printing'
color_hex = GameData.hex_blue
else:
status_label.text = 'Status: Free'
status = 'Free'
color_hex = GameData.hex_green
GameData.display_msg('Print completed!',color_hex)
status_label.text = 'Status: [color=%s]%s[/color]' % [color_hex, status]
func calculate_fail_thresholds() -> Array:
var failure_checkpoints: Array = []

View file

@ -6,8 +6,11 @@
[node name="Printer" type="PanelContainer" unique_id=1372437203]
custom_minimum_size = Vector2(0, 150)
offset_right = 271.0
offset_bottom = 182.0
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
script = ExtResource("1_dlbos")
@ -30,11 +33,13 @@ size_flags_horizontal = 3
theme_override_font_sizes/font_size = 30
text = "Printer #1"
[node name="StatusLabel" type="Label" parent="MarginContainer/MainArea/TopInfo" unique_id=2117616913]
[node name="StatusLabel" type="RichTextLabel" parent="MarginContainer/MainArea/TopInfo" unique_id=157586427]
layout_mode = 2
size_flags_horizontal = 3
bbcode_enabled = true
text = "Status: Free"
horizontal_alignment = 2
vertical_alignment = 1
[node name="PrinterModelLabel" type="Label" parent="MarginContainer/MainArea" unique_id=666140345]
layout_mode = 2
@ -50,9 +55,10 @@ layout_mode = 2
layout_mode = 2
text = "Material: ###"
[node name="QualityLabel" type="Label" parent="MarginContainer/MainArea/PrintInfo/InfoRow1" unique_id=1362675397]
[node name="QualityLabel" type="RichTextLabel" parent="MarginContainer/MainArea/PrintInfo/InfoRow1" unique_id=937206053]
layout_mode = 2
size_flags_horizontal = 3
bbcode_enabled = true
text = "Print quality: ###%"
horizontal_alignment = 2
@ -63,9 +69,10 @@ layout_mode = 2
layout_mode = 2
text = "Time left: ###s"
[node name="RewardLabel" type="Label" parent="MarginContainer/MainArea/PrintInfo/InfoRow2" unique_id=1767576134]
[node name="RewardLabel" type="RichTextLabel" parent="MarginContainer/MainArea/PrintInfo/InfoRow2" unique_id=700892606]
layout_mode = 2
size_flags_horizontal = 3
bbcode_enabled = true
text = "Reward: ###€"
horizontal_alignment = 2

View file

@ -0,0 +1,34 @@
extends PanelContainer
signal buy_filament
var filament_data: FilamentData
@onready var filament_material: Label = %Material
@onready var description: Label = %Description
@onready var reward_multiplier: Label = %RewardMultiplier
@onready var xp_multiplier: Label = %ExperienceMultiplier
@onready var amount: Label = %Amount
@onready var price_tag: Label = %PriceTag
@onready var buy_button: Button = $Margin/Info/Price/BuyButton
func _ready() -> void:
PlayerData.money_changed.connect(_on_toggle_button)
func initialize_filament(data: FilamentData) -> void:
filament_data = data
filament_material.text = filament_data.material
description.text = filament_data.description
reward_multiplier.text = 'Reward multiplier: x%.1f' % filament_data.reward_multiplier
xp_multiplier.text = 'Experience multiplier: x%.1f' % filament_data.xp_multiplier
amount.text = 'Amount: %.0f g' % filament_data.amount
price_tag.text = 'Price: %.2f' % filament_data.price
func _on_buy_button_pressed() -> void:
buy_filament.emit(self)
func _on_toggle_button(money) -> void:
if PlayerData.money >= filament_data.price:
buy_button.disabled = false
else:
buy_button.disabled = true

View file

@ -0,0 +1 @@
uid://o733qdkp8lxl

View file

@ -0,0 +1,76 @@
[gd_scene format=3 uid="uid://csq76iufxrb4y"]
[ext_resource type="Script" uid="uid://o733qdkp8lxl" path="res://Scenes/Shop/Filaments/shop_filament_card.gd" id="1_gtjvs"]
[node name="FilamentsCard" type="PanelContainer" unique_id=368185874]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_gtjvs")
[node name="Margin" type="MarginContainer" parent="." unique_id=1163688479]
layout_mode = 2
theme_override_constants/margin_left = 10
theme_override_constants/margin_top = 10
theme_override_constants/margin_right = 10
theme_override_constants/margin_bottom = 10
[node name="Info" type="VBoxContainer" parent="Margin" unique_id=1453497579]
layout_mode = 2
[node name="Title" type="VBoxContainer" parent="Margin/Info" unique_id=1904589169]
layout_mode = 2
[node name="Material" type="Label" parent="Margin/Info/Title" unique_id=24143253]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
text = "LOL-CF"
[node name="Description" type="Label" parent="Margin/Info/Title" unique_id=870869096]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
text = "Filament description goes here"
[node name="Multipliers" type="HBoxContainer" parent="Margin/Info" unique_id=2026319482]
layout_mode = 2
[node name="RewardMultiplier" type="Label" parent="Margin/Info/Multipliers" unique_id=867010603]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
text = "Reward multiplier: x1.0"
[node name="ExperienceMultiplier" type="Label" parent="Margin/Info/Multipliers" unique_id=1033367043]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
text = "Experience multiplier: x1.0"
[node name="ProductInfo" type="HBoxContainer" parent="Margin/Info" unique_id=1243250288]
layout_mode = 2
[node name="Amount" type="Label" parent="Margin/Info/ProductInfo" unique_id=1356405418]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
text = "Amount: 123 g"
[node name="Price" type="HBoxContainer" parent="Margin/Info" unique_id=926000726]
layout_mode = 2
[node name="PriceTag" type="Label" parent="Margin/Info/Price" unique_id=881459224]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
text = "Price: 1.23 €"
[node name="BuyButton" type="Button" parent="Margin/Info/Price" unique_id=780730344]
layout_mode = 2
size_flags_horizontal = 3
text = "Buy"
[connection signal="pressed" from="Margin/Info/Price/BuyButton" to="." method="_on_buy_button_pressed"]

View file

@ -1,11 +1,14 @@
[gd_scene format=3 uid="uid://bdpqvwvwmaian"]
[ext_resource type="Script" uid="uid://ttfk4n2fkifj" path="res://Scenes/Shop/Printers/printer_card.gd" id="1_tl8ce"]
[ext_resource type="Script" uid="uid://ttfk4n2fkifj" path="res://Scenes/Shop/Printers/shop_printer_card.gd" id="1_tl8ce"]
[ext_resource type="StyleBox" uid="uid://csahw36txnewl" path="res://Styles/btn_style_box_green_hover.tres" id="2_tl8ce"]
[node name="PrinterCard" type="PanelContainer" unique_id=1714388686]
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
size_flags_horizontal = 3
script = ExtResource("1_tl8ce")

View file

@ -0,0 +1,22 @@
extends PanelContainer
signal filament_purchase_requested(filament_data: FilamentData)
@export var filaments_array: Array[FilamentData]
const SHOP_FILAMENTS_CARD = preload("uid://csq76iufxrb4y")
func _ready() -> void:
generate_filaments()
filament_purchase_requested.connect(GameData._on_shop_filament_purchase_req)
func generate_filaments() -> void:
for filament in filaments_array:
if PlayerData.level >= filament.level_req:
var new_filament = SHOP_FILAMENTS_CARD.instantiate()
%FilamentList.add_child(new_filament)
new_filament.initialize_filament(filament)
new_filament.buy_filament.connect(_on_buy_filament_pressed)
func _on_buy_filament_pressed(bought_filament) -> void:
filament_purchase_requested.emit(bought_filament)

View file

@ -0,0 +1 @@
uid://bcowlm04qsgqc

View file

@ -1,9 +1,11 @@
[gd_scene format=3 uid="uid://d24rvu5c0gd1w"]
[ext_resource type="Script" uid="uid://d0sgvbphgssmi" path="res://Scenes/UI/ui.gd" id="1_vqjbf"]
[ext_resource type="PackedScene" uid="uid://c4tdg221rvm53" path="res://Scenes/UI/ui_notification.tscn" id="2_s3gqk"]
[ext_resource type="Script" uid="uid://bcowlm04qsgqc" path="res://Scenes/UI/shop_filaments.gd" id="9_mbl0m"]
[ext_resource type="Script" uid="uid://q8cf21vq4ka6" path="res://Scenes/tab_switcher.gd" id="13_vqjbf"]
[ext_resource type="Script" uid="uid://cg2kskiky8iur" path="res://Scenes/Shop/shop_tab_switcher.gd" id="14_vqjbf"]
[ext_resource type="Script" uid="uid://d3g5e8wjfqy5i" path="res://Scenes/Shop/Printers/printers.gd" id="15_vqjbf"]
[ext_resource type="Script" uid="uid://d3g5e8wjfqy5i" path="res://Scenes/Shop/Printers/shop_printers.gd" id="15_vqjbf"]
[ext_resource type="Script" uid="uid://bed8wdnwod4wu" path="res://Resources/printer_data.gd" id="16_rdojl"]
[ext_resource type="Resource" uid="uid://bdis2u0tfvlch" path="res://Resources/Printers/printer_bambulab_A1_mini.tres" id="17_llrls"]
[ext_resource type="Resource" uid="uid://b6x4k150ugskw" path="res://Resources/Printers/printer_creality_ender_3.tres" id="18_8rt22"]
@ -171,6 +173,9 @@ size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_constants/separation = 8
[node name="Printer" parent="VBoxContainer/MainAreaMargin/MainArea/LeftColumn/MainMargin/PrinterScroll/MarginContainer/PrinterContainer" unique_id=1372437203 instance_placeholder="res://Scenes/Printer/printer.tscn"]
layout_mode = 2
[node name="RightColumn" type="VBoxContainer" parent="VBoxContainer/MainAreaMargin/MainArea" unique_id=653054059]
layout_mode = 2
size_flags_horizontal = 3
@ -295,6 +300,7 @@ unique_name_in_owner = true
layout_mode = 2
size_flags_vertical = 3
theme_override_styles/panel = SubResource("StyleBoxFlat_mmlst")
script = ExtResource("9_mbl0m")
[node name="ScrollContainer" type="ScrollContainer" parent="VBoxContainer/MainAreaMargin/MainArea/RightColumn/MainMargin/ShopTab/VBoxContainer/Filaments" unique_id=1087434821]
layout_mode = 2
@ -319,6 +325,16 @@ unique_name_in_owner = true
visible = false
layout_mode = 2
[node name="UiNotification" parent="." unique_id=1468421214 instance=ExtResource("2_s3gqk")]
layout_mode = 0
anchors_preset = 0
anchor_right = 0.0
anchor_bottom = 0.0
offset_right = 1152.0
offset_bottom = 649.0
grow_horizontal = 1
grow_vertical = 1
[node name="JobSpawner" type="Timer" parent="." unique_id=1696213535]
autostart = true

View file

@ -0,0 +1,11 @@
extends Control
@onready var message_label: RichTextLabel = $Base/Margin/Message
@onready var animation_player: AnimationPlayer = $AnimationPlayer
func _ready() -> void:
GameData.notification_requested.connect(_on_notification_requested)
func _on_notification_requested(message: String, color: String) -> void:
message_label.text = '[color=%s]%s[/color]' % [color, message]
animation_player.play("show_notification")

View file

@ -0,0 +1 @@
uid://y3jtgv0vknvk

View file

@ -0,0 +1,104 @@
[gd_scene format=3 uid="uid://c4tdg221rvm53"]
[ext_resource type="Script" uid="uid://y3jtgv0vknvk" path="res://Scenes/UI/ui_notification.gd" id="1_7y7gh"]
[sub_resource type="Animation" id="Animation_8qs5e"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Base:position:y")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [-50.0]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Base:modulate:a")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [1.0]
}
[sub_resource type="Animation" id="Animation_np30a"]
resource_name = "show_notification"
length = 3.0000000000000004
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Base:position:y")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.29999995),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [-50.0, 10.0]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Base:modulate:a")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 1.5, 3),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [1.0, 1.0, 0.0]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_7ag70"]
_data = {
&"RESET": SubResource("Animation_8qs5e"),
&"show_notification": SubResource("Animation_np30a")
}
[node name="UiNotification" type="Control" unique_id=1468421214]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
script = ExtResource("1_7y7gh")
[node name="Base" type="PanelContainer" parent="." unique_id=870318481]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -79.0
offset_top = -50.0
offset_right = 79.0
offset_bottom = -7.0
grow_horizontal = 2
[node name="Margin" type="MarginContainer" parent="Base" unique_id=716680500]
layout_mode = 2
theme_override_constants/margin_left = 10
theme_override_constants/margin_top = 10
theme_override_constants/margin_right = 10
theme_override_constants/margin_bottom = 10
[node name="Message" type="RichTextLabel" parent="Base/Margin" unique_id=438265807]
layout_mode = 2
bbcode_enabled = true
text = "Example message"
fit_content = true
autowrap_mode = 0
horizontal_alignment = 1
vertical_alignment = 1
[node name="AnimationPlayer" type="AnimationPlayer" parent="." unique_id=152270752]
libraries/ = SubResource("AnimationLibrary_7ag70")