let structure; let components; let collections; const generators = { 'advancement': ['1.15'], 'loot-table': ['1.13', '1.14', '1.15'], 'predicate': ['1.15'] } const generator = window.location.pathname.replace(/\/$/, '').replace(/^\//, ''); generators[generator].forEach(v => { $('#versionList').append(`${v}`) }); changeVersion('1.15'); function changeVersion(version) { $.getJSON('schemas/' + version + '.json', json => { if (json.root) { structure = json.root; } else if (json.roots) { structure = json.roots.find(e => e.id === generator) || json.roots[0] ; } components = json.components; collections = json.collections; }).fail((jqXHR, textStatus, errorThrown) => { let message = 'Failed loading ' + version + ' schema'; structure = { fields: [ { id: 'pools', type: 'error', message: message } ] }; console.error(message + '\n' + errorThrown); }).always(() => { $('#versionLabel').text(version); updateView(); }); } changeTheme(localStorage.getItem('theme')) function changeTheme(theme) { if (theme === null) { theme = 'light'; } $('body').attr('data-style', theme); localStorage.setItem('theme', theme); } function updateView() { if (structure) { let {out: sourceOut, component: $component} = generateSourceAndView(table, structure); $('#structure').removeClass('d-none').html(''); $('#descriptionSpan').attr('data-i18n', structure.description); $('title').attr('data-i18n', structure.title); $('#structure').append($component); if (i18next.isInitialized) { $('html').localize(); } $('#source').val(JSON.stringify(sourceOut, null, indentation)); } } function generateSourceAndView(data, struct) { if (generator === 'loot-table') { $('#lootTableToolbar').removeClass('d-none'); $('#structure').attr('data-index', 'pools'); return generateTable(data, struct); } else { let {out: sourceOut, component: $component} = generateObject(data, struct); $component.removeClass('mt-3'); return {out: sourceOut, component: $component}; } } function generateTable(data, struct) { let out = {}; let $el = $('
'); let type = struct.fields.find(e => e.id === 'type'); if (type) { $('.table-type').removeClass('d-none'); $('#tableType').html(''); for (let option of type.values) { $('#tableType').append(setValueAndName($('