Complete resource manager

This commit is contained in:
2025-08-29 00:10:19 +08:00
parent 0d3c84491b
commit 850628ca72
5 changed files with 287 additions and 29 deletions

View File

@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using Godot;
using static System.Int32;
namespace AceFieldNewHorizon.Scripts.System;
@@ -101,12 +102,22 @@ public partial class BuildingRegistry : Node
{
int val;
var obj = costDict[mat];
if (obj.VariantType == Variant.Type.PackedInt64Array)
val = (int)obj.AsInt64();
else if (obj.VariantType == Variant.Type.PackedInt32Array)
val = obj.AsInt32();
else
int.TryParse(obj.ToString(), out val);
switch (obj.VariantType)
{
case Variant.Type.PackedInt64Array:
val = (int)obj.AsInt64();
break;
case Variant.Type.PackedInt32Array:
val = obj.AsInt32();
break;
case Variant.Type.Float:
val = (int)obj.AsDouble();
break;
default:
if (!TryParse(obj.ToString(), out val))
GD.PrintErr($"[BuildingRegistry] Failed to parse cost for '{key}': {obj.ToString()}");
break;
}
cost[mat] = val;
}
}
@@ -120,7 +131,7 @@ public partial class BuildingRegistry : Node
else if (dObj.VariantType == Variant.Type.PackedInt32Array)
durability = dObj.AsInt32();
else
int.TryParse(dObj.ToString(), out durability);
TryParse(dObj.ToString(), out durability);
}
// Parse buildTime