Files
aetherbound-guild/runtime/ui/session_presenter.gd
T

79 lines
3.1 KiB
GDScript

class_name P91SessionPresenter
extends RefCounted
var host: Control
func _init(runtime_host: Control) -> void:
host = runtime_host
func render(snapshot: Dictionary, actions: Dictionary = {}) -> void:
if snapshot.is_empty() or not snapshot.has("screen"):
host.render_binding_error()
return
_reset_legacy_references()
clear_root(host.display_root)
var page: int = host.page
var background_texture: Texture2D = host.FIELD_BACKGROUND if page in host.BATTLE_PRESENTATION_PAGES else host.YARD_BACKGROUND
host.add_background(background_texture)
if host.portrait_layout():
host.render_portrait_notice()
else:
_dispatch_legacy_page(page)
if host.restart_confirmation:
host.render_restart_confirmation()
func _reset_legacy_references() -> void:
host.render_pending = false
host.front_sprite = null
host.rear_sprite = null
host.added_rear_sprite = null
host.enemy_sprite = null
host.battle_feedback_label = null
host.battle_feedback_vfx = null
host.victory_front_sprite = null
host.victory_rear_sprite = null
host.victory_enemy_sprite = null
host.projectile = null
func _dispatch_legacy_page(page: int) -> void:
match page:
host.AppPage.BOOT: host.render_boot()
host.AppPage.TITLE: host.render_title()
host.AppPage.MAIN_MENU: host.render_main_menu()
host.AppPage.GAME_INTRO: host.render_game_intro()
host.AppPage.SETTINGS: host.render_settings()
host.AppPage.FIRST_MISSION: host.render_first_mission()
host.AppPage.RECRUIT_SELECTION: host.render_recruit_selection()
host.AppPage.FRONT_SELECTION: host.render_role_selection(true)
host.AppPage.REAR_SELECTION: host.render_role_selection(false)
host.AppPage.FORMATION_REVIEW: host.render_formation_review()
host.AppPage.YARD: host.render_yard()
host.AppPage.BATTLE, host.AppPage.SECOND_BATTLE, host.AppPage.THIRD_BATTLE, host.AppPage.FOURTH_BATTLE, host.AppPage.FIFTH_BATTLE: host.render_battle()
host.AppPage.VICTORY: host.render_victory()
host.AppPage.ADAPTATION: host.render_adaptation()
host.AppPage.SECOND_RESULT: host.render_second_result()
host.AppPage.GUILD_RETURN: host.render_guild_return()
host.AppPage.SESSION_RESULT: host.render_session_result()
host.AppPage.ROUTE_BOARD: host.render_route_board()
host.AppPage.ROUTE_REVIEW: host.render_route_review()
host.AppPage.SECOND_CYCLE_RESULT: host.render_second_cycle_result()
host.AppPage.TRAINING: host.render_training()
host.AppPage.TRAINING_REVIEW: host.render_training_review()
host.AppPage.THIRD_CYCLE_RESULT: host.render_third_cycle_result()
func clear_root(root: Control) -> void:
for child in root.get_children():
root.remove_child(child)
child.queue_free()
func add_background(texture: Texture2D) -> void:
var background := TextureRect.new()
background.name = "WorldBackground"
background.texture = texture
background.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
background.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_COVERED
background.texture_filter = CanvasItem.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS
background.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
background.mouse_filter = Control.MOUSE_FILTER_IGNORE
host.display_root.add_child(background)