From 2f5067d7e587c6f7114fb869ab94c2d2384b708d Mon Sep 17 00:00:00 2001 From: Tomasz Boruc Date: Fri, 7 Nov 2025 21:24:36 +0100 Subject: [PATCH] Wstep do technolgi i wymagan budynkow --- mods/buildings.json | 4 ++-- scenes/galaxy.tscn | 1 + scripts/BuildingsList.gd | 16 ++++++------- scripts/PlayerData.gd | 3 ++- scripts/planet_panel.gd | 52 +++++++++++++++++++++++++++++++++------- scripts/top_panel.gd | 6 ++--- 6 files changed, 59 insertions(+), 23 deletions(-) diff --git a/mods/buildings.json b/mods/buildings.json index 14731d6..e7ee4b8 100644 --- a/mods/buildings.json +++ b/mods/buildings.json @@ -3,10 +3,10 @@ "name": "Aluminium ore mine", "description": "Wydobywa boksyt.", "resource": "aluminium", - "cost": {"iron": 500, "carbon": 200, "uranium": 50}, + "cost": {"iron": 100, "copper": 100}, "bonuses": {"biosfere": 0.1}, "build_time": 15.0, "texture": "res://assets/buildings/aluminium_ore_mine.png", - "required_tech": "fusion_power" + "required_tech": "advanced_mining" } } diff --git a/scenes/galaxy.tscn b/scenes/galaxy.tscn index 0337a07..17a94ea 100644 --- a/scenes/galaxy.tscn +++ b/scenes/galaxy.tscn @@ -45,6 +45,7 @@ offset = Vector2(50, 50) transform = Transform2D(1, 0, 0, 1, 50, 50) [node name="PlanetPanel" parent="UI" instance=ExtResource("7_xhm0b")] +visible = false show_behind_parent = true anchors_preset = 0 anchor_left = 0.0 diff --git a/scripts/BuildingsList.gd b/scripts/BuildingsList.gd index 25c3ea9..b050345 100644 --- a/scripts/BuildingsList.gd +++ b/scripts/BuildingsList.gd @@ -5,7 +5,7 @@ var BUILDINGS = { "name": "Iron Mine", "description": "Pozwala wydobywać żelazo z powierzchni planety.", "resource": "iron", - "cost": {"iron": 100, "carbon": 50}, + "cost": {"iron": 0}, "bonuses": { }, @@ -17,7 +17,7 @@ var BUILDINGS = { "name": "Water Purifier", "description": "Pozwala wydobywać i oczyszczać wodę do użytku kolonii.", "resource": "water", - "cost": {"iron": 80, "carbon": 40}, + "cost": {"iron": 10}, "bonuses": { }, @@ -29,25 +29,25 @@ var BUILDINGS = { "name": "Copper Mine", "description": "Pozwala wydobywać miedź.", "resource": "copper", - "cost": {"iron": 80, "carbon": 40}, + "cost": {"iron": 10}, "bonuses": { }, "build_time": 20.0, "texture": "res://assets/buildings/copper_mine.png", - "required_tech": null + "required_tech": "advanced_mining" }, "uran_mine": { "name": "Uran Mine", "description": "Pozwala wydobywać uran.", "resource": "uranium", - "cost": {"iron": 80, "carbon": 40}, + "cost": {"iron": 80}, "bonuses": { }, "build_time": 5.0, "texture": "res://assets/buildings/uran_mine.png", - "required_tech": null + "required_tech": "advanced_mining" }, "residential_zone": { "name": "Residential Zone", @@ -56,7 +56,7 @@ var BUILDINGS = { "total_pop_bonus": 25 }, "resource": null, - "cost": {"iron": 80, "carbon": 40}, + "cost": {"iron": 10}, "build_time": 5.0, "texture": "res://assets/buildings/residential_zone.png", "required_tech": null @@ -68,7 +68,7 @@ var BUILDINGS = { "biosfere": 0.5 }, "resource": null, - "cost": {"iron": 80, "carbon": 40}, + "cost": {"iron": 10}, "build_time": 5.0, "texture": "res://assets/buildings/terraforming_center.png", "required_tech": null diff --git a/scripts/PlayerData.gd b/scripts/PlayerData.gd index 6c5341c..7e92587 100644 --- a/scripts/PlayerData.gd +++ b/scripts/PlayerData.gd @@ -30,7 +30,8 @@ var resources := { var science_points: float = 0.0 # Technologie odkryte -var discovered_technologies: Array = [] +var unlocked_techs = ["advanced_mining"] + # Lista skolonizowanych planet var planets: Array = [] diff --git a/scripts/planet_panel.gd b/scripts/planet_panel.gd index 31cc1ee..b44db41 100644 --- a/scripts/planet_panel.gd +++ b/scripts/planet_panel.gd @@ -70,23 +70,57 @@ func _create_building_buttons(): # Tworzymy nowe przyciski dla wszystkich budynków w definicjach for b_id in BuildingsList.BUILDINGS.keys(): var b_data = BuildingsList.BUILDINGS[b_id] - var btn = TextureButton.new() - btn.texture_normal = load(b_data.texture) - #btn.stretch_mode = TextureButton.STRETCH_KEEP_ASPECT_COVERED - #btn.ignore_texture_size = true - - - - btn.connect("pressed", Callable(self, "_on_building_pressed").bind(b_id)) - buildings_container.add_child(btn) + # Sprawdź, czy budynek wymaga technologii + var required_tech = b_data.get("required_tech", null) + print("Tech unlocked:", PlayerData.unlocked_techs) + print("Building:", b_id, "requires:", required_tech) + # Jeżeli nie wymaga lub gracz ma już tę technologię + if not required_tech or required_tech in PlayerData.unlocked_techs: + var btn = TextureButton.new() + btn.texture_normal = load(b_data.texture) + + btn.connect("pressed", Callable(self, "_on_building_pressed").bind(b_id)) + buildings_container.add_child(btn) + + func _on_building_pressed(b_id): if not planet: return + var b_data = BuildingsList.BUILDINGS[b_id] + + # Sprawdź czy planeta ma wymagany surowiec + if b_data.has("resource") and b_data["resource"] != null: + var required_resource = b_data["resource"] + if not planet.resources.has(required_resource): + print("❌ Planeta nie ma zasobu: %s" % required_resource) + return + + var res_info = planet.resources[required_resource] + if not res_info.has("exist") or not res_info["exist"]: + print("❌ Surowiec %s nie występuje na planecie!" % required_resource) + return + + # Sprawdź koszt budynku (czy planeta ma odpowiednie zasoby) + if b_data.has("cost"): + for cost_res in b_data.cost.keys(): + var cost_val = b_data.cost[cost_res] + if not planet.resources.has(cost_res) or planet.resources[cost_res].get("amount", 0) < cost_val: + print("❌ Brak wystarczającej ilości surowca: %s (wymagane %s)" % [cost_res, cost_val]) + return + + # Odejmij koszt budowy z zasobów planety + for cost_res in b_data.cost.keys(): + var cost_val = b_data.cost[cost_res] + planet.resources[cost_res]["amount"] -= cost_val + + # Dodaj budynek planet.add_building(b_id) _update_info() + print("✅ Zbudowano budynek: %s" % b_data.name) + func _on_button_pressed() -> void: diff --git a/scripts/top_panel.gd b/scripts/top_panel.gd index 99c71bd..de6cade 100644 --- a/scripts/top_panel.gd +++ b/scripts/top_panel.gd @@ -12,9 +12,9 @@ func update_info(): label_player_name.text = "Gracz: %s" % PlayerData.PlayerName #label_science.text = "🔬 Nauka: %s" % player.science - label_iron.text = "%s: %.2f" % [tr("Iron"), PlayerData.resources.iron] - label_water.text = "%s: %.2f" % [tr("Water"), PlayerData.resources.water] - label_copper.text = "%s: %.2f" % [tr("Copper"), PlayerData.resources.copper] + label_iron.text = "%s: %.2f" % [tr("iron"), PlayerData.resources.iron] + label_water.text = "%s: %.2f" % [tr("water"), PlayerData.resources.water] + label_copper.text = "%s: %.2f" % [tr("copper"), PlayerData.resources.copper] #label_population.text = "👥 Populacja: %s" % GameData.format_number(player.total_population)