临时提交

This commit is contained in:
2025-06-22 20:39:47 +08:00
parent b3d1135e23
commit d274ae0fec
24 changed files with 603 additions and 50 deletions

View File

@ -0,0 +1,7 @@
[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://dyr6ete55krfi"]
[ext_resource type="Texture2D" uid="uid://dqu31gnodu6dx" path="res://assets/textures/Vanilla.png" id="1_n71hd"]
[resource]
atlas = ExtResource("1_n71hd")
region = Rect2(80, 160, 80, 80)

View File

@ -0,0 +1,7 @@
[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://ljhsda0pev1o"]
[ext_resource type="Texture2D" uid="uid://dqu31gnodu6dx" path="res://assets/textures/Vanilla.png" id="1_n71hd"]
[resource]
atlas = ExtResource("1_n71hd")
region = Rect2(0, 400, 80, 80)

View File

@ -0,0 +1,7 @@
[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://xrp6coqiavf7"]
[ext_resource type="Texture2D" uid="uid://dqu31gnodu6dx" path="res://assets/textures/Vanilla.png" id="1_n71hd"]
[resource]
atlas = ExtResource("1_n71hd")
region = Rect2(160, 800, 80, 80)

View File

@ -0,0 +1,7 @@
[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://hg6jie5wpn7n"]
[ext_resource type="Texture2D" uid="uid://dqu31gnodu6dx" path="res://assets/textures/Vanilla.png" id="1_n71hd"]
[resource]
atlas = ExtResource("1_n71hd")
region = Rect2(160, 1040, 80, 80)

View File

@ -0,0 +1,7 @@
[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://cb7ypsed1beme"]
[ext_resource type="Texture2D" uid="uid://dqu31gnodu6dx" path="res://assets/textures/Vanilla.png" id="1_n71hd"]
[resource]
atlas = ExtResource("1_n71hd")
region = Rect2(160, 400, 80, 80)

View File

@ -0,0 +1,7 @@
[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://cgjew5x6poch7"]
[ext_resource type="Texture2D" uid="uid://dqu31gnodu6dx" path="res://assets/textures/Vanilla.png" id="1_n71hd"]
[resource]
atlas = ExtResource("1_n71hd")
region = Rect2(960, 0, 80, 80)

View File

@ -0,0 +1,7 @@
[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://lff3iusficps"]
[ext_resource type="Texture2D" uid="uid://dqu31gnodu6dx" path="res://assets/textures/Vanilla.png" id="1_n71hd"]
[resource]
atlas = ExtResource("1_n71hd")
region = Rect2(80, 400, 80, 80)

View File

@ -0,0 +1,7 @@
[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://wv8cee4ujgjy"]
[ext_resource type="Texture2D" uid="uid://dqu31gnodu6dx" path="res://assets/textures/Vanilla.png" id="1_n71hd"]
[resource]
atlas = ExtResource("1_n71hd")
region = Rect2(960, 800, 80, 80)

View File

@ -0,0 +1,7 @@
[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://b6f5au0rllatr"]
[ext_resource type="Texture2D" uid="uid://dqu31gnodu6dx" path="res://assets/textures/Vanilla.png" id="1_n71hd"]
[resource]
atlas = ExtResource("1_n71hd")
region = Rect2(560, 720, 80, 80)

View File

@ -0,0 +1,7 @@
[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://bheaslcbv6mm1"]
[ext_resource type="Texture2D" uid="uid://dqu31gnodu6dx" path="res://assets/textures/Vanilla.png" id="1_n71hd"]
[resource]
atlas = ExtResource("1_n71hd")
region = Rect2(480, 720, 80, 80)

View File

@ -0,0 +1,7 @@
[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://o8q2yjyo5s0i"]
[ext_resource type="Texture2D" uid="uid://dqu31gnodu6dx" path="res://assets/textures/Vanilla.png" id="1_n71hd"]
[resource]
atlas = ExtResource("1_n71hd")
region = Rect2(800, 80, 80, 80)

View File

@ -0,0 +1,7 @@
[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://cfhoduft46a00"]
[ext_resource type="Texture2D" uid="uid://dqu31gnodu6dx" path="res://assets/textures/Vanilla.png" id="1_n71hd"]
[resource]
atlas = ExtResource("1_n71hd")
region = Rect2(720, 560, 80, 80)

View File

@ -0,0 +1,7 @@
[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://dsy5mm1nl1hxi"]
[ext_resource type="Texture2D" uid="uid://dqu31gnodu6dx" path="res://assets/textures/Vanilla.png" id="1_n71hd"]
[resource]
atlas = ExtResource("1_n71hd")
region = Rect2(240, 400, 80, 80)

View File

@ -0,0 +1,7 @@
[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://col70aenshr2b"]
[ext_resource type="Texture2D" uid="uid://dqu31gnodu6dx" path="res://assets/textures/Vanilla.png" id="1_n71hd"]
[resource]
atlas = ExtResource("1_n71hd")
region = Rect2(240, 1040, 80, 80)

View File

@ -0,0 +1,7 @@
[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://byto04beepu23"]
[ext_resource type="Texture2D" uid="uid://dqu31gnodu6dx" path="res://assets/textures/Vanilla.png" id="1_n71hd"]
[resource]
atlas = ExtResource("1_n71hd")
region = Rect2(640, 320, 80, 80)

View File

@ -110,6 +110,31 @@
"quantity": 2 "quantity": 2
} }
] ]
},
{
"id": "wind_turbine_crafting",
"outputItem": "wind_turbine",
"outputQuantity": 1,
"craftingMethod": "组装",
"craftingTime": 8.0,
"ingredients": [
{
"itemId": "iron_ingot",
"quantity": 8
},
{
"itemId": "copper_ingot",
"quantity": 4
},
{
"itemId": "magnetic_coil",
"quantity": 2
},
{
"itemId": "circuit_board",
"quantity": 1
}
]
} }
] ]
} }

View File

@ -34,7 +34,8 @@
"furnace", "furnace",
"miner", "miner",
"assembler", "assembler",
"chemical_plant" "chemical_plant",
"wind_turbine"
] ]
} }
] ]

