Single module modding
This commit is contained in:
@@ -12,7 +12,7 @@ import { copy_dir, stone_floor, test_game } from "./helpers.ts";
|
||||
|
||||
const SERVER_SCRIPT = `
|
||||
import type { ServerContext } from "cubi/server";
|
||||
export function setup(ctx: ServerContext) {
|
||||
export function server(ctx: ServerContext) {
|
||||
const log = (event: unknown[]) => ctx.storage.set("log", [...ctx.storage.get<unknown[]>("log") ?? [], event]);
|
||||
const at = ({ x, y, z }: { x: number; y: number; z: number }) => x + " " + y + " " + z;
|
||||
ctx.components.register_block("testmod:watcher", {
|
||||
@@ -57,7 +57,7 @@ export function setup(ctx: ServerContext) {
|
||||
|
||||
const SHARED_SCRIPT = `
|
||||
import type { SharedContext } from "cubi/shared";
|
||||
export function setup(ctx: SharedContext) {
|
||||
export function shared(ctx: SharedContext) {
|
||||
// marks the watcher once anything beside it changes
|
||||
ctx.components.register_block("testmod:watcher", {
|
||||
on_neighbor_change(block) { ctx.world.set_state(block.x, block.y, block.z, "seen", 1); },
|
||||
@@ -93,7 +93,7 @@ function test_mods() {
|
||||
name: "Test",
|
||||
version: "1.0.0",
|
||||
dependencies: [{ id: "bworld", version: "*" }],
|
||||
scripts: { server: "scripts/server.ts", shared: "scripts/shared.ts" },
|
||||
main: "scripts/main.ts",
|
||||
});
|
||||
const block = (name: string, states: unknown[] = []) =>
|
||||
write(`blocks/${name}.json`, {
|
||||
@@ -113,6 +113,10 @@ function test_mods() {
|
||||
block("flipper", [{ name: "on", bits: 1, default: 0 }]);
|
||||
Deno.writeTextFileSync(`${mod}/scripts/server.ts`, SERVER_SCRIPT);
|
||||
Deno.writeTextFileSync(`${mod}/scripts/shared.ts`, SHARED_SCRIPT);
|
||||
Deno.writeTextFileSync(
|
||||
`${mod}/scripts/main.ts`,
|
||||
`export { server } from "./server.ts";\nexport { shared } from "./shared.ts";\n`,
|
||||
);
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user