Skip to content

Commit

Permalink
v0.11.0 pt.8
Browse files Browse the repository at this point in the history
- fixed dynamic auto-completions being cached
- added new problem fix type "script"
- added problems for spawn_rules, animations & animation_controllers
- updated auto-completions to v1.11.0.7
- added new problem components
- error scanning upon opening a file with bridge. for the first time
- fixed adding an attribute's value not updating the history
  • Loading branch information
solvedDev committed Mar 22, 2019
1 parent 075d051 commit 095226f
Show file tree
Hide file tree
Showing 21 changed files with 370 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bridge",
"productName": "bridge.",
"version": "0.11.0",
"version": "0.11.1",
"author": "solvedDev <[email protected]>",
"description": "A powerful add-on editor",
"license": null,
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/components/editor_shell/JsonEditor/JsonInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
this.expandPath(this.value);
} else if(this.file_navigation !== "global" && this.type === "value") {
TabSystem.getHistory().add(new JSONAction("edit-data", current, current.data));
current.data += this.value + "";
current.type = typeof this.value;
this.navigationBack();
Expand All @@ -124,6 +125,11 @@
current.data = this.value;
TabSystem.setCurrentFileNav(current.path + "/" + this.value);
}
//PLUGIN HOOK
PluginEnv.trigger("bridge:modifiedNode", {
node: current
});
}
TabSystem.setCurrentUnsaved();
EventBus.trigger("updateCurrentContent");
Expand Down
1 change: 1 addition & 0 deletions src/renderer/components/editor_shell/JsonEditor/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
:mark="e.mark_color"
:error="e.error"
:child_contains_error="e.child_contains_error"
:context="e"
/>

<json-editor-main
Expand Down
5 changes: 3 additions & 2 deletions src/renderer/components/editor_shell/JsonEditor/ObjectKey.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<v-btn
slot="activator"
color="amber darken-1"
@click.native="error.fix.function"
@click.native="error.fix.function(context)"
style="margin: 0; height: 20px; width: 20px;"
flat
small
Expand Down Expand Up @@ -79,7 +79,8 @@
},
object: Object,
error: Object,
child_contains_error: Boolean
child_contains_error: Boolean,
context: Object
},
computed: {
selected_class() {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/scripts/FileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class FileSystem {
})
)
.catch((err) => {
console.log("[OPEN] Not opened from cache");
console.log("[OPEN] Not opened from cache", err);
fs.readFile(path, (err, data) => {
if(err) throw err;
this.addAsTab(path, data.toString(), 0, data);
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/scripts/TabSystem/CommonHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export class History {
}

updateError() {
if(Store.state.Settings.when_error === "On File Change") ProblemIterator.repeatLast();
if(Store.state.Settings.when_error === "On File Change") {
setTimeout(() => ProblemIterator.repeatLast(), 10);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/scripts/constants/app_version.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
* Version number is in a dedicated file because it's also used by the main thread.
* Otherwise, any changes to the main constant file would completely restart "bridge." (in development mode).
*/
export default "v0.11.0";
export default "v0.11.1";
5 changes: 4 additions & 1 deletion src/renderer/scripts/editor/Json.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import saveEval from "safe-eval";
import JSONTree from "./JsonTree";
import ProblemIterator from "./problems/Problems";

function private_toJSON(tree, build_arrays) {
if(tree.type != "array" && tree.type != "object") {
Expand Down Expand Up @@ -45,7 +46,9 @@ export class Format {
}

static toTree(obj) {
return new JSONTree("global").buildFromObject(obj);
let tree = new JSONTree("global").buildFromObject(obj);
setTimeout(() => ProblemIterator.findProblems(tree), 10);
return tree;
}
}

Expand Down
29 changes: 22 additions & 7 deletions src/renderer/scripts/editor/autoCompletions.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ let LIB = {
animation_controller: {
current_states() {
let current = TabSystem.getCurrentNavObj();
if(Object.keys(current.toJSON()).length > 0) return [];


while(current !== undefined && current.key !== "states") {
current = current.parent;
}
Expand All @@ -104,14 +107,22 @@ let LIB = {
return NODE_CONTEXT.toJSON();
},
loot_table_files() {
return walkSync(BASE_PATH + Store.state.Explorer.project + "\\loot_tables").map(e => {
return e.replace(BASE_PATH.replace(/\//g, "\\") + Store.state.Explorer.project + "\\", "").replace(/\\/g, "/");
});
try {
return walkSync(BASE_PATH + Store.state.Explorer.project + "\\loot_tables").map(e => {
return e.replace(BASE_PATH.replace(/\//g, "\\") + Store.state.Explorer.project + "\\", "").replace(/\\/g, "/");
});
} catch(e) {
return [];
}
},
trade_table_files() {
return walkSync(BASE_PATH + Store.state.Explorer.project + "\\trading").map(e => {
return e.replace(BASE_PATH.replace(/\//g, "\\") + Store.state.Explorer.project + "\\", "").replace(/\\/g, "/");
});
try {
return walkSync(BASE_PATH + Store.state.Explorer.project + "\\trading").map(e => {
return e.replace(BASE_PATH.replace(/\//g, "\\") + Store.state.Explorer.project + "\\", "").replace(/\\/g, "/");
});
} catch(e) {
return [];
}
}
}
};
Expand Down Expand Up @@ -215,7 +226,11 @@ class Provider {
let key = path_arr.shift();

if(typeof current[key] === "string") {
current[key] = this.omegaExpression(current[key], null, null, false);
let o = this.omegaExpression(current[key], null, null, false);
if(!current[key].startsWith("$dynamic."))
current[key] = o;
else
return this.walk(path_arr, o);
} else if(current["$dynamic_template." + key] !== undefined) {
current = this.compileTemplate(current["$dynamic_template." + key]);
if(typeof current === "string") {
Expand Down
43 changes: 35 additions & 8 deletions src/renderer/scripts/editor/problems/CommonProblem.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,49 @@
//@ts-check
import Snippets from "../../../windows/Snippets";
import ProblemIterator from "./Problems";
import TabSystem from "../../TabSystem";
import { JSONAction } from "../../TabSystem/CommonHistory";

function run(code, self) {
return (function(self, History, Unsaved){
return eval(code);
})(self, History, Unsaved);
}
function History(type, node, data) {
TabSystem.getHistory().add(new JSONAction(type, node, data));
TabSystem.setCurrentUnsaved();
}
function Unsaved() {
TabSystem.setCurrentUnsaved();
}


export default class CommonProblem {
constructor({ error_message, is_warning, fix }) {
if(error_message) this.error_message = error_message;
this.is_warning = is_warning;
this.store_nodes = [];

if(fix && fix.type === "snippet") {
this.fix = {
function: () => {
Snippets.insert(fix.name, true);
ProblemIterator.repeatLast();
},
text: fix.display_text
};
if(fix !== undefined) {
if(fix.type === "snippet") {
this.fix = {
function: () => {
Snippets.insert(fix.name, true);
ProblemIterator.repeatLast();
},
text: fix.display_text
};
} else if(fix.type === "script") {
this.fix = {
function: (context) => {
run(fix.run, context);
ProblemIterator.repeatLast();
},
text: fix.display_text
};
}
}

}

processPeek(node) {
Expand Down
12 changes: 11 additions & 1 deletion src/renderer/scripts/editor/problems/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,24 @@ import NeedsThree from "./components/NeedsThree";
import NeedsThreeIfBoth from "./components/NeedsThreeIfBoth";
import FirstNeedsSecond from "./components/FirstNeedsSecond";
import FindOne from "./components/FindOne";
import ChildMustStartWith from "./components/ChildMustStartWith";
import ChildMustBeNumber from "./components/ChildMustBeNumber";
import EventCheck from "./components/EventCheck";
import BehaviorCheck from "./components/BehaviorCheck";
import FormatVersionCheck from "./components/FormatVersionCheck";

const MAP = {
"bridge:two_incompatible": TwoIncompatible,
"bridge:first_needs_second": FirstNeedsSecond,
"bridge:needs_both": NeedsBoth,
"bridge:needs_three": NeedsThree,
"bridge:needs_three_if_both": NeedsThreeIfBoth,
"bridge:find_one": FindOne
"bridge:find_one": FindOne,
"bridge:child_must_start_with": ChildMustStartWith,
"bridge:child_must_be_number": ChildMustBeNumber,
"bridge:event_check": EventCheck,
"bridge:behavior_check": BehaviorCheck,
"bridge:format_version_check": FormatVersionCheck
};

//@ts-ignore
Expand Down
44 changes: 44 additions & 0 deletions src/renderer/scripts/editor/problems/components/BehaviorCheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//@ts-check
import CommonProblem from "../CommonProblem";
import JsonCacheUtils from "../../JSONCacheUtils";
import TabSystem from "../../../TabSystem";

export default class BehaviorCheck extends CommonProblem {
constructor({ ...other }) {
//@ts-ignore
super(other);
this.found_behavior = false;
this.found_pathfinder = false;
this.found_movement = false;
}

peek(node) {
if(node.key.startsWith("minecraft:behavior.")) {
this.found_behavior = true;
return true;
} else if(node.key.startsWith("minecraft:navigation.")) {
this.found_pathfinder = true;
} else if(node.key.startsWith("minecraft:movement.")) {
this.found_movement = true;
}

return false;
}
found() {
return this.found_behavior && (!this.found_movement || !this.found_pathfinder);
}
report() {
let old = this.error_message;
this.error_message = this.error_message.replace(/\$failure_name/g, !this.found_pathfinder ? "minecraft:navigation.<type>" : "minecraft:movement.<type>");
let res = super.report();
this.error_message = old;

return res;
}
reset() {
super.reset();
this.found_behavior = false;
this.found_pathfinder = false;
this.found_movement = false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//@ts-check
import CommonProblem from "../CommonProblem";

export default class ChildMustBeNumber extends CommonProblem {
constructor({ search, ...other }) {
//@ts-ignore
super(other);
this.search = search;
this.problem_found = false;
}

peek(node) {
if(node.parent !== undefined && node.parent.key === this.search) {
if(Number.isNaN(Number(node.key))) {
this.problem_found = true;
return true;
}
}
return false;
}
found() {
return this.problem_found;
}
reset() {
super.reset();
this.problem_found = false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//@ts-check
import CommonProblem from "../CommonProblem";

export default class ChildMustStartWith extends CommonProblem {
constructor({ search, start, ...other }) {
//@ts-ignore
super(other);
this.search = search;
this.start = start;
this.problem_found = false;
}

peek(node) {
if(node.parent !== undefined && node.parent.key === this.search) {
if(!node.key.startsWith(this.start)) {
this.problem_found = true;
return true;
}
}
return false;
}
found() {
return this.problem_found;
}
reset() {
super.reset();
this.problem_found = false;
}
}
43 changes: 43 additions & 0 deletions src/renderer/scripts/editor/problems/components/EventCheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//@ts-check
import CommonProblem from "../CommonProblem";
import JsonCacheUtils from "../../JSONCacheUtils";
import TabSystem from "../../../TabSystem";

export default class EventCheck extends CommonProblem {
constructor({ ...other }) {
//@ts-ignore
super(other);
this.problem_found = false;
}

peek(node) {
if(node.key === "event") {
let t = node.parent.get("target");

if(t === undefined || t === "self") {
try {
let current_events = TabSystem.getSelected().content.get("minecraft:entity/events");

if(!Object.keys(current_events.toJSON()).includes(node.data)) {
this.problem_found = true;
return true;
}
} catch(e) {}
} else {
if(!JsonCacheUtils.events.includes(node.data)) {
this.problem_found = true;
return true;
}
}
}

return false;
}
found() {
return this.problem_found;
}
reset() {
super.reset();
this.problem_found = false;
}
}
Loading

0 comments on commit 095226f

Please sign in to comment.