Add basic error pings to buildings
This commit is contained in:
parent
02e05b95b2
commit
439cbf5767
5 changed files with 66 additions and 3 deletions
|
@ -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():
|
||||
|
|
13
ErrorPing.tscn
Normal file
13
ErrorPing.tscn
Normal file
|
@ -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")
|
18
error_ping.gd
Normal file
18
error_ping.gd
Normal file
|
@ -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)
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
time_to_flood_change: 10
|
||||
time_to_flood_change: 25
|
||||
flood_levels[]
|
||||
0
|
||||
4
|
||||
1
|
||||
0
|
||||
1
|
||||
2
|
||||
|
|
Loading…
Reference in a new issue