Skip to content

Commit

Permalink
Showing 3 changed files with 31 additions and 19 deletions.
18 changes: 15 additions & 3 deletions Source/EntryCosts/EntryCostDatabase.cs
Original file line number Diff line number Diff line change
@@ -73,19 +73,19 @@ protected static void FillHolders()

#region Helpers
// from RF
public static string GetPartName(Part part)
protected static string GetPartName(Part part)
{
if (part.partInfo != null)
return GetPartName(part.partInfo);
return GetPartName(part.name);
}

public static string GetPartName(AvailablePart ap)
protected static string GetPartName(AvailablePart ap)
{
return GetPartName(ap.name);
}

public static string GetPartName(string partName)
protected static string GetPartName(string partName)
{
partName = partName.Replace(".", "-");
return partName.Replace("_", "-");
@@ -98,6 +98,10 @@ public static bool IsUnlocked(string name)
return unlocks.Contains(name) || RealFuels.RFUpgradeManager.Instance.ConfigUnlocked(name);
}

public static void SetUnlocked(AvailablePart ap)
{
SetUnlocked(GetPartName(ap));
}
public static void SetUnlocked(string name)
{
// RF's current unlock system doesn't allow checking unlock status.
@@ -108,6 +112,13 @@ public static void SetUnlocked(string name)
RealFuels.RFUpgradeManager.Instance.SetConfigUnlock(name, true);

unlocks.Add(name); // add regardless

PartEntryCostHolder h;
if (holders.TryGetValue(name, out h))
{
foreach (string s in h.children)
SetUnlocked(s);
}
}

public static int GetCost(string name)
@@ -122,6 +133,7 @@ public static int GetCost(string name)
public static void UpdateEntryCost(AvailablePart ap)
{
string name = GetPartName(ap);

PartEntryCostHolder h;
if (holders.TryGetValue(name, out h))
ap.SetEntryCost(h.GetCost());
13 changes: 5 additions & 8 deletions Source/EntryCosts/EntryCostModifier.cs
Original file line number Diff line number Diff line change
@@ -40,22 +40,19 @@ public override void OnSave(ConfigNode node)
#region Methods
public void onPartPurchased(AvailablePart ap)
{
EntryCostDatabase.SetUnlocked(ap);
UpdatePartEntryCosts();
}
public void UpdatePartEntryCosts()
{
for (int a = PartLoader.LoadedPartsList.Count - 1; a >= 0; --a)
{
AvailablePart ap = PartLoader.LoadedPartsList[a];
if (ap == null)
{

if (ap == null || ap.partPrefab == null)
continue;
}
Part part = ap.partPrefab;
if (part != null)
{
EntryCostDatabase.UpdateEntryCost(ap);
}

EntryCostDatabase.UpdateEntryCost(ap);
}
}
#endregion
19 changes: 11 additions & 8 deletions Source/EntryCosts/PartEntryCostHolder.cs
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ public class PartEntryCostHolder

public int cost = 0;

public List<string> children;
public List<string> children = new List<string>();
#endregion

#region Constructors
@@ -20,10 +20,14 @@ public PartEntryCostHolder(string name, string val)
this.name = name;

int tmp;
if (int.TryParse(val, out tmp))
cost = tmp;
else
children = new List<string>(val.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries));
string[] split = val.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string s in split)
{
if (int.TryParse(s, out tmp))
cost += tmp;
else
children.Add(s);
}
}
#endregion

@@ -35,9 +39,8 @@ public int GetCost()

int c = cost;

if (children != null)
foreach (string s in children)
c += EntryCostDatabase.GetCost(name);
foreach (string s in children)
c += EntryCostDatabase.GetCost(s);

return c;
}

0 comments on commit 89b5a0b

Please sign in to comment.