2024/Mar #14

Merged
gitea merged 19 commits from 2024/Mar into main 2024-04-09 10:13:41 -05:00
8 changed files with 53 additions and 9 deletions
Showing only changes of commit d74bfda9a3 - Show all commits

View File

@@ -37,3 +37,6 @@ func get_location_data(pos: Vector2i) -> CellData:
func change_location_resource(pos: Vector2i, data: GameResource) -> void:
world_data[pos].change_resource(data)
world_grid.set_cell(Constants.TilemapLayers.ENVIRONMENT, pos, 0, data.atlas_location)
func change_location_building(pos: Vector2i, data: BuildingBase) -> void:
world_data[pos].change_building(data)

View File

@@ -1,4 +1,4 @@
extends Node
signal changed_resource
@export var resources := {}
@@ -10,6 +10,29 @@ func _on_gained_resource(res: GameResource) -> void:
}
changed_resource.emit(ResourceChangedSignal.new(changed_resources))
func pickup(resource: GameResource) -> void:
if not resources.has(resource):
resources[resource] = 0
resources[resource] += resource.pickup_value
var changed_resources := {
resource: resource.pickup_value
}
changed_resource.emit(ResourceChangedSignal.new(changed_resources))
func has_amount(res: GameResource, amount: int) -> bool:
return resources[res] >= amount if resources.has(res) else false
func has_resources(cost: Dictionary) -> bool:
return cost.keys().reduce(func(accum, res): return accum and has_amount(res, cost[res]), true)
func use_resources(cost: Dictionary) -> void:
var changed_resources := {
}
for res in cost.keys():
resources[res] -= cost[res]
changed_resources[res] = -cost[res]
changed_resource.emit(ResourceChangedSignal.new(changed_resources))
#func _on_timer_timeout() -> void:
#var corrupted_resources := Grid.get_corrupted_resources()
#if corrupted_resources.size() > 0:

View File

@@ -20,7 +20,7 @@ const BASIC_BUILDING_GROUP = preload("res://data/buildings/basic/basic_building_
func _ready() -> void:
_add_building_group(BASIC_BUILDING_GROUP)
_add_building_group(ADVANCED_BUILDING_GROUP)
building_groups.set_focus()
#building_groups.set_focus()
func _add_building_group(group: BuildingGroup) -> void:
building_groups.add_item(group.name, group.atlas_texture)
@@ -55,6 +55,8 @@ func _on_buildings_item_selected(index: int) -> void:
build_materials.add_child(image)
var label = Label.new()
label.text = str(selected_building.cost[res])
if not ResourceManager.has_amount(res, selected_building.cost[res]):
label.add_theme_color_override("font_color", Color.RED)
build_materials.add_child(label)
description.show()

View File

@@ -25,6 +25,9 @@ func change_layer(layer: int, data: Variant) -> bool:
func change_resource(data: GameResource) -> void:
layer_info[Constants.TilemapLayers.ENVIRONMENT] = data
func change_building(data: BuildingBase) -> void:
layer_info[Constants.TilemapLayers.BUILDINGS] = data
func get_resource() -> GameResource:
return layer_info[Constants.TilemapLayers.ENVIRONMENT] as GameResource
@@ -44,7 +47,7 @@ func is_interactable() -> bool:
return has_resource() or has_building()
func is_buildable() -> bool:
return not has_resource() or not has_building()
return not has_resource() and not has_building()
func get_interaction_options() -> Array[Interaction]:
var interactions: Array[Interaction] = []

View File

@@ -6,6 +6,9 @@ const SCIFI_TILESHEET = preload("res://assets/scifi_tilesheet@2.png")
var _resource_displays := {}
func _ready() -> void:
ResourceManager.changed_resource.connect(_on_resource_manager_changed_resource)
func _on_resource_manager_changed_resource(changed: ResourceChangedSignal) -> void:
for resource: GameResource in changed.changed_resources.keys():
if not _resource_displays.has(resource):

View File

@@ -15,5 +15,5 @@ func _ready() -> void:
func _cleanup_gather() -> void:
interaction_finished.emit()
var res: GameResource = Grid.get_location_data(grid_position).get_resource()
res.gained_resource.emit(res)
ResourceManager.pickup(res)
self.queue_free()

View File

@@ -35,13 +35,12 @@ func _physics_process(delta: float) -> void:
if _build_placement:
_build_placement.position = Grid.grid_to_world_center(interaction_location)
_build_placement.self_modulate = Color(0, 1, 0, 0.5) if Grid.get_location_data(interaction_location).is_buildable() else Color(1, 0, 0, 0.4)
func _input(event: InputEvent) -> void:
if event.is_action_pressed("interact"):
if _attempting_build and Grid.get_location_data(interaction_location).is_buildable():
var build: BuildingBase = BUILDING_BASE.instantiate()
build.initialize(_attempting_build, interaction_location)
add_sibling(build)
_build()
elif not _interacting and Grid.get_location_data(interaction_location).is_interactable():
var interaction = INTERACTION_BAR.instantiate()
interaction.interaction_finished.connect(_on_interaction_finished)
@@ -64,6 +63,18 @@ func _on_build_menu_build(building: Building) -> void:
_build_placement.self_modulate = Color(1, 0, 0, 0.4)
add_sibling(_build_placement)
func _build() -> void:
ResourceManager.use_resources(_attempting_build.cost)
var build: BuildingBase = BUILDING_BASE.instantiate()
build.initialize(_attempting_build, interaction_location)
add_sibling(build)
Grid.change_location_building(interaction_location, build)
if not ResourceManager.has_resources(_attempting_build.cost):
_attempting_build = null
_build_placement.queue_free()
_build_placement = null
func _on_interation_options_closed() -> void:
_interaction_options = null

View File

@@ -14,7 +14,6 @@ var noise_regions := [-999,0,999]
var atlas_regions := [Vector2i(0,1),Vector2i(0,0)]
@onready var world_grid: TileMap = $world_grid
@onready var resource_manager: Node2D = $ResourceManager
func get_noise_value(x: int, y: int):
return terrain_noise.get_noise_2d(x,y) * 500
@@ -62,7 +61,7 @@ func corrupt_location(loc: Vector2i):
func add_resources_to_map() -> void:
for res: GameResource in game_resources:
res.gained_resource.connect(resource_manager._on_gained_resource)
#res.gained_resource.connect(ResourceManager._on_gained_resource)
var spawns = res.get_spawn_locations()
for spawn in spawns:
Grid.change_location_resource(spawn, res)