Cleaned up UI and GameData interaction and code
This commit is contained in:
parent
57aa8c867c
commit
c291ae9259
3 changed files with 33 additions and 24 deletions
|
|
@ -1,15 +1,22 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
signal job_generated(job: JobData)
|
# - Signals
|
||||||
|
signal job_generated(job: Node)
|
||||||
|
signal job_interact
|
||||||
|
|
||||||
|
# - Variables - Code managed
|
||||||
var job_spawn_timer: Timer
|
var job_spawn_timer: Timer
|
||||||
var jobs_array: Array[JobData]
|
var jobs_array: Array[JobData]
|
||||||
|
var current_job_count: int = 0
|
||||||
|
|
||||||
#Job spawn interval
|
# Scenes
|
||||||
|
const JOB_CARD = preload("uid://dvfcie8hqcb0")
|
||||||
|
|
||||||
|
# - Constants - Settings
|
||||||
|
# Jobs
|
||||||
const JOB_SPAWN_WAIT: float = 2.0
|
const JOB_SPAWN_WAIT: float = 2.0
|
||||||
const MAX_JOBS: int = 4
|
const MAX_JOBS: int = 4
|
||||||
|
|
||||||
var current_job_count: int = 0
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
load_all_jobs("res://Resources/Jobs/")
|
load_all_jobs("res://Resources/Jobs/")
|
||||||
|
|
@ -30,11 +37,21 @@ func generate_job():
|
||||||
if not current_job_count >= MAX_JOBS:
|
if not current_job_count >= MAX_JOBS:
|
||||||
var random_job: JobData = jobs_array.pick_random()
|
var random_job: JobData = jobs_array.pick_random()
|
||||||
current_job_count += 1
|
current_job_count += 1
|
||||||
print("Generated job: ")
|
var new_job = JOB_CARD.instantiate()
|
||||||
print(random_job)
|
job_generated.emit(new_job)
|
||||||
job_generated.emit(random_job)
|
new_job.initialize_job(random_job)
|
||||||
|
new_job.job_accepted.connect(_on_job_accepted_pressed)
|
||||||
|
job_interact.emit()
|
||||||
|
|
||||||
# Load job resources
|
func _on_job_accepted_pressed(accepted_job):
|
||||||
|
print("Job accepted")
|
||||||
|
PlayerData.jobs.append(accepted_job.job_data)
|
||||||
|
print(PlayerData.jobs[0].job_name)
|
||||||
|
GameData.current_job_count -= 1
|
||||||
|
accepted_job.queue_free()
|
||||||
|
job_interact.emit()
|
||||||
|
|
||||||
|
#region Load job resources
|
||||||
func load_all_jobs(path: String) -> void:
|
func load_all_jobs(path: String) -> void:
|
||||||
var dir = DirAccess.open(path)
|
var dir = DirAccess.open(path)
|
||||||
|
|
||||||
|
|
@ -55,3 +72,4 @@ func load_all_jobs(path: String) -> void:
|
||||||
#print(jobs_array)
|
#print(jobs_array)
|
||||||
else:
|
else:
|
||||||
print("No files found on path")
|
print("No files found on path")
|
||||||
|
#endregion
|
||||||
|
|
|
||||||
|
|
@ -42,3 +42,4 @@ func _on_accept_job_pressed() -> void:
|
||||||
|
|
||||||
func _on_skip_job_pressed() -> void:
|
func _on_skip_job_pressed() -> void:
|
||||||
queue_free()
|
queue_free()
|
||||||
|
GameData.current_job_count -= 1
|
||||||
|
|
|
||||||
|
|
@ -3,29 +3,26 @@ extends Control
|
||||||
@export var jobs_array: Array[JobData]
|
@export var jobs_array: Array[JobData]
|
||||||
@export var job_limit: int = 5
|
@export var job_limit: int = 5
|
||||||
@export var debug: bool = false
|
@export var debug: bool = false
|
||||||
var jobs_tab_button: Button
|
|
||||||
|
|
||||||
@onready var debug_xp: Button = $VBoxContainer/TopBar/VBoxContainer/MarginContainer/HBoxContainer/DebugXP
|
@onready var debug_xp: Button = $VBoxContainer/TopBar/VBoxContainer/MarginContainer/HBoxContainer/DebugXP
|
||||||
@onready var debug_money: Button = $VBoxContainer/TopBar/VBoxContainer/MarginContainer/HBoxContainer/DebugMoney
|
@onready var debug_money: Button = $VBoxContainer/TopBar/VBoxContainer/MarginContainer/HBoxContainer/DebugMoney
|
||||||
@onready var debug_button: Button = $VBoxContainer/TopBar/VBoxContainer/MarginContainer/HBoxContainer/DebugButton
|
@onready var debug_button: Button = $VBoxContainer/TopBar/VBoxContainer/MarginContainer/HBoxContainer/DebugButton
|
||||||
|
@onready var jobs_tab_button: Button = $VBoxContainer/MainArea/RightColumn/TabSwitcher/TabButtons/JobsTabButton
|
||||||
|
|
||||||
const JOB_SCENE = preload("uid://dvfcie8hqcb0")
|
|
||||||
const PRINTER = preload("uid://33ctlyrpibs3")
|
const PRINTER = preload("uid://33ctlyrpibs3")
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
check_debug()
|
check_debug()
|
||||||
|
|
||||||
print(jobs_array)
|
|
||||||
|
|
||||||
%Money.text = "Money: " + str(PlayerData.money) + " €"
|
%Money.text = "Money: " + str(PlayerData.money) + " €"
|
||||||
%Experience.value = PlayerData.xp
|
%Experience.value = PlayerData.xp
|
||||||
%Level.text = "Level: " + str(PlayerData.level)
|
%Level.text = "Level: " + str(PlayerData.level)
|
||||||
jobs_tab_button = $VBoxContainer/MainArea/RightColumn/TabSwitcher/TabButtons/JobsTabButton
|
|
||||||
|
|
||||||
PlayerData.xp_changed.connect(_on_xp_changed)
|
PlayerData.xp_changed.connect(_on_xp_changed)
|
||||||
PlayerData.level_changed.connect(_on_level_changed)
|
PlayerData.level_changed.connect(_on_level_changed)
|
||||||
PlayerData.money_changed.connect(_on_money_changed)
|
PlayerData.money_changed.connect(_on_money_changed)
|
||||||
GameData.job_generated.connect(_on_job_generated)
|
GameData.job_generated.connect(_on_job_generated)
|
||||||
|
GameData.job_interact.connect(_on_job_interact)
|
||||||
|
|
||||||
# --- Experience, Level and Money update ---
|
# --- Experience, Level and Money update ---
|
||||||
func _on_xp_changed(xp):
|
func _on_xp_changed(xp):
|
||||||
|
|
@ -35,19 +32,10 @@ func _on_level_changed(level):
|
||||||
func _on_money_changed(money):
|
func _on_money_changed(money):
|
||||||
%Money.text = "Money: " + str(money) + "€"
|
%Money.text = "Money: " + str(money) + "€"
|
||||||
|
|
||||||
func _on_job_generated(job: JobData):
|
func _on_job_generated(job: Node):
|
||||||
var new_job = JOB_SCENE.instantiate()
|
%JobContainer.add_child(job)
|
||||||
%JobContainer.add_child(new_job)
|
|
||||||
new_job.initialize_job(job)
|
|
||||||
jobs_tab_button.text = "Jobs (" + str(GameData.current_job_count) + "/" + str(GameData.MAX_JOBS) + ")"
|
|
||||||
new_job.job_accepted.connect(_on_job_accepted_pressed)
|
|
||||||
|
|
||||||
func _on_job_accepted_pressed(accepted_job):
|
func _on_job_interact() -> void:
|
||||||
print("Job accepted")
|
|
||||||
PlayerData.jobs.append(accepted_job.job_data)
|
|
||||||
print(PlayerData.jobs[0].job_name)
|
|
||||||
GameData.current_job_count -= 1
|
|
||||||
accepted_job.queue_free()
|
|
||||||
jobs_tab_button.text = "Jobs (" + str(GameData.current_job_count) + "/" + str(GameData.MAX_JOBS) + ")"
|
jobs_tab_button.text = "Jobs (" + str(GameData.current_job_count) + "/" + str(GameData.MAX_JOBS) + ")"
|
||||||
|
|
||||||
func _on_printers_printer_purchase_requested(printer_data: PrinterData) -> void:
|
func _on_printers_printer_purchase_requested(printer_data: PrinterData) -> void:
|
||||||
|
|
@ -57,6 +45,7 @@ func _on_printers_printer_purchase_requested(printer_data: PrinterData) -> void:
|
||||||
%PrinterContainer.add_child(new_printer)
|
%PrinterContainer.add_child(new_printer)
|
||||||
new_printer.initialize_printer(printer_data)
|
new_printer.initialize_printer(printer_data)
|
||||||
|
|
||||||
|
#region Debug
|
||||||
func check_debug() -> void:
|
func check_debug() -> void:
|
||||||
debug_xp.visible = false
|
debug_xp.visible = false
|
||||||
debug_money.visible = false
|
debug_money.visible = false
|
||||||
|
|
@ -80,3 +69,4 @@ func toggle_debug() -> void:
|
||||||
else:
|
else:
|
||||||
debug = true
|
debug = true
|
||||||
check_debug()
|
check_debug()
|
||||||
|
#endregion
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue