forked from 2121578/gai-ca2
Added "better" implementation for camp UI
parent
f3f4cef1bf
commit
3d716ed06d
File diff suppressed because one or more lines are too long
|
@ -15,7 +15,6 @@ var tilemap_types: TileMapTileTypes = TileMapTileTypes.new()
|
|||
@onready var time_of_day_bar: ProgressBar = %TimeOfDayBar
|
||||
|
||||
var tilemap_navigation: TilemapNavigation = TilemapNavigation.new()
|
||||
var camp: CampManager = CampManager.new()
|
||||
|
||||
@onready var tree_visualizer: BehaviorTreeVisualizer = %TreeVisualizer
|
||||
|
||||
|
@ -26,298 +25,271 @@ var waiting_for_input: bool = true
|
|||
|
||||
|
||||
func _ready() -> void:
|
||||
tilemap_navigation.world = world
|
||||
tilemap_navigation.player = player
|
||||
player.game_manager = self
|
||||
world.camp_manager.game_manager = self
|
||||
world.step_visualizer.game_manager = self
|
||||
world.step_visualizer.world = world
|
||||
camp.camp_add_item(tilemap_types.OBJECT_I_BERRY)
|
||||
camp.camp_add_item(tilemap_types.OBJECT_I_STICK)
|
||||
update_bars()
|
||||
update_camp_ui()
|
||||
update_boat_progress()
|
||||
call_deferred("defer_ready")
|
||||
tilemap_navigation.world = world
|
||||
tilemap_navigation.player = player
|
||||
player.game_manager = self
|
||||
world.camp_manager.game_manager = self
|
||||
world.step_visualizer.game_manager = self
|
||||
world.step_visualizer.world = world
|
||||
update_bars()
|
||||
call_deferred("defer_ready")
|
||||
|
||||
|
||||
func defer_ready() -> void:
|
||||
tree_visualizer.behavior_tree = player.behavior_tree
|
||||
tree_visualizer.build_tree()
|
||||
tree_visualizer.behavior_tree = player.behavior_tree
|
||||
tree_visualizer.build_tree()
|
||||
|
||||
intro_image.visible = true
|
||||
await wait_for_key_press()
|
||||
get_tree().create_tween().tween_method(set_intro_opacity, 1.0, 0.0, 1.0)
|
||||
get_tree().create_tween().tween_method(set_instructions_opacity, 0.0, 1.0, 1.0)
|
||||
intro_image.visible = true
|
||||
await wait_for_key_press()
|
||||
get_tree().create_tween().tween_method(set_intro_opacity, 1.0, 0.0, 1.0)
|
||||
get_tree().create_tween().tween_method(set_instructions_opacity, 0.0, 1.0, 1.0)
|
||||
|
||||
|
||||
# game_ticker.start()
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if Input.is_action_just_pressed("force_game_tick"):
|
||||
Task.print_behavior_tree_evaluation = true
|
||||
_on_game_tick_timeout()
|
||||
Task.print_behavior_tree_evaluation = false
|
||||
if Input.is_action_pressed("force_game_tick_fast"):
|
||||
_on_game_tick_timeout()
|
||||
if Input.is_action_just_pressed("toggle_temperature_layer"):
|
||||
toggle_temperature_layer()
|
||||
camera.print_config()
|
||||
if Input.is_action_just_pressed("auto_tick"):
|
||||
if game_ticker.is_stopped():
|
||||
game_ticker.start()
|
||||
else:
|
||||
game_ticker.stop()
|
||||
if Input.is_action_just_pressed("key_1"):
|
||||
get_tree().reload_current_scene()
|
||||
if Input.is_action_just_pressed("key_2"):
|
||||
player.exploration_task.current_goal = world.tilemap_ground.local_to_cell(world.get_local_mouse_position())
|
||||
player.behavior_tree.blackboard["cached_paths"] = {}
|
||||
player.behavior_tree.blackboard["path"] = []
|
||||
if Input.is_action_just_pressed("key_3"):
|
||||
player.board_position = Vector2i(world.camp_manager.camp)
|
||||
player.board_position.y += 1
|
||||
if Input.is_action_just_pressed("force_game_tick"):
|
||||
Task.print_behavior_tree_evaluation = true
|
||||
_on_game_tick_timeout()
|
||||
Task.print_behavior_tree_evaluation = false
|
||||
if Input.is_action_pressed("force_game_tick_fast"):
|
||||
_on_game_tick_timeout()
|
||||
if Input.is_action_just_pressed("toggle_temperature_layer"):
|
||||
toggle_temperature_layer()
|
||||
camera.print_config()
|
||||
if Input.is_action_just_pressed("auto_tick"):
|
||||
if game_ticker.is_stopped():
|
||||
game_ticker.start()
|
||||
else:
|
||||
game_ticker.stop()
|
||||
if Input.is_action_just_pressed("key_1"):
|
||||
get_tree().reload_current_scene()
|
||||
if Input.is_action_just_pressed("key_2"):
|
||||
player.exploration_task.current_goal = world.tilemap_ground.local_to_cell(world.get_local_mouse_position())
|
||||
player.behavior_tree.blackboard["cached_paths"] = {}
|
||||
player.behavior_tree.blackboard["path"] = []
|
||||
if Input.is_action_just_pressed("key_3"):
|
||||
player.board_position = Vector2i(world.camp_manager.camp)
|
||||
player.board_position.y += 1
|
||||
|
||||
if intro_image.is_visible():
|
||||
intro_image.set_scale(calculate_scale(intro_image.texture.get_size()))
|
||||
if intro_image.is_visible():
|
||||
intro_image.set_scale(calculate_scale(intro_image.texture.get_size()))
|
||||
|
||||
|
||||
func calculate_scale(image_size: Vector2) -> Vector2:
|
||||
var viewport_size: Vector2 = world.get_viewport_rect().size
|
||||
var scale: float = viewport_size.x / image_size.x
|
||||
return Vector2(scale, scale)
|
||||
var viewport_size: Vector2 = world.get_viewport_rect().size
|
||||
var scale: float = viewport_size.x / image_size.x
|
||||
return Vector2(scale, scale)
|
||||
|
||||
|
||||
# SECTION: intro / outro
|
||||
|
||||
func set_intro_opacity(opacity: float) -> void:
|
||||
intro_image.set_modulate(Color(1, 1, 1, opacity))
|
||||
intro_image.set_modulate(Color(1, 1, 1, opacity))
|
||||
|
||||
|
||||
func set_instructions_opacity(opacity: float) -> void:
|
||||
%InstructionsRect.set_modulate(Color(1, 1, 1, opacity))
|
||||
%InstructionsRect.show()
|
||||
%InstructionsRect.set_modulate(Color(1, 1, 1, opacity))
|
||||
%InstructionsRect.show()
|
||||
|
||||
|
||||
func set_outro_opacity(opacity: float) -> void:
|
||||
%OutroImageContainer.set_modulate(Color(1, 1, 1, opacity))
|
||||
%OutroImageContainer.show()
|
||||
%OutroImageContainer.set_modulate(Color(1, 1, 1, opacity))
|
||||
%OutroImageContainer.show()
|
||||
|
||||
|
||||
# SECTION: game tick
|
||||
|
||||
func player_health_depleted():
|
||||
# TODO
|
||||
pass
|
||||
# TODO
|
||||
pass
|
||||
|
||||
|
||||
func _on_game_tick_timeout() -> void:
|
||||
var timer_on_game_tick_timeout: PerformanceTimer = PerformanceTimer.new()
|
||||
timer_on_game_tick_timeout.display_name = "frame"
|
||||
var timer_on_game_tick_timeout: PerformanceTimer = PerformanceTimer.new()
|
||||
timer_on_game_tick_timeout.display_name = "frame"
|
||||
|
||||
tilemap_navigation.game_tick_start()
|
||||
world.game_tick_start()
|
||||
tilemap_navigation.game_tick_start()
|
||||
world.game_tick_start()
|
||||
|
||||
player.game_tick()
|
||||
player.game_tick()
|
||||
|
||||
apply_player_exploration_distance()
|
||||
apply_player_exploration_distance()
|
||||
|
||||
tree_visualizer.update_task_statuses(player.behavior_tree.blackboard)
|
||||
tree_visualizer.update_task_statuses(player.behavior_tree.blackboard)
|
||||
|
||||
tilemap_navigation.game_tick_end()
|
||||
world.game_tick_end()
|
||||
EventsTracker.populate_visual_log(%RecentEventsLog, self)
|
||||
tilemap_navigation.game_tick_end()
|
||||
world.game_tick_end()
|
||||
EventsTracker.populate_visual_log(%RecentEventsLog, self)
|
||||
|
||||
update_bars()
|
||||
update_boat_progress()
|
||||
handle_result_game_state(player.behavior_tree.blackboard)
|
||||
update_bars()
|
||||
world.camp_manager.populate_camp_visualization(%BoatProcessUI, %CampItemUI)
|
||||
handle_result_game_state(player.behavior_tree.blackboard)
|
||||
|
||||
if not game_ticker.is_stopped():
|
||||
camera_follow_player()
|
||||
if not game_ticker.is_stopped():
|
||||
camera_follow_player()
|
||||
|
||||
timer_on_game_tick_timeout.stop()
|
||||
timer_on_game_tick_timeout.stop()
|
||||
|
||||
|
||||
func camera_follow_player() -> void:
|
||||
var player_position: Vector2 = world.tilemap_player.cell_to_local(player.board_position)
|
||||
var targeted_position = null
|
||||
var player_position: Vector2 = world.tilemap_player.cell_to_local(player.board_position)
|
||||
var targeted_position = null
|
||||
|
||||
if player.behavior_tree.blackboard.has("path"):
|
||||
var path: Array = player.behavior_tree.blackboard["path"]
|
||||
if path.size() > 0:
|
||||
targeted_position = world.tilemap_player.cell_to_local(path[path.size() - 1])
|
||||
if player.behavior_tree.blackboard.has("path"):
|
||||
var path: Array = player.behavior_tree.blackboard["path"]
|
||||
if path.size() > 0:
|
||||
targeted_position = world.tilemap_player.cell_to_local(path[path.size() - 1])
|
||||
|
||||
if not targeted_position:
|
||||
camera.go_to(player_position)
|
||||
return
|
||||
if not targeted_position:
|
||||
camera.go_to(player_position)
|
||||
return
|
||||
|
||||
var avg_position = (player_position + targeted_position) / 2
|
||||
var distance: float = player_position.distance_to(targeted_position)
|
||||
var zoom_level: float
|
||||
if distance < 200:
|
||||
zoom_level = distance_to_zoom_level(200)
|
||||
else:
|
||||
zoom_level = distance_to_zoom_level(distance)
|
||||
var avg_position = (player_position + targeted_position) / 2
|
||||
var distance: float = player_position.distance_to(targeted_position)
|
||||
var zoom_level: float
|
||||
if distance < 200:
|
||||
zoom_level = distance_to_zoom_level(200)
|
||||
else:
|
||||
zoom_level = distance_to_zoom_level(distance)
|
||||
|
||||
avg_position.x += distance / 2
|
||||
avg_position.x += distance / 2
|
||||
|
||||
camera.go_to_zooming(avg_position, zoom_level)
|
||||
camera.go_to_zooming(avg_position, zoom_level)
|
||||
|
||||
|
||||
func apply_player_exploration_distance():
|
||||
player.exploration_task.closest_distance_to_goal = min(player.exploration_task.closest_distance_to_goal, TilemapNavigation.manhattan_distance(player.board_position, player.exploration_task.current_goal))
|
||||
player.exploration_task.closest_distance_to_goal = min(player.exploration_task.closest_distance_to_goal, TilemapNavigation.manhattan_distance(player.board_position, player.exploration_task.current_goal))
|
||||
|
||||
|
||||
func distance_to_zoom_level(distance: float) -> float:
|
||||
var a: float = 862.08
|
||||
var b: float = 274.13
|
||||
return a / (distance + b)
|
||||
var a: float = 862.08
|
||||
var b: float = 274.13
|
||||
return a / (distance + b)
|
||||
|
||||
|
||||
func handle_result_game_state(blackboard: Dictionary) -> void:
|
||||
if blackboard.has("game_state_win"):
|
||||
EventsTracker.track(EventsTracker.Event.GAME_STATE_WIN)
|
||||
game_ticker.stop()
|
||||
get_tree().create_tween().tween_method(set_outro_opacity, 0.0, 1.0, 1.0)
|
||||
if blackboard.has("game_state_win"):
|
||||
EventsTracker.track(EventsTracker.Event.GAME_STATE_WIN)
|
||||
game_ticker.stop()
|
||||
get_tree().create_tween().tween_method(set_outro_opacity, 0.0, 1.0, 1.0)
|
||||
|
||||
|
||||
func update_boat_progress() -> void:
|
||||
func update_boat_progress_old() -> void:
|
||||
var part_counts: Dictionary = { # @formatter:off
|
||||
tilemap_types.OBJECT_I_BOAT_PART_ENGINE: 0,
|
||||
tilemap_types.OBJECT_I_BOAT_PART_FUEL: 0,
|
||||
tilemap_types.OBJECT_I_BOAT_PART_ANCHOR: 0,
|
||||
tilemap_types.OBJECT_I_BOAT_PART_CHEST: 0,
|
||||
tilemap_types.OBJECT_I_BOAT_PART_GEARS: 0,
|
||||
tilemap_types.OBJECT_I_BOAT_PART_MEDIKIT: 0,
|
||||
tilemap_types.OBJECT_I_BOAT_PART_PADDLE: 0,
|
||||
tilemap_types.OBJECT_I_BOAT_PART_GAS_STOVE: 0
|
||||
} # @formatter:on
|
||||
|
||||
# Dictionary zur Zählung der Bootsteile
|
||||
var part_counts = {
|
||||
tilemap_types.OBJECT_I_BOAT_PART_ENGINE: 0,
|
||||
tilemap_types.OBJECT_I_BOAT_PART_FUEL: 0,
|
||||
tilemap_types.OBJECT_I_BOAT_PART_ANCHOR: 0,
|
||||
tilemap_types.OBJECT_I_BOAT_PART_CHEST: 0,
|
||||
tilemap_types.OBJECT_I_BOAT_PART_GEARS: 0,
|
||||
tilemap_types.OBJECT_I_BOAT_PART_MEDIKIT: 0,
|
||||
tilemap_types.OBJECT_I_BOAT_PART_PADDLE: 0,
|
||||
tilemap_types.OBJECT_I_BOAT_PART_GAS_STOVE: 0
|
||||
}
|
||||
for boat_part in world.camp_manager.boat_items:
|
||||
if part_counts.has(boat_part):
|
||||
part_counts[boat_part] += 1
|
||||
|
||||
# Teile in boat_items zählen
|
||||
for boat_part in world.camp_manager.boat_items:
|
||||
if part_counts.has(boat_part):
|
||||
part_counts[boat_part] += 1
|
||||
for part in part_counts.keys():
|
||||
var count = part_counts[part]
|
||||
if count > 0:
|
||||
if part == tilemap_types.OBJECT_I_BOAT_PART_ENGINE:
|
||||
%BoatPartEngine.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_ENGINE)
|
||||
%BoatPartEngine.visible = true
|
||||
%EngineCount.text = str(count)
|
||||
elif part == tilemap_types.OBJECT_I_BOAT_PART_FUEL:
|
||||
%BoatPartFuel.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_FUEL)
|
||||
%BoatPartFuel.visible = true
|
||||
%FuelCount.text = str(count)
|
||||
elif part == tilemap_types.OBJECT_I_BOAT_PART_ANCHOR:
|
||||
%BoatPartAnchor.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_ANCHOR)
|
||||
%BoatPartAnchor.visible = true
|
||||
%AnchorCount.text = str(count)
|
||||
elif part == tilemap_types.OBJECT_I_BOAT_PART_CHEST:
|
||||
%BoatPartChest.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_CHEST)
|
||||
%BoatPartChest.visible = true
|
||||
%ChestCount.text = str(count)
|
||||
elif part == tilemap_types.OBJECT_I_BOAT_PART_GEARS:
|
||||
%BoatPartGears.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_GEARS)
|
||||
%BoatPartGears.visible = true
|
||||
%GearsCount.text = str(count)
|
||||
elif part == tilemap_types.OBJECT_I_BOAT_PART_MEDIKIT:
|
||||
%BoatPartMedikit.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_MEDIKIT)
|
||||
%BoatPartMedikit.visible = true
|
||||
%MedikitCount.text = str(count)
|
||||
elif part == tilemap_types.OBJECT_I_BOAT_PART_PADDLE:
|
||||
%BoatPartPaddle.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_PADDLE)
|
||||
%BoatPartPaddle.visible = true
|
||||
%PaddleCount.text = str(count)
|
||||
elif part == tilemap_types.OBJECT_I_BOAT_PART_GAS_STOVE:
|
||||
%BoatPartGasStove.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_GAS_STOVE)
|
||||
%BoatPartGasStove.visible = true
|
||||
%StoveCount.text = str(count)
|
||||
else:
|
||||
push_error("Unknown boat part: " + str(part))
|
||||
|
||||
# Aktualisiere die UI basierend auf den gezählten Teilen
|
||||
for part in part_counts.keys():
|
||||
var count = part_counts[part]
|
||||
if count > 0:
|
||||
if part == tilemap_types.OBJECT_I_BOAT_PART_ENGINE:
|
||||
%BoatPartEngine.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_ENGINE)
|
||||
%BoatPartEngine.visible = true
|
||||
%EngineCount.text = str(count)
|
||||
elif part == tilemap_types.OBJECT_I_BOAT_PART_FUEL:
|
||||
%BoatPartFuel.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_FUEL)
|
||||
%BoatPartFuel.visible = true
|
||||
%FuelCount.text = str(count)
|
||||
elif part == tilemap_types.OBJECT_I_BOAT_PART_ANCHOR:
|
||||
%BoatPartAnchor.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_ANCHOR)
|
||||
%BoatPartAnchor.visible = true
|
||||
%AnchorCount.text = str(count)
|
||||
elif part == tilemap_types.OBJECT_I_BOAT_PART_CHEST:
|
||||
%BoatPartChest.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_CHEST)
|
||||
%BoatPartChest.visible = true
|
||||
%ChestCount.text = str(count)
|
||||
elif part == tilemap_types.OBJECT_I_BOAT_PART_GEARS:
|
||||
%BoatPartGears.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_GEARS)
|
||||
%BoatPartGears.visible = true
|
||||
%GearsCount.text = str(count)
|
||||
elif part == tilemap_types.OBJECT_I_BOAT_PART_MEDIKIT:
|
||||
%BoatPartMedikit.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_MEDIKIT)
|
||||
%BoatPartMedikit.visible = true
|
||||
%MedikitCount.text = str(count)
|
||||
elif part == tilemap_types.OBJECT_I_BOAT_PART_PADDLE:
|
||||
%BoatPartPaddle.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_PADDLE)
|
||||
%BoatPartPaddle.visible = true
|
||||
%PaddleCount.text = str(count)
|
||||
elif part == tilemap_types.OBJECT_I_BOAT_PART_GAS_STOVE:
|
||||
%BoatPartGasStove.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_GAS_STOVE)
|
||||
%BoatPartGasStove.visible = true
|
||||
%StoveCount.text = str(count)
|
||||
else:
|
||||
push_error("Unknown boat part: " + str(part))
|
||||
|
||||
|
||||
func update_camp_ui() -> void:
|
||||
# Get the count of berries and sticks from the camp inventory
|
||||
var berry_count_value = camp.camp_item_count(tilemap_types.OBJECT_I_BERRY)
|
||||
var stick_count_value = camp.camp_item_count(tilemap_types.OBJECT_I_STICK)
|
||||
|
||||
# Update Berry UI
|
||||
%BerryCount.text = str(berry_count_value) # Update the count label
|
||||
%BerryTexture.visible = berry_count_value > 0 # Show texture only if count > 0
|
||||
if berry_count_value > 0:
|
||||
%BerryTexture.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BERRY)
|
||||
|
||||
# Update Stick UI
|
||||
%StickCount.text = str(stick_count_value) # Update the count label
|
||||
%StickTexture.visible = stick_count_value > 0 # Show texture only if count > 0
|
||||
if stick_count_value > 0:
|
||||
%StickTexture.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_STICK)
|
||||
|
||||
func update_bars() -> void:
|
||||
if health_bar != null:
|
||||
health_bar.max_value = player.max_health
|
||||
health_bar.value = clamp(player.health, 0, player.max_health)
|
||||
%HealthLabel.text = str(health_bar.value) + "/" + str(player.max_health)
|
||||
%HealthLabel.add_theme_color_override("font_color", Color(1, 1, 1))
|
||||
if health_bar != null:
|
||||
health_bar.max_value = player.max_health
|
||||
health_bar.value = clamp(player.health, 0, player.max_health)
|
||||
%HealthLabel.text = str(health_bar.value) + "/" + str(player.max_health)
|
||||
%HealthLabel.add_theme_color_override("font_color", Color(1, 1, 1))
|
||||
|
||||
if food_bar != null:
|
||||
food_bar.max_value = player.max_food
|
||||
food_bar.value = clamp(player.food, 0, player.max_food)
|
||||
%FoodLabel.text = str(food_bar.value) + "/" + str(player.max_food)
|
||||
if food_bar != null:
|
||||
food_bar.max_value = player.max_food
|
||||
food_bar.value = clamp(player.food, 0, player.max_food)
|
||||
%FoodLabel.text = str(food_bar.value) + "/" + str(player.max_food)
|
||||
|
||||
if temperature_resistance_bar != null:
|
||||
temperature_resistance_bar.max_value = player.temperature_set_buff_value
|
||||
temperature_resistance_bar.value = clamp(player.temperature_buff_timer, 0, player.temperature_set_buff_value)
|
||||
%TemperatureResistanceLabel.text = str(temperature_resistance_bar.value) + "/" + str(player.temperature_set_buff_value)
|
||||
if temperature_resistance_bar != null:
|
||||
temperature_resistance_bar.max_value = player.temperature_set_buff_value
|
||||
temperature_resistance_bar.value = clamp(player.temperature_buff_timer, 0, player.temperature_set_buff_value)
|
||||
%TemperatureResistanceLabel.text = str(temperature_resistance_bar.value) + "/" + str(player.temperature_set_buff_value)
|
||||
|
||||
if temperature_bar != null:
|
||||
temperature_bar.max_value = player.temperature_endure
|
||||
# invert the value to show the time left
|
||||
var countdown: int = player.temperature_endure - player.temperature_timer
|
||||
temperature_bar.value = clamp(countdown, 0, player.temperature_endure)
|
||||
%TemperatureLabel.text = str(temperature_bar.value) + "/" + str(player.temperature_endure)
|
||||
if temperature_bar != null:
|
||||
temperature_bar.max_value = player.temperature_endure
|
||||
# invert the value to show the time left
|
||||
var countdown: int = player.temperature_endure - player.temperature_timer
|
||||
temperature_bar.value = clamp(countdown, 0, player.temperature_endure)
|
||||
%TemperatureLabel.text = str(temperature_bar.value) + "/" + str(player.temperature_endure)
|
||||
|
||||
if time_of_day_bar != null:
|
||||
time_of_day_bar.max_value = 1
|
||||
time_of_day_bar.value = float(world.camp_manager.time_of_day) / world.camp_manager.day_length
|
||||
time_of_day_bar.self_modulate = calculate_time_of_day_color(world.camp_manager.time_of_day, world.camp_manager.day_length)
|
||||
%TimeOfDayLabel.text = calculate_display_time_of_day(world.camp_manager.time_of_day, world.camp_manager.day_length)
|
||||
if time_of_day_bar != null:
|
||||
time_of_day_bar.max_value = 1
|
||||
time_of_day_bar.value = float(world.camp_manager.time_of_day) / world.camp_manager.day_length
|
||||
time_of_day_bar.self_modulate = calculate_time_of_day_color(world.camp_manager.time_of_day, world.camp_manager.day_length)
|
||||
%TimeOfDayLabel.text = calculate_display_time_of_day(world.camp_manager.time_of_day, world.camp_manager.day_length)
|
||||
|
||||
|
||||
func calculate_display_time_of_day(current_time: int, day_length: int) -> String:
|
||||
# format as 24 hour clock, start at 06:00 and end at 21:00
|
||||
var start: int = 6
|
||||
var end: int = 21
|
||||
var hours_per_day: int = end - start
|
||||
var time_of_day: float = float(current_time) / day_length * hours_per_day + start
|
||||
var hours: int = int(time_of_day)
|
||||
var minutes: int = int((time_of_day - hours) * 60)
|
||||
hours %= 24
|
||||
return str(hours).pad_zeros(2) + ":" + str(minutes).pad_zeros(2)
|
||||
# format as 24 hour clock, start at 06:00 and end at 21:00
|
||||
var start: int = 6
|
||||
var end: int = 21
|
||||
var hours_per_day: int = end - start
|
||||
var time_of_day: float = float(current_time) / day_length * hours_per_day + start
|
||||
var hours: int = int(time_of_day)
|
||||
var minutes: int = int((time_of_day - hours) * 60)
|
||||
hours %= 24
|
||||
return str(hours).pad_zeros(2) + ":" + str(minutes).pad_zeros(2)
|
||||
|
||||
|
||||
func calculate_time_of_day_color(current_time: int, day_length: int) -> Color:
|
||||
var start: Color = Color(1, 1, 0)
|
||||
var end: Color = Color(1, 0, 0)
|
||||
var progress: float = float(current_time) / day_length
|
||||
progress = clamp(progress, 0, 1)
|
||||
progress = pow(progress, 2)
|
||||
return start.lerp(end, progress)
|
||||
var start: Color = Color(1, 1, 0)
|
||||
var end: Color = Color(1, 0, 0)
|
||||
var progress: float = float(current_time) / day_length
|
||||
progress = clamp(progress, 0, 1)
|
||||
progress = pow(progress, 2)
|
||||
return start.lerp(end, progress)
|
||||
|
||||
|
||||
func toggle_temperature_layer() -> void:
|
||||
world.tilemap_temperature.tilemap.visible = not world.tilemap_temperature.tilemap.visible
|
||||
world.tilemap_temperature.tilemap.visible = not world.tilemap_temperature.tilemap.visible
|
||||
|
||||
|
||||
func wait_for_key_press():
|
||||
waiting_for_input = true
|
||||
while waiting_for_input:
|
||||
await get_tree().process_frame
|
||||
waiting_for_input = true
|
||||
while waiting_for_input:
|
||||
await get_tree().process_frame
|
||||
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventKey and event.pressed:
|
||||
waiting_for_input = false
|
||||
if event is InputEventKey and event.pressed:
|
||||
waiting_for_input = false
|
||||
|
|
|
@ -16,148 +16,169 @@ var boat_leave_location: Vector2i = tilemap_types.EMPTY
|
|||
var time_of_day: int = 0
|
||||
var day_length: int = 1000
|
||||
|
||||
@export var required_boat_parts: int = 6
|
||||
@export var required_boat_parts: int = 8
|
||||
|
||||
|
||||
func setup() -> void:
|
||||
tilemap_interactive = game_manager.world.tilemap_interactive
|
||||
var camp_locations: Array[Vector2i] = tilemap_interactive.get_cells_by_type(tilemap_types.OBJECT_I_TENT)
|
||||
if len(camp_locations) > 0:
|
||||
camp = camp_locations[0]
|
||||
else:
|
||||
push_error("No camp location found on tilemap")
|
||||
tilemap_interactive = game_manager.world.tilemap_interactive
|
||||
var camp_locations: Array[Vector2i] = tilemap_interactive.get_cells_by_type(tilemap_types.OBJECT_I_TENT)
|
||||
if len(camp_locations) > 0:
|
||||
camp = camp_locations[0]
|
||||
else:
|
||||
push_error("No camp location found on tilemap")
|
||||
|
||||
var firepit_locations: Array[Vector2i] = tilemap_interactive.get_cells_by_type_collection(tilemap_types.OBJECT_COLLECTION_FIREPIT)
|
||||
if len(firepit_locations) > 0:
|
||||
campfire = firepit_locations[0]
|
||||
else:
|
||||
push_error("No firepit location found on tilemap")
|
||||
var firepit_locations: Array[Vector2i] = tilemap_interactive.get_cells_by_type_collection(tilemap_types.OBJECT_COLLECTION_FIREPIT)
|
||||
if len(firepit_locations) > 0:
|
||||
campfire = firepit_locations[0]
|
||||
else:
|
||||
push_error("No firepit location found on tilemap")
|
||||
|
||||
var boat_build_locations: Array[Vector2i] = tilemap_interactive.get_cells_by_type(tilemap_types.OBJECT_I_BOAT_NO_ENIGNE)
|
||||
if len(boat_build_locations) > 0:
|
||||
boat_build_location = boat_build_locations[0]
|
||||
else:
|
||||
push_error("No boat build location found on tilemap")
|
||||
var boat_build_locations: Array[Vector2i] = tilemap_interactive.get_cells_by_type(tilemap_types.OBJECT_I_BOAT_NO_ENIGNE)
|
||||
if len(boat_build_locations) > 0:
|
||||
boat_build_location = boat_build_locations[0]
|
||||
else:
|
||||
push_error("No boat build location found on tilemap")
|
||||
|
||||
var boat_leave_locations: Array[Vector2i] = tilemap_interactive.get_cells_by_type(tilemap_types.OBJECT_I_BOAT_WITH_ENGINE)
|
||||
if len(boat_leave_locations) > 0:
|
||||
boat_leave_location = boat_leave_locations[0]
|
||||
tilemap_interactive.set_cell(boat_leave_location, tilemap_types.EMPTY)
|
||||
else:
|
||||
push_error("No boat leave location found on tilemap")
|
||||
var boat_leave_locations: Array[Vector2i] = tilemap_interactive.get_cells_by_type(tilemap_types.OBJECT_I_BOAT_WITH_ENGINE)
|
||||
if len(boat_leave_locations) > 0:
|
||||
boat_leave_location = boat_leave_locations[0]
|
||||
tilemap_interactive.set_cell(boat_leave_location, tilemap_types.EMPTY)
|
||||
else:
|
||||
push_error("No boat leave location found on tilemap")
|
||||
|
||||
print("CampManager: camp=", camp, " campfire=", campfire, " boat_build_location=", boat_build_location, " boat_leave_location=", boat_leave_location)
|
||||
print("CampManager: camp=", camp, " campfire=", campfire, " boat_build_location=", boat_build_location, " boat_leave_location=", boat_leave_location)
|
||||
|
||||
tilemap_interactive.set_cell(campfire, tilemap_types.OBJECT_I_FIREPIT_OFF)
|
||||
tilemap_interactive.set_cell(campfire, tilemap_types.OBJECT_I_FIREPIT_OFF)
|
||||
|
||||
|
||||
func game_tick_start() -> void:
|
||||
time_of_day += 1
|
||||
time_of_day += 1
|
||||
|
||||
|
||||
func game_tick_end() -> void:
|
||||
if time_of_day == day_length:
|
||||
EventsTracker.track(EventsTracker.Event.TIME_SUNDOWN)
|
||||
if time_of_day == day_length:
|
||||
EventsTracker.track(EventsTracker.Event.TIME_SUNDOWN)
|
||||
|
||||
|
||||
func is_sundown() -> bool:
|
||||
return time_of_day >= day_length
|
||||
return time_of_day >= day_length
|
||||
|
||||
|
||||
func camp_contains_enough_sticks_to_light_campfire() -> bool:
|
||||
return camp_item_count(tilemap_types.OBJECT_I_STICK) >= 2
|
||||
return camp_item_count(tilemap_types.OBJECT_I_STICK) >= 2
|
||||
|
||||
|
||||
func camp_contains_item(item: Vector2i) -> bool:
|
||||
return camp_items.find(item) != -1
|
||||
return camp_items.find(item) != -1
|
||||
|
||||
|
||||
func camp_contains_item_collection(item: Array[Vector2i]) -> bool:
|
||||
for i in item:
|
||||
if camp_items.find(i) == -1:
|
||||
return false
|
||||
return true
|
||||
for i in item:
|
||||
if camp_items.find(i) == -1:
|
||||
return false
|
||||
return true
|
||||
|
||||
|
||||
func camp_item_count(item: Vector2i) -> int:
|
||||
var count: int = 0
|
||||
for i in camp_items:
|
||||
if i == item:
|
||||
count += 1
|
||||
return count
|
||||
var count: int = 0
|
||||
for i in camp_items:
|
||||
if i == item:
|
||||
count += 1
|
||||
return count
|
||||
|
||||
|
||||
func camp_item_collection_count(item: Array[Vector2i]) -> int:
|
||||
var count: int = 0
|
||||
for i in camp_items:
|
||||
if item.find(i) != -1:
|
||||
count += 1
|
||||
return count
|
||||
var count: int = 0
|
||||
for i in camp_items:
|
||||
if item.find(i) != -1:
|
||||
count += 1
|
||||
return count
|
||||
|
||||
|
||||
func camp_take_item(item: Vector2i, count: int = 1) -> bool:
|
||||
if camp_item_count(item) < count:
|
||||
push_error("CampManager: not enough items to take: " + str(item))
|
||||
EventsTracker.track(EventsTracker.Event.CAMP_TAKE_ITEM_FAILED, {"item": item, "count": count})
|
||||
return false
|
||||
if camp_item_count(item) < count:
|
||||
push_error("CampManager: not enough items to take: " + str(item))
|
||||
EventsTracker.track(EventsTracker.Event.CAMP_TAKE_ITEM_FAILED, {"item": item, "count": count})
|
||||
return false
|
||||
|
||||
var taken: int = 0
|
||||
for i in range(camp_items.size() - 1, -1, -1):
|
||||
if camp_items[i] == item:
|
||||
camp_items.remove_at(i)
|
||||
taken += 1
|
||||
if taken == count:
|
||||
break
|
||||
var taken: int = 0
|
||||
for i in range(camp_items.size() - 1, -1, -1):
|
||||
if camp_items[i] == item:
|
||||
camp_items.remove_at(i)
|
||||
taken += 1
|
||||
if taken == count:
|
||||
break
|
||||
|
||||
EventsTracker.track(EventsTracker.Event.CAMP_TAKEN_ITEM, {"item": item, "count": count})
|
||||
if game_manager:
|
||||
game_manager.update_camp_ui()
|
||||
return true
|
||||
EventsTracker.track(EventsTracker.Event.CAMP_TAKEN_ITEM, {"item": item, "count": count})
|
||||
return true
|
||||
|
||||
|
||||
func camp_add_item(item: Vector2i) -> void:
|
||||
camp_items.append(item)
|
||||
if tilemap_types.is_part_of_collection(tilemap_types.OBJECT_COLLECTION_BOAT_PARTS, item):
|
||||
if not boat_items.has(item):
|
||||
boat_items.append(item)
|
||||
EventsTracker.track(EventsTracker.Event.CAMP_ADDED_ITEM, {"item": item, "count": 1, "new_count": camp_item_count(item)})
|
||||
if game_manager:
|
||||
game_manager.update_camp_ui()
|
||||
|
||||
camp_items.append(item)
|
||||
EventsTracker.track(EventsTracker.Event.CAMP_ADDED_ITEM, {"item": item, "count": 1, "new_count": camp_item_count(item)})
|
||||
|
||||
|
||||
func campfire_light() -> bool:
|
||||
# requires two sticks in the camp
|
||||
if camp_take_item(tilemap_types.OBJECT_I_STICK, 2):
|
||||
tilemap_interactive.set_cell(campfire, tilemap_types.OBJECT_I_FIREPIT_ON)
|
||||
EventsTracker.track(EventsTracker.Event.CAMPFIRE_LIT)
|
||||
return true
|
||||
else:
|
||||
EventsTracker.track(EventsTracker.Event.CAMPFIRE_LIT_FAILED)
|
||||
return false
|
||||
# requires two sticks in the camp
|
||||
if camp_take_item(tilemap_types.OBJECT_I_STICK, 2):
|
||||
tilemap_interactive.set_cell(campfire, tilemap_types.OBJECT_I_FIREPIT_ON)
|
||||
EventsTracker.track(EventsTracker.Event.CAMPFIRE_LIT)
|
||||
return true
|
||||
else:
|
||||
EventsTracker.track(EventsTracker.Event.CAMPFIRE_LIT_FAILED)
|
||||
return false
|
||||
|
||||
|
||||
func campfire_extinguish() -> void:
|
||||
tilemap_interactive.set_cell(campfire, tilemap_types.OBJECT_I_FIREPIT_OFF)
|
||||
EventsTracker.track(EventsTracker.Event.CAMPFIRE_EXTINGUISHED)
|
||||
tilemap_interactive.set_cell(campfire, tilemap_types.OBJECT_I_FIREPIT_OFF)
|
||||
EventsTracker.track(EventsTracker.Event.CAMPFIRE_EXTINGUISHED)
|
||||
|
||||
var is_sleep_active: bool = false
|
||||
|
||||
|
||||
func sleep_effect() -> void:
|
||||
if is_sleep_active:
|
||||
return
|
||||
is_sleep_active = true
|
||||
EventsTracker.track(EventsTracker.Event.SLEEP)
|
||||
if is_sleep_active:
|
||||
return
|
||||
is_sleep_active = true
|
||||
EventsTracker.track(EventsTracker.Event.SLEEP)
|
||||
|
||||
game_manager.camera.go_to_zooming(game_manager.world.tilemap_player.cell_to_local(camp), 3)
|
||||
var tween_in: Tween = game_manager.world.get_tree().create_tween()
|
||||
tween_in.tween_method(game_manager.camera.set_vignette_intensity, 0.0, 1.0, 2.0).set_delay(0.5)
|
||||
var tween_out: Tween = game_manager.world.get_tree().create_tween()
|
||||
tween_out.tween_method(game_manager.camera.set_vignette_intensity, 1.0, 0.0, 2.0).set_delay(4.0)
|
||||
game_manager.camera.go_to_zooming(game_manager.world.tilemap_player.cell_to_local(camp), 3)
|
||||
var tween_in: Tween = game_manager.world.get_tree().create_tween()
|
||||
tween_in.tween_method(game_manager.camera.set_vignette_intensity, 0.0, 1.0, 2.0).set_delay(0.5)
|
||||
var tween_out: Tween = game_manager.world.get_tree().create_tween()
|
||||
tween_out.tween_method(game_manager.camera.set_vignette_intensity, 1.0, 0.0, 2.0).set_delay(4.0)
|
||||
|
||||
await game_manager.world.get_tree().create_timer(6.0).timeout
|
||||
await game_manager.world.get_tree().create_timer(6.0).timeout
|
||||
|
||||
print("Sleep effect done")
|
||||
is_sleep_active = false
|
||||
time_of_day = 0
|
||||
print("Sleep effect done")
|
||||
is_sleep_active = false
|
||||
time_of_day = 0
|
||||
|
||||
|
||||
func populate_camp_visualization(boat_ui: HBoxContainer, camp_ui: HBoxContainer) -> void:
|
||||
for child in boat_ui.get_children():
|
||||
if child.name != "HeightLabel":
|
||||
boat_ui.remove_child(child)
|
||||
|
||||
for boat_part in boat_items:
|
||||
var texture: TextureRect = create_item_texture(boat_part)
|
||||
boat_ui.add_child(texture)
|
||||
|
||||
for child in camp_ui.get_children():
|
||||
if child.name != "HeightLabel":
|
||||
camp_ui.remove_child(child)
|
||||
|
||||
for boat_part in camp_items:
|
||||
var texture: TextureRect = create_item_texture(boat_part)
|
||||
camp_ui.add_child(texture)
|
||||
|
||||
|
||||
func create_item_texture(item: Vector2i) -> TextureRect:
|
||||
var item_texture: Texture = game_manager.world.tilemap_interactive.get_cell_texture(item)
|
||||
if item_texture:
|
||||
var item_texture_rect: TextureRect = TextureRect.new()
|
||||
item_texture_rect.texture = item_texture
|
||||
item_texture_rect.set_expand_mode(TextureRect.EXPAND_FIT_WIDTH)
|
||||
item_texture_rect.set_stretch_mode(TextureRect.STRETCH_KEEP_ASPECT_CENTERED)
|
||||
return item_texture_rect
|
||||
return null
|
||||
|
|
Loading…
Reference in New Issue