From b443ee61fe850b44193233bf628cad504d873144 Mon Sep 17 00:00:00 2001 From: Tony Bark <35226681+tonytins@users.noreply.github.com> Date: Sat, 29 May 2021 03:09:09 -0400 Subject: [PATCH] Moved date variables to dedicated singleton Due to the growing complexity of date system, it's been moved to its own dedicated singleton. --- project.godot | 1 + scripts/autoload/sim_data.gd | 15 ++++++--------- scripts/autoload/sim_time.gd | 32 ++++++++++++++++++++++++++++++++ scripts/city_status.gd | 6 +++--- scripts/command_handler.gd | 4 ++-- scripts/game.gd | 31 ++++++++++++------------------- 6 files changed, 56 insertions(+), 33 deletions(-) create mode 100644 scripts/autoload/sim_time.gd diff --git a/project.godot b/project.godot index 2a28b7d..ec76d78 100644 --- a/project.godot +++ b/project.godot @@ -24,6 +24,7 @@ config/windows_native_icon="res://icon.ico" SimData="*res://scripts/autoload/sim_data.gd" SimEvents="*res://scripts/autoload/sim_events.gd" +SimTime="*res://scripts/autoload/sim_time.gd" [display] diff --git a/scripts/autoload/sim_data.gd b/scripts/autoload/sim_data.gd index be2b550..f77974b 100644 --- a/scripts/autoload/sim_data.gd +++ b/scripts/autoload/sim_data.gd @@ -8,15 +8,6 @@ var expenses: int var on_alert: bool = false var has_ctower: bool = false # Central Tower -var year: int = 2000 -var prev_year: int -var month: int = 1 -var prev_month: int -var day: int = 1 -var prev_day: int -var last_total_days: int -var total_days: int = 1 - var power_grid: int # Number of power stations in the area. Helps provide redundancies. var power_capacity: int var current_power_cap: int @@ -35,6 +26,12 @@ var fire_tax: int var police_tax: int var power_tax: int +var ticker_files: Array = [ + "adverts.json", + "sammy.json" +] +var prev_ticker_files: Array = [] + enum GameSpeed { SLOW, MEDIUM, diff --git a/scripts/autoload/sim_time.gd b/scripts/autoload/sim_time.gd new file mode 100644 index 0000000..cdfb76c --- /dev/null +++ b/scripts/autoload/sim_time.gd @@ -0,0 +1,32 @@ +extends Node + +var year: int = 2000 setget increment_year +var prev_year: int +var month: int = 1 setget increment_month +var prev_month: int +var day: int = 1 setget increment_day +var prev_day: int + +func new_year(): + prev_year = year + prev_day = day + prev_month = month + increment_year(1) + day = 1 + month = 1 + +func reset_day(): + prev_day = day + day = 1 + +func increment_day(new_day): + prev_day = day + day += new_day + +func increment_year(new_year): + prev_year = year + year += new_year + +func increment_month(new_month): + prev_month = month + month += new_month diff --git a/scripts/city_status.gd b/scripts/city_status.gd index 4fcf85c..ee69645 100644 --- a/scripts/city_status.gd +++ b/scripts/city_status.gd @@ -7,6 +7,6 @@ onready var calendar = $NameDate/YearCtr/CalendarLbl func _process(delta): city_name.text = SimData.city_name budget.text = str(SimData.budget) - var day = "%02d" % SimData.day - var month = "%02d" % SimData.month - calendar.text = str(day) + "/" + str(month) + "/" + str(SimData.year) + var day = "%02d" % SimTime.day + var month = "%02d" % SimTime.month + calendar.text = str(day) + "/" + str(month) + "/" + str(SimTime.year) diff --git a/scripts/command_handler.gd b/scripts/command_handler.gd index 5cc718c..99417de 100644 --- a/scripts/command_handler.gd +++ b/scripts/command_handler.gd @@ -17,10 +17,10 @@ const valid_commands = [ ] func set_month(month): - SimData.month = month + SimTime.month = month func set_year(year): - SimData.year = year + SimTime.year = year func show_policy(policy): SimEvents.emit_signal("policy_message", policy) diff --git a/scripts/game.gd b/scripts/game.gd index 9e508eb..3fedebb 100644 --- a/scripts/game.gd +++ b/scripts/game.gd @@ -17,31 +17,24 @@ func _resume_rotation(): func _on_DayCycle_timeout(): - if SimData.prev_month < 12: - SimData.last_total_days = SimData.total_days - SimData.total_days += 1 - # Increment the number days until it reaches 30 - if SimData.prev_day < 30: - SimData.day += 1 + if SimTime.prev_day < 30: + SimTime.increment_day(1) # Reset the number of days to 1 on day 30 and increment the month - if SimData.prev_day == 30: - SimData.day = 1 - SimData.prev_month = SimData.month - SimData.month += 1 + if SimTime.prev_day == 30: + SimTime.reset_day() + + # Increment month up until the 12th + if SimTime.prev_month != 12: + SimTime.increment_month(1) + SimEvents.emit_signal("budget") # Increment the year on the 12th month - if SimData.prev_month == 12: - SimData.prev_year = SimData.year - SimData.total_days = 1 - SimData.month = 1 - SimData.year += 1 - - SimData.last_total_days = SimData.total_days - SimData.prev_day = SimData.day - + if SimTime.prev_month == 12: + SimTime.new_year() + func _on_TurtleBtn_toggled(button_pressed): if button_pressed: day_cycle.wait_time = 12