2024/Mar #14

Merged
gitea merged 19 commits from 2024/Mar into main 2024-04-09 10:13:41 -05:00
11 changed files with 51 additions and 25 deletions
Showing only changes of commit 82675b6ed2 - Show all commits

View File

@@ -1,9 +1,10 @@
[gd_resource type="Resource" script_class="BuildingGroup" load_steps=6 format=3 uid="uid://dqv53okb3evb7"]
[gd_resource type="Resource" script_class="BuildingGroup" load_steps=7 format=3 uid="uid://dqv53okb3evb7"]
[ext_resource type="Texture2D" uid="uid://n806c03hgaq1" path="res://assets/scifi_tilesheet@2.png" id="1_p1crr"]
[ext_resource type="Script" path="res://data/buildings/building_group.gd" id="1_xphre"]
[ext_resource type="Resource" uid="uid://d38xgwstvtcm4" path="res://data/buildings/basic/harvester/harvester_building.tres" id="2_5rd2r"]
[ext_resource type="Resource" uid="uid://cta6ngelbwo8b" path="res://data/buildings/basic/warehouse/warehouse_building.tres" id="3_vxs34"]
[ext_resource type="Resource" uid="uid://bibep1rd0jml2" path="res://data/buildings/basic/researcher/researcher_building.tres" id="4_fxdio"]
[sub_resource type="AtlasTexture" id="AtlasTexture_nleix"]
atlas = ExtResource("1_p1crr")
@@ -13,4 +14,4 @@ region = Rect2(1024, 576, 64, 64)
script = ExtResource("1_xphre")
name = "Basic"
atlas_texture = SubResource("AtlasTexture_nleix")
buildings = Array[Resource("res://data/buildings/building.gd")]([ExtResource("2_5rd2r"), ExtResource("3_vxs34")])
buildings = Array[Resource("res://data/buildings/building.gd")]([ExtResource("2_5rd2r"), ExtResource("3_vxs34"), ExtResource("4_fxdio")])

View File

@@ -11,6 +11,7 @@ func initialize(building: BuildingBase) -> void:
nearest_res = Grid.get_nearest_resource(building.position, CARBON_RESOURCE)
_distance = building.position.distance_to(nearest_res)
_direction = nearest_res.direction_to(building.position)
BuildingManager.add_resource_building(CARBON_RESOURCE, building)
func ready(building: BuildingBase) -> void:
var particles = HARVESTER_PARTICLES.instantiate()

View File

@@ -0,0 +1 @@
extends Building

View File

@@ -0,0 +1,18 @@
[gd_resource type="Resource" load_steps=5 format=3 uid="uid://bibep1rd0jml2"]
[ext_resource type="Texture2D" uid="uid://n806c03hgaq1" path="res://assets/scifi_tilesheet@2.png" id="1_kruad"]
[ext_resource type="Resource" uid="uid://bpjj0x7jr1k6u" path="res://data/game_resources/carbon/carbon_resource.tres" id="2_hybxl"]
[ext_resource type="Script" path="res://data/buildings/basic/researcher/researcher.gd" id="3_h2kjx"]
[sub_resource type="AtlasTexture" id="AtlasTexture_ejp6g"]
atlas = ExtResource("1_kruad")
region = Rect2(1024, 128, 64, 64)
[resource]
script = ExtResource("3_h2kjx")
atlas_texture = SubResource("AtlasTexture_ejp6g")
name = "Researcher"
description = "Research new buildings and technologies"
cost = {
ExtResource("2_hybxl"): 6000
}

View File

@@ -1,7 +1,9 @@
extends Building
const CARBON_RESOURCE = preload("res://data/game_resources/carbon/carbon_resource.tres")
func initialize(building: BuildingBase) -> void:
pass
BuildingManager.add_storage_building(CARBON_RESOURCE, building)
func ready(building: BuildingBase) -> void:
pass

View File

@@ -19,6 +19,7 @@ config/icon="res://icon.svg"
Grid="*res://scripts/autoloads/grid.gd"
ResourceManager="*res://scripts/autoloads/resource_manager.gd"
BuildingManager="*res://scripts/autoloads/building_manager.gd"
[debug]

View File

@@ -1,10 +1,9 @@
[gd_scene load_steps=11 format=3 uid="uid://m0us5xqa3gnk"]
[gd_scene load_steps=10 format=3 uid="uid://m0us5xqa3gnk"]
[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="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="Script" path="res://scripts/building_manager.gd" id="4_61js3"]
[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"]
@@ -37,9 +36,6 @@ layer_3/tile_data = PackedInt32Array()
layer_4/name = "buildings"
layer_4/tile_data = PackedInt32Array()
[node name="BuildingManager" type="Node2D" parent="."]
script = ExtResource("4_61js3")
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="GUI" type="Control" parent="CanvasLayer"]

View File

@@ -0,0 +1,17 @@
extends Node
var _resource_buildings = {}
var _storage_buildings = {}
func add_resource_building(res: GameResource, building: BuildingBase) -> void:
if not _resource_buildings.has(res):
_resource_buildings[res] = []
_resource_buildings[res].append(building)
func add_storage_building(res: GameResource, building: BuildingBase) -> void:
if not _storage_buildings.has(res):
_storage_buildings[res] = []
_storage_buildings[res].append(building)
func get_storage_count_for_resource(res: GameResource) -> int:
return 0 if not _storage_buildings.has(res) else _storage_buildings[res].size()

View File

@@ -13,7 +13,7 @@ func _on_gained_resource(res: GameResource) -> void:
func pickup(resource: GameResource) -> void:
if not resources.has(resource):
resources[resource] = 0
var pickup_amount = min(resource.pickup_value, resource.storage_max - resources[resource])
var pickup_amount = min(resource.pickup_value, get_resource_limit(resource) - resources[resource])
if pickup_amount > 0:
resources[resource] += pickup_amount
var changed_resources := {
@@ -34,6 +34,9 @@ func use_resources(cost: Dictionary) -> void:
resources[res] -= cost[res]
changed_resources[res] = -cost[res]
changed_resource.emit(ResourceChangedSignal.new(changed_resources))
func get_resource_limit(resource: GameResource) -> int:
return resource.storage_max * (1 + BuildingManager.get_storage_count_for_resource(resource))
#func _on_timer_timeout() -> void:
#var corrupted_resources := Grid.get_corrupted_resources()

View File

@@ -1,14 +0,0 @@
extends Node2D
@onready var world: World = $".."
var base = preload("res://scene/base.tscn")
var building = preload("res://data/buildings/hub.tres")
#func _unhandled_input(event):
#if event is InputEventMouseButton and event.is_pressed() and event.button_index == MOUSE_BUTTON_LEFT:
#var build: Base = base.instantiate()
#build.position = get_global_mouse_position()
#build.world = world
#build.building_data = building.duplicate(true)
#add_child(build)
#world_grid.set_cell(2, world_grid.local_to_map(get_global_mouse_position()), 0, Vector2i(16,2))

View File

@@ -29,11 +29,11 @@ func _on_resource_manager_changed_resource(changed: ResourceChangedSignal) -> vo
data.value = changed.changed_resources[resource]
_resource_displays[resource] = data
label.text = "%s / %s" % [data.value, resource.storage_max]
label.text = "%s / %s" % [data.value, ResourceManager.get_resource_limit(resource)]
else:
var data: ResourceData = _resource_displays[resource]
data.value += changed.changed_resources[resource]
data.label.text = "%s / %s" % [data.value, resource.storage_max]
data.label.text = "%s / %s" % [data.value, ResourceManager.get_resource_limit(resource)]
class ResourceData:
var image: TextureRect