From d63f1aa745d51967389ccd3e8e08258029752586 Mon Sep 17 00:00:00 2001 From: Stephen Fasciani Date: Tue, 8 Sep 2026 06:48:57 -0400 Subject: [PATCH] Opt-in auto-remove: picking up the goal item counts it done. /satistaskory auto-remove. Off by default. A gain in held target items reduces quantity and removes the goal at 0. Player inventory only. Already-held stacks are a baseline, not a wipe. --- AGENTS.md | 2 +- README.md | 2 +- docs/02-Domain/βœ… Completed Goal.md | 9 +-- docs/02-Domain/🎯 Goal.md | 2 +- docs/03-Architecture/▢️ Create Goal.md | 1 + docs/03-Architecture/πŸ“ Decisions.md | 22 +++++- docs/03-Architecture/πŸ“¦ Packages.md | 6 +- docs/04-Planning/πŸ—ΊοΈ Roadmap.md | 3 +- .../04-Planning/🧭 Notes for the Wayfinder.md | 10 +++ docs/05-Experience/πŸ–₯️ Experience.md | 2 + docs/99-backlog/🚧 Future Ideas.md | 2 +- .../application/ObtainedCompletion.java | 48 ++++++++++++ .../satistaskory/application/Planner.java | 23 ++++++ .../satistaskory/domain/InventoryState.java | 4 + .../infrastructure/client/ClientCommands.java | 26 ++++++- .../infrastructure/client/ClientSettings.java | 78 +++++++++++++++++++ .../infrastructure/client/PlannerSession.java | 17 ++++ .../infrastructure/client/PlayOverlay.java | 2 +- .../assets/satistaskory/lang/en_us.json | 4 +- .../application/ObtainedCompletionTest.java | 65 ++++++++++++++++ 20 files changed, 311 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/sufficient/satistaskory/application/ObtainedCompletion.java create mode 100644 src/main/java/com/sufficient/satistaskory/infrastructure/client/ClientSettings.java create mode 100644 src/test/java/com/sufficient/satistaskory/application/ObtainedCompletionTest.java diff --git a/AGENTS.md b/AGENTS.md index 6eddfbc..4a6804e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -40,7 +40,7 @@ Read [[🧠 Philosophy]] before changing the vault. The Bookshelf Principle, Pre ## Code -The first slice is in code and has been played (ADRs 012–019): [[▢️ Create Goal]], [[πŸ”Œ Recipe Provider]] via `RecipeManager`, overlay HUD, capture = tooltip + rebindable Add key, client-owned plan files. Tag ingredients are any-of (ADR-019). +The first slice is in code and has been played (ADRs 012–020): [[▢️ Create Goal]], [[πŸ”Œ Recipe Provider]] via `RecipeManager`, overlay HUD, capture = tooltip + rebindable Add key, client-owned plan files. Tag ingredients are any-of (ADR-019). Completion is manual, plus opt-in `/satistaskory auto-remove` (ADR-020). Do not start EMI/JEI/REI. Recipe source is `RecipeManager` (ADR-016). The host does not need this mod (ADR-018). Project waits until settled. Do not rewrite the overlay as a `Screen` unless the HUD path fails. diff --git a/README.md b/README.md index a9a916b..b242423 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ First slice is in `src/` and has been played: domain, `VanillaRecipeProvider` (` On a server, the plan follows the **name you gave that server in the multiplayer list** (and its MOTD), not the IP. **Do not rename the list entry** if you still need those Crafting Goals. Renaming starts an empty plan. Rebuilding it from memory is the thing this mod is supposed to spare you. -`/satistaskory add minecraft:furnace` is a debug command. Not EMI. Template example block/item is gone. +`/satistaskory add minecraft:furnace` is a debug command. `/satistaskory auto-remove` counts picking up a goal item as done (off by default). Not EMI. Template example block/item is gone. --- diff --git a/docs/02-Domain/βœ… Completed Goal.md b/docs/02-Domain/βœ… Completed Goal.md index 4111bd3..f1f3689 100644 --- a/docs/02-Domain/βœ… Completed Goal.md +++ b/docs/02-Domain/βœ… Completed Goal.md @@ -8,13 +8,12 @@ A [[🎯 Goal]] that the player considers finished. Must be configurable. -Examples: +Shipped: -- Manual completion -- Inventory detection -- Future implementations +- Manual: `[βˆ’]` at 1, or Clear +- Inventory detection (opt-in): `/satistaskory auto-remove` β€” picking up the goal item counts that many as done. Player inventory only. Dumping the item in a chest does not restore the quantity. Turning it on (or joining a world) baselines what you already hold; it does not wipe the list for items already on you. -Ready To Craft is not completion. See [[πŸ› οΈ Ready To Craft]] and Philosophy Rule #5. +Ready To Craft is not completion. Auto-remove is off until the player turns it on. See [[πŸ› οΈ Ready To Craft]] and Philosophy Rule #5. --- diff --git a/docs/02-Domain/🎯 Goal.md b/docs/02-Domain/🎯 Goal.md index 663f608..bdd509a 100644 --- a/docs/02-Domain/🎯 Goal.md +++ b/docs/02-Domain/🎯 Goal.md @@ -67,7 +67,7 @@ Completed A goal is created with a target item and quantity. [[🧾 Recipe Resolution]] produces its [[🧱 Material Requirement|material requirements]] for **how many are still to obtain** (target quantity minus how many of that item are already available). [[πŸ“ˆ Progress Calculation]] compares those requirements to [[πŸŽ’ Inventory State]], yielding [[πŸ“‰ Missing Material|missing materials]] and eventually [[πŸ› οΈ Ready To Craft]]. -[[βœ… Completed Goal|Completion]] is a separate decision from readiness. It is **not in the first slice**. +[[βœ… Completed Goal|Completion]] is a separate decision from readiness. Manual `[βˆ’]` / Clear always. Inventory detection is opt-in (`/satistaskory auto-remove`): a gain in held target items reduces quantity and removes the goal at 0. --- diff --git a/docs/03-Architecture/▢️ Create Goal.md b/docs/03-Architecture/▢️ Create Goal.md index 648f77a..ce644f6 100644 --- a/docs/03-Architecture/▢️ Create Goal.md +++ b/docs/03-Architecture/▢️ Create Goal.md @@ -51,6 +51,7 @@ Needed so Screen 2’s `[+]`, `[-]`, and Clear are not invented in the UI. | **Remove Goal** | ItemId | Goal gone, then RefreshProgress | | **Clear Goals** | β€” | All goals gone, then RefreshProgress | | **Refresh Progress** | β€” | Recompute missing list from current goals + inventory | +| **Auto-remove (opt-in)** | Pickup of the goal item | Quantity down by the gain; gone at 0. `/satistaskory auto-remove` | `[-]` on the overlay: if quantity > 1, Adjust βˆ’1; if quantity is 1, Remove Goal. The overlay does not keep a 0. diff --git a/docs/03-Architecture/πŸ“ Decisions.md b/docs/03-Architecture/πŸ“ Decisions.md index 84707fe..d2d8c5e 100644 --- a/docs/03-Architecture/πŸ“ Decisions.md +++ b/docs/03-Architecture/πŸ“ Decisions.md @@ -114,7 +114,7 @@ Resolution converts one goal into requirements. Aggregation combines active goal Having the diamonds is not the same as considering the work finished. -**Status:** βœ… Accepted +**Status:** βœ… Accepted. Opt-in inventory detection: ADR-020. --- @@ -348,6 +348,26 @@ A chest crafts from any `#minecraft:planks`. Picking `getItems()[0]` made spruce --- +### ADR-020 β€” Opt-in: picking up the goal item can complete it + +**Date:** 2026-09-08 + +**Decision:** Inventory-detection completion is a **player toggle**: `/satistaskory auto-remove` `[on|off]`. Default **off**. + +When on, an **increase** in how many of the goal item the player is holding counts that many toward the goal. Quantity drops. At 0 the goal is removed. Player inventory only. Putting the item in a chest does not restore quantity. Enabling the toggle, or joining a world, baselines current holdings so already-held stacks do not wipe the list. + +Manual `[βˆ’]` / Clear remain. Ready is still not complete. + +**Reason:** + +The walk: finished items stayed on the overlay until a click. For a prosthetic that is extra working memory. Auto-removing whenever `held >= target` would also delete a new goal the moment they add it while carrying any of that item. Counting **gains** avoids that. + +**Status:** βœ… Accepted + +**Refines:** ADR-008 (completion is configurable; this is the inventory-detection option) + +--- + ## Related Documents [[πŸ›οΈ Architecture]] diff --git a/docs/03-Architecture/πŸ“¦ Packages.md b/docs/03-Architecture/πŸ“¦ Packages.md index b7ce12e..223b67b 100644 --- a/docs/03-Architecture/πŸ“¦ Packages.md +++ b/docs/03-Architecture/πŸ“¦ Packages.md @@ -27,6 +27,7 @@ com.sufficient.satistaskory Planner # create / increment / decrement / clear / snapshot GoalStore # port InMemoryGoalStore # unit tests; inner store for persist + ObtainedCompletion # opt-in: pickup counts as done infrastructure/ recipe/ @@ -43,7 +44,8 @@ com.sufficient.satistaskory PlayOverlay # Screen 2 HUD (not a Screen) CaptureHook # tooltip + KeyMapping ADD_GOAL PlannerSession - ClientCommands # debug /satistaskory add|clear + ClientSettings # auto-remove preference + ClientCommands # debug /satistaskory add|clear|auto-remove ``` Dependencies point inward: `infrastructure` and `application` may import `domain`. `domain` imports nothing from NeoForge, EMI, JEI, REI, or `infrastructure`. @@ -55,7 +57,7 @@ Dependencies point inward: `infrastructure` and `application` may import `domain | Omitted | Why | |---------|-----| | `Project` | Organizational only; not in the slice | -| Completion strategy | Ready β‰  complete; complete is not in the slice | +| Full completion UI | Ready β‰  complete. Opt-in inventory detection exists (`/satistaskory auto-remove`). No complete button. | | Full-screen planner | Not discovered | The NeoForge template example block/item is gone. Do not put it back. diff --git a/docs/04-Planning/πŸ—ΊοΈ Roadmap.md b/docs/04-Planning/πŸ—ΊοΈ Roadmap.md index aa6eb12..8726314 100644 --- a/docs/04-Planning/πŸ—ΊοΈ Roadmap.md +++ b/docs/04-Planning/πŸ—ΊοΈ Roadmap.md @@ -6,7 +6,7 @@ What exists, and what is next. Implementation detail will live in an Implementat ## βœ… Now (docs) -- Philosophy Rules #1–#10; ADRs **001–019** +- Philosophy Rules #1–#10; ADRs **001–020** - Vision, ubiquitous language, bounded context (one: Goal Planning) - Goal invariants: one per ItemId, quantity β‰₯ 1, create at 1 / +1, `[-]` at 1 removes - Packages named; [[πŸ”Œ Recipe Provider]] sketched; [[▢️ Create Goal]] written @@ -27,7 +27,6 @@ EMI is not a dependency. See ADR-016. ## ⏸ Not opened - Project -- Completion - Full-screen planner --- diff --git a/docs/04-Planning/🧭 Notes for the Wayfinder.md b/docs/04-Planning/🧭 Notes for the Wayfinder.md index 1f2f8b8..eb1ed9e 100644 --- a/docs/04-Planning/🧭 Notes for the Wayfinder.md +++ b/docs/04-Planning/🧭 Notes for the Wayfinder.md @@ -435,6 +435,16 @@ ADR-019: a tag ingredient is one requirement, every member counts. Overlay names --- +## πŸ“œ 2026-09-08 (auto-remove) + +Greetings, Wayfinder. + +The walk: completed items stayed on the overlay. + +ADR-020: `/satistaskory auto-remove`. Off by default. When on, a **gain** in held goal items reduces quantity and removes at 0. Not β€œheld >= target” (that would eat a new goal while they are carrying the item). Not storage. Baseline on join/enable. + +--- + ## Related Documents [[🌟 Project Vision]] diff --git a/docs/05-Experience/πŸ–₯️ Experience.md b/docs/05-Experience/πŸ–₯️ Experience.md index 0f8de63..cd629e0 100644 --- a/docs/05-Experience/πŸ–₯️ Experience.md +++ b/docs/05-Experience/πŸ–₯️ Experience.md @@ -60,6 +60,8 @@ The overlay answers both halves of the vision question: `[-]` at quantity 1 removes that goal. +`/satistaskory auto-remove` (off by default): picking up the goal item counts it done and drops the quantity (gone at 0). Only what is on you. A chest you just filled does not count. Dumping the item does not bring the row back. + Walking has no cursor. Overlay `[+]` / `[-]` / Clear are HUD hit-tests (vanilla button sprites + click sound), not a `Screen`. Open chat (`T` or `/`) to click them. Capture does not use a clickable chip you leave the item to hit. Same material from two goals is one row. Any-plank recipes (chest, crafting table) are one row too: spruce counts, mixed stacks count. If they hold none, the row says Planks, not Oak. Changing a goal quantity recalculates the lower list. As inventory fills, counts shrink. diff --git a/docs/99-backlog/🚧 Future Ideas.md b/docs/99-backlog/🚧 Future Ideas.md index a56ae12..7348d27 100644 --- a/docs/99-backlog/🚧 Future Ideas.md +++ b/docs/99-backlog/🚧 Future Ideas.md @@ -8,7 +8,7 @@ Not a build queue. - Viewer-only recipe adapter (EMI/JEI/REI) **if** a recipe never appears in `RecipeManager` - Persistence (server save / cloud) -- Inventory-detection completion (alongside manual) +- Other completion strategies (the opt-in pickup path is shipped: `/satistaskory auto-remove`) - Ender chest / later storage in the inventory snapshot - Projects packaged - Full-screen planner diff --git a/src/main/java/com/sufficient/satistaskory/application/ObtainedCompletion.java b/src/main/java/com/sufficient/satistaskory/application/ObtainedCompletion.java new file mode 100644 index 0000000..463eeb2 --- /dev/null +++ b/src/main/java/com/sufficient/satistaskory/application/ObtainedCompletion.java @@ -0,0 +1,48 @@ +package com.sufficient.satistaskory.application; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.sufficient.satistaskory.domain.Goal; +import com.sufficient.satistaskory.domain.InventoryState; +import com.sufficient.satistaskory.domain.ItemId; + +/** + * When auto-remove is on: an increase in held target items counts as obtained. + * Dumping items does not put quantity back. First look after enable/join is a baseline, not a gain. + */ +public final class ObtainedCompletion { + private final Map lastHeld = new HashMap<>(); + private boolean primed; + + public void reset() { + lastHeld.clear(); + primed = false; + } + + public void apply(Planner planner, InventoryState inventory) { + if (!primed) { + seed(planner, inventory); + primed = true; + return; + } + for (Goal goal : List.copyOf(planner.goals())) { + int now = inventory.get(goal.targetItem()); + int was = lastHeld.getOrDefault(goal.targetItem(), 0); + int gained = now - was; + if (gained > 0) { + planner.reduce(goal.targetItem(), gained); + } + } + seed(planner, inventory); + } + + private void seed(Planner planner, InventoryState inventory) { + lastHeld.clear(); + lastHeld.putAll(inventory.contents()); + for (Goal goal : planner.goals()) { + lastHeld.putIfAbsent(goal.targetItem(), 0); + } + } +} diff --git a/src/main/java/com/sufficient/satistaskory/application/Planner.java b/src/main/java/com/sufficient/satistaskory/application/Planner.java index 099426a..0b257dd 100644 --- a/src/main/java/com/sufficient/satistaskory/application/Planner.java +++ b/src/main/java/com/sufficient/satistaskory/application/Planner.java @@ -1,5 +1,6 @@ package com.sufficient.satistaskory.application; +import java.util.List; import java.util.Objects; import java.util.function.Supplier; @@ -23,6 +24,10 @@ public final class Planner { this.inventory = Objects.requireNonNull(inventory, "inventory"); } + public List goals() { + return store.all(); + } + public ProgressSnapshot snapshot() { return refresh(); } @@ -64,6 +69,24 @@ public final class Planner { return refresh(); } + /** + * Count obtained items toward the goal. Removes the goal when quantity hits 0. + */ + public void reduce(ItemId item, int amount) { + Objects.requireNonNull(item, "item"); + if (amount < 1) { + return; + } + store.find(item).ifPresent(existing -> { + int left = existing.quantity() - amount; + if (left < 1) { + store.remove(item); + } else { + store.put(new Goal(item, left)); + } + }); + } + private ProgressSnapshot refresh() { return progress.calculate(store.all(), inventory.get()); } diff --git a/src/main/java/com/sufficient/satistaskory/domain/InventoryState.java b/src/main/java/com/sufficient/satistaskory/domain/InventoryState.java index 8afdcbc..44f5c08 100644 --- a/src/main/java/com/sufficient/satistaskory/domain/InventoryState.java +++ b/src/main/java/com/sufficient/satistaskory/domain/InventoryState.java @@ -40,4 +40,8 @@ public final class InventoryState { } return total; } + + public Map contents() { + return available; + } } diff --git a/src/main/java/com/sufficient/satistaskory/infrastructure/client/ClientCommands.java b/src/main/java/com/sufficient/satistaskory/infrastructure/client/ClientCommands.java index eca85a2..e450824 100644 --- a/src/main/java/com/sufficient/satistaskory/infrastructure/client/ClientCommands.java +++ b/src/main/java/com/sufficient/satistaskory/infrastructure/client/ClientCommands.java @@ -26,7 +26,11 @@ public final class ClientCommands { PlannerSession.get().clear(); ctx.getSource().sendSuccess(() -> Component.literal("Cleared crafting goals"), false); return 1; - }))); + })) + .then(Commands.literal("auto-remove") + .executes(ClientCommands::toggleAutoRemove) + .then(Commands.literal("on").executes(ctx -> setAutoRemove(ctx, true))) + .then(Commands.literal("off").executes(ctx -> setAutoRemove(ctx, false))))); } private static int add(CommandContext ctx) { @@ -43,4 +47,24 @@ public final class ClientCommands { ctx.getSource().sendSuccess(() -> Component.literal("Added " + item), false); return 1; } + + private static int toggleAutoRemove(CommandContext ctx) { + boolean on = ClientSettings.toggleAutoRemove(); + tellAutoRemove(ctx, on); + return 1; + } + + private static int setAutoRemove(CommandContext ctx, boolean on) { + ClientSettings.setAutoRemove(on); + tellAutoRemove(ctx, on); + return 1; + } + + private static void tellAutoRemove(CommandContext ctx, boolean on) { + ctx.getSource().sendSuccess( + () -> Component.translatable(on + ? "satistaskory.message.auto_remove.on" + : "satistaskory.message.auto_remove.off"), + false); + } } diff --git a/src/main/java/com/sufficient/satistaskory/infrastructure/client/ClientSettings.java b/src/main/java/com/sufficient/satistaskory/infrastructure/client/ClientSettings.java new file mode 100644 index 0000000..96b6a19 --- /dev/null +++ b/src/main/java/com/sufficient/satistaskory/infrastructure/client/ClientSettings.java @@ -0,0 +1,78 @@ +package com.sufficient.satistaskory.infrastructure.client; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; + +import com.sufficient.satistaskory.Satistaskory; + +import net.minecraft.client.Minecraft; + +/** + * Client preferences. Not per-world. Auto-remove is off until the player turns it on. + */ +public final class ClientSettings { + private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + private static boolean autoRemove; + + private ClientSettings() {} + + public static boolean autoRemove() { + return autoRemove; + } + + public static boolean toggleAutoRemove() { + return setAutoRemove(!autoRemove); + } + + public static boolean setAutoRemove(boolean value) { + autoRemove = value; + save(); + return autoRemove; + } + + public static void load() { + Path file = file(); + if (file == null || !Files.isRegularFile(file)) { + autoRemove = false; + return; + } + try { + JsonObject json = GSON.fromJson(Files.readString(file), JsonObject.class); + autoRemove = json != null && json.has("autoRemove") && json.get("autoRemove").getAsBoolean(); + } catch (RuntimeException | IOException e) { + Satistaskory.LOGGER.warn("Could not read Satistaskory settings at {}", file, e); + autoRemove = false; + } + } + + private static void save() { + Path file = file(); + if (file == null) { + return; + } + JsonObject json = new JsonObject(); + json.addProperty("autoRemove", autoRemove); + try { + Path parent = file.getParent(); + if (parent != null) { + Files.createDirectories(parent); + } + Files.writeString(file, GSON.toJson(json)); + } catch (IOException e) { + Satistaskory.LOGGER.warn("Could not write Satistaskory settings at {}", file, e); + } + } + + private static Path file() { + Minecraft minecraft = Minecraft.getInstance(); + if (minecraft == null) { + return null; + } + return minecraft.gameDirectory.toPath().resolve("satistaskory").resolve("settings.json"); + } +} diff --git a/src/main/java/com/sufficient/satistaskory/infrastructure/client/PlannerSession.java b/src/main/java/com/sufficient/satistaskory/infrastructure/client/PlannerSession.java index 409bd94..e3768b1 100644 --- a/src/main/java/com/sufficient/satistaskory/infrastructure/client/PlannerSession.java +++ b/src/main/java/com/sufficient/satistaskory/infrastructure/client/PlannerSession.java @@ -1,9 +1,11 @@ package com.sufficient.satistaskory.infrastructure.client; +import com.sufficient.satistaskory.application.ObtainedCompletion; import com.sufficient.satistaskory.application.Planner; import com.sufficient.satistaskory.domain.InventoryState; import com.sufficient.satistaskory.domain.MaterialAggregation; import com.sufficient.satistaskory.domain.ProgressCalculation; +import com.sufficient.satistaskory.domain.ProgressSnapshot; import com.sufficient.satistaskory.domain.RecipeResolution; import com.sufficient.satistaskory.infrastructure.inventory.PlayerInventoryAdapter; import com.sufficient.satistaskory.infrastructure.persistence.PersistingGoalStore; @@ -19,6 +21,7 @@ import net.minecraft.client.player.LocalPlayer; public final class PlannerSession { private static PersistingGoalStore store; private static Planner planner; + private static final ObtainedCompletion obtained = new ObtainedCompletion(); private PlannerSession() {} @@ -30,6 +33,8 @@ public final class PlannerSession { ProgressCalculation progress = new ProgressCalculation(resolution, new MaterialAggregation()); store = new PersistingGoalStore(); planner = new Planner(store, progress, PlannerSession::currentInventory); + ClientSettings.load(); + obtained.reset(); } public static Planner get() { @@ -39,15 +44,27 @@ public final class PlannerSession { return planner; } + public static ProgressSnapshot snapshot() { + bootstrap(); + if (ClientSettings.autoRemove()) { + obtained.apply(planner, currentInventory()); + } else { + obtained.reset(); + } + return planner.snapshot(); + } + public static void onJoinWorld() { bootstrap(); store.loadFromWorld(ClientGoalPersistence.load()); + obtained.reset(); } public static void onLeaveWorld() { if (store != null) { store.unload(); } + obtained.reset(); } private static InventoryState currentInventory() { diff --git a/src/main/java/com/sufficient/satistaskory/infrastructure/client/PlayOverlay.java b/src/main/java/com/sufficient/satistaskory/infrastructure/client/PlayOverlay.java index d33c8e2..f688d1d 100644 --- a/src/main/java/com/sufficient/satistaskory/infrastructure/client/PlayOverlay.java +++ b/src/main/java/com/sufficient/satistaskory/infrastructure/client/PlayOverlay.java @@ -46,7 +46,7 @@ public final class PlayOverlay { return; } - ProgressSnapshot snapshot = PlannerSession.get().snapshot(); + ProgressSnapshot snapshot = PlannerSession.snapshot(); if (snapshot.goals().isEmpty()) { return; } diff --git a/src/main/resources/assets/satistaskory/lang/en_us.json b/src/main/resources/assets/satistaskory/lang/en_us.json index 5ca2f23..776e29f 100644 --- a/src/main/resources/assets/satistaskory/lang/en_us.json +++ b/src/main/resources/assets/satistaskory/lang/en_us.json @@ -4,5 +4,7 @@ "key.categories.satistaskory": "Satistaskory", "key.satistaskory.add_goal": "Add to Crafting Goals", "satistaskory.tooltip.add": "[%s] Add to Crafting Goals", - "satistaskory.message.added": "Added %s to crafting goals" + "satistaskory.message.added": "Added %s to crafting goals", + "satistaskory.message.auto_remove.on": "Auto-remove ON: picking up a goal item counts it done. Dumping it in a chest does not bring it back.", + "satistaskory.message.auto_remove.off": "Auto-remove OFF: goals stay until you [-] or Clear." } diff --git a/src/test/java/com/sufficient/satistaskory/application/ObtainedCompletionTest.java b/src/test/java/com/sufficient/satistaskory/application/ObtainedCompletionTest.java new file mode 100644 index 0000000..4e9a1e2 --- /dev/null +++ b/src/test/java/com/sufficient/satistaskory/application/ObtainedCompletionTest.java @@ -0,0 +1,65 @@ +package com.sufficient.satistaskory.application; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Map; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import com.sufficient.satistaskory.domain.InventoryState; +import com.sufficient.satistaskory.domain.ItemId; +import com.sufficient.satistaskory.domain.MaterialAggregation; +import com.sufficient.satistaskory.domain.ProgressCalculation; +import com.sufficient.satistaskory.domain.RecipeResolution; +import com.sufficient.satistaskory.infrastructure.recipe.StubRecipeProvider; + +class ObtainedCompletionTest { + private static final ItemId CHEST = ItemId.parse("minecraft:chest"); + + private Planner planner; + private ObtainedCompletion completion; + + @BeforeEach + void setUp() { + RecipeResolution resolution = new RecipeResolution(new StubRecipeProvider()); + ProgressCalculation progress = new ProgressCalculation(resolution, new MaterialAggregation()); + planner = new Planner(new InMemoryGoalStore(), progress, InventoryState::empty); + completion = new ObtainedCompletion(); + } + + @Test + void firstLookDoesNotCountWhatIsAlreadyHeld() { + planner.create(CHEST); + completion.apply(planner, new InventoryState(Map.of(CHEST, 5))); + assertEquals(1, planner.goals().getFirst().quantity()); + } + + @Test + void pickingUpReducesQuantity() { + planner.create(CHEST); + planner.increment(CHEST); + completion.apply(planner, InventoryState.empty()); + completion.apply(planner, new InventoryState(Map.of(CHEST, 1))); + assertEquals(1, planner.goals().getFirst().quantity()); + } + + @Test + void pickingUpTheLastRemovesTheGoal() { + planner.create(CHEST); + completion.apply(planner, InventoryState.empty()); + completion.apply(planner, new InventoryState(Map.of(CHEST, 1))); + assertTrue(planner.goals().isEmpty()); + } + + @Test + void dumpingDoesNotRestoreQuantity() { + planner.create(CHEST); + planner.increment(CHEST); + completion.apply(planner, InventoryState.empty()); + completion.apply(planner, new InventoryState(Map.of(CHEST, 1))); + completion.apply(planner, InventoryState.empty()); + assertEquals(1, planner.goals().getFirst().quantity()); + } +}