Recipe viewer for fishing
This commit is contained in:
@@ -11,7 +11,9 @@ The recipes open in a screen of their own, laid out like JEI's: a tab for each c
|
||||
made down its left side, the category and the page between their arrows, then the recipes. Clicking items in it follows
|
||||
them, Backspace goes back, and Escape or the inventory key (E) returns to the inventory.
|
||||
|
||||
It reads every mod's recipes with `ctx.recipes.list()`.
|
||||
It reads every mod's recipes with `ctx.recipes.list()`. Fish, the items with the base game's `bworld:fish` component,
|
||||
get a Fishing category too: clicking one shows its seasons, biomes, hours and the liquid it's caught in, read with
|
||||
`ctx.items.components`, and the fishing rod's uses are every fish.
|
||||
|
||||
- `scripts/categories.ts` has a category for each recipe type, like JEI's `IRecipeCategory`: its title, size, where it's
|
||||
made (`MOD_CATALYSTS` for mods' types) and where its items go. Types without one are drawn from their JSON: the items
|
||||
|
||||
@@ -98,9 +98,65 @@ function base_categories(tags: TagApi): RecipeCategory[] {
|
||||
layout.slot({ ids: [recipe.result], count: 1 }, 90, 0);
|
||||
},
|
||||
},
|
||||
{
|
||||
// when and where a fish bites, see fishing_recipes
|
||||
type: FISHING,
|
||||
title: "Fishing",
|
||||
width: 180,
|
||||
height: 54,
|
||||
catalysts: ["bworld:fishing_rod"],
|
||||
draw(recipe, layout) {
|
||||
const fish = recipe.fish as FishParams;
|
||||
layout.slot({ ids: [recipe.result], count: 1 }, 0, 0);
|
||||
const lines = [
|
||||
// all four is "all", which also fits
|
||||
`Seasons: ${
|
||||
fish.seasons && fish.seasons.length < 4 ? fish.seasons.map(title_case).join(", ") : "all"
|
||||
}`,
|
||||
`Biomes: ${fish.biomes?.map(biome_name).join(", ") ?? "all"}`,
|
||||
`Time: ${fish.time ? `${clock(fish.time.from)} to ${clock(fish.time.to)}` : "all day"}`,
|
||||
`In: ${biome_name(fish.liquid ?? "bworld:water")}`,
|
||||
];
|
||||
lines.forEach((line, i) => layout.text(line, 24, 1 + i * 13));
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
// the base game's fish, the items with bworld:fish, as recipes of their own type that make them, so clicking one shows
|
||||
// when and where it bites. their params are under "fish", which reading a recipe's inputs skips
|
||||
const FISHING = "bworld:fishing";
|
||||
|
||||
interface FishParams {
|
||||
seasons?: string[];
|
||||
biomes?: string[];
|
||||
time?: { from: number; to: number };
|
||||
liquid?: string;
|
||||
}
|
||||
|
||||
export function fishing_recipes(ctx: ClientContext): Recipe[] {
|
||||
return ctx.items.ids().flatMap((id) => {
|
||||
const fish = ctx.items.components(id)["bworld:fish"];
|
||||
return fish ? [{ type: FISHING, result: id, fish }] : [];
|
||||
});
|
||||
}
|
||||
|
||||
// "autumn" is "Autumn", "dark_oak" is "Dark Oak"
|
||||
function title_case(name: string): string {
|
||||
return name.split("_").map((word) => word[0].toUpperCase() + word.slice(1)).join(" ");
|
||||
}
|
||||
|
||||
// a biome, liquid or #biome tag by its name: "bworld:swamp" is "Swamp", "#bworld:is_ocean" is "Ocean"
|
||||
function biome_name(id: string): string {
|
||||
return title_case(id.replace(/^#/, "").split(":")[1].replace(/^is_/, ""));
|
||||
}
|
||||
|
||||
// hours on a 24 hour clock, fractions as minutes: 6.5 is "6:30"
|
||||
function clock(hours: number): string {
|
||||
const minutes = Math.round((hours % 1) * 60);
|
||||
return `${Math.floor(hours)}:${String(minutes).padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
// a mod's own type, from its recipes' json: the items in its lists in a grid, a single item (like a bowl to serve in)
|
||||
// under the arrow, then what it makes, one under the other
|
||||
function mod_category(type: string, tags: TagApi): RecipeCategory {
|
||||
@@ -144,6 +200,7 @@ export function category_name(type: string): string {
|
||||
furnace: "Smelting",
|
||||
fuel: "Fuel",
|
||||
smithing: "Smithing",
|
||||
[FISHING]: "Fishing",
|
||||
};
|
||||
if (base[type]) return base[type];
|
||||
const name = type.split(":")[1] ?? type;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// many recipes as fit, one under the other. the item list stays on the right. escape or the inventory key go back to
|
||||
// the inventory, and backspace to what was shown before
|
||||
import type { ClientContext, Graphics, Screen } from "bworld/client";
|
||||
import { make_categories, type RecipeCategory, type RecipeLayout, SLOT } from "./categories.ts";
|
||||
import { fishing_recipes, make_categories, type RecipeCategory, type RecipeLayout, SLOT } from "./categories.ts";
|
||||
import { BUTTON, item_cell, ItemList, LABEL_COLOR, type Mode, SLOT_COLOR } from "./item_list.ts";
|
||||
import { type Ingredient, inputs, outputs, type Recipe } from "./recipes.ts";
|
||||
|
||||
@@ -32,7 +32,7 @@ export class RecipeIndex {
|
||||
|
||||
get categories(): RecipeCategory[] {
|
||||
if (!this.#categories) {
|
||||
this.#recipes = this.ctx.recipes.list();
|
||||
this.#recipes = [...this.ctx.recipes.list(), ...fishing_recipes(this.ctx)];
|
||||
this.#categories = make_categories(this.ctx, this.#recipes);
|
||||
}
|
||||
return this.#categories;
|
||||
|
||||
Reference in New Issue
Block a user