Engine api
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
} from "./everything_registry.ts";
|
||||
import { type BlockPart, type BlockVariant, MODEL_FACES, type ModelFace } from "./block_models.ts";
|
||||
import { expand_items, list_matches } from "./tags.ts";
|
||||
import { GAME_VERSION } from "./constants.ts";
|
||||
|
||||
export const FORMAT_VERSION = 1;
|
||||
export const ID_PATTERN = /^[a-z0-9_]+:[a-z0-9_]+$/;
|
||||
@@ -35,6 +36,8 @@ export interface ManifestJson {
|
||||
version: string;
|
||||
authors?: string[];
|
||||
game_version?: string;
|
||||
// imports bworld/engine to reach into the engine and hook its methods. needs game_version within one minor version
|
||||
engine_access?: boolean;
|
||||
dependencies?: { id: string; version: string }[];
|
||||
scripts?: { server?: string; client?: string; worldgen?: string; shared?: string };
|
||||
credits?: string;
|
||||
@@ -448,6 +451,13 @@ export function validate_manifest(json: unknown, folder_name: string): Problems
|
||||
if (typeof json.version !== "string" || !/^\d+\.\d+\.\d+/.test(json.version)) {
|
||||
problems.push("version must be semver, like 1.0.0");
|
||||
}
|
||||
if (json.engine_access !== undefined && typeof json.engine_access !== "boolean") {
|
||||
problems.push("engine_access must be true or false");
|
||||
}
|
||||
if (json.engine_access === true) {
|
||||
const problem = engine_version_problem(json.game_version);
|
||||
if (problem) problems.push(problem);
|
||||
}
|
||||
if (json.dependencies !== undefined) {
|
||||
if (!Array.isArray(json.dependencies)) {
|
||||
problems.push("dependencies must be a list");
|
||||
@@ -474,6 +484,20 @@ export function validate_manifest(json: unknown, folder_name: string): Problems
|
||||
return problems;
|
||||
}
|
||||
|
||||
// engine access isn't a stable api: a mod using it names one minor version of the game, like "~0.4.0" or "0.4.2", and
|
||||
// loading it on another is an error. game is the version it's loading on
|
||||
export function engine_version_problem(range: unknown, game = GAME_VERSION): string | undefined {
|
||||
const [major, minor, patch] = game.split(".").map(Number);
|
||||
const match = typeof range === "string" ? range.match(/^(~?)(\d+)\.(\d+)\.(\d+)$/) : null;
|
||||
if (!match) {
|
||||
return `engine_access needs game_version to be one minor version, like "~${major}.${minor}.0"`;
|
||||
}
|
||||
const [, tilde, m, n, p] = match;
|
||||
const fits = Number(m) === major && Number(n) === minor &&
|
||||
(tilde ? Number(p) <= patch : Number(p) === patch);
|
||||
if (!fits) return `uses engine_access for game_version ${range}, this is the game's ${game}`;
|
||||
}
|
||||
|
||||
export function validate_block(json: unknown): Problems {
|
||||
if (!is_object(json)) return ["block must be an object"];
|
||||
const problems = validate_id(json.id, "id");
|
||||
|
||||
Reference in New Issue
Block a user