mirror of
https://github.com/tonytins/citylimits.git
synced 2025-03-16 04:41:24 +00:00
Moved date variables to dedicated singleton
Due to the growing complexity of date system, it's been moved to its own dedicated singleton.
This commit is contained in:
parent
ae1b600928
commit
b443ee61fe
6 changed files with 56 additions and 33 deletions
|
@ -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]
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
32
scripts/autoload/sim_time.gd
Normal file
32
scripts/autoload/sim_time.gd
Normal file
|
@ -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
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue