extends Node

var BUILDINGS = {
	"iron_mine": {
		"name": "Iron Mine",
		"description": "Pozwala wydobywać żelazo z powierzchni planety.",
		"resource": "iron",
		"cost": {"iron": 0},
		"bonuses": {
			
			},
		"build_time": 10.0,
		"texture": "res://assets/buildings/iron_mine.png",
		"required_tech": null
	},
	"water_purifier": {
		"name": "Water Purifier",
		"description": "Pozwala wydobywać i oczyszczać wodę do użytku kolonii.",
		"resource": "water",
		"cost": {"iron": 10},
		"bonuses": {
			
			},
		"build_time": 8.0,
		"texture": "res://assets/buildings/water_purifier.png",
		"required_tech": null
	},
	"copper_mine": {
		"name": "Copper Mine",
		"description": "Pozwala wydobywać miedź.",
		"resource": "copper",
		"cost": {"iron": 10},
		"bonuses": {
			
			},
		"build_time": 20.0,
		"texture": "res://assets/buildings/copper_mine.png",
		"required_tech": "advanced_mining"
	},
	"uran_mine": {
		"name": "Uran Mine",
		"description": "Pozwala wydobywać uran.",
		"resource": "uranium",
		"cost": {"iron": 80},
		"bonuses": {
			
			},
		"build_time": 5.0,
		"texture": "res://assets/buildings/uran_mine.png",
		"required_tech": "advanced_mining"
	},
	"residential_zone": {
		"name": "Residential Zone",
		"description": "Zwiększa limit populacji",
		"bonuses": {
			"total_pop_bonus": 25
			},
		"resource": null,
		"cost": {"iron": 10},
		"build_time": 5.0,
		"texture": "res://assets/buildings/residential_zone.png",
		"required_tech": null
	},
	"terraforming_center": {
		"name": "Terraforming Center",
		"description": "Zwiększa limit populacji",
		"bonuses": {
			"biosfere": 0.5
			},
		"resource": null,
		"cost": {"iron": 10},
		"build_time": 5.0,
		"texture": "res://assets/buildings/terraforming_center.png",
		"required_tech": "terraforming"
	},
	"laboratory": {
		"name": "Laboratory",
		"description": "Umożliwia prace naukowe",
		"bonuses": {
			
			},
		"resource": null,
		"cost": {"iron": 10},
		"build_time": 5.0,
		"texture": "res://assets/buildings/labolatory.png",
		"required_tech": null
	},
	
	"aluminium_ore_mine": {
		"name": "Aluminium ore mine",
		"description": "Wydobywa boksyt.",
		"resource": "aluminium",
		"cost": {"iron": 100, "copper": 100},
		"bonuses": {"biosfere": 0.1},
		"build_time": 15.0,
		"texture": "res://assets/buildings/aluminium_ore_mine.png",
		"required_tech": "advanced_mining"
	}
}


func _ready():
	_load_mod_buildings()


func _load_mod_buildings():
	var mod_path = "res://mods/buildings.json"

	if not FileAccess.file_exists(mod_path):
		print("Brak pliku modów: ", mod_path)
		return

	var file = FileAccess.open(mod_path, FileAccess.READ)
	if file == null:
		print("Nie można otworzyć pliku modów:", mod_path)
		return

	var content = file.get_as_text()
	file.close()

	var parsed = JSON.parse_string(content)
	if parsed == null or typeof(parsed) != TYPE_DICTIONARY:
		print("Błąd: niepoprawny format JSON w", mod_path)
		return

	for key in parsed.keys():
		if not BUILDINGS.has(key):
			BUILDINGS[key] = parsed[key]
			print("Dodano budynek z moda:", key)
		else:
			print("Pominięto (już istnieje):", key)
