Single module modding

This commit is contained in:
2026-11-14 12:18:41 -03:00
parent 605008f584
commit 313098892e
134 changed files with 919 additions and 924 deletions
+6 -6
View File
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
// SPDX-License-Identifier: AGPL-3.0-or-later
// item tooltips: the game's lines, the ones client scripts add and where they go
// item tooltips: the game's lines, the ones client phases add and where they go
import { assertEquals } from "@std/assert";
import { item_tooltip } from "@/client/gui/tooltip.ts";
import { ItemStack } from "@/common/inventory.ts";
@@ -9,7 +9,7 @@ import { copy_dir, load_as_player } from "./helpers.ts";
const SNACK = "tips:snack";
// mods/bworld, then tips: a snack with food and lore that sells for 4, and a client script adding lines to its tooltip
// mods/bworld, then tips: a snack with food and lore that sells for 4, and a client phase adding lines to its tooltip
async function load(client_script: string) {
const dir = Deno.makeTempDirSync({ prefix: "bworld_tooltips_" });
copy_dir("mods/bworld", `${dir}/bworld`);
@@ -24,7 +24,7 @@ async function load(client_script: string) {
id: "tips",
name: "Tips",
version: "1.0.0",
scripts: { client: "scripts/client.ts" },
main: "scripts/client.ts",
}),
);
write(
@@ -49,10 +49,10 @@ async function load(client_script: string) {
return (id: string) => item_tooltip(new ItemStack(id)).map((line) => line.text);
}
Deno.test("a client script's lines show in item tooltips, and bworld's sell value goes after the food", async () => {
Deno.test("a mod's client phase's lines show in item tooltips, and bworld's sell value goes after the food", async () => {
const tooltip = await load(`
import type { ClientContext } from "cubi/client";
export function setup(ctx: ClientContext) {
export function client(ctx: ClientContext) {
ctx.ui.add_item_tooltip((item, lines) => lines.push({ text: "from tips: " + item.id }));
}
`);
@@ -63,7 +63,7 @@ Deno.test("a client script's lines show in item tooltips, and bworld's sell valu
Deno.test("tooltip lines go where their priority says, and ones with the same priority keep their order", async () => {
const tooltip = await load(`
import { type ClientContext, TOOLTIP_PRIORITY } from "cubi/client";
export function setup(ctx: ClientContext) {
export function client(ctx: ClientContext) {
ctx.ui.add_item_tooltip((item, lines) => {
if (item.id !== "${SNACK}") return;
lines.push({ text: "last", priority: TOOLTIP_PRIORITY.lore + 1 });