From 18ed16e5b5bdbe833dd6885adcc703b1d0a53969 Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Fri, 10 Jan 2025 17:58:57 +0100 Subject: [PATCH] Optimize doc using chatgpt. Changes - pagination - lazy rendering by subsets instead of prerendering everything - some formatting --- showValues.js | 196 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 149 insertions(+), 47 deletions(-) diff --git a/showValues.js b/showValues.js index cccf89b38..0ee5c2697 100644 --- a/showValues.js +++ b/showValues.js @@ -19,122 +19,224 @@ function toggleAnchor () { } function fieldsToColumns (fields) { - return fields.map(function (field) { return { title: field } }) + return fields.map(function (field) { + return { title: field } + }) } function nameToImage (version, name) { let assetsVersion if (version.substr(0, 3) === '1.8') { assetsVersion = '1.8.8' - } if (version.substr(0, 3) === '1.9') { + } else if (version.substr(0, 3) === '1.9') { assetsVersion = '1.9' - } if (version.substr(0, 4) === '1.10') { + } else if (version.substr(0, 4) === '1.10') { assetsVersion = '1.10' - } if (version.substr(0, 4) === '1.11') { + } else if (version.substr(0, 4) === '1.11') { assetsVersion = '1.11' - } if (version.substr(0, 4) === '1.12') { + } else if (version.substr(0, 4) === '1.12') { assetsVersion = '1.12' - } if (version.substr(0, 4) === '1.13') { + } else if (version.substr(0, 4) === '1.13') { assetsVersion = '1.13' - } if (version.substr(0, 4) === '1.14') { + } else if (version.substr(0, 4) === '1.14') { assetsVersion = '1.14.4' - } if (version.substr(0, 4) === '1.15') { + } else if (version.substr(0, 4) === '1.15') { assetsVersion = '1.15.2' } else { assetsVersion = '1.13' } const mcAssets = require('minecraft-assets')(assetsVersion) - if (!mcAssets.textureContent[name]) { return '' } + if (!mcAssets.textureContent[name]) { + return '' + } const texture = mcAssets.textureContent[name].texture return texture ? '' : '' } function loadBlocks (version) { - loadData(version, 'blocks', + loadData( + version, + 'blocks', function (block) { - return [nameToImage(version, block.name), block.id, '' + block.name + '', - block.displayName, block.stackSize, block.hardness, - block.diggable, block.boundingBox, block.material ? block.material : null, - block.transparent, block.emitLight, block.filterLight] + return [ + nameToImage(version, block.name), + block.id, + '' + block.name + '', + block.displayName, + block.stackSize, + block.hardness, + block.diggable, + block.boundingBox, + block.material ? block.material : null, + block.transparent, + block.emitLight, + block.filterLight + ] }, - ['texture', 'id', 'name', 'displayName', 'stackSize', 'hardness', 'diggable', 'boundingBox', 'material', 'transparent', 'emitLight', 'filterLight'], + [ + 'texture', + 'id', + 'name', + 'displayName', + 'stackSize', + 'hardness', + 'diggable', + 'boundingBox', + 'material', + 'transparent', + 'emitLight', + 'filterLight' + ], [7, 8, 9, 10, 11], 1 ) } function loadItems (version) { - loadData(version, 'items', + loadData( + version, + 'items', function (item) { - return [nameToImage(version, item.name), item.id, '' + item.name + '', - item.displayName, item.stackSize] + return [ + nameToImage(version, item.name), + item.id, + '' + item.name + '', + item.displayName, + item.stackSize + ] }, - ['texture', 'id', 'name', 'displayName', 'stackSize'], [], 1 + ['texture', 'id', 'name', 'displayName', 'stackSize'], + [], + 1 ) } function loadBiomes (version) { - loadData(version, 'biomes', - function (e) { - return [e.id, '' + e.name + '', - e.color === undefined ? '' : e.color, e.temperature, e.rainfall == null ? 'N/A' : e.rainfall] + loadData( + version, + 'biomes', + function (biome) { + return [ + biome.id, + '' + biome.name + '', + biome.color === undefined ? '' : biome.color, + biome.temperature, + biome.rainfall == null ? 'N/A' : biome.rainfall + ] }, ['id', 'name', 'color', 'temperature', 'rainfall'], - [] + [], + 0 ) } function loadEntities (version) { - loadData(version, 'entities', - function (e) { - return [e.id, '' + e.name + '', - e.displayName, e.type, e.internalId ? e.internalId : '', e.width, e.height, e.category ? e.category : ''] + loadData( + version, + 'entities', + function (entity) { + return [ + entity.id, + '' + entity.name + '', + entity.displayName, + entity.type, + entity.internalId ? entity.internalId : '', + entity.width, + entity.height, + entity.category ? entity.category : '' + ] }, ['id', 'name', 'displayName', 'type', 'internalId', 'width', 'height', 'category'], - [] + [], + 0 ) } function loadInstruments (version) { - loadData(version, 'instruments', - function (e) { return [e.id, '' + e.name + ''] }, + loadData( + version, + 'instruments', + function (instrument) { + return [ + instrument.id, + '' + instrument.name + '' + ] + }, ['id', 'name'], - [] + [], + 0 ) } function loadWindows (version) { - loadData(version, 'windows', - function (e) { return [e.id, '' + e.name + ''] }, + loadData( + version, + 'windows', + function (window) { + return [ + window.id, + '' + window.name + '' + ] + }, ['id', 'name'], - [] + [], + 0 ) } function loadEffects (version) { - loadData(version, 'effects', - function (e) { return [e.id, '' + e.name + '', e.displayName, e.type] }, + loadData( + version, + 'effects', + function (effect) { + return [ + effect.id, + '' + effect.name + '', + effect.displayName, + effect.type + ] + }, ['id', 'name', 'displayName', 'type'], - [] + [], + 0 ) } function loadData (version, enumName, elementToArray, fields, hiddenColumns, orderColumn) { const data = require('minecraft-data')(version)[enumName + 'Array'] if (!data) return + const dataset = data.map(elementToArray) - $j('#' + enumName + 'Table').html('
') + + $j('#' + enumName + 'Table').html( + '
' + ) + $j('#' + enumName + 'ActualTable').dataTable({ - data: dataset, - paging: false, + serverSide: true, + ajax: function (data, callback) { + const start = data.start + const length = data.length + const filteredData = dataset.slice(start, start + length) + // eslint-disable-next-line n/no-callback-literal + callback({ + data: filteredData, + recordsTotal: dataset.length, + recordsFiltered: dataset.length + }) + }, + deferRender: true, + scrollY: '400px', + scrollCollapse: true, + scroller: true, + paging: true, columns: fieldsToColumns(fields), dom: 'C<"clear">lfrtip', - columnDefs: [ - { visible: false, targets: hiddenColumns } - ], + columnDefs: [{ visible: false, targets: hiddenColumns }], order: [[orderColumn || 0, 'asc']] - } - ) + }) }