Big project cleanup with overhaul of file responsibilities (KISS) and code (DRY, YAGNI)
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
public class Building
|
||||
{
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://cl2yvllo35qbb
|
||||
@@ -1,92 +1,95 @@
|
||||
public class GameResource
|
||||
{
|
||||
private const float NormalExtractionSpeed = 1f;
|
||||
private const float EndlessExtractionSpeed = 4f;
|
||||
private const float NormalExtractionSpeed = 1f;
|
||||
private const float EndlessExtractionSpeed = 4f;
|
||||
|
||||
public string name;
|
||||
public ItemData item;
|
||||
public string name;
|
||||
public ItemData item;
|
||||
|
||||
private int currentAmount;
|
||||
private int maxAmount;
|
||||
private bool isEndless;
|
||||
private float extractionSpeed;
|
||||
private double timeSinceLastExtraction;
|
||||
private int currentAmount;
|
||||
private int maxAmount;
|
||||
private bool isEndless;
|
||||
private float extractionSpeed;
|
||||
private double timeSinceLastExtraction;
|
||||
|
||||
public GameResource(string name)
|
||||
{
|
||||
this.name = name;
|
||||
maxAmount = GameData.rand.Next(1000, 10000);
|
||||
currentAmount = maxAmount;
|
||||
isEndless = false;
|
||||
extractionSpeed = NormalExtractionSpeed;
|
||||
item = GameData.availableItems[name];
|
||||
}
|
||||
public GameResource(string name)
|
||||
{
|
||||
this.name = name;
|
||||
maxAmount = GameData.rand.Next(1000, 10000);
|
||||
currentAmount = maxAmount;
|
||||
isEndless = false;
|
||||
extractionSpeed = NormalExtractionSpeed;
|
||||
item = GameData.availableItems[name];
|
||||
}
|
||||
|
||||
public static GameResource FromSaveData(ResourceSaveData saveData)
|
||||
{
|
||||
GameResource resource = new GameResource(saveData.Name)
|
||||
{
|
||||
currentAmount = saveData.CurrentAmount,
|
||||
maxAmount = saveData.MaxAmount,
|
||||
isEndless = saveData.IsEndless,
|
||||
extractionSpeed = saveData.ExtractionSpeed
|
||||
};
|
||||
if (resource.isEndless && resource.extractionSpeed <= NormalExtractionSpeed)
|
||||
{
|
||||
resource.extractionSpeed = EndlessExtractionSpeed;
|
||||
}
|
||||
resource.timeSinceLastExtraction = saveData.TimeSinceLastExtraction;
|
||||
return resource;
|
||||
}
|
||||
public static GameResource FromSaveData(ResourceSaveData saveData)
|
||||
{
|
||||
GameResource resource = new GameResource(saveData.Name)
|
||||
{
|
||||
currentAmount = saveData.CurrentAmount,
|
||||
maxAmount = saveData.MaxAmount,
|
||||
isEndless = saveData.IsEndless,
|
||||
extractionSpeed = saveData.ExtractionSpeed,
|
||||
timeSinceLastExtraction = saveData.TimeSinceLastExtraction
|
||||
};
|
||||
resource.NormalizeExtractionSpeed();
|
||||
return resource;
|
||||
}
|
||||
|
||||
public ResourceSaveData CreateSaveData()
|
||||
{
|
||||
return new ResourceSaveData
|
||||
{
|
||||
Name = name,
|
||||
CurrentAmount = currentAmount,
|
||||
MaxAmount = maxAmount,
|
||||
IsEndless = isEndless,
|
||||
ExtractionSpeed = extractionSpeed,
|
||||
TimeSinceLastExtraction = timeSinceLastExtraction
|
||||
};
|
||||
}
|
||||
public ResourceSaveData CreateSaveData()
|
||||
{
|
||||
return new ResourceSaveData
|
||||
{
|
||||
Name = name,
|
||||
CurrentAmount = currentAmount,
|
||||
MaxAmount = maxAmount,
|
||||
IsEndless = isEndless,
|
||||
ExtractionSpeed = extractionSpeed,
|
||||
TimeSinceLastExtraction = timeSinceLastExtraction
|
||||
};
|
||||
}
|
||||
|
||||
public bool Extract(double delta)
|
||||
{
|
||||
timeSinceLastExtraction += delta;
|
||||
if (timeSinceLastExtraction < extractionSpeed) return false;
|
||||
public bool Extract(double delta)
|
||||
{
|
||||
timeSinceLastExtraction += delta;
|
||||
if (timeSinceLastExtraction < extractionSpeed) return false;
|
||||
|
||||
timeSinceLastExtraction = 0;
|
||||
if (isEndless) return true;
|
||||
timeSinceLastExtraction = 0;
|
||||
if (isEndless) return true;
|
||||
|
||||
if (currentAmount > 0)
|
||||
{
|
||||
currentAmount--;
|
||||
return true;
|
||||
}
|
||||
if (currentAmount <= 0) return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
currentAmount--;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanExtract()
|
||||
{
|
||||
return (isEndless || currentAmount > 0) && GameData.availableResearch[item.Research].state == ResearchState.RESEARCHED;
|
||||
}
|
||||
public bool CanExtract()
|
||||
{
|
||||
return (isEndless || currentAmount > 0)
|
||||
&& GameData.availableResearch[item.Research].state == ResearchState.RESEARCHED;
|
||||
}
|
||||
|
||||
public void MakeEndless()
|
||||
{
|
||||
isEndless = true;
|
||||
extractionSpeed = EndlessExtractionSpeed;
|
||||
}
|
||||
public void MakeEndless()
|
||||
{
|
||||
isEndless = true;
|
||||
extractionSpeed = EndlessExtractionSpeed;
|
||||
}
|
||||
|
||||
public bool IsEndless()
|
||||
{
|
||||
return isEndless;
|
||||
}
|
||||
public bool IsEndless()
|
||||
{
|
||||
return isEndless;
|
||||
}
|
||||
|
||||
public float GetExtractionSpeed()
|
||||
{
|
||||
return extractionSpeed;
|
||||
}
|
||||
public float GetExtractionSpeed()
|
||||
{
|
||||
return extractionSpeed;
|
||||
}
|
||||
|
||||
private void NormalizeExtractionSpeed()
|
||||
{
|
||||
if (!isEndless) return;
|
||||
if (extractionSpeed > NormalExtractionSpeed) return;
|
||||
|
||||
extractionSpeed = EndlessExtractionSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,12 +29,13 @@ public class ItemData
|
||||
|
||||
public string GetReadableName()
|
||||
{
|
||||
string noUnderscore = Id.Replace("_", " ").ToLower();
|
||||
return char.ToUpper(noUnderscore[0]) + noUnderscore.Substring(1);
|
||||
return GetReadableName(Id);
|
||||
}
|
||||
|
||||
public static string GetReadableName(string input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input)) return "";
|
||||
|
||||
string noUnderscore = input.Replace("_", " ").ToLower();
|
||||
return char.ToUpper(noUnderscore[0]) + noUnderscore.Substring(1);
|
||||
}
|
||||
@@ -46,6 +47,8 @@ public class ItemData
|
||||
|
||||
public string GetCraftingDisplay()
|
||||
{
|
||||
if (Inputs.Count <= 0) return GetReadableName() + ": \r";
|
||||
|
||||
string result = GetReadableName() + ": \r";
|
||||
|
||||
foreach (Ingredient ingredient in Inputs)
|
||||
@@ -53,8 +56,6 @@ public class ItemData
|
||||
result += $"{GetReadableName(ingredient.Item)} ({ingredient.Amount}),\r";
|
||||
}
|
||||
|
||||
if (Inputs.Count <= 0) return result;
|
||||
|
||||
result = result.Remove(result.Length - 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user