View File

@ -1,19 +1,19 @@
Id,Name,Category,Description,Recipe,CraftTime,PowerConsumption,IconPath Id,Name,Category,Description,Recipe,CraftTime,PowerConsumption,IconPath
iron_ore,铁矿,RawMaterial,基础原材料,可用于冶炼铁块,null,0,0,res://assets/textures/items/iron_ore.png iron_ore,铁矿,RawMaterial,基础原材料,可用于冶炼铁块,null,0,0,res://assets/textures/items/铁矿.tres
copper_ore,铜矿,RawMaterial,基础原材料,可用于冶炼铜块,null,0,0,res://assets/textures/items/copper_ore.png copper_ore,铜矿,RawMaterial,基础原材料,可用于冶炼铜块,null,0,0,res://assets/textures/items/铜矿.tres
stone_ore,石矿,RawMaterial,基础建筑材料,可用于建造建筑,null,0,0,res://assets/textures/items/stone_ore.png stone_ore,石矿,RawMaterial,基础建筑材料,可用于建造建筑,null,0,0,res://assets/textures/items/石矿.tres
coal_ore,煤矿,RawMaterial,重要的能源资源,可用于发电,null,0,0,res://assets/textures/items/coal_ore.png coal_ore,煤矿,RawMaterial,重要的能源资源,可用于发电,null,0,0,res://assets/textures/items/煤矿.tres
water,,RawMaterial,基础资源,可用于多种生产,null,0,0,res://assets/textures/items/water.png water,,RawMaterial,基础资源,可用于多种生产,null,0,0,res://assets/textures/items/水.tres
crude_oil,原油,RawMaterial,重要的能源资源,可用于生产燃料,null,0,0,res://assets/textures/items/crude_oil.png crude_oil,原油,RawMaterial,重要的能源资源,可用于生产燃料,null,0,0,res://assets/textures/items/原油.tres
iron_ingot,铁块,ProcessedMaterial,由铁矿冶炼而成的基础材料,iron_ore:1,1.0,60.0,res://assets/textures/items/铁块.tres iron_ingot,铁块,ProcessedMaterial,由铁矿冶炼而成的基础材料,iron_ore:1,1.0,60.0,res://assets/textures/items/铁块.tres
copper_ingot,铜块,ProcessedMaterial,由铜矿冶炼而成的基础材料,copper_ore:1,1.0,60.0,res://assets/textures/items/铜块.tres copper_ingot,铜块,ProcessedMaterial,由铜矿冶炼而成的基础材料,copper_ore:1,1.0,60.0,res://assets/textures/items/铜块.tres
magnet,磁铁,ProcessedMaterial,由铁矿制作的磁性材料,用于制造电机等设备,iron_ore:2,1.5,0,res://assets/textures/items/magnet.png magnet,磁铁,ProcessedMaterial,由铁矿制作的磁性材料,用于制造电机等设备,iron_ore:2,1.5,0,res://assets/textures/items/磁铁.tres
gear,齿轮,ProcessedMaterial,由铁块制作的机械部件,用于制造复杂设备,iron_ingot:1,2.0,0,res://assets/textures/items/gear.png gear,齿轮,ProcessedMaterial,由铁块制作的机械部件,用于制造复杂设备,iron_ingot:1,2.0,0,res://assets/textures/items/齿轮.tres
magnetic_coil,磁线圈,Component,由磁铁和铜块制作的电磁组件,用于制造高级设备,magnet:2;copper_ingot:1,3.0,0,res://assets/textures/items/magnetic_coil.png magnetic_coil,磁线圈,Component,由磁铁和铜块制作的电磁组件,用于制造高级设备,magnet:2;copper_ingot:1,3.0,0,res://assets/textures/items/磁线圈.tres
circuit_board,电路板,Component,由铁块和铜块制作的电子组件,用于制造高级设备,iron_ingot:2;copper_ingot:1,2.5,0,res://assets/textures/items/circuit_board.png circuit_board,电路板,Component,由铁块和铜块制作的电子组件,用于制造高级设备,iron_ingot:2;copper_ingot:1,2.5,0,res://assets/textures/items/电路板.tres
drill_machine,钻机,ProductionDevice,由多种组件制作的高级钻探设备,效率更高,iron_ingot:4;circuit_board:2;magnetic_coil:2;gear:2,8.0,500.0,res://assets/textures/items/drill_machine.png furnace,熔炉,Building,自动冶炼矿石的熔炉设备,iron_ingot:4;stone_ore:2,3.5,250.0,res://assets/textures/items/熔炉.tres
furnace,熔炉,Building,自动冶炼矿石的熔炉设备,iron_ingot:4;stone_ore:2,3.5,250.0,res://assets/textures/buildings/furnace.png smelter,冶炼厂,Building,用于冶炼矿石的基础建筑,iron_ingot:4;copper_ingot:2,3.0,360.0,res://assets/textures/items/冶炼厂.tres
smelter,冶炼厂,Building,用于冶炼矿石的基础建筑,iron_ingot:4;copper_ingot:2,3.0,360.0,res://assets/textures/buildings/smelter.png miner,采矿机,Building,自动采集矿石的基础建筑,iron_ingot:3;copper_ingot:1,2.0,420.0,res://assets/textures/items/采矿机.tres
miner,采矿机,Building,自动采集矿石的基础建筑,iron_ingot:3;copper_ingot:1,2.0,420.0,res://assets/textures/buildings/miner.png assembler,制造台1,ProductionDevice,高级生产设备,可制造复杂物品,iron_ingot:6;copper_ingot:4,5.0,480.0,res://assets/textures/items/制造台 MK 1.tres
assembler,组装机,ProductionDevice,高级生产设备,可制造复杂物品,iron_ingot:6;copper_ingot:4,5.0,480.0,res://assets/textures/buildings/assembler.png chemical_plant,化工厂,ProductionDevice,专业化工生产设备,可处理液体,iron_ingot:8;copper_ingot:6,6.0,600.0,res://assets/textures/items/化工厂.tres
chemical_plant,化工厂,ProductionDevice,专业化工生产设备,可处理液体,iron_ingot:8;copper_ingot:6,6.0,600.0,res://assets/textures/buildings/chemical_plant.png wind_turbine,风力发电机,Building,利用风力发电的清洁能源设备,iron_ingot:8;copper_ingot:4;magnetic_coil:2;circuit_board:1,8.0,0,res://assets/textures/items/风力发电机.tres
1 Id Name Category Description Recipe CraftTime PowerConsumption IconPath
2 iron_ore 铁矿 RawMaterial 基础原材料,可用于冶炼铁块 null 0 0 res://assets/textures/items/iron_ore.png res://assets/textures/items/铁矿.tres
3 copper_ore 铜矿 RawMaterial 基础原材料,可用于冶炼铜块 null 0 0 res://assets/textures/items/copper_ore.png res://assets/textures/items/铜矿.tres
4 stone_ore 石矿 RawMaterial 基础建筑材料,可用于建造建筑 null 0 0 res://assets/textures/items/stone_ore.png res://assets/textures/items/石矿.tres
5 coal_ore 煤矿 RawMaterial 重要的能源资源,可用于发电 null 0 0 res://assets/textures/items/coal_ore.png res://assets/textures/items/煤矿.tres
6 water RawMaterial 基础资源,可用于多种生产 null 0 0 res://assets/textures/items/water.png res://assets/textures/items/水.tres
7 crude_oil 原油 RawMaterial 重要的能源资源,可用于生产燃料 null 0 0 res://assets/textures/items/crude_oil.png res://assets/textures/items/原油.tres
8 iron_ingot 铁块 ProcessedMaterial 由铁矿冶炼而成的基础材料 iron_ore:1 1.0 60.0 res://assets/textures/items/铁块.tres
9 copper_ingot 铜块 ProcessedMaterial 由铜矿冶炼而成的基础材料 copper_ore:1 1.0 60.0 res://assets/textures/items/铜块.tres
10 magnet 磁铁 ProcessedMaterial 由铁矿制作的磁性材料,用于制造电机等设备 iron_ore:2 1.5 0 res://assets/textures/items/magnet.png res://assets/textures/items/磁铁.tres
11 gear 齿轮 ProcessedMaterial 由铁块制作的机械部件,用于制造复杂设备 iron_ingot:1 2.0 0 res://assets/textures/items/gear.png res://assets/textures/items/齿轮.tres
12 magnetic_coil 磁线圈 Component 由磁铁和铜块制作的电磁组件,用于制造高级设备 magnet:2;copper_ingot:1 3.0 0 res://assets/textures/items/magnetic_coil.png res://assets/textures/items/磁线圈.tres
13 circuit_board 电路板 Component 由铁块和铜块制作的电子组件,用于制造高级设备 iron_ingot:2;copper_ingot:1 2.5 0 res://assets/textures/items/circuit_board.png res://assets/textures/items/电路板.tres
14 drill_machine furnace 钻机 熔炉 ProductionDevice Building 由多种组件制作的高级钻探设备,效率更高 自动冶炼矿石的熔炉设备 iron_ingot:4;circuit_board:2;magnetic_coil:2;gear:2 iron_ingot:4;stone_ore:2 8.0 3.5 500.0 250.0 res://assets/textures/items/drill_machine.png res://assets/textures/items/熔炉.tres
15 furnace smelter 熔炉 冶炼厂 Building 自动冶炼矿石的熔炉设备 用于冶炼矿石的基础建筑 iron_ingot:4;stone_ore:2 iron_ingot:4;copper_ingot:2 3.5 3.0 250.0 360.0 res://assets/textures/buildings/furnace.png res://assets/textures/items/冶炼厂.tres
16 smelter miner 冶炼厂 采矿机 Building 用于冶炼矿石的基础建筑 自动采集矿石的基础建筑 iron_ingot:4;copper_ingot:2 iron_ingot:3;copper_ingot:1 3.0 2.0 360.0 420.0 res://assets/textures/buildings/smelter.png res://assets/textures/items/采矿机.tres
17 miner assembler 采矿机 制造台1 Building ProductionDevice 自动采集矿石的基础建筑 高级生产设备,可制造复杂物品 iron_ingot:3;copper_ingot:1 iron_ingot:6;copper_ingot:4 2.0 5.0 420.0 480.0 res://assets/textures/buildings/miner.png res://assets/textures/items/制造台 MK 1.tres
18 assembler chemical_plant 组装机 化工厂 ProductionDevice 高级生产设备,可制造复杂物品 专业化工生产设备,可处理液体 iron_ingot:6;copper_ingot:4 iron_ingot:8;copper_ingot:6 5.0 6.0 480.0 600.0 res://assets/textures/buildings/assembler.png res://assets/textures/items/化工厂.tres
19 chemical_plant wind_turbine 化工厂 风力发电机 ProductionDevice Building 专业化工生产设备,可处理液体 利用风力发电的清洁能源设备 iron_ingot:8;copper_ingot:6 iron_ingot:8;copper_ingot:4;magnetic_coil:2;circuit_board:1 6.0 8.0 600.0 0 res://assets/textures/buildings/chemical_plant.png res://assets/textures/items/风力发电机.tres

View File

@ -147,6 +147,25 @@
} }
] ]
} }
},
{
"id": "wind_turbine_generation",
"name": "风力发电机",
"category": "发电设备",
"description": "利用风力自动发电,无需燃料",
"productionTime": 0.0,
"powerConsumption": 0,
"powerGeneration": 50,
"buildingRequirements": [
{
"itemId": "wind_turbine",
"quantity": 1
}
],
"recipe": {
"inputs": [],
"outputs": []
}
} }
] ]
} }

View File

@ -62,7 +62,12 @@ public partial class GameScene : Control
productionProcessor.Name = "ProductionProcessor"; productionProcessor.Name = "ProductionProcessor";
AddChild(productionProcessor); AddChild(productionProcessor);
GD.Print("自动产线管理器初始化完成"); // 创建PowerManager
var powerManager = new PowerManager();
powerManager.Name = "PowerManager";
AddChild(powerManager);
GD.Print("自动产线管理器和电力管理器初始化完成");
} }
private void InitializeUI() private void InitializeUI()
@ -89,12 +94,12 @@ public partial class GameScene : Control
} }
// 获取UI引用 // 获取UI引用
powerGenerationLabel = GetNode<Label>("HSplitContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow1/PowerGeneration"); powerGenerationLabel = GetNode<Label>("HBoxContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow1/PowerGeneration");
powerConsumptionLabel = GetNode<Label>("HSplitContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow1/PowerConsumption"); powerConsumptionLabel = GetNode<Label>("HBoxContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow1/PowerConsumption");
powerStorageLabel = GetNode<Label>("HSplitContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow2/PowerStorage"); powerStorageLabel = GetNode<Label>("HBoxContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow2/PowerStorage");
powerDischargeLabel = GetNode<Label>("HSplitContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow2/PowerDischarge"); powerDischargeLabel = GetNode<Label>("HBoxContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow2/PowerDischarge");
categoryTabs = GetNode<TabContainer>("HSplitContainer/RightPanel/VBoxContainer/CategoryTabs"); categoryTabs = GetNode<TabContainer>("HBoxContainer/RightPanel/VBoxContainer/CategoryTabs");
craftingQueue = GetNode<CraftingQueueManager>("HSplitContainer/LeftPanel/VBoxContainer/CraftingQueue"); craftingQueue = GetNode<CraftingQueueManager>("HBoxContainer/LeftPanel/VBoxContainer/CraftingQueue");
// 初始化库存(保留用于兼容性) // 初始化库存(保留用于兼容性)
InitializeInventory(); InitializeInventory();
@ -148,19 +153,53 @@ public partial class GameScene : Control
private void UpdatePowerInfo() private void UpdatePowerInfo()
{ {
// 这里可以从电力管理器获取实际数据 // 从PowerManager获取真实的电力数据
// 目前使用占位符数据 var powerManager = PowerManager.Instance;
if (powerGenerationLabel != null) if (powerManager != null)
powerGenerationLabel.Text = "发电: 0 KW"; {
var (generation, consumption, ratio) = powerManager.GetPowerStats();
if (powerConsumptionLabel != null)
powerConsumptionLabel.Text = "耗电: 0 KW"; if (powerGenerationLabel != null)
powerGenerationLabel.Text = $"发电: {generation:F1} W";
if (powerStorageLabel != null)
powerStorageLabel.Text = "蓄电: 0 KWh"; if (powerConsumptionLabel != null)
powerConsumptionLabel.Text = $"耗电: {consumption:F1} W";
if (powerDischargeLabel != null)
powerDischargeLabel.Text = "放电: 0 KW"; if (powerStorageLabel != null)
powerStorageLabel.Text = $"电力满足率: {ratio * 100:F1}%";
if (powerDischargeLabel != null)
{
float deficit = Mathf.Max(0, consumption - generation);
powerDischargeLabel.Text = $"电力不足: {deficit:F1} W";
// 根据电力状态设置颜色
if (deficit > 0)
{
powerDischargeLabel.Modulate = new Color(1.0f, 0.3f, 0.3f); // 红色表示不足
}
else
{
powerDischargeLabel.Modulate = new Color(0.3f, 1.0f, 0.3f); // 绿色表示充足
powerDischargeLabel.Text = "电力充足";
}
}
}
else
{
// PowerManager未初始化时的默认显示
if (powerGenerationLabel != null)
powerGenerationLabel.Text = "发电: 0 W";
if (powerConsumptionLabel != null)
powerConsumptionLabel.Text = "耗电: 0 W";
if (powerStorageLabel != null)
powerStorageLabel.Text = "电力满足率: 100%";
if (powerDischargeLabel != null)
powerDischargeLabel.Text = "电力充足";
}
} }
public override void _Input(InputEvent @event) public override void _Input(InputEvent @event)
@ -295,6 +334,7 @@ public partial class GameScene : Control
inventoryManager.AddItem("miner", 6); // 添加6个采矿机 inventoryManager.AddItem("miner", 6); // 添加6个采矿机
inventoryManager.AddItem("assembler", 3); // 添加3个组装机 inventoryManager.AddItem("assembler", 3); // 添加3个组装机
inventoryManager.AddItem("chemical_plant", 2); // 添加2个化工厂 inventoryManager.AddItem("chemical_plant", 2); // 添加2个化工厂
inventoryManager.AddItem("wind_turbine", 5); // 添加5个风力发电机
// 原材料 // 原材料
inventoryManager.AddItem("iron_ore", 50); // 添加50个铁矿 inventoryManager.AddItem("iron_ore", 50); // 添加50个铁矿
@ -309,10 +349,12 @@ public partial class GameScene : Control
inventoryManager.AddItem("copper_ingot", 20); // 添加20个铜块 inventoryManager.AddItem("copper_ingot", 20); // 添加20个铜块
GD.Print("已添加测试建筑设施和材料到库存:"); GD.Print("已添加测试建筑设施和材料到库存:");
GD.Print("建筑设施: 钻机x10, 熔炉x8, 冶炼厂x5, 采矿机x6, 组装机x3, 化工厂x2"); GD.Print("建筑设施: 钻机x10, 熔炉x8, 冶炼厂x5, 采矿机x6, 组装机x3, 化工厂x2, 风力发电机x5");
GD.Print("原材料: 铁矿x50, 铜矿x40, 煤矿x60, 石矿x80, 水x100, 原油x30"); GD.Print("原材料: 铁矿x50, 铜矿x40, 煤矿x60, 石矿x80, 水x100, 原油x30");
GD.Print("加工材料: 铁块x25, 铜块x20"); GD.Print("加工材料: 铁块x25, 铜块x20");
GD.Print("现在可以在生产线和合成标签中测试各种功能了!"); GD.Print("现在可以在生产线和合成标签中测试各种功能了!");
} }
} }

View File

@ -0,0 +1,190 @@
using Godot;
using System.Collections.Generic;
using System;
public partial class PowerManager : Node
{
public static PowerManager Instance { get; private set; }
// 电力系统状态
private float totalGeneration = 0.0f; // 总发电量 (W)
private float totalConsumption = 0.0f; // 总耗电量 (W)
private float currentPowerRatio = 1.0f; // 当前电力满足率 0-1
// 发电设备列表 - 记录每个发电设备的发电量
private Dictionary<string, float> generators = new Dictionary<string, float>();
// 信号事件
[Signal] public delegate void PowerRatioChangedEventHandler(float ratio);
[Signal] public delegate void PowerStatsChangedEventHandler(float generation, float consumption);
public override void _Ready()
{
if (Instance == null)
{
Instance = this;
GD.Print("PowerManager 初始化完成");
}
else
{
QueueFree();
}
}
// 添加发电设备
public void AddGenerator(string generatorId, float powerOutput)
{
if (powerOutput <= 0) return;
// 如果发电设备已存在,移除旧的再添加新的
if (generators.ContainsKey(generatorId))
{
float oldPower = generators[generatorId];
generators[generatorId] = powerOutput;
GD.Print($"更新发电设备 {generatorId}: {oldPower}W -> {powerOutput}W");
}
else
{
generators[generatorId] = powerOutput;
GD.Print($"添加发电设备 {generatorId}: +{powerOutput}W");
}
UpdatePowerBalance();
}
// 移除发电设备
public void RemoveGenerator(string generatorId)
{
if (generators.ContainsKey(generatorId))
{
float removedPower = generators[generatorId];
generators.Remove(generatorId);
UpdatePowerBalance();
GD.Print($"移除发电设备 {generatorId}: -{removedPower}W");
}
}
// 更新发电设备状态(发电机异常或没有原料时调用)
public void UpdateGeneratorStatus(string generatorId, bool isActive)
{
// 这里可以实现发电设备状态管理
// 暂时简化直接通过AddGenerator/RemoveGenerator来管理
GD.Print($"发电设备 {generatorId} 状态更新: {(isActive ? "" : "")}");
}
// 更新电力平衡
private void UpdatePowerBalance()
{
// 计算总发电量
totalGeneration = 0;
foreach (var generator in generators.Values)
{
totalGeneration += generator;
}
// 获取总耗电量(从生产线管理器获取)
UpdateTotalConsumption();
// 计算电力满足率
float newPowerRatio;
if (totalConsumption > 0)
{
newPowerRatio = Mathf.Min(1.0f, totalGeneration / totalConsumption);
}
else
{
newPowerRatio = 1.0f; // 没有耗电设备时电力充足
}
// 只有当电力状态发生显著变化时才打印日志和发送信号
if (Math.Abs(newPowerRatio - currentPowerRatio) > 0.01f ||
Math.Abs(totalGeneration - GetPreviousGeneration()) > 1.0f ||
Math.Abs(totalConsumption - GetPreviousConsumption()) > 1.0f)
{
currentPowerRatio = newPowerRatio;
// 发送信号通知其他系统
EmitSignal(SignalName.PowerRatioChanged, currentPowerRatio);
EmitSignal(SignalName.PowerStatsChanged, totalGeneration, totalConsumption);
GD.Print($"电力平衡更新: 发电 {totalGeneration}W, 耗电 {totalConsumption}W, 满足率 {currentPowerRatio * 100:F1}%");
}
else
{
currentPowerRatio = newPowerRatio;
}
}
private float previousGeneration = 0;
private float previousConsumption = 0;
private float GetPreviousGeneration()
{
float prev = previousGeneration;
previousGeneration = totalGeneration;
return prev;
}
private float GetPreviousConsumption()
{
float prev = previousConsumption;
previousConsumption = totalConsumption;
return prev;
}
// 更新总耗电量
private void UpdateTotalConsumption()
{
totalConsumption = 0;
var productionLineManager = ProductionLineManager.Instance;
if (productionLineManager != null)
{
var activeLines = productionLineManager.GetAllActiveProductionLines();
foreach (var activeLine in activeLines.Values)
{
if (activeLine.IsActive)
{
totalConsumption += activeLine.TotalPowerConsumption;
}
}
}
}
// 获取当前电力满足率
public float GetPowerRatio()
{
return currentPowerRatio;
}
// 获取电力统计信息
public (float generation, float consumption, float ratio) GetPowerStats()
{
return (totalGeneration, totalConsumption, currentPowerRatio);
}
// 定期更新电力系统通过_Process调用
private float updateTimer = 0.0f;
private const float UPDATE_INTERVAL = 0.5f; // 每0.5秒更新一次
public override void _Process(double delta)
{
updateTimer += (float)delta;
// 每0.5秒更新一次电力平衡,而不是每帧都更新
if (updateTimer >= UPDATE_INTERVAL)
{
updateTimer = 0.0f;
UpdatePowerBalance();
}
}
public override void _ExitTree()
{
if (Instance == this)
{
Instance = null;
}
}
}

