Add the ability to destroy buildings

This commit is contained in:
Ategon 2024-09-23 20:36:55 -04:00
parent 974efa76cf
commit 02e05b95b2
10 changed files with 160 additions and 11 deletions

View file

@ -212,7 +212,7 @@ func _on_flood_level(data):
if building.has("workers"):
Persister.change_value("avail_population", building.workers)
elif build_data.type == "housing":
Persister.change_value("avail_population", -build_data.amount)
Persister.change_value("max_population", -build_data.amount)
ruins_spots.push_back(coords)
set_cell(coords, source, Vector2i(atlas,building.rand), 0)
@ -243,17 +243,30 @@ func pick_block():
Persister.persist_data("building_key", building_data[tile].key)
func destroy(tile: Vector2i):
if building_data.has(tile):
var building = building_data[tile]
var build_data = Data.data.buildings[building.key]
if building.has("workers"):
Persister.change_value("avail_population", building.workers)
elif build_data.type == "housing":
Persister.change_value("max_population", -build_data.amount)
building_data.erase(tile)
ruins_spots = ruins_spots.filter(func(coords): return coords != tile)
func place_building():
if Persister.get_value("win") or Persister.get_value("lose"):
return
var tile = local_to_map(get_global_mouse_position())
if building_spots.has(tile) and not building_data.has(tile) and not tree_spots.has(tile) and not rock_spots.has(tile) and not th_spots.has(tile) and not ruins_spots.has(tile):
if building_spots.has(tile) and not building_data.has(tile) and not tree_spots.has(tile) and not rock_spots.has(tile) and not th_spots.has(tile):
Persister.persist_data("building_mode", false)
building_data[tile] = {
"key": Persister.get_value("building_key"),
"rand": rand,
"level": level
"level": level,
"coords": tile
}
var build_data = Data.data.buildings[Persister.get_value("building_key")]
@ -282,3 +295,9 @@ func show_info_building():
var tile = local_to_map(get_global_mouse_position())
if building_data.has(tile):
Triggerer.trigger("show_info", building_data[tile])
elif ruins_spots.has(tile):
Triggerer.trigger("show_info", {
"key": "ruins",
"coords": tile,
"level": level
})

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=7 format=3 uid="uid://byyyhq3x8t2d8"]
[gd_scene load_steps=8 format=3 uid="uid://byyyhq3x8t2d8"]
[ext_resource type="Theme" uid="uid://d035h7upxrw3h" path="res://theme.tres" id="1_emusj"]
[ext_resource type="Script" path="res://info_window.gd" id="1_oy31s"]
@ -9,6 +9,9 @@
[sub_resource type="RectangleShape2D" id="RectangleShape2D_fnpfc"]
size = Vector2(15, 16)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_2wrr4"]
size = Vector2(41, 16)
[node name="InfoWindow" type="Control"]
layout_mode = 3
anchors_preset = 6
@ -148,9 +151,9 @@ anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = 3.0
offset_top = 26.0
offset_top = 16.0
offset_right = 69.0
offset_bottom = 66.0
offset_bottom = 56.0
grow_horizontal = 2
grow_vertical = 2
theme = ExtResource("1_emusj")
@ -304,6 +307,45 @@ offset_right = 33.5
offset_bottom = 80.0
grow_horizontal = 2
[node name="ColorRect6" type="ColorRect" parent="."]
self_modulate = Color(1, 1, 1, 0.647059)
layout_mode = 1
anchors_preset = 7
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = -20.5
offset_top = -28.0
offset_right = 20.5
offset_bottom = -12.0
grow_horizontal = 2
grow_vertical = 0
pivot_offset = Vector2(8, 9)
color = Color(0, 0, 0, 1)
[node name="RichTextLabel" type="RichTextLabel" parent="ColorRect6"]
clip_contents = false
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -11.0
offset_top = 5.0
offset_right = 14.0
offset_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_constants/outline_size = 3
bbcode_enabled = true
text = "[center]Destroy"
[node name="DestroyHandler" parent="ColorRect6" instance=ExtResource("5_38jqb")]
[node name="CollisionShape2D" type="CollisionShape2D" parent="ColorRect6/DestroyHandler"]
position = Vector2(20.5, 8)
shape = SubResource("RectangleShape2D_2wrr4")
[connection signal="clicked" from="ColorRect5/MouseHandler3" to="." method="_on_mouse_handler_3_clicked"]
[connection signal="hovered" from="ColorRect5/MouseHandler3" to="." method="_on_mouse_handler_3_hovered"]
[connection signal="unhovered" from="ColorRect5/MouseHandler3" to="." method="_on_mouse_handler_3_unhovered"]
@ -313,3 +355,6 @@ grow_horizontal = 2
[connection signal="clicked" from="ResourceAllocation/ColorRect3/MouseHandler2" to="." method="_on_mouse_handler_2_clicked"]
[connection signal="hovered" from="ResourceAllocation/ColorRect3/MouseHandler2" to="." method="_on_mouse_handler_2_hovered"]
[connection signal="unhovered" from="ResourceAllocation/ColorRect3/MouseHandler2" to="." method="_on_mouse_handler_2_unhovered"]
[connection signal="clicked" from="ColorRect6/DestroyHandler" to="." method="_on_destroy_handler_clicked"]
[connection signal="hovered" from="ColorRect6/DestroyHandler" to="." method="_on_destroy_handler_hovered"]
[connection signal="unhovered" from="ColorRect6/DestroyHandler" to="." method="_on_destroy_handler_unhovered"]

