Compare commits
2 Commits
ca8cfee1e8
...
d74bfda9a3
| Author | SHA1 | Date | |
|---|---|---|---|
| d74bfda9a3 | |||
| 856b6a0400 |
@@ -18,6 +18,7 @@ config/icon="res://icon.svg"
|
|||||||
[autoload]
|
[autoload]
|
||||||
|
|
||||||
Grid="*res://scripts/autoloads/grid.gd"
|
Grid="*res://scripts/autoloads/grid.gd"
|
||||||
|
ResourceManager="*res://scripts/autoloads/resource_manager.gd"
|
||||||
|
|
||||||
[debug]
|
[debug]
|
||||||
|
|
||||||
@@ -29,6 +30,38 @@ theme/custom="res://data/world_theme.tres"
|
|||||||
|
|
||||||
[input]
|
[input]
|
||||||
|
|
||||||
|
ui_left={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194319,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
|
||||||
|
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
|
||||||
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
ui_right={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194321,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
|
||||||
|
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
|
||||||
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
ui_up={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194320,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":11,"pressure":0.0,"pressed":false,"script":null)
|
||||||
|
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
|
||||||
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
ui_down={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194322,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
|
||||||
|
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
|
||||||
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
view_right={
|
view_right={
|
||||||
"deadzone": 0.5,
|
"deadzone": 0.5,
|
||||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"echo":false,"script":null)
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ size_flags_horizontal = 3
|
|||||||
[node name="BuildingGroups" type="ItemList" parent="MarginContainer/PanelContainer/HBoxContainer/ScrollContainer/VBoxContainer"]
|
[node name="BuildingGroups" type="ItemList" parent="MarginContainer/PanelContainer/HBoxContainer/ScrollContainer/VBoxContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_vertical = 3
|
size_flags_vertical = 3
|
||||||
|
allow_search = false
|
||||||
auto_height = true
|
auto_height = true
|
||||||
|
|
||||||
[node name="ScrollContainer2" type="ScrollContainer" parent="MarginContainer/PanelContainer/HBoxContainer"]
|
[node name="ScrollContainer2" type="ScrollContainer" parent="MarginContainer/PanelContainer/HBoxContainer"]
|
||||||
|
|||||||
@@ -3,12 +3,7 @@
|
|||||||
[ext_resource type="Script" path="res://scripts/interaction_bar.gd" id="1_qwnlc"]
|
[ext_resource type="Script" path="res://scripts/interaction_bar.gd" id="1_qwnlc"]
|
||||||
|
|
||||||
[node name="InteractionBar" type="ProgressBar"]
|
[node name="InteractionBar" type="ProgressBar"]
|
||||||
anchors_preset = 15
|
offset_right = 60.0
|
||||||
anchor_right = 1.0
|
offset_bottom = 20.0
|
||||||
anchor_bottom = 1.0
|
|
||||||
offset_right = -1092.0
|
|
||||||
offset_bottom = -628.0
|
|
||||||
grow_horizontal = 2
|
|
||||||
grow_vertical = 2
|
|
||||||
show_percentage = false
|
show_percentage = false
|
||||||
script = ExtResource("1_qwnlc")
|
script = ExtResource("1_qwnlc")
|
||||||
|
|||||||
@@ -82,7 +82,6 @@ size = Vector2(40, 45)
|
|||||||
[node name="Player" type="CharacterBody2D"]
|
[node name="Player" type="CharacterBody2D"]
|
||||||
motion_mode = 1
|
motion_mode = 1
|
||||||
script = ExtResource("1_j0htm")
|
script = ExtResource("1_j0htm")
|
||||||
SPEED = null
|
|
||||||
|
|
||||||
[node name="Sprite" type="AnimatedSprite2D" parent="."]
|
[node name="Sprite" type="AnimatedSprite2D" parent="."]
|
||||||
sprite_frames = SubResource("SpriteFrames_tj1nq")
|
sprite_frames = SubResource("SpriteFrames_tj1nq")
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
[gd_scene load_steps=12 format=3 uid="uid://m0us5xqa3gnk"]
|
[gd_scene load_steps=11 format=3 uid="uid://m0us5xqa3gnk"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://scripts/world.gd" id="1_yf6q1"]
|
[ext_resource type="Script" path="res://scripts/world.gd" id="1_yf6q1"]
|
||||||
[ext_resource type="Resource" uid="uid://dr00rd4f42jqe" path="res://data/game_resources/gem/gem_resource.tres" id="2_rn4a2"]
|
[ext_resource type="Resource" uid="uid://dr00rd4f42jqe" path="res://data/game_resources/gem/gem_resource.tres" id="2_rn4a2"]
|
||||||
[ext_resource type="TileSet" uid="uid://d1sh6dy2w10b0" path="res://data/scifi_tileset.tres" id="2_sa7dm"]
|
[ext_resource type="TileSet" uid="uid://d1sh6dy2w10b0" path="res://data/scifi_tileset.tres" id="2_sa7dm"]
|
||||||
[ext_resource type="Resource" uid="uid://bpjj0x7jr1k6u" path="res://data/game_resources/carbon/carbon_resource.tres" id="3_pq6ic"]
|
[ext_resource type="Resource" uid="uid://bpjj0x7jr1k6u" path="res://data/game_resources/carbon/carbon_resource.tres" id="3_pq6ic"]
|
||||||
[ext_resource type="Script" path="res://scripts/building_manager.gd" id="4_61js3"]
|
[ext_resource type="Script" path="res://scripts/building_manager.gd" id="4_61js3"]
|
||||||
[ext_resource type="Script" path="res://scripts/resource_manager.gd" id="5_k5643"]
|
|
||||||
[ext_resource type="Texture2D" uid="uid://n806c03hgaq1" path="res://assets/scifi_tilesheet@2.png" id="5_qhth7"]
|
[ext_resource type="Texture2D" uid="uid://n806c03hgaq1" path="res://assets/scifi_tilesheet@2.png" id="5_qhth7"]
|
||||||
[ext_resource type="Script" path="res://scripts/gui.gd" id="6_yuatk"]
|
[ext_resource type="Script" path="res://scripts/gui.gd" id="6_yuatk"]
|
||||||
|
|
||||||
@@ -41,13 +40,6 @@ layer_4/tile_data = PackedInt32Array()
|
|||||||
[node name="BuildingManager" type="Node2D" parent="."]
|
[node name="BuildingManager" type="Node2D" parent="."]
|
||||||
script = ExtResource("4_61js3")
|
script = ExtResource("4_61js3")
|
||||||
|
|
||||||
[node name="ResourceManager" type="Node2D" parent="."]
|
|
||||||
script = ExtResource("5_k5643")
|
|
||||||
|
|
||||||
[node name="Timer" type="Timer" parent="ResourceManager"]
|
|
||||||
wait_time = 5.0
|
|
||||||
autostart = true
|
|
||||||
|
|
||||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||||
|
|
||||||
[node name="GUI" type="Control" parent="CanvasLayer"]
|
[node name="GUI" type="Control" parent="CanvasLayer"]
|
||||||
@@ -146,6 +138,3 @@ other info here too"
|
|||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
size_flags_stretch_ratio = 2.0
|
size_flags_stretch_ratio = 2.0
|
||||||
|
|
||||||
[connection signal="changed_resource" from="ResourceManager" to="CanvasLayer/GUI" method="_on_resource_manager_changed_resource"]
|
|
||||||
[connection signal="timeout" from="ResourceManager/Timer" to="ResourceManager" method="_on_timer_timeout"]
|
|
||||||
|
|||||||
@@ -37,3 +37,6 @@ func get_location_data(pos: Vector2i) -> CellData:
|
|||||||
func change_location_resource(pos: Vector2i, data: GameResource) -> void:
|
func change_location_resource(pos: Vector2i, data: GameResource) -> void:
|
||||||
world_data[pos].change_resource(data)
|
world_data[pos].change_resource(data)
|
||||||
world_grid.set_cell(Constants.TilemapLayers.ENVIRONMENT, pos, 0, data.atlas_location)
|
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)
|
||||||
|
|||||||
46
scripts/autoloads/resource_manager.gd
Normal file
46
scripts/autoloads/resource_manager.gd
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
extends Node
|
||||||
|
signal changed_resource
|
||||||
|
|
||||||
|
@export var resources := {}
|
||||||
|
|
||||||
|
func _on_gained_resource(res: GameResource) -> void:
|
||||||
|
print("Gained Resource: %s" % res)
|
||||||
|
var changed_resources := {
|
||||||
|
res: res.pickup_value
|
||||||
|
}
|
||||||
|
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:
|
||||||
|
#var changed_resources := {}
|
||||||
|
#for corrupted_resource: CellData in corrupted_resources:
|
||||||
|
#var res: GameResource = corrupted_resource.get_resource()
|
||||||
|
#if not resources.has(res):
|
||||||
|
#resources[res] = 0
|
||||||
|
#resources[res] += res.pickup_value
|
||||||
|
#changed_resources[res] = resources[res]
|
||||||
|
#changed_resource.emit(ResourceChangedSignal.new(changed_resources))
|
||||||
@@ -20,6 +20,7 @@ const BASIC_BUILDING_GROUP = preload("res://data/buildings/basic/basic_building_
|
|||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
_add_building_group(BASIC_BUILDING_GROUP)
|
_add_building_group(BASIC_BUILDING_GROUP)
|
||||||
_add_building_group(ADVANCED_BUILDING_GROUP)
|
_add_building_group(ADVANCED_BUILDING_GROUP)
|
||||||
|
#building_groups.set_focus()
|
||||||
|
|
||||||
func _add_building_group(group: BuildingGroup) -> void:
|
func _add_building_group(group: BuildingGroup) -> void:
|
||||||
building_groups.add_item(group.name, group.atlas_texture)
|
building_groups.add_item(group.name, group.atlas_texture)
|
||||||
@@ -54,6 +55,8 @@ func _on_buildings_item_selected(index: int) -> void:
|
|||||||
build_materials.add_child(image)
|
build_materials.add_child(image)
|
||||||
var label = Label.new()
|
var label = Label.new()
|
||||||
label.text = str(selected_building.cost[res])
|
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)
|
build_materials.add_child(label)
|
||||||
|
|
||||||
description.show()
|
description.show()
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ extends Node2D
|
|||||||
var base = preload("res://scene/base.tscn")
|
var base = preload("res://scene/base.tscn")
|
||||||
var building = preload("res://data/buildings/hub.tres")
|
var building = preload("res://data/buildings/hub.tres")
|
||||||
|
|
||||||
func _unhandled_input(event):
|
#func _unhandled_input(event):
|
||||||
if event is InputEventMouseButton and event.is_pressed() and event.button_index == MOUSE_BUTTON_LEFT:
|
#if event is InputEventMouseButton and event.is_pressed() and event.button_index == MOUSE_BUTTON_LEFT:
|
||||||
var build: Base = base.instantiate()
|
#var build: Base = base.instantiate()
|
||||||
build.position = get_global_mouse_position()
|
#build.position = get_global_mouse_position()
|
||||||
build.world = world
|
#build.world = world
|
||||||
build.building_data = building.duplicate(true)
|
#build.building_data = building.duplicate(true)
|
||||||
add_child(build)
|
#add_child(build)
|
||||||
#world_grid.set_cell(2, world_grid.local_to_map(get_global_mouse_position()), 0, Vector2i(16,2))
|
#world_grid.set_cell(2, world_grid.local_to_map(get_global_mouse_position()), 0, Vector2i(16,2))
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ func change_layer(layer: int, data: Variant) -> bool:
|
|||||||
func change_resource(data: GameResource) -> void:
|
func change_resource(data: GameResource) -> void:
|
||||||
layer_info[Constants.TilemapLayers.ENVIRONMENT] = data
|
layer_info[Constants.TilemapLayers.ENVIRONMENT] = data
|
||||||
|
|
||||||
|
func change_building(data: BuildingBase) -> void:
|
||||||
|
layer_info[Constants.TilemapLayers.BUILDINGS] = data
|
||||||
|
|
||||||
func get_resource() -> GameResource:
|
func get_resource() -> GameResource:
|
||||||
return layer_info[Constants.TilemapLayers.ENVIRONMENT] as GameResource
|
return layer_info[Constants.TilemapLayers.ENVIRONMENT] as GameResource
|
||||||
|
|
||||||
@@ -44,7 +47,7 @@ func is_interactable() -> bool:
|
|||||||
return has_resource() or has_building()
|
return has_resource() or has_building()
|
||||||
|
|
||||||
func is_buildable() -> bool:
|
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]:
|
func get_interaction_options() -> Array[Interaction]:
|
||||||
var interactions: Array[Interaction] = []
|
var interactions: Array[Interaction] = []
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ const SCIFI_TILESHEET = preload("res://assets/scifi_tilesheet@2.png")
|
|||||||
|
|
||||||
var _resource_displays := {}
|
var _resource_displays := {}
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
ResourceManager.changed_resource.connect(_on_resource_manager_changed_resource)
|
||||||
|
|
||||||
func _on_resource_manager_changed_resource(changed: ResourceChangedSignal) -> void:
|
func _on_resource_manager_changed_resource(changed: ResourceChangedSignal) -> void:
|
||||||
for resource: GameResource in changed.changed_resources.keys():
|
for resource: GameResource in changed.changed_resources.keys():
|
||||||
if not _resource_displays.has(resource):
|
if not _resource_displays.has(resource):
|
||||||
@@ -17,11 +20,11 @@ func _on_resource_manager_changed_resource(changed: ResourceChangedSignal) -> vo
|
|||||||
img.expand_mode = TextureRect.EXPAND_FIT_WIDTH_PROPORTIONAL
|
img.expand_mode = TextureRect.EXPAND_FIT_WIDTH_PROPORTIONAL
|
||||||
resource_container.add_child(img)
|
resource_container.add_child(img)
|
||||||
|
|
||||||
var label = Label.new()
|
var label := Label.new()
|
||||||
label.text = str(changed.changed_resources[resource])
|
label.text = str(changed.changed_resources[resource])
|
||||||
resource_container.add_child(label)
|
resource_container.add_child(label)
|
||||||
|
|
||||||
var data = ResourceData.new()
|
var data := ResourceData.new()
|
||||||
data.image = img
|
data.image = img
|
||||||
data.label = label
|
data.label = label
|
||||||
data.value = changed.changed_resources[resource]
|
data.value = changed.changed_resources[resource]
|
||||||
|
|||||||
@@ -3,11 +3,17 @@ class_name InteractionBar
|
|||||||
|
|
||||||
signal interaction_finished
|
signal interaction_finished
|
||||||
|
|
||||||
|
var grid_position: Vector2i
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
position = Grid.grid_to_world_center(grid_position) - Vector2(30,10)
|
||||||
|
|
||||||
var tween = get_tree().create_tween()
|
var tween = get_tree().create_tween()
|
||||||
tween.tween_property(self, "value", 100, 3)
|
tween.tween_property(self, "value", 100, 3)
|
||||||
tween.tween_callback(_cleanup_gather)
|
tween.tween_callback(_cleanup_gather)
|
||||||
|
|
||||||
func _cleanup_gather() -> void:
|
func _cleanup_gather() -> void:
|
||||||
interaction_finished.emit()
|
interaction_finished.emit()
|
||||||
|
var res: GameResource = Grid.get_location_data(grid_position).get_resource()
|
||||||
|
ResourceManager.pickup(res)
|
||||||
self.queue_free()
|
self.queue_free()
|
||||||
|
|||||||
@@ -35,16 +35,16 @@ func _physics_process(delta: float) -> void:
|
|||||||
|
|
||||||
if _build_placement:
|
if _build_placement:
|
||||||
_build_placement.position = Grid.grid_to_world_center(interaction_location)
|
_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:
|
func _input(event: InputEvent) -> void:
|
||||||
if event.is_action_pressed("interact"):
|
if event.is_action_pressed("interact"):
|
||||||
if _attempting_build and Grid.get_location_data(interaction_location).is_buildable():
|
if _attempting_build and Grid.get_location_data(interaction_location).is_buildable():
|
||||||
var build: BuildingBase = BUILDING_BASE.instantiate()
|
_build()
|
||||||
build.initialize(_attempting_build, interaction_location)
|
elif not _interacting and Grid.get_location_data(interaction_location).is_interactable():
|
||||||
add_sibling(build)
|
|
||||||
if not _interacting and Grid.get_location_data(interaction_location).is_interactable():
|
|
||||||
var interaction = INTERACTION_BAR.instantiate()
|
var interaction = INTERACTION_BAR.instantiate()
|
||||||
interaction.position = Grid.grid_to_world_center(interaction_location) - Vector2(30,10)
|
interaction.interaction_finished.connect(_on_interaction_finished)
|
||||||
|
interaction.grid_position = interaction_location
|
||||||
_interacting = true
|
_interacting = true
|
||||||
add_sibling(interaction)
|
add_sibling(interaction)
|
||||||
if event.is_action_pressed("build"):
|
if event.is_action_pressed("build"):
|
||||||
@@ -52,6 +52,9 @@ func _input(event: InputEvent) -> void:
|
|||||||
build_menu.build.connect(_on_build_menu_build)
|
build_menu.build.connect(_on_build_menu_build)
|
||||||
add_sibling(build_menu)
|
add_sibling(build_menu)
|
||||||
|
|
||||||
|
func _on_interaction_finished() -> void:
|
||||||
|
_interacting = false
|
||||||
|
|
||||||
func _on_build_menu_build(building: Building) -> void:
|
func _on_build_menu_build(building: Building) -> void:
|
||||||
print("Building: %s" % building.name)
|
print("Building: %s" % building.name)
|
||||||
_attempting_build = building
|
_attempting_build = building
|
||||||
@@ -60,6 +63,18 @@ func _on_build_menu_build(building: Building) -> void:
|
|||||||
_build_placement.self_modulate = Color(1, 0, 0, 0.4)
|
_build_placement.self_modulate = Color(1, 0, 0, 0.4)
|
||||||
add_sibling(_build_placement)
|
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:
|
func _on_interation_options_closed() -> void:
|
||||||
_interaction_options = null
|
_interaction_options = null
|
||||||
|
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
extends Node2D
|
|
||||||
|
|
||||||
signal changed_resource
|
|
||||||
|
|
||||||
@onready var world: World = $".."
|
|
||||||
|
|
||||||
@export var resources := {}
|
|
||||||
|
|
||||||
func _on_gained_resource(res: GameResource) -> void:
|
|
||||||
print("Gained Resource: %s" % res)
|
|
||||||
var changed_resources := {
|
|
||||||
res: res.pickup_value
|
|
||||||
}
|
|
||||||
changed_resource.emit(ResourceChangedSignal.new(changed_resources))
|
|
||||||
|
|
||||||
#func _on_timer_timeout() -> void:
|
|
||||||
#var corrupted_resources := Grid.get_corrupted_resources()
|
|
||||||
#if corrupted_resources.size() > 0:
|
|
||||||
#var changed_resources := {}
|
|
||||||
#for corrupted_resource: CellData in corrupted_resources:
|
|
||||||
#var res: GameResource = corrupted_resource.get_resource()
|
|
||||||
#if not resources.has(res):
|
|
||||||
#resources[res] = 0
|
|
||||||
#resources[res] += res.pickup_value
|
|
||||||
#changed_resources[res] = resources[res]
|
|
||||||
#changed_resource.emit(ResourceChangedSignal.new(changed_resources))
|
|
||||||
@@ -14,7 +14,6 @@ var noise_regions := [-999,0,999]
|
|||||||
var atlas_regions := [Vector2i(0,1),Vector2i(0,0)]
|
var atlas_regions := [Vector2i(0,1),Vector2i(0,0)]
|
||||||
|
|
||||||
@onready var world_grid: TileMap = $world_grid
|
@onready var world_grid: TileMap = $world_grid
|
||||||
@onready var resource_manager: Node2D = $ResourceManager
|
|
||||||
|
|
||||||
func get_noise_value(x: int, y: int):
|
func get_noise_value(x: int, y: int):
|
||||||
return terrain_noise.get_noise_2d(x,y) * 500
|
return terrain_noise.get_noise_2d(x,y) * 500
|
||||||
@@ -62,7 +61,7 @@ func corrupt_location(loc: Vector2i):
|
|||||||
|
|
||||||
func add_resources_to_map() -> void:
|
func add_resources_to_map() -> void:
|
||||||
for res: GameResource in game_resources:
|
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()
|
var spawns = res.get_spawn_locations()
|
||||||
for spawn in spawns:
|
for spawn in spawns:
|
||||||
Grid.change_location_resource(spawn, res)
|
Grid.change_location_resource(spawn, res)
|
||||||
|
|||||||
Reference in New Issue
Block a user