From b082cfc198638559fb198e08dd4eaa62903eb663 Mon Sep 17 00:00:00 2001 From: solvedDev <33347616+solvedDev@users.noreply.github.com> Date: Tue, 12 Mar 2019 15:24:35 +0100 Subject: [PATCH] v0.10.0 pt.4 - ScopeGuard is back in action - fixed pollution of proposal scope - improved loot_table auto-completions - tweaks to the settings window - added new setting "auto fill inputs" --- .../editor_shell/JsonEditor/JsonInput.vue | 16 ++--- .../windowFactory/WindowContent.vue | 1 + src/renderer/scripts/EventBus.js | 2 +- src/renderer/scripts/detachObj.js | 8 +-- .../scripts/editor/autoCompletions.js | 25 +++++-- src/renderer/store/Settings.js | 1 + src/renderer/store/data/settings | 2 +- src/renderer/windows/Settings.js | 67 ++++++++++++++++--- static/auto_completions/loot_table/main.json | 17 +++-- 9 files changed, 107 insertions(+), 32 deletions(-) diff --git a/src/renderer/components/editor_shell/JsonEditor/JsonInput.vue b/src/renderer/components/editor_shell/JsonEditor/JsonInput.vue index fe7c1aca2..9b4bc9dfe 100644 --- a/src/renderer/components/editor_shell/JsonEditor/JsonInput.vue +++ b/src/renderer/components/editor_shell/JsonEditor/JsonInput.vue @@ -18,6 +18,7 @@ :auto-select-first="true" :menu-props="{ maxHeight: 130, top: false }" :hide-no-data="true" + no-data-text="No suggestions available..." dense class="json-input-menu" > @@ -137,7 +138,6 @@ } else if(this.file_navigation != "global") { current.data += this.value + ""; current.type = typeof this.value; - this.updateAutoCompletions(); this.navigationBack(); //PLUGIN HOOK @@ -151,6 +151,7 @@ this.$nextTick(() => { this.value = ""; }); + }, updateAutoCompletions() { @@ -182,16 +183,13 @@ return this.items = []; this.items = propose.filter(e => !context.includes(e)); - - // CURRENTLY MAKES IT IMPOSSIBLE TO SELECT A NODE WHICH IS CONSIDERED "FILLED" - // if(this.items.length == 0) { - // this.navigationBack(); - // } + this.$nextTick(() => { - if(this.items && this.items.length > 0 && this.$refs.input) - this.$refs.input.focus(); + if(this.items && this.items.length > 0 && this.$refs.input) { + if(this.$store.state.Settings.auto_fill_inputs) this.value = this.items[0]; + this.$refs.input.focus(); + } }); - }, expandPath(path) { diff --git a/src/renderer/components/windowFactory/WindowContent.vue b/src/renderer/components/windowFactory/WindowContent.vue index 952f06fc6..934ef65ef 100644 --- a/src/renderer/components/windowFactory/WindowContent.vue +++ b/src/renderer/components/windowFactory/WindowContent.vue @@ -109,6 +109,7 @@ :items="content.options" @change="action.default" :color="content.color" + background-color="rgba(0, 0, 0, 0)" :value="content.input" solo /> diff --git a/src/renderer/scripts/EventBus.js b/src/renderer/scripts/EventBus.js index 552090291..c4104e241 100644 --- a/src/renderer/scripts/EventBus.js +++ b/src/renderer/scripts/EventBus.js @@ -13,7 +13,7 @@ export default class EventBus { else { for(let i = 0; i < events[event].length; i++) { if(events[event][i] === cb) { - console.log(events[event].splice(i, 1)); + events[event].splice(i, 1); return; } } diff --git a/src/renderer/scripts/detachObj.js b/src/renderer/scripts/detachObj.js index 73045b86d..23a95e96d 100644 --- a/src/renderer/scripts/detachObj.js +++ b/src/renderer/scripts/detachObj.js @@ -5,15 +5,15 @@ const ARRAY_MERGE = (target, source) => { let tmp = []; source.forEach(e => { if(typeof e != "object") tmp.push(e); - else tmp.push(DETACH({}, e)); + else tmp.push(detachObj({}, e)); }) return tmp; }; -const DETACH = (...objs) => { +const detachObj = (...objs) => { if(objs.length == 1) return deepmerge({}, objs[0], { arrayMerge: ARRAY_MERGE }); - if(objs.length == 2) return deepmerge.all([{}, ...objs], { arrayMerge: ARRAY_MERGE }); + if(objs.length == 2) return deepmerge(objs[0], objs[1], { arrayMerge: ARRAY_MERGE }); return deepmerge.all(objs, { arrayMerge: ARRAY_MERGE }); } -export default DETACH; \ No newline at end of file +export default detachObj; \ No newline at end of file diff --git a/src/renderer/scripts/editor/autoCompletions.js b/src/renderer/scripts/editor/autoCompletions.js index efa834805..4779618d0 100644 --- a/src/renderer/scripts/editor/autoCompletions.js +++ b/src/renderer/scripts/editor/autoCompletions.js @@ -5,6 +5,7 @@ import deepmerge from "deepmerge"; import VersionMap from "./VersionMap"; import Store from "../../store/index"; import detachObj from "../detachObj"; +import ScopeGuard from "./ScopeGuard"; let FILE_DEFS = []; let PARENT_CONTEXT = {}; @@ -132,7 +133,10 @@ class Provider { } if(propose.$dynamic_template !== undefined) { let t = this.compileTemplate(propose.$dynamic_template); - if(t !== undefined) propose = detachObj(propose, t); + if(t !== undefined) { + propose = Object.assign(propose, t); + this.installScopeGuard(propose, t); + } } return { @@ -155,7 +159,6 @@ class Provider { walk(path_arr, current=LIB) { if(path_arr === undefined || path_arr.length === 0 || current === undefined) return current; let key = path_arr.shift(); - let key_backup = key; if(typeof current[key] === "string") { current[key] = this.omegaExpression(current[key], null, null, false); @@ -168,13 +171,17 @@ class Provider { } else if(current[key] === undefined) { if(current["$dynamic_template"] !== undefined) { for(let i = 0; i < path_arr.length + 1; i++) this.contextUp(); + let t = this.compileTemplate(current["$dynamic_template"]); - if(t !== undefined) current = detachObj(current, t); + if(t !== undefined) { + current = Object.assign(current, t); + this.installScopeGuard(current, t); + } } if(current[key] === undefined && current["$placeholder"] === undefined && current !== LIB) { for(let k of Object.keys(current)) { - if(k[0] == "$") { + if(k.startsWith("$dynamic.")) { key = k; break; } @@ -224,6 +231,16 @@ class Provider { if(PARENT_CONTEXT !== undefined) PARENT_CONTEXT = PARENT_CONTEXT.parent; } + installScopeGuard(propose, new_propose) { + ScopeGuard.onScopeChange(() => { + // console.log(JSON.stringify(propose)); + Object.keys(new_propose).forEach(key => { + delete propose[key]; + }); + // console.log(JSON.stringify(propose)); + }); + } + compileTemplate(template) { // console.log(template["$key"], this.dynamic(template["$key"]), template[this.dynamic(template["$key"])]); return template[this.dynamic(template["$key"])]; diff --git a/src/renderer/store/Settings.js b/src/renderer/store/Settings.js index b410dd58f..e97267ba4 100644 --- a/src/renderer/store/Settings.js +++ b/src/renderer/store/Settings.js @@ -17,6 +17,7 @@ function setup() { use_tabs: true, line_wraps: false, auto_completions: true, + auto_fill_inputs: false, open_all_nodes: false, default_project: "", target_version: "" diff --git a/src/renderer/store/data/settings b/src/renderer/store/data/settings index 9ea0230d9..ec1fff281 100644 --- a/src/renderer/store/data/settings +++ b/src/renderer/store/data/settings @@ -1 +1 @@ -{"is_dev_mode":false,"is_dark_mode":false,"inversed_arrows":false,"use_tabs":true,"line_wraps":false,"auto_completions":true,"open_all_nodes":false,"default_project":"MysticBP","target_version":"v1.11"} \ No newline at end of file +{"is_dev_mode":false,"is_dark_mode":false,"inversed_arrows":false,"use_tabs":true,"line_wraps":false,"auto_completions":true,"open_all_nodes":false,"default_project":"MysticBP","target_version":"v1.11","auto_fill_inputs":true} \ No newline at end of file diff --git a/src/renderer/windows/Settings.js b/src/renderer/windows/Settings.js index 4637ffd7e..4b68c107c 100644 --- a/src/renderer/windows/Settings.js +++ b/src/renderer/windows/Settings.js @@ -69,11 +69,45 @@ export default class SettingsWindow extends TabWindow { color: "grey", text: "\nTarget Minecraft Version" }, - new ReactiveDropdown(this, "target_version", MINECRAFT_VERSIONS ,{ text: "Choose a version...", key: `settings.editor.tab.target_version.${Math.random()}` }, () => EventBus.trigger("updateAutoCompletions")), - new ReactiveSwitch(this, "use_tabs", { color: "light-green", text: "Use Tabs", key: `settings.editor.tab.tabs.${Math.random()}` }), - new ReactiveSwitch(this, "line_wraps", { color: "light-green", text: "Word Wrap", key: `settings.editor.tab.tabs.${Math.random()}` }), - new ReactiveSwitch(this, "open_all_nodes", { color: "light-green", text: "Open All Nodes", key: `settings.editor.tab.open_all_nodes.${Math.random()}` }), - new ReactiveSwitch(this, "auto_completions", { color: "light-green", text: "Provide Auto-Completions", key: `settings.editor.tab.auto_completions.${Math.random()}` }) + new ReactiveDropdown(this, "target_version", MINECRAFT_VERSIONS, { + text: "Choose a version...", + key: `settings.editor.tab.target_version.${Math.random()}` + }, () => EventBus.trigger("updateAutoCompletions")), + + { + color: "grey", + text: "\nGeneral" + }, + new ReactiveSwitch(this, "use_tabs", { + color: "light-green", + text: "Use Tabs", + key: `settings.editor.tab.tabs.${Math.random()}` + }), + new ReactiveSwitch(this, "line_wraps", { + color: "light-green", + text: "Word Wrap", + key: `settings.editor.tab.line_wraps.${Math.random()}` + }), + new ReactiveSwitch(this, "open_all_nodes", { + color: "light-green", + text: "Open All Nodes", + key: `settings.editor.tab.open_all_nodes.${Math.random()}` + }), + + { + color: "grey", + text: "\nAuto-Completions" + }, + new ReactiveSwitch(this, "auto_completions", { + color: "light-green", + text: "Provide Auto-Completions", + key: `settings.editor.tab.auto_completions.${Math.random()}` + }), + new ReactiveSwitch(this, "auto_fill_inputs", { + color: "light-green", + text: "Auto Fill Inputs", + key: `settings.editor.tab.auto_fill_inputs.${Math.random()}` + }) ] }); this.addTab({ @@ -82,7 +116,10 @@ export default class SettingsWindow extends TabWindow { title: "Explorer" }, content: [ - new ReactiveInput(this, "default_project", { text: "Default Project", key: `settings.editor.tab.default_project.${Math.random()}` }) + new ReactiveInput(this, "default_project", { + text: "Default Project", + key: `settings.editor.tab.default_project.${Math.random()}` + }) ] }); this.addTab({ @@ -91,8 +128,16 @@ export default class SettingsWindow extends TabWindow { title: "Appearance" }, content: [ - new ReactiveSwitch(this, "is_dark_mode", { color: "light-green", text: "Dark Mode", key: `settings.appearance.tab.${Math.random()}` }), - new ReactiveSwitch(this, "inversed_arrows", { color: "light-green", text: "Inverse Arrows", key: `settings.editor.tab.arrows.${Math.random()}` }) + new ReactiveSwitch(this, "is_dark_mode", { + color: "light-green", + text: "Dark Mode", + key: `settings.appearance.tab.${Math.random()}` + }), + new ReactiveSwitch(this, "inversed_arrows", { + color: "light-green", + text: "Inverse Arrows", + key: `settings.editor.tab.arrows.${Math.random()}` + }) ] }); this.addTab({ @@ -101,7 +146,11 @@ export default class SettingsWindow extends TabWindow { title: "Developer Mode" }, content: [ - new ReactiveSwitch(this, "is_dev_mode", { color: "error", text: "Asserts", key: `settings.dev.tab.${Math.random()}` }) + new ReactiveSwitch(this, "is_dev_mode", { + color: "error", + text: "Asserts", + key: `settings.dev.tab.${Math.random()}` + }) ] }); diff --git a/static/auto_completions/loot_table/main.json b/static/auto_completions/loot_table/main.json index 0b245e71a..8c8327fb7 100644 --- a/static/auto_completions/loot_table/main.json +++ b/static/auto_completions/loot_table/main.json @@ -11,10 +11,19 @@ "entries": { "$dynamic.list.next_index": { "type": [ "item", "loot_table" ], - "name": "$general.item_identifier and $dynamic.loot_table_files", - "weight": "$general.number", - "functions": "$loot_table.functions", - "pools": "$loot_table.main.pools" + "$dynamic_template": { + "$key": "$dynamic.children.type", + + "item": { + "name": "$general.item_identifier", + "weight": "$general.number", + "functions": "$loot_table.functions", + "pools": "$loot_table.main.pools" + }, + "loot_table": { + "name": "$dynamic.loot_table_files" + } + } } } }