104 lines
3.3 KiB
GDScript
104 lines
3.3 KiB
GDScript
extends RoomState
|
|
|
|
|
|
var trans_tween: Tween
|
|
var player_light_tween: Tween
|
|
var wake_timer: Timer
|
|
|
|
|
|
func _enter(_previous_state_path: String, _data: Dictionary = {}) -> void:
|
|
print("entering room")
|
|
room.player = _instantiate_player(true)
|
|
assert(room.player != null, "player is null")
|
|
room.camera.global_position = room.config.camera_position
|
|
|
|
var ps_material: ShaderMaterial = room.palette_shader.material as ShaderMaterial
|
|
assert(ps_material != null, "palette shader is null")
|
|
ps_material.set_shader_parameter("palette", room.config.room_palette)
|
|
ps_material.set_shader_parameter("palette_size", room.config.palette_size)
|
|
|
|
room.player.enable_point_light(true, 0.4)
|
|
room.player.point_light.texture_scale = 0
|
|
|
|
room.canvas_modulate.visible = true
|
|
room.canvas_modulate.color = Color.BLACK
|
|
|
|
var timer: Timer = Timer.new()
|
|
room.add_child(timer)
|
|
timer.one_shot = true
|
|
timer.start(room.config.transition_in_duration)
|
|
|
|
await timer.timeout
|
|
timer.queue_free()
|
|
|
|
if player_light_tween:
|
|
player_light_tween.kill()
|
|
|
|
player_light_tween = create_tween()
|
|
|
|
player_light_tween.tween_property(room.player.point_light, "texture_scale", 1.0, room.config.transition_in_duration).set_trans(Tween.TRANS_CIRC).set_ease(Tween.EASE_OUT)
|
|
|
|
await player_light_tween.finished
|
|
|
|
if player_light_tween:
|
|
player_light_tween.kill()
|
|
|
|
player_light_tween = create_tween()
|
|
|
|
if room.config.enable_point_light:
|
|
player_light_tween.tween_property(room.player.point_light, "energy", room.config.point_light_energy, room.config.transition_in_duration).set_trans(room.config.transition_in_type).set_ease(Tween.EASE_OUT)
|
|
player_light_tween.tween_callback(func() -> void:
|
|
player_light_tween = null
|
|
)
|
|
else:
|
|
player_light_tween.tween_property(room.player.point_light, "energy", 0, room.config.transition_in_duration).set_trans(room.config.transition_in_type).set_ease(Tween.EASE_OUT)
|
|
player_light_tween.tween_callback(func() -> void:
|
|
room.player.enable_point_light(false)
|
|
player_light_tween = null
|
|
)
|
|
|
|
if trans_tween:
|
|
trans_tween.kill()
|
|
|
|
assert(trans_tween == null, "transgender tween wasnt nulled")
|
|
|
|
trans_tween = create_tween()
|
|
|
|
if room.config.enable_canvas_modulate:
|
|
trans_tween.tween_property(room.canvas_modulate, "color", room.config.modulate_color, room.config.transition_in_duration).set_trans(room.config.transition_in_type).set_ease(Tween.EASE_OUT)
|
|
else:
|
|
trans_tween.tween_property(room.canvas_modulate, "color", Color.WHITE, room.config.transition_in_duration).set_trans(room.config.transition_in_type).set_ease(Tween.EASE_OUT)
|
|
|
|
await trans_tween.finished
|
|
|
|
finished.emit(PLAYING)
|
|
|
|
|
|
func _instantiate_player(waking: bool) -> Player:
|
|
var p: Player = room.player_scene.instantiate()
|
|
room.add_child(p)
|
|
if waking:
|
|
wake_timer = Timer.new()
|
|
p.add_child(wake_timer)
|
|
wake_timer.one_shot = true
|
|
wake_timer.start(room.config.transition_in_duration)
|
|
|
|
wake_timer.timeout.connect(_on_wake_timer)
|
|
|
|
p.state_machine._transition_to_next_state(PlayerState.PAUSED)
|
|
|
|
if room.initial_spawn != Vector2i.ZERO:
|
|
p.global_position = room.initial_spawn
|
|
else:
|
|
assert(
|
|
room.config.initial_spawn != Vector2i.ZERO,
|
|
"invalid player initial spawn provided"
|
|
)
|
|
p.global_position = room.config.initial_spawn
|
|
|
|
return p
|
|
|
|
|
|
func _on_wake_timer() -> void:
|
|
room.player.state_machine._transition_to_next_state(PlayerState.WAKING)
|
|
wake_timer.queue_free()
|