View File

@ -26,6 +26,7 @@ public partial class ProductionLineManager : Node
public string Description { get; set; } public string Description { get; set; }
public float ProductionTime { get; set; } public float ProductionTime { get; set; }
public int PowerConsumption { get; set; } public int PowerConsumption { get; set; }
public int PowerGeneration { get; set; } = 0; // 新增:发电量
public List<ProductionRecipeItem> BuildingRequirements { get; set; } = new List<ProductionRecipeItem>(); public List<ProductionRecipeItem> BuildingRequirements { get; set; } = new List<ProductionRecipeItem>();
public ProductionRecipe Recipe { get; set; } = new ProductionRecipe(); public ProductionRecipe Recipe { get; set; } = new ProductionRecipe();
} }
@ -44,6 +45,7 @@ public partial class ProductionLineManager : Node
public bool IsActive { get; set; } = false; // 是否激活 public bool IsActive { get; set; } = false; // 是否激活
public float ProductionRate { get; set; } = 0; // 每秒产出率 public float ProductionRate { get; set; } = 0; // 每秒产出率
public int TotalPowerConsumption { get; set; } = 0; // 总功耗 public int TotalPowerConsumption { get; set; } = 0; // 总功耗
public int TotalPowerGeneration { get; set; } = 0; // 总发电量
} }
private ProductionLineData productionLineData; private ProductionLineData productionLineData;
@ -191,19 +193,59 @@ public partial class ProductionLineManager : Node
activeProductionLines[productionLineId] = new ActiveProductionLine activeProductionLines[productionLineId] = new ActiveProductionLine
{ {
ProductionLineId = productionLineId, ProductionLineId = productionLineId,
RemainingTime = productionLine.ProductionTime // 从完整的生产时间开始 RemainingTime = productionLine.PowerGeneration > 0 && productionLine.ProductionTime <= 0
? 0 // 发电设备不需要生产时间
: productionLine.ProductionTime // 普通生产设备从完整的生产时间开始
}; };
GD.Print($"创建新产线 {productionLine.Name},初始剩余时间: {productionLine.ProductionTime}s");
if (productionLine.PowerGeneration > 0 && productionLine.ProductionTime <= 0)
{
GD.Print($"创建新发电设备 {productionLine.Name},无需生产周期");
}
else
{
GD.Print($"创建新产线 {productionLine.Name},初始剩余时间: {productionLine.ProductionTime}s");
}
} }
var activeLine = activeProductionLines[productionLineId]; var activeLine = activeProductionLines[productionLineId];
activeLine.BuildingCount += count; activeLine.BuildingCount += count;
activeLine.IsActive = true; activeLine.IsActive = true;
activeLine.ProductionRate = activeLine.BuildingCount / productionLine.ProductionTime; // 每秒产出率
// 重新计算产出率:发电设备特殊处理
if (productionLine.PowerGeneration > 0 && productionLine.ProductionTime <= 0)
{
// 发电设备不产出物品产出率设为0
activeLine.ProductionRate = 0;
}
else if (productionLine.ProductionTime > 0)
{
activeLine.ProductionRate = activeLine.BuildingCount / productionLine.ProductionTime;
}
else
{
activeLine.ProductionRate = 0; // 避免除零
}
activeLine.TotalPowerConsumption = activeLine.BuildingCount * productionLine.PowerConsumption; activeLine.TotalPowerConsumption = activeLine.BuildingCount * productionLine.PowerConsumption;
activeLine.TotalPowerGeneration = activeLine.BuildingCount * productionLine.PowerGeneration;
// 如果是发电设备通知PowerManager
if (productionLine.PowerGeneration > 0)
{
var powerManager = PowerManager.Instance;
if (powerManager != null)
{
// 使用更简单的generatorId避免重复问题
string generatorId = $"{productionLineId}";
float totalGeneration = productionLine.PowerGeneration * activeLine.BuildingCount;
powerManager.AddGenerator(generatorId, totalGeneration);
GD.Print($"发电设备 {productionLine.Name} 已添加到电网: +{totalGeneration}W");
}
}
GD.Print($"成功添加 {count} 个设备到产线 {productionLine.Name}"); GD.Print($"成功添加 {count} 个设备到产线 {productionLine.Name}");
GD.Print($"当前产线状态: {activeLine.BuildingCount} 个建筑, 产出率: {activeLine.ProductionRate:F2}/s, 功耗: {activeLine.TotalPowerConsumption}W"); GD.Print($"当前产线状态: {activeLine.BuildingCount} 个建筑, 产出率: {activeLine.ProductionRate:F2}/s, 功耗: {activeLine.TotalPowerConsumption}W, 发电: {activeLine.TotalPowerGeneration}W");
} }
public void RemoveBuilding(string productionLineId, int count = 1) public void RemoveBuilding(string productionLineId, int count = 1)
@ -220,6 +262,18 @@ public partial class ProductionLineManager : Node
count = Mathf.Min(count, activeLine.BuildingCount); count = Mathf.Min(count, activeLine.BuildingCount);
if (count <= 0) return; if (count <= 0) return;
// 如果是发电设备先通知PowerManager移除发电量
if (productionLine.PowerGeneration > 0)
{
var powerManager = PowerManager.Instance;
if (powerManager != null)
{
string generatorId = $"{productionLineId}";
float totalGeneration = productionLine.PowerGeneration * activeLine.BuildingCount;
powerManager.RemoveGenerator(generatorId);
}
}
activeLine.BuildingCount -= count; activeLine.BuildingCount -= count;
if (activeLine.BuildingCount <= 0) if (activeLine.BuildingCount <= 0)
@ -227,11 +281,40 @@ public partial class ProductionLineManager : Node
activeLine.IsActive = false; activeLine.IsActive = false;
activeLine.ProductionRate = 0; activeLine.ProductionRate = 0;
activeLine.TotalPowerConsumption = 0; activeLine.TotalPowerConsumption = 0;
activeLine.TotalPowerGeneration = 0;
} }
else else
{ {
activeLine.ProductionRate = activeLine.BuildingCount / productionLine.ProductionTime; // 重新计算产出率:发电设备特殊处理
if (productionLine.PowerGeneration > 0 && productionLine.ProductionTime <= 0)
{
// 发电设备不产出物品产出率设为0
activeLine.ProductionRate = 0;
}
else if (productionLine.ProductionTime > 0)
{
activeLine.ProductionRate = activeLine.BuildingCount / productionLine.ProductionTime;
}
else
{
activeLine.ProductionRate = 0; // 避免除零
}
activeLine.TotalPowerConsumption = activeLine.BuildingCount * productionLine.PowerConsumption; activeLine.TotalPowerConsumption = activeLine.BuildingCount * productionLine.PowerConsumption;
activeLine.TotalPowerGeneration = activeLine.BuildingCount * productionLine.PowerGeneration;
// 如果是发电设备且还有剩余建筑重新添加到PowerManager
if (productionLine.PowerGeneration > 0)
{
var powerManager = PowerManager.Instance;
if (powerManager != null)
{
string newGeneratorId = $"{productionLineId}";
float totalGeneration = productionLine.PowerGeneration * activeLine.BuildingCount;
powerManager.AddGenerator(newGeneratorId, totalGeneration);
GD.Print($"发电设备 {productionLine.Name} 已添加到电网: +{totalGeneration}W");
}
}
} }
// 归还建筑材料到库存 // 归还建筑材料到库存
@ -246,7 +329,7 @@ public partial class ProductionLineManager : Node
} }
GD.Print($"移除 {count} 个设备从产线 {productionLine.Name}"); GD.Print($"移除 {count} 个设备从产线 {productionLine.Name}");
GD.Print($"当前产线状态: {activeLine.BuildingCount} 个建筑, 产出率: {activeLine.ProductionRate:F2}/s, 功耗: {activeLine.TotalPowerConsumption}W"); GD.Print($"当前产线状态: {activeLine.BuildingCount} 个建筑, 产出率: {activeLine.ProductionRate:F2}/s, 功耗: {activeLine.TotalPowerConsumption}W, 发电: {activeLine.TotalPowerGeneration}W");
} }
public ActiveProductionLine GetActiveProductionLine(string productionLineId) public ActiveProductionLine GetActiveProductionLine(string productionLineId)

