forked from unimatrix/web
Publish authoritative grades for every Cookbook output
This commit is contained in:
parent
1e86aab3e5
commit
d347f7a3d7
1 changed files with 304 additions and 5 deletions
|
|
@ -5,6 +5,7 @@ const smoker = new URL('../data/cookbook/survival-food-recipes.json', import.met
|
|||
|
||||
const repairParts = new URL('../data/cookbook/starter-repair-parts.json', import.meta.url);
|
||||
const duneChest = new URL('../data/cookbook/dunechest-recipes.json', import.meta.url);
|
||||
const itemGrades = new URL('../data/cookbook/item-grades.json', import.meta.url);
|
||||
const arrakisItems = new URL('../data/cookbook/items/', import.meta.url);
|
||||
const vanillaFoodSaturation = { beef: 1.8, enchanted_golden_apple: 9.6 };
|
||||
const itemSummaries = {
|
||||
|
|
@ -41,6 +42,20 @@ function entry(id, name, material = id, custom = false) {
|
|||
return { id, name, material, custom };
|
||||
}
|
||||
|
||||
export function withRecipeGrade(output, definition) {
|
||||
if (!definition || definition.material !== output.material) throw Error('Missing or mismatched Cookbook grade for ' + output.id);
|
||||
if (definition.mode === 'input') {
|
||||
if (output.quality !== undefined || output.equipmentMark !== undefined || definition.quality !== undefined || definition.equipmentMark !== undefined) throw Error('Input-dependent item has a fixed grade: ' + output.id);
|
||||
return { ...output, metadataMode: 'input' };
|
||||
}
|
||||
const { quality, equipmentMark } = definition;
|
||||
if (!['common', 'uncommon', 'rare', 'very_rare', 'legendary', 'mythic', 'relic'].includes(quality)
|
||||
|| (quality === 'relic' ? equipmentMark !== 'infinite' : !Number.isInteger(equipmentMark) || equipmentMark < 0 || equipmentMark > 14)) throw Error('Invalid Cookbook grade for ' + output.id);
|
||||
if (output.quality !== undefined && output.quality !== quality
|
||||
|| output.equipmentMark !== undefined && output.equipmentMark !== equipmentMark) throw Error('Cookbook grade conflicts with its item definition: ' + output.id);
|
||||
return { ...output, quality, equipmentMark };
|
||||
}
|
||||
|
||||
function item(command) {
|
||||
const material = command.match(/^minecraft:([a-z0-9_]+)/)?.[1];
|
||||
if (!material) throw Error('Unrecognised recipe item ' + command);
|
||||
|
|
@ -59,6 +74,8 @@ function item(command) {
|
|||
|
||||
export function recipeCatalogue() {
|
||||
const recipes = [];
|
||||
const metadata = JSON.parse(readFileSync(itemGrades, 'utf8'));
|
||||
if (metadata.schema !== 1 || metadata.policy !== 's1-item-metadata-v1') throw Error('Unsupported Cookbook item metadata');
|
||||
const spice = entry('spice', 'Melange Spice', 'orange_dye', true);
|
||||
const requiresSpice = new Set(['dunesponge.yml', 'spice_paste.yml', 'spice_dough.yml', 'weirding_module.yml']);
|
||||
for (const file of readdirSync(source).filter(name => name.endsWith('.yml')).sort()) {
|
||||
|
|
@ -127,6 +144,7 @@ export function recipeCatalogue() {
|
|||
if (!Number.isFinite(saturation)) throw Error('Missing saturation for ' + recipe.output.id);
|
||||
recipe.output = { ...recipe.output, material, stats: [{ label: 'Saturation per serving', value: '+' + saturation + ' points' }] };
|
||||
}
|
||||
recipe.output = withRecipeGrade(recipe.output, metadata.items[recipe.output.id]);
|
||||
const summary = itemSummaries[recipe.output.id] ?? recipe.output.summary;
|
||||
if (!summary) throw Error('Missing item summary for ' + recipe.output.id);
|
||||
recipe.output = { ...recipe.output, summary };
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff