diff --git a/.github/workflows/update_generators.yml b/.github/workflows/update_generators.yml deleted file mode 100644 index c830162e..00000000 --- a/.github/workflows/update_generators.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Update Generators - -on: - push: - branches: [master] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: Update predicate - uses: ad-m/github-push-action@master - with: - repository: misode/predicate - github_token: ${{ secrets.GENERATORS_TOKEN }} - - name: Update advancement - uses: ad-m/github-push-action@master - with: - repository: misode/advancement - github_token: ${{ secrets.GENERATORS_TOKEN }} diff --git a/advancement/index.html b/advancement/index.html new file mode 100644 index 00000000..dfac209d --- /dev/null +++ b/advancement/index.html @@ -0,0 +1,58 @@ + + + + + + + + + + + Advancement Generator Minecraft 1.15 + + + + +
+ + + + + + + + + + + + + diff --git a/components.html b/components.html new file mode 100644 index 00000000..a40bad4f --- /dev/null +++ b/components.html @@ -0,0 +1,130 @@ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ + + +
+ + + + + + + + + +
+
+
+ + + +
+ + + + + +
+
+
+ +
+ + + + +
+
+
+ +
+
+ + +
+
+
+
+ +
+ +
+
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+ + +
+
+
+
+
+
+ +
+ +
+ +
+
+
+
diff --git a/custom.css b/css/custom.css similarity index 94% rename from custom.css rename to css/custom.css index 987606eb..a9be45d6 100644 --- a/custom.css +++ b/css/custom.css @@ -100,6 +100,15 @@ textarea.invalid:focus { overflow-x: scroll; } +.card a { + color: #000 !important; +} + +.card a:hover { + color: #333 !important; + text-decoration: none; +} + body[data-style="dark"] { background-color: #222529; } @@ -208,3 +217,11 @@ body[data-style="dark"] .help-tooltip { color: #fff; border-color: #24282c; } + +body[data-style="dark"] .card a { + color: #fff !important; +} + +body[data-style="dark"] .card a:hover { + color: #ccc !important; +} diff --git a/i18n.js b/i18n.js deleted file mode 100644 index faee506f..00000000 --- a/i18n.js +++ /dev/null @@ -1,27 +0,0 @@ -const lngs = [ - ['en', 'English'], - ['ru', 'Русский'], - ['zh-CN', '简体中文'] -] - -lngs.forEach(v => $('#lngList').append(`${v[1]}`)) - -i18next - .use(i18nextBrowserLanguageDetector) - .use(i18nextXHRBackend) - .init({ - backend: { loadPath: 'locales/{{lng}}.json' }, - fallbackLng: 'en', - whitelist: lngs.map(v => v[0]), - keySeparator: false - }) - .then(() => { - jqueryI18next.init(i18next, $, { parseDefaultValueFromContent: false }) - updateView() - }) - -function changeLng(code) { - i18next.changeLanguage(code).then(() => { - updateView() - }) -} diff --git a/index.html b/index.html index 87ecdfe1..44a44239 100644 --- a/index.html +++ b/index.html @@ -11,196 +11,53 @@ - + Minecraft Generators 1.13 1.14 1.15 - + -
-
-
-
- -
- +
+ - -
-
-
-
- -
- -
-
-
- -
- -
-
-
- - - -
- - - - - - - - - -
-
-
- - - -
- - - - - -
-
-
- -
- - - - -
-
-
- -
-
- - -
-
-
-
- -
- -
-
- -
-
-
- -
- -
-
-
- -
- -
-
-
-
- -
-
- - -
-
-
-
-
-
- -
- -
- -
-
+
@@ -212,8 +69,9 @@ - - - + + + + diff --git a/js/i18n.js b/js/i18n.js new file mode 100644 index 00000000..d6fe2ca5 --- /dev/null +++ b/js/i18n.js @@ -0,0 +1,32 @@ +const lngs = [ + ['en', 'English'], + ['ru', 'Русский'], + ['zh-CN', '简体中文'] +] + +lngs.forEach(v => $('#lngList').append(`${v[1]}`)) + +function initLng() { + return i18next + .use(i18nextBrowserLanguageDetector) + .use(i18nextXHRBackend) + .init({ + backend: { loadPath: '../locales/{{lng}}.json' }, + fallbackLng: 'en', + whitelist: lngs.map(v => v[0]), + keySeparator: false + }) + .then(() => { + jqueryI18next.init(i18next, $, { parseDefaultValueFromContent: false }); + }); +} + +function changeLng(code) { + i18next.changeLanguage(code).then(() => { + if ('listeners' in window) { + listeners.forEach(l => l()); + } else { + $('html').localize(); + } + }) +} diff --git a/model.js b/js/model.js similarity index 86% rename from model.js rename to js/model.js index 991998cd..b385b025 100644 --- a/model.js +++ b/js/model.js @@ -1,30 +1,67 @@ +let indentation = 2; +let luckBased = false; +let historyBuffer = 100; +let history = ['{}']; +let historyIndex = 0; + +let structure; +let components; +let collections; +let table = {}; +let listeners = []; + +const generators = { + 'advancement': ['1.15'], + 'loot-table': ['1.13', '1.14', '1.15'], + 'predicate': ['1.15'] +} + +function addListener(listener) { + listeners.push(listener); + listener(); +} + +loadGenerator($('[data-generator]').attr('data-generator')); +function loadGenerator(generator) { + if (!generator) return; + const versions = generators[generator] || []; + versions.forEach(v => { + $('#versionList').append(`${v}`) + }); + const promises = [initShared(), initLng(), loadVersion(generator, '1.15')]; + Promise.all(promises).then(() => { + invalidated() + }); +} + +function loadVersion(generator, version) { + return $.getJSON('../schemas/' + version + '.json', json => { + structure = json.roots.find(e => e.id === generator); + table = structure.default; + components = json.components; + collections = json.collections; + }).fail((jqXHR, textStatus, errorThrown) => { + let message = 'Failed loading ' + version + ' schema'; + structure = {}; + console.error(message + '\n' + errorThrown); + }).always(() => { + $('#versionLabel').text(version); + }); +} + +async function initShared() { + const components = await fetch('../components.html').then(r => r.text()); + const shared = await fetch('../shared.html').then(r => r.text()); + $('body').append(components); + $('div.container').append(shared); +} + $("#source").val(''); $('#luckBased').prop('checked', false); $('#tableType').val("minecraft:generic"); $('#indentationSelect').val("2"); -let indentation = 2; -let luckBased = false; -let table = { - type: "minecraft:generic", - pools: [ - { - "rolls": 1, - "entries": [ - { - "type": "minecraft:item", - "name": "minecraft:stone" - } - ] - } - ] -}; -let historyBuffer = 100; -let history = ['{}']; -let historyIndex = 0; -invalidated(); - const params = new URLSearchParams(window.location.search); if (params.has('q')) { $('#source').val(atob(params.get('q'))); @@ -49,7 +86,7 @@ function undo() { if (historyIndex > 0) { historyIndex -= 1; table = JSON.parse(history[historyIndex]); - updateView(); + listeners.forEach(l => l()); } } @@ -57,7 +94,7 @@ function redo() { if (historyIndex < history.length - 1) { historyIndex += 1; table = JSON.parse(history[historyIndex]); - updateView(); + listeners.forEach(l => l()); } } @@ -73,7 +110,7 @@ function invalidated() { history = history.slice(0, historyIndex); history.push(JSON.stringify(table)); } - updateView(); + listeners.forEach(l => l()); } function updateTableType() { @@ -219,10 +256,7 @@ function addToSet(el, array) { function removeFromSet(el, array) { let parent = getParent(el); - console.warn(parent[array]); - console.log($(el).attr('value')); let index = parent[array].indexOf($(el).attr('value')); - console.log(parent, index); if (index > -1) { parent[array].splice(index, 1); invalidated(); diff --git a/view.js b/js/view.js similarity index 93% rename from view.js rename to js/view.js index 298af75d..501dadfb 100644 --- a/view.js +++ b/js/view.js @@ -1,48 +1,13 @@ -let structure; -let components; -let collections; -const generators = { - 'advancement': ['1.15'], - 'loot-table': ['1.13', '1.14', '1.15'], - 'predicate': ['1.15'] -} +const themes = ["light", "dark"]; -const generator = window.location.pathname.replace(/\/$/, '').replace(/^\//, ''); -generators[generator].forEach(v => { - $('#versionList').append(`${v}`) -}); +themes.forEach(v => $('#themeList').append(``)); -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(); - }); -} +addListener(updateView); changeTheme(localStorage.getItem('theme')) function changeTheme(theme) { + console.log(theme); if (theme === null) { theme = 'light'; } @@ -65,7 +30,7 @@ function updateView() { } function generateSourceAndView(data, struct) { - if (generator === 'loot-table') { + if (struct.id === 'loot-table') { $('#lootTableToolbar').removeClass('d-none'); $('#structure').attr('data-index', 'pools'); return generateTable(data, struct); diff --git a/locales/en.json b/locales/en.json index 5cf71924..16067697 100644 --- a/locales/en.json +++ b/locales/en.json @@ -128,6 +128,7 @@ "damage_source.is_magic": "Magic", "damage_source.is_projectile": "Projectile", "damage_source.source_entity": "Source Entity", + "description": "Minecraft Generators", "description.loot-table": "Loot Table Generator for Minecraft", "description.predicate": "Predicate Generator for Minecraft", "description.advancement": "Advancement Generator for Minecraft", @@ -421,6 +422,7 @@ "theme": "Theme", "theme.dark": "Dark", "theme.light": "Light", + "title": "Minecraft Generators", "title.loot-table": "Loot Table Generator", "title.predicate": "Predicate Generator", "title.advancement": "Advancement Generator", diff --git a/loot-table/index.html b/loot-table/index.html new file mode 100644 index 00000000..567fb4d1 --- /dev/null +++ b/loot-table/index.html @@ -0,0 +1,58 @@ + + + + + + + + + + + Loot Table Generator Minecraft 1.15 + + + + +
+ + + + + + + + + + + + + diff --git a/predicate/index.html b/predicate/index.html new file mode 100644 index 00000000..cfe7b81d --- /dev/null +++ b/predicate/index.html @@ -0,0 +1,58 @@ + + + + + + + + + + + Predicate Generator Minecraft 1.15 + + + + +
+ + + + + + + + + + + + + diff --git a/schemas/1.15.json b/schemas/1.15.json index 47568e91..bf02b492 100644 --- a/schemas/1.15.json +++ b/schemas/1.15.json @@ -26,14 +26,31 @@ "translate": "pool", "values": "pool" } - ] + ], + "default": { + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "minecraft:stone" + } + ] + } + ] + } }, { "id": "predicate", "title": "title.predicate", "description": "description.predicate", "type": "object", - "value": "condition" + "value": "condition", + "default": { + "condition": "minecraft:entity_properties", + "predicate": {} + } }, { "id": "advancement", @@ -156,7 +173,15 @@ "value": "criterion" } } - ] + ], + "default": { + "criteria": { + "requirement": { + "trigger": "minecraft:location", + "conditions": {} + } + } + } } ], "components": [ diff --git a/shared.html b/shared.html new file mode 100644 index 00000000..2c721169 --- /dev/null +++ b/shared.html @@ -0,0 +1,47 @@ +
+
+
+ +
+ +
+ +
+ + +
+
+ +
+
+
+
+
+
+
+
+
+ + +
+ + +
+
+
+ + +
+ +
+