View File

@ -44,8 +44,33 @@ public partial class ProductionProcessor : Node
var productionLine = ProductionLineManager.Instance?.GetProductionLine(activeLine.ProductionLineId); var productionLine = ProductionLineManager.Instance?.GetProductionLine(activeLine.ProductionLineId);
if (productionLine == null) return; if (productionLine == null) return;
// 特殊处理如果是发电设备powerGeneration > 0 且 productionTime <= 0跳过生产处理
if (productionLine.PowerGeneration > 0 && productionLine.ProductionTime <= 0)
{
// 发电设备不需要生产周期,直接返回
// 发电量已经在添加建筑时注册到PowerManager了
return;
}
// 获取电力满足率
float powerRatio = 1.0f;
var powerManager = PowerManager.Instance;
if (powerManager != null)
{
powerRatio = powerManager.GetPowerRatio();
}
// 根据电力满足率调整生产速度
float adjustedDeltaTime = deltaTime * powerRatio;
// 如果电力不足,减慢生产速度
if (powerRatio < 1.0f)
{
GD.Print($"产线 {productionLine.Name} 电力不足,生产速度调整为 {powerRatio * 100:F1}%");
}
// 更新生产时间 // 更新生产时间
activeLine.RemainingTime -= deltaTime; activeLine.RemainingTime -= adjustedDeltaTime;
if (activeLine.RemainingTime <= 0) if (activeLine.RemainingTime <= 0)
{ {
@ -62,12 +87,32 @@ public partial class ProductionProcessor : Node
activeLine.RemainingTime = productionLine.ProductionTime; activeLine.RemainingTime = productionLine.ProductionTime;
GD.Print($"产线 {productionLine.Name} 完成一轮生产,{activeLine.BuildingCount} 个建筑同时运行"); GD.Print($"产线 {productionLine.Name} 完成一轮生产,{activeLine.BuildingCount} 个建筑同时运行");
// 如果是发电设备通知PowerManager发电机运行
if (productionLine.PowerGeneration > 0)
{
if (powerManager != null)
{
string generatorId = $"{activeLine.ProductionLineId}_{activeLine.BuildingCount}";
powerManager.UpdateGeneratorStatus(generatorId, true);
}
}
} }
else else
{ {
// 原料不足,暂停生产 // 原料不足,暂停生产
activeLine.RemainingTime = 0.1f; // 短暂等待后再检查 activeLine.RemainingTime = 0.1f; // 短暂等待后再检查
GD.Print($"产线 {productionLine.Name} 原料不足,暂停生产"); GD.Print($"产线 {productionLine.Name} 原料不足,暂停生产");
// 如果是发电设备通知PowerManager发电机异常
if (productionLine.PowerGeneration > 0)
{
if (powerManager != null)
{
string generatorId = $"{activeLine.ProductionLineId}_{activeLine.BuildingCount}";
powerManager.UpdateGeneratorStatus(generatorId, false);
}
}
} }
} }
} }
@ -77,6 +122,12 @@ public partial class ProductionProcessor : Node
var inventoryManager = InventoryManager.Instance; var inventoryManager = InventoryManager.Instance;
if (inventoryManager == null) return false; if (inventoryManager == null) return false;
// 如果没有输入材料需求如发电设备直接返回true
if (productionLine.Recipe.Inputs == null || productionLine.Recipe.Inputs.Count == 0)
{
return true;
}
// 检查所有输入材料 // 检查所有输入材料
foreach (var input in productionLine.Recipe.Inputs) foreach (var input in productionLine.Recipe.Inputs)
{ {
@ -143,7 +194,12 @@ public partial class ProductionProcessor : Node
} }
float progress = 0; float progress = 0;
if (activeLine.IsActive && productionLine.ProductionTime > 0) // 发电设备的进度条始终显示100%
if (productionLine.PowerGeneration > 0 && productionLine.ProductionTime <= 0)
{
progress = 1.0f; // 发电设备进度始终为100%
}
else if (activeLine.IsActive && productionLine.ProductionTime > 0)
{ {
progress = 1.0f - (activeLine.RemainingTime / productionLine.ProductionTime); progress = 1.0f - (activeLine.RemainingTime / productionLine.ProductionTime);
} }