View file

@ -14,12 +14,14 @@ var window_tween
@onready var color_rect_3: ColorRect = $ResourceAllocation/ColorRect3
@onready var color_rect_4: ColorRect = $ResourceAllocation/ColorRect4
@onready var description_2: RichTextLabel = $ResourceAllocation/Description2
@onready var color_rect_6: ColorRect = $ColorRect6
var recent_data
var close_tween
var minus_tween
var plus_tween
var destroy_tween
func _ready() -> void:
Triggerer.listen("show_info", _show_info_window)
@ -51,7 +53,7 @@ func _show_info_window(data):
window_tween.tween_callback(func():
title.text = "[center]%s" % [building_data.name]
icon.texture = Data.data.images[data.key]
subtitle.text = "[center]%s" % [building_data.short]
subtitle.text = "[center]%s" % [building_data.short if building_data.has("short") else ""]
if data.has("workers"):
rich_text_label_2.text = "[center]%d/%d" % [data.workers, data.max_workers]
description_3.text = "[center]EFFICIENCY: %d%%" % [data.efficiency]
@ -192,3 +194,42 @@ func _on_mouse_handler_3_unhovered() -> void:
close_tween.set_ease(Tween.EASE_OUT)
close_tween.set_trans(Tween.TRANS_QUAD)
close_tween.tween_property(color_rect_5, "scale", Vector2.ONE, 0.25)
func _on_destroy_handler_clicked() -> void:
Triggerer.trigger("destroy", {"tile": recent_data.coords})
Triggerer.trigger("hide_info")
var data = Data.data.buildings[recent_data.key]
if data.has("cost"):
for key in data.cost:
Persister.change_value(key, ceil(data.cost[key]/2))
if destroy_tween:
destroy_tween.kill()
destroy_tween = create_tween()
destroy_tween.set_trans(Tween.TRANS_QUAD)
destroy_tween.tween_property(color_rect_6, "scale", Vector2.ONE * 0.95, 0.125)
destroy_tween.tween_property(color_rect_6, "scale", Vector2.ONE, 0.125)
func _on_destroy_handler_hovered() -> void:
if destroy_tween:
destroy_tween.kill()
destroy_tween = create_tween()
destroy_tween.set_ease(Tween.EASE_OUT)
destroy_tween.set_trans(Tween.TRANS_BACK)
destroy_tween.tween_property(color_rect_6, "scale", Vector2.ONE * 1.05, 0.25)
func _on_destroy_handler_unhovered() -> void:
if close_tween:
close_tween.kill()
destroy_tween = create_tween()
destroy_tween.set_ease(Tween.EASE_OUT)
destroy_tween.set_trans(Tween.TRANS_QUAD)
destroy_tween.tween_property(color_rect_6, "scale", Vector2.ONE, 0.25)

View file

@ -14,6 +14,7 @@ var timer2 = 0
func _ready() -> void:
Triggerer.listen("game_started", _on_game_started)
Triggerer.listen("destroy", _on_destroy)
func _on_game_started(_data):
@ -90,6 +91,13 @@ func _process(delta: float) -> void:
timer -= 5
func _on_destroy(data):
var tile = data.tile
for build_level in building_levels:
build_level.destroy(tile)
func _kill_citizen():
for build_level in building_levels:
var val = build_level.kill_citizen()

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bq1pxqo5u270n"
path="res://.godot/imported/ruins.png-d04f8883378a9d2a2942e00c3b80056b.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://parts/buildings/images/ruins.png"
dest_files=["res://.godot/imported/ruins.png-d04f8883378a9d2a2942e00c3b80056b.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View file

@ -0,0 +1,2 @@
name: Ruins
short: A ruined building

View file

@ -1,7 +1,7 @@
time_to_flood_change: 25
time_to_flood_change: 10
flood_levels[]
0
1
4
0
1
2

View file

@ -2,7 +2,7 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://cps3axbh7qgc0"
uid="uid://dok8p5jnxckak"
path="res://.godot/imported/tiles_ruined_houses.png-11ac51b49ecd60169c9343b644bb8b82.ctex"
metadata={
"vram_texture": false

View file

@ -37,7 +37,7 @@ func swap_to_tab(index):
else:
tabs[i].unselect()
var filtered_buildings = buildings.filter(func(building): return building_data[building].type == tabs[index].key and (not building_data[building].has("disabled") or not building_data[building].disabled))
var filtered_buildings = buildings.filter(func(building): return building_data[building].has("type") and building_data[building].type == tabs[index].key and (not building_data[building].has("disabled") or not building_data[building].disabled))
for i in range(0, icons.size()):
if i < filtered_buildings.size():