Implement apocalypse mechanics: add apocalypse queue, controller, and integrate into production logic
This commit is contained in:
+43
-1
@@ -100,6 +100,12 @@ var active_actions_dirty: bool = true
|
||||
var active_actions_elapsed: float = 0.0
|
||||
var clock_display_elapsed: float = 0.0
|
||||
var interface_sounds_enabled: bool = false
|
||||
var apocalypse_elapsed: float = 0.0
|
||||
var apocalypse_ui_phase: int = -1
|
||||
var apocalypse_screen: int = -1
|
||||
@onready var time_minus_button: TextureButton = $World/TopMenu/TimeMinus
|
||||
@onready var time_plus_button: TextureButton = $World/TopMenu/TimePlus
|
||||
@onready var apocalypse_music: OwniverseMusicPlayer = $"../MusicPlayer"
|
||||
|
||||
var owniverse:Owniverse = Owniverse.new()
|
||||
var owniverse_items: Dictionary[String, OwniverseItem] = {}
|
||||
@@ -274,6 +280,7 @@ func _swipe_to_nearest_page() -> void:
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if E.eq(owniverse.state.get("apocalypse", {}).get("phase", 0), 1): return
|
||||
if event is InputEventScreenDrag:
|
||||
#effects_player.play_effect("swipe")
|
||||
stage_page_scroller.scroll_horizontal = clamp(
|
||||
@@ -299,7 +306,7 @@ func _set_active_page_actions() -> void:
|
||||
#var amount = owniverse.get_available_to_produce(item_id)
|
||||
|
||||
#var amount = owniverse.get_available_to_produce(entity)
|
||||
var amount = owniverse.production.calculate_max_producible(entity)
|
||||
var amount = (0 if E.gt(owniverse.state.get("apocalypse", {}).get("phase", 0), 0) else owniverse.production.calculate_max_producible(entity))
|
||||
#print(item_id, " : ", amount)
|
||||
if item_id == "SMBH":
|
||||
var preview: Callable = func(requested):
|
||||
@@ -398,6 +405,7 @@ func _refresh_universe_ui() -> void:
|
||||
func _process(delta: float) -> void:
|
||||
|
||||
owniverse.evolute_frame(delta, get_tree())
|
||||
_process_apocalypse(delta)
|
||||
clock_display_elapsed += delta
|
||||
if clock_display_elapsed >= 0.1:
|
||||
clock_display_elapsed = fmod(clock_display_elapsed, 0.1)
|
||||
@@ -431,6 +439,7 @@ func _process(delta: float) -> void:
|
||||
|
||||
|
||||
func _change_speed(delta: int) -> void:
|
||||
if E.eq(owniverse.state.get("apocalypse", {}).get("phase", 0), 1) and delta != 0: return
|
||||
var previous_speed: int = owniverse.speed
|
||||
owniverse.speed = owniverse.speed + delta
|
||||
|
||||
@@ -458,6 +467,39 @@ func _change_speed(delta: int) -> void:
|
||||
g_time_plus.texture_normal = load(SPEED_TEXTURE_NAME_TEMPLATE % str(speed + 1))
|
||||
|
||||
|
||||
func _process_apocalypse(delta: float) -> void:
|
||||
var apocalypse: Dictionary = owniverse.state.get("apocalypse", {})
|
||||
var phase: int = int(apocalypse.get("phase", 0))
|
||||
if phase != apocalypse_ui_phase:
|
||||
apocalypse_ui_phase = phase
|
||||
if phase == 1:
|
||||
apocalypse_music.play_apocalypse()
|
||||
owniverse.speed = 1
|
||||
_change_speed(0)
|
||||
elif phase == 2:
|
||||
owniverse.speed = 1
|
||||
_change_speed(0)
|
||||
time_minus_button.disabled = phase == 1
|
||||
time_plus_button.disabled = phase == 1
|
||||
active_actions_dirty = true
|
||||
if phase == 1:
|
||||
_set_active_page_actions()
|
||||
if phase != 1:
|
||||
apocalypse_elapsed = 0.0
|
||||
return
|
||||
apocalypse_elapsed += delta
|
||||
if owniverse.frame_busy or owniverse.production_queue_busy:
|
||||
return
|
||||
while apocalypse_elapsed >= OwniverseApocalypseController.TICK_SECONDS and E.eq(owniverse.state.apocalypse.phase, 1):
|
||||
apocalypse_elapsed -= OwniverseApocalypseController.TICK_SECONDS
|
||||
var result: Dictionary = owniverse.apocalypse.process_tick(owniverse.state)
|
||||
if int(result.screen) >= 0 and int(result.screen) != apocalypse_screen:
|
||||
apocalypse_screen = int(result.screen)
|
||||
stage_page_scroller.scroll_horizontal = apocalypse_screen * PAGE_WIDTH
|
||||
if bool(result.finished):
|
||||
_change_speed(0)
|
||||
|
||||
|
||||
func _on_topmenu_button_pressed(screen_name: String) -> void:
|
||||
var current_screen: String = ""
|
||||
for screen_id in screens:
|
||||
|
||||
Reference in New Issue
Block a user