Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add the send-to-orbit trigger I left out of #350. #355

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Yafc.Model/Data/DataClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ public enum RecipeFlags {
HasResearchTriggerBuildEntity = 1 << 7,
/// <summary>Set when the technology has a research trigger to launch a space platform starter pack</summary>
HasResearchTriggerCreateSpacePlatform = 1 << 8,
/// <summary>Set when the technology has a research trigger to launch an arbitrary item.</summary>
HasResearchTriggerSendToOrbit = 1 << 9,

HasResearchTriggerMask = HasResearchTriggerCraft | HasResearchTriggerCaptureEntity | HasResearchTriggerMineEntity | HasResearchTriggerBuildEntity
| HasResearchTriggerCreateSpacePlatform,
| HasResearchTriggerCreateSpacePlatform | HasResearchTriggerSendToOrbit,
}

public abstract class RecipeOrTechnology : FactorioObject {
Expand Down Expand Up @@ -773,6 +775,7 @@ public class Technology : RecipeOrTechnology { // Technology is very similar to
/// </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;
public Item? triggerItem { get; internal set; }

/// <summary>
/// Sets the value used to construct <see cref="triggerEntities"/>.
Expand All @@ -795,6 +798,9 @@ public override void GetDependencies(IDependencyCollector collector, List<Factor
var items = Database.items.all.Where(i => i.factorioType == "space-platform-starter-pack");
collector.Add([.. items.Select(i => Database.objectsByTypeName["Mechanics.launch." + i.name])], DependencyList.Flags.Source);
}
if (flags.HasFlag(RecipeFlags.HasResearchTriggerSendToOrbit)) {
collector.Add([Database.objectsByTypeName["Mechanics.launch." + triggerItem]], DependencyList.Flags.Source);
}

if (hidden && !enabled) {
collector.Add(Array.Empty<FactorioId>(), DependencyList.Flags.Hidden);
Expand Down
26 changes: 18 additions & 8 deletions Yafc.Parser/Data/FactorioDataDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,14 +437,7 @@ void readTrigger(LuaTable table) {
launchProducts = [];
}

var recipe = CreateSpecialRecipe(item, SpecialNames.RocketLaunch, "launched");
recipe.ingredients =
[
new Ingredient(item, item.stackSize),
new Ingredient(rocketLaunch, 1)
];
recipe.products = launchProducts;
recipe.time = 0f; // TODO what to put here?
EnsureLaunchRecipe(item, launchProducts);
}

if (GetRef(table, "spoil_result", out Item? spoiled)) {
Expand Down Expand Up @@ -485,6 +478,23 @@ void readEffect(LuaTable effect) {
}
}

/// <summary>
/// Creates, or confirms the existence of, a recipe for launching a particular item.
/// </summary>
/// <param name="item">The <see cref="Item"/> to be launched.</param>
/// <param name="launchProducts">The result of launching <see cref="Item"/>, if known. Otherwise <see langword="null"/>, to preserve
/// the existing launch products of a preexisting recipe, or set no products for a new recipe.</param>
private void EnsureLaunchRecipe(Item item, Product[]? launchProducts) {
Recipe recipe = CreateSpecialRecipe(item, SpecialNames.RocketLaunch, "launched");
recipe.ingredients =
[
new Ingredient(item, item.stackSize),
new Ingredient(rocketLaunch, 1),
];
recipe.products = launchProducts ?? recipe.products ?? [];
recipe.time = 0f; // TODO what to put here?
}

private Fluid SplitFluid(Fluid basic, int temperature) {
logger.Information("Splitting fluid {FluidName} at {Temperature}", basic.name, temperature);
basic.variants ??= [basic];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,17 @@ private void LoadResearchTrigger(LuaTable researchTriggerTable, ref Technology t
case "create-space-platform":
technology.flags = RecipeFlags.HasResearchTriggerCreateSpacePlatform;
break;
case "send-item-to-orbit":
if (!researchTriggerTable.Get("item", out string? itemName)) {
errorCollector.Error($"Research trigger {type} of {technology.typeDotName} does not have an item field", ErrorSeverity.MinorDataLoss);
break;
}
Item item = GetObject<Item>(itemName);
technology.triggerItem = item;
technology.flags |= RecipeFlags.HasResearchTriggerSendToOrbit;
// Create a launch recipe for items without a `rocket_launch_products`, without altering existing launch recipes.
EnsureLaunchRecipe(item, null);
break;
default:
errorCollector.Error($"Research trigger of {technology.typeDotName} has an unsupported type {type}", ErrorSeverity.MinorDataLoss);
break;
Expand Down
7 changes: 7 additions & 0 deletions Yafc/Widgets/ObjectTooltip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ private static void BuildTechnology(Technology technology, ImGui gui) {
bool isResearchTriggerMine = technology.flags.HasFlag(RecipeFlags.HasResearchTriggerMineEntity);
bool isResearchTriggerBuild = technology.flags.HasFlag(RecipeFlags.HasResearchTriggerBuildEntity);
bool isResearchTriggerPlatform = technology.flags.HasFlag(RecipeFlags.HasResearchTriggerCreateSpacePlatform);
bool isResearchTriggerLaunch = technology.flags.HasFlag(RecipeFlags.HasResearchTriggerSendToOrbit);

if (!technology.flags.HasFlagAny(RecipeFlags.HasResearchTriggerMask)) {
BuildRecipe(technology, gui);
Expand Down Expand Up @@ -580,6 +581,12 @@ private static void BuildTechnology(Technology technology, ImGui gui) {
BuildIconRow(gui, items, 2);
}
}
else if (isResearchTriggerLaunch) {
BuildSubHeader(gui, "Launch this item");
using (gui.EnterGroup(contentPadding)) {
gui.BuildFactorioObjectButtonWithText(technology.triggerItem);
}
}

if (technology.unlockRecipes.Count > 0) {
BuildSubHeader(gui, "Unlocks recipes");
Expand Down