From 439cbf576786b223eb89520fd9e6427ce117ac60 Mon Sep 17 00:00:00 2001 From: Ategon Date: Mon, 23 Sep 2024 21:07:44 -0400 Subject: [PATCH] Add basic error pings to buildings --- BuildingLevel.gd | 29 +++++++++++++++++++++++++++++ ErrorPing.tscn | 13 +++++++++++++ error_ping.gd | 18 ++++++++++++++++++ info_window.gd | 5 ++++- parts/globals.txt | 4 ++-- 5 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 ErrorPing.tscn create mode 100644 error_ping.gd diff --git a/BuildingLevel.gd b/BuildingLevel.gd index cd9842e..d9323ca 100644 --- a/BuildingLevel.gd +++ b/BuildingLevel.gd @@ -6,6 +6,7 @@ extends TileMapLayer @export var th_spots: Array[Vector2i] @export var level: int var ruins_spots: Array[Vector2i] +var error_pings: Dictionary var building_data = {} var last_tile @@ -16,6 +17,7 @@ var rand = 0 const NAME_ICON = preload("res://NameIcon.tscn") const RESOURCE_GAIN = preload("res://ResourceGain.tscn") +const ERROR_PING = preload("res://ErrorPing.tscn") var building_to_tile_map = { "tents": { @@ -131,6 +133,16 @@ func _process(delta: float) -> void: if building.has("workers"): var close_bonus = 1.0 + if building.workers == 0 and not error_pings.has(coords): + var new_ping = ERROR_PING.instantiate() + new_ping.type = "workers" + new_ping.position = map_to_local(coords) + Vector2(2, -10) + add_sibling(new_ping) + error_pings[coords] = new_ping + elif building.workers != 0 and error_pings.has(coords) and error_pings[coords].type == "workers": + error_pings[coords].queue_free() + error_pings.erase(coords) + if building.key == "woodcutter": if tree_spots.size() == 0: close_bonus = 0 @@ -172,6 +184,16 @@ func _process(delta: float) -> void: close_bonus = (3 - amount) building.efficiency = (100 + Persister.get_value("conduit_bonus", PersisterEnums.Scope.UNKNOWN, 0)) * building.workers * 0.5 * close_bonus + + if building.efficiency == 0 and not building.workers == 0 and not error_pings.has(coords): + var new_ping = ERROR_PING.instantiate() + new_ping.type = "resources" + new_ping.position = map_to_local(coords) + Vector2(2, -10) + add_sibling(new_ping) + error_pings[coords] = new_ping + elif (building.efficiency != 0 or building.workers == 0) and error_pings.has(coords) and error_pings[coords].type == "resources": + error_pings[coords].queue_free() + error_pings.erase(coords) last_tile = tile @@ -217,6 +239,10 @@ func _on_flood_level(data): ruins_spots.push_back(coords) set_cell(coords, source, Vector2i(atlas,building.rand), 0) building_data.clear() + + for error_ping in error_pings: + error_pings[error_ping].queue_free() + error_pings.clear() func kill_citizen(): @@ -253,6 +279,9 @@ func destroy(tile: Vector2i): Persister.change_value("max_population", -build_data.amount) building_data.erase(tile) ruins_spots = ruins_spots.filter(func(coords): return coords != tile) + if error_pings.has(tile): + error_pings[tile].queue_free() + error_pings.erase(tile) func place_building(): diff --git a/ErrorPing.tscn b/ErrorPing.tscn new file mode 100644 index 0000000..258cf6f --- /dev/null +++ b/ErrorPing.tscn @@ -0,0 +1,13 @@ +[gd_scene load_steps=2 format=3 uid="uid://ctpkwdh7lprae"] + +[ext_resource type="Script" path="res://error_ping.gd" id="1_5564w"] + +[node name="ErrorPing" type="ColorRect"] +z_index = 1 +offset_left = -2.0 +offset_top = -2.0 +offset_right = 2.0 +offset_bottom = 2.0 +pivot_offset = Vector2(2, 2) +color = Color(1, 0.121569, 0.113725, 1) +script = ExtResource("1_5564w") diff --git a/error_ping.gd b/error_ping.gd new file mode 100644 index 0000000..42c8542 --- /dev/null +++ b/error_ping.gd @@ -0,0 +1,18 @@ +extends ColorRect + +var type + +func _ready() -> void: + scale = Vector2.ZERO + + var tween = create_tween() + tween.set_ease(Tween.EASE_IN_OUT) + tween.set_trans(Tween.TRANS_QUAD) + tween.set_loops() + tween.tween_property(self, "modulate", Color(1, 1, 1, 0.75), 1) + tween.tween_property(self, "modulate", Color.WHITE, 1) + + var tween2 = create_tween() + tween2.set_ease(Tween.EASE_OUT) + tween2.set_trans(Tween.TRANS_BACK) + tween2.tween_property(self, "scale", Vector2.ONE, 0.5) diff --git a/info_window.gd b/info_window.gd index 6c1fbba..2a90f00 100644 --- a/info_window.gd +++ b/info_window.gd @@ -75,7 +75,10 @@ func _process(delta: float) -> void: color_rect_4.scale.x = (float(recent_data.progress) / Data.data.buildings[recent_data.key].time) if recent_data and recent_data.has("workers") and recent_data.workers > 0: - description_2.text = "[center]STATUS: WORKING" + if recent_data.efficiency == 0: + description_2.text = "[center]STATUS: NO RESOURCES" + else: + description_2.text = "[center]STATUS: WORKING" else: description_2.text = "[center]STATUS: STOPPED" diff --git a/parts/globals.txt b/parts/globals.txt index 12e0ef5..3add872 100644 --- a/parts/globals.txt +++ b/parts/globals.txt @@ -1,7 +1,7 @@ -time_to_flood_change: 10 +time_to_flood_change: 25 flood_levels[] 0 - 4 + 1 0 1 2