View File

@ -80,8 +80,30 @@ public partial class ProductionLineItem : Panel
// 设置基本信息 // 设置基本信息
nameLabel.Text = productionLine.Name; nameLabel.Text = productionLine.Name;
timeLabel.Text = $"{productionLine.ProductionTime:F1}s";
powerLabel.Text = $"{productionLine.PowerConsumption}W"; // 设置时间显示:发电设备显示"持续",其他显示具体时间
if (productionLine.PowerGeneration > 0 && productionLine.ProductionTime <= 0)
{
timeLabel.Text = "持续";
timeLabel.Modulate = new Color(0.3f, 1.0f, 0.3f); // 绿色表示持续运行
}
else
{
timeLabel.Text = $"{productionLine.ProductionTime:F1}s";
timeLabel.Modulate = new Color(1.0f, 1.0f, 1.0f); // 默认白色
}
// 设置功耗或发电量显示
if (productionLine.PowerGeneration > 0)
{
powerLabel.Text = $"+{productionLine.PowerGeneration}W";
powerLabel.Modulate = new Color(0.3f, 1.0f, 0.3f); // 绿色表示发电
}
else
{
powerLabel.Text = $"{productionLine.PowerConsumption}W";
powerLabel.Modulate = new Color(1.0f, 0.9f, 0.7f); // 原来的颜色表示耗电
}
// 设置建筑需求信息 // 设置建筑需求信息
if (productionLine.BuildingRequirements != null && productionLine.BuildingRequirements.Count > 0) if (productionLine.BuildingRequirements != null && productionLine.BuildingRequirements.Count > 0)
@ -176,14 +198,24 @@ public partial class ProductionLineItem : Panel
// 更新设备数量 // 更新设备数量
deviceLabel.Text = $"设备: {activeLine.BuildingCount}"; deviceLabel.Text = $"设备: {activeLine.BuildingCount}";
// 更新产出率 // 更新产出率或发电量显示
if (activeLine.IsActive && activeLine.ProductionRate > 0) if (productionLine.PowerGeneration > 0 && productionLine.ProductionTime <= 0)
{ {
// 发电设备显示发电量
float totalGeneration = productionLine.PowerGeneration * activeLine.BuildingCount;
productionLabel.Text = $"{totalGeneration}W";
productionLabel.Modulate = new Color(0.3f, 1.0f, 0.3f); // 绿色表示发电
}
else if (activeLine.IsActive && activeLine.ProductionRate > 0)
{
// 普通生产设备显示产出率
productionLabel.Text = $"{activeLine.ProductionRate:F1}/s"; productionLabel.Text = $"{activeLine.ProductionRate:F1}/s";
productionLabel.Modulate = new Color(1.0f, 1.0f, 1.0f); // 白色
} }
else else
{ {
productionLabel.Text = "0/s"; productionLabel.Text = "0/s";
productionLabel.Modulate = new Color(0.7f, 0.7f, 0.7f); // 灰色表示未激活
} }
// 更新进度条(添加边界检查,避免闪烁) // 更新进度条(添加边界检查,避免闪烁)