Skip to content

Commit

Permalink
feat(#315): Parse and display the capture-spawner tech trigger.
Browse files Browse the repository at this point in the history
  • Loading branch information
DaleStan committed Nov 7, 2024
1 parent 18cbf04 commit c1776c1
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
12 changes: 12 additions & 0 deletions Yafc.Model/Data/DataClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public enum RecipeFlags {
ScaleProductionWithPower = 1 << 3,
/// <summary>Set when the technology has a research trigger to craft an item</summary>
HasResearchTriggerCraft = 1 << 4,
/// <summary>Set when the technology has a research trigger to capture a spawner</summary>
HasResearchTriggerCaptureEntity = 1 << 8,
}

public abstract class RecipeOrTechnology : FactorioObject {
Expand Down Expand Up @@ -690,6 +692,16 @@ public class Technology : RecipeOrTechnology { // Technology is very similar to
public Dictionary<Recipe, float> changeRecipeProductivity { get; internal set; } = [];
internal override FactorioObjectSortOrder sortingOrder => FactorioObjectSortOrder.Technologies;
public override string type => "Technology";
/// <summary>
/// If the technology has a trigger that requires entities, they are stored here.
/// </summary>
/// <remarks>Lazy-loaded so the database can load and correctly type (eg EntityCrafter, EntitySpawner, etc.) the entities without having to do another pass.</remarks>
public IReadOnlyList<Entity> triggerEntities => getTriggerEntities.Value;

/// <summary>
/// Sets the value used to construct <see cref="triggerEntities"/>.
/// </summary>
internal Lazy<IReadOnlyList<Entity>> getTriggerEntities { get; set; } = new Lazy<IReadOnlyList<Entity>>(() => []);

public override void GetDependencies(IDependencyCollector collector, List<FactorioObject> temp) {
base.GetDependencies(collector, temp);
Expand Down
12 changes: 12 additions & 0 deletions Yafc.Parser/Data/FactorioDataDeserializer_RecipeAndTechnology.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,18 @@ private void LoadResearchTrigger(LuaTable researchTriggerTable, ref Technology t
technology.ingredients = [new Ingredient(GetObject<Item>(craftItemName), craftCount)];
technology.flags = RecipeFlags.HasResearchTriggerCraft;

break;
case "capture-spawner":
technology.flags = RecipeFlags.HasResearchTriggerCaptureEntity;
if (researchTriggerTable.Get<string>("entity") is string entity) {
technology.getTriggerEntities = new(() => [((Entity)Database.objectsByTypeName["Entity." + entity])]);
}
else {
technology.getTriggerEntities = new(static () =>
Database.entities.all.OfType<EntitySpawner>()
.Where(e => e.capturedEntityName != null)
.ToList());
}
break;
default:
errorCollector.Error($"Research trigger of {technology.typeDotName} has an unsupported type {type}", ErrorSeverity.MinorDataLoss);
Expand Down
22 changes: 20 additions & 2 deletions Yafc/Widgets/ObjectTooltip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,10 @@ private static void BuildRecipe(RecipeOrTechnology recipe, ImGui gui) {
}

private static void BuildTechnology(Technology technology, ImGui gui) {
bool isResearchTriggerCraft = (technology.flags & RecipeFlags.HasResearchTriggerCraft) == RecipeFlags.HasResearchTriggerCraft;
if (!isResearchTriggerCraft) {
bool isResearchTriggerCraft = technology.flags.HasFlag(RecipeFlags.HasResearchTriggerCraft);
bool isResearchTriggerCapture = technology.flags.HasFlag(RecipeFlags.HasResearchTriggerCaptureEntity);

if (!isResearchTriggerCraft && !isResearchTriggerCapture) {
BuildRecipe(technology, gui);
}

Expand All @@ -524,6 +526,22 @@ private static void BuildTechnology(Technology technology, ImGui gui) {
_ = gui.BuildFactorioObjectWithAmount(technology.ingredients[0].goods, technology.ingredients[0].amount, ButtonDisplayStyle.ProductionTableUnscaled);
}
}
else if (isResearchTriggerCapture) {
BuildSubHeader(gui, "Entity capture required");
using (gui.EnterGroup(contentPadding)) {
if (technology.triggerEntities.Count == 1) {
gui.BuildText("Capture:");
gui.BuildFactorioObjectButtonWithText(technology.triggerEntities[0]);

}
else {
gui.BuildText("Capture one of:");
foreach (var entity in technology.triggerEntities) {
gui.BuildFactorioObjectButtonWithText(entity);
}
}
}
}

if (technology.unlockRecipes.Count > 0) {
BuildSubHeader(gui, "Unlocks recipes");
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Version:
Date:
Features:
- (SA) Process accessiblilty of captured spawners, which also fixes biter eggs and subsequent Gleba recipes.
- (SA) Add support for the capture-spawner technology trigger.
----------------------------------------------------------------------------------------------------------------------
Version: 2.2.0
Date: November 6th 2024
Expand Down

0 comments on commit c1776c1

Please sign in to comment.