Merge pull request #27 from STEMuli-Tx/feature/propogate-starting-structure-and-unlocks

Created Global function to unlock structures and then setup listener …
pull/18/head^2
jc-stemuli 2025-05-08 16:07:56 +07:00 committed by GitHub
commit 8eddc5fb32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
29 changed files with 88 additions and 79 deletions

@ -3,6 +3,7 @@ extends Node
signal population_update(count:int)
signal receive_data_from_browser(args)
signal set_structure(structure:Structure)
signal structure_unlocked(structure:Structure)
var current_scene = null

@ -26,4 +26,8 @@ func set_structure(structure:Structure) -> void:
# Emit the signal to notify other nodes
EventBus.set_structure.emit(structure)
# Used when a new structure is unlocked
func structure_unlocked(structure:Structure) ->void:
EventBus.structure_unlocked.emit(structure)

@ -9,7 +9,7 @@ script = ExtResource("1_objective")
type = 0
target_count = 3
current_count = 0
description = "Build 3 Type A houses to unlock all building types"
description = "Build 3 Fountains to unlock all homes!"
completed = false
structure = ExtResource("2_hfe31")

@ -32,11 +32,8 @@ layout_mode = 2
[node name="Roads" type="MenuButton" parent="Panel/VBoxContainer/Row_1_HBoxContainer"]
layout_mode = 2
tooltip_text = "Residential Structures"
tooltip_text = "Roads"
icon = ExtResource("6_46yqr")
item_count = 1
popup/item_0/text = "Residential"
popup/item_0/id = 0
script = ExtResource("2_sqdls")
[node name="Residential" type="MenuButton" parent="Panel/VBoxContainer/Row_1_HBoxContainer"]
@ -61,7 +58,7 @@ filter_type = 2
[node name="Industrial" type="MenuButton" parent="Panel/VBoxContainer/Row_2_HBoxContainer2"]
layout_mode = 2
tooltip_text = "Residential Structures"
tooltip_text = "Industrial Structures"
icon = ExtResource("4_ebilp")
item_count = 1
popup/item_0/text = "Residential"
@ -74,14 +71,14 @@ layout_mode = 2
[node name="Power" type="MenuButton" parent="Panel/VBoxContainer/Row_3_HBoxContainer3"]
layout_mode = 2
tooltip_text = "Commercial Structures"
tooltip_text = "Power Structures"
icon = ExtResource("6_r3beh")
script = ExtResource("2_sqdls")
filter_type = 6
[node name="Landscape" type="MenuButton" parent="Panel/VBoxContainer/Row_3_HBoxContainer3"]
layout_mode = 2
tooltip_text = "Commercial Structures"
tooltip_text = "Landscaping"
icon = ExtResource("5_46yqr")
script = ExtResource("2_sqdls")
filter_type = 5

@ -15,7 +15,10 @@ func _ready():
# Add to group for easy refreshing of all structure menus
add_to_group("structure_menus")
EventBus.structure_unlocked.connect(_on_structure_unlock)
# Load icons (you'll need to create or find these icons)
_lock_icon = load("res://sprites/sticky_builder_icons/lock.png") if ResourceLoader.exists("res://sprites/sticky_builder_icons/lock.png") else null
if(_lock_icon):
@ -60,6 +63,8 @@ func _populate_menu():
popup.clear()
var current_size_category = -1
var menu_item_to_structure_index = {} # Map menu item IDs to structure indices
var current_item_id = 0
for i in range(_structures.size()):
var structure = _structures[i]
@ -67,6 +72,7 @@ func _populate_menu():
if structure.size_category != current_size_category:
if i > 0:
popup.add_separator()
current_item_id += 1
current_size_category = structure.size_category
# Add size category header (optional)
@ -107,16 +113,24 @@ func _populate_menu():
if not structure.unlocked:
if _lock_icon:
popup.add_icon_item(_lock_icon, item_text)
popup.set_item_disabled(popup.item_count - 1, true)
popup.set_item_disabled(current_item_id, true)
menu_item_to_structure_index[current_item_id] = i
current_item_id += 1
else:
popup.add_item(item_text, i)
var icon = load(structure.icon) if ResourceLoader.exists(structure.icon) else null
popup.add_icon_item(icon, item_text)
menu_item_to_structure_index[current_item_id] = i
current_item_id += 1
# Store the mapping for use in _on_item_selected
set_meta("menu_item_to_structure_index", menu_item_to_structure_index)
# Handle the menu item selection
func _on_item_selected(id: int):
if id >= 0 and id < _structures.size():
var selected_structure = _structures[id]
# Get the original structure index in the builder's structure array
var structure_resource_path = selected_structure.resource_path
var menu_item_to_structure_index = get_meta("menu_item_to_structure_index", {})
if id in menu_item_to_structure_index:
var structure_index = menu_item_to_structure_index[id]
var selected_structure = _structures[structure_index]
Globals.set_structure(selected_structure)
# Consume the input event to prevent it from reaching the game
get_viewport().set_input_as_handled()
@ -178,3 +192,6 @@ func _unhandled_input(event: InputEvent) -> void:
get_viewport().set_input_as_handled()
if event is InputEventMouseButton:
event.pressed = false
func _on_structure_unlock(structure:Structure)->void:
refresh()

@ -578,8 +578,13 @@ func action_clear_selection():
# Toggle between structures to build
func action_structure_toggle(structure:Structure):
var found_index = _structures.find(structure)
if not found_index:
var found_index = -1
for i in range(_structures.size()):
if _structures[i].resource_path == structure.resource_path:
found_index = i
break
if found_index == -1:
print("No structure found!")
else:
index = found_index

@ -166,7 +166,7 @@ func _create_filter_buttons():
# Get unique structure types
var structure_types = {}
for structure in builder.get_structures():
if structure.type == Structure.StructureType.TERRAIN:
if structure.type == Structure.StructureType.LANDSCAPE:
structure_types["Ground"] = true
else:
structure_types["Buildings"] = true
@ -216,14 +216,14 @@ func _create_option_buttons():
if current_filter != "All":
match current_filter:
"Ground":
if structure.type != Structure.StructureType.TERRAIN:
if structure.type != Structure.StructureType.LANDSCAPE:
continue
"Buildings":
if structure.type == Structure.StructureType.TERRAIN:
if structure.type == Structure.StructureType.LANDSCAPE:
continue
# Add to appropriate list
if structure.type == Structure.StructureType.TERRAIN:
if structure.type == Structure.StructureType.LANDSCAPE:
ground_structures.append(structure)
else:
building_structures.append(structure)

@ -93,6 +93,8 @@ func _unlock_starting_structures(structure_paths: Array) -> void:
if structure_path == possible_path:
structure.unlocked = true
found_match = true
# Let the rest of the game know a structure has been unlocked
Globals.structure_unlocked(structure)
break
if found_match:

@ -864,6 +864,7 @@ func _handle_structure_unlocking(mission):
if "unlocked" in structure:
structure.unlocked = true
unlocked_structures.append(structure)
Globals.structure_unlocked(structure)
found = true
if not found:
print("[Unlock] No match found for item_path: ", item_path)

@ -39,6 +39,10 @@ enum SizeCategory {
@export_subgroup("Visual")
@export var selector_scale:float = 1.0 # Scale factor for the selector when this structure is selected
@export var thumbnail: String = "Thumbnail" # Display for player
@export var icon: String = "" # Small version of thumbnail. I know thumbnail should be small... But I messed up already so here we are xD.
@export_subgroup("Game Progression")
@export var unlocked:bool = false # Whether this structure is available to the player
@ -48,7 +52,3 @@ enum SizeCategory {
@export_subgroup("Game Progression")
@export var description: String = "Description" # Whether this structure is available to the player
@export_subgroup("Game Progression")
@export var thumbnail: String = "Thumbnail" # Whether this structure is available to the player

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 KiB

@ -1,34 +0,0 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://3wvmf0xvpx53"
path="res://.godot/imported/power-plant.png-ab18836cf433027f79b47cfc0a22f79a.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/updated/power-plant.png"
dest_files=["res://.godot/imported/power-plant.png-ab18836cf433027f79b47cfc0a22f79a.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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 267 KiB

After

Width:  |  Height:  |  Size: 120 KiB

@ -14,7 +14,8 @@ population_count = 0
kW_usage = 0.0
kW_production = 0.0
selector_scale = 2.8
thumbnail = "res://sprites/updated/garage.png"
icon = "res://sprites/updated/icon/garage_icon.png"
unlocked = false
spawn_builder = true
description = "Garage"
thumbnail = "res://sprites/updated/garage.png"

@ -14,7 +14,8 @@ population_count = 1
kW_usage = 1.0
kW_production = 0.0
selector_scale = 2.8
thumbnail = "res://sprites/updated/building-small-a.png"
icon = "res://sprites/updated/icon/building-small-a_icon.png"
unlocked = false
spawn_builder = false
spawn_builder = true
description = "A small residential building that can house 1 person. Perfect for getting your city started!"
thumbnail = "res://sprites/updated/building-small-a.png"

@ -7,14 +7,15 @@
script = ExtResource("2_a2t3e")
title = "Medium Residential"
type = 1
price = 60
price = 100
size_category = 1
model = ExtResource("1_klt7o")
population_count = 10
kW_usage = 1.0
kW_production = 0.0
selector_scale = 2.8
thumbnail = "res://sprites/updated/building-small-b.png"
icon = "res://sprites/updated/icon/building-small-b_icon.png"
unlocked = false
spawn_builder = false
spawn_builder = true
description = "A slightly larger residential building that can house 1 person. A good upgrade from the basic house!"
thumbnail = "res://sprites/updated/building-small-b.png"

@ -7,14 +7,15 @@
script = ExtResource("2_rkiq0")
title = "Large Residential"
type = 1
price = 70
price = 200
size_category = 2
model = ExtResource("1_6yyww")
population_count = 20
kW_usage = 1.0
kW_production = 0.0
selector_scale = 2.8
thumbnail = "res://sprites/updated/building-small-c.png"
icon = "res://sprites/updated/icon/building-small-c_icon.png"
unlocked = false
spawn_builder = true
description = "A spacious multi-story apartment complex that comfortably houses 5 citizens, providing efficient population growth for your expanding city."
thumbnail = "res://sprites/updated/building-small-c.png"

@ -7,14 +7,15 @@
script = ExtResource("2_b2sah")
title = "Tall Trees"
type = 5
price = 25
price = 50
size_category = 0
model = ExtResource("1_nbdd1")
population_count = 0
kW_usage = 0.0
kW_production = 0.0
selector_scale = 2.8
thumbnail = "res://sprites/updated/grass-trees-tall.png"
icon = "res://sprites/updated/icon/grass-trees-tall_icon.png"
unlocked = false
spawn_builder = false
description = "A lush area featuring small trees that provides shade, clean air, and a pleasant atmosphere for nearby residents."
thumbnail = "res://sprites/updated/grass-trees-tall.png"

@ -14,7 +14,8 @@ population_count = 0
kW_usage = 0.0
kW_production = 0.0
selector_scale = 2.8
thumbnail = "res://sprites/updated/grass-trees.png"
icon = "res://sprites/updated/icon/grass-trees_icon.png"
unlocked = false
spawn_builder = false
description = "Some cool trees and grass!"
thumbnail = "res://sprites/updated/grass-trees.png"

@ -14,7 +14,8 @@ population_count = 0
kW_usage = 0.0
kW_production = 0.0
selector_scale = 2.8
thumbnail = "res://sprites/updated/grass.png"
icon = "res://sprites/updated/icon/grass_icon.png"
unlocked = false
spawn_builder = false
description = "Some lush green grass!"
thumbnail = "res://sprites/residential/grass.png"

@ -14,7 +14,8 @@ population_count = 0
kW_usage = 0.0
kW_production = 0.0
selector_scale = 2.8
thumbnail = "res://sprites/updated/fountain.png"
icon = "res://sprites/updated/icon/fountain_icon.png"
unlocked = false
spawn_builder = false
description = "A beautiful centerpiece that adds charm to your city while providing citizens with a place to relax and socialize."
thumbnail = "res://sprites/updated/fountain.png"

@ -14,7 +14,8 @@ population_count = 0
kW_usage = 0.0
kW_production = 0.0
selector_scale = 2.8
thumbnail = "res://sprites/updated/icon/pavement_icon.png"
icon = "res://sprites/updated/icon/pavement_icon.png"
unlocked = false
spawn_builder = false
description = "A pedestrian-friendly surface that creates walkable areas and enhances the appearance of your city spaces."
thumbnail = "res://sprites/updated/pavement.png"

@ -14,7 +14,8 @@ population_count = 0
kW_usage = 0.0
kW_production = 40.0
selector_scale = 2.8
thumbnail = "res://sprites/updated/power_plant.png"
icon = "res://sprites/updated/icon/power_plant_icon.png"
unlocked = false
spawn_builder = false
description = "A power-generating facility that produces electricity to keep your city's buildings operational and citizens happy. Produces 40 kW of energy."
thumbnail = "res://sprites/updated/power-plant.png"

@ -14,7 +14,8 @@ population_count = 0
kW_usage = 0.0
kW_production = 0.0
selector_scale = 2.8
thumbnail = "res://sprites/roads/road-corner.png"
icon = "res://sprites/roads/icon/road-corner_icon.png"
unlocked = false
spawn_builder = false
description = "A gently curved road section that helps create more natural and flowing city layouts."
thumbnail = "res://sprites/roads/road-corner.png"

@ -14,7 +14,8 @@ population_count = 0
kW_usage = 0.0
kW_production = 0.0
selector_scale = 2.8
thumbnail = "res://sprites/roads/intersection.png"
icon = "res://sprites/roads/icon/intersection_icon.png"
unlocked = false
spawn_builder = false
description = "A crucial junction where roads meet, allowing traffic to flow in multiple directions throughout your city."
thumbnail = "res://sprites/updated/road-intersection.png"

@ -14,7 +14,8 @@ population_count = 0
kW_usage = 0.0
kW_production = 0.0
selector_scale = 2.8
thumbnail = "res://sprites/updated/road-split.png"
icon = "res://sprites/updated/icon/road-split_icon.png"
unlocked = false
spawn_builder = false
description = "Road Split"
thumbnail = "res://sprites/updated/road-split.png"

@ -14,7 +14,8 @@ population_count = 0
kW_usage = 0.0
kW_production = 0.0
selector_scale = 2.8
thumbnail = "res://sprites/updated/icon/road-straight-light_icon.png"
icon = "res://sprites/updated/icon/road-straight-light_icon.png"
unlocked = false
spawn_builder = false
description = "An illuminated road segment that provides safety and visibility for your citizens at night."
thumbnail = "res://sprites/updated/road-straight-light.png"

@ -14,7 +14,8 @@ population_count = 0
kW_usage = 0.0
kW_production = 0.0
selector_scale = 2.8
thumbnail = "res://sprites/updated/road-straight.png"
icon = "res://sprites/updated/icon/road-straight_icon.png"
unlocked = false
spawn_builder = false
description = "A basic road for connecting parts of your city."
thumbnail = "res://sprites/updated/road-straight.png"

@ -14,7 +14,8 @@ population_count = 0
kW_usage = 1.0
kW_production = 0.0
selector_scale = 2.8
thumbnail = "res://sprites/updated/store.png"
icon = "res://sprites/updated/icon/store_icon.png"
unlocked = false
spawn_builder = true
description = "A commercial building where citizens can purchase goods, providing essential services while generating income for your city."
thumbnail = "res://sprites/updated/store.png"