Skip to content

Commit

Permalink
v0.10.0 pt.3
Browse files Browse the repository at this point in the history
- improved loot_table auto-completions
- improved trade_table auto-completions
- added currently unused ScopeGuard
- new $dynamic_template option which imports directly into the scope in which it's placed
  • Loading branch information
solvedDev committed Mar 12, 2019
1 parent c6c4493 commit 32cd761
Showing 13 changed files with 203 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/renderer/scripts/EventBus.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let events = {};
export default class {
export default class EventBus {
static on(event, cb) {
if(event in events) events[event].push(cb);
else events[event] = [cb];
2 changes: 1 addition & 1 deletion src/renderer/scripts/detachObj.js
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ const ARRAY_MERGE = (target, source) => {

const DETACH = (...objs) => {
if(objs.length == 1) return deepmerge({}, objs[0], { arrayMerge: ARRAY_MERGE });
if(objs.length == 2) return deepmerge(objs[0], objs[1], { arrayMerge: ARRAY_MERGE });
if(objs.length == 2) return deepmerge.all([{}, ...objs], { arrayMerge: ARRAY_MERGE });
return deepmerge.all(objs, { arrayMerge: ARRAY_MERGE });
}

50 changes: 50 additions & 0 deletions src/renderer/scripts/editor/ScopeGuard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//@ts-check
import EventBus from "../EventBus";
import TabSystem from "../TabSystem";

class ScopeGuard {
constructor() {
EventBus.on("updateSelectedTab", () => this.installListener());
this.scope_units = [];
this.installListener();
}

onScopeChange(f) {
let scope = new ScopeUnit(TabSystem.getCurrentNavObj());
scope.onChange = f;
this.scope_units.push(scope);
}

installListener() {
EventBus.on("updateFileNavigation", () => this.updateScope());
}

updateScope() {
let scope_node = TabSystem.getCurrentNavObj();
this.scope_units.forEach(s => s.update(scope_node));
}
}

class ScopeUnit {
constructor(scope_init) {
this.last_scope = scope_init;
}

in(scope) {
while(scope !== undefined && this.last_scope !== scope) {
scope = scope.parent;
}

return scope !== undefined;
}
update(scope) {
if(!this.in(scope)) {
console.log("[SCOPE] Changed!");
if(typeof this.onChange === "function") this.onChange();
this.last_scope = scope;
}
}
onChange() {}
}

export default new ScopeGuard();
44 changes: 31 additions & 13 deletions src/renderer/scripts/editor/autoCompletions.js
Original file line number Diff line number Diff line change
@@ -4,9 +4,11 @@ import TabSystem from "../TabSystem";
import deepmerge from "deepmerge";
import VersionMap from "./VersionMap";
import Store from "../../store/index";
import detachObj from "../detachObj";

let FILE_DEFS = [];
let SIBLINGS = {};
let CHILDREN = {};
let PARENT_CONTEXT = {};
let NODE_CONTEXT = {};

let LIB = {
$dynamic: {
@@ -29,10 +31,10 @@ let LIB = {
}
},
siblings() {
return SIBLINGS;
return PARENT_CONTEXT.toJSON();
},
children() {
return CHILDREN;
return NODE_CONTEXT.toJSON();
},

next_list_index() {
@@ -124,16 +126,21 @@ class Provider {
if(Array.isArray(propose)) return { value: propose };

//DYNAMIC LOAD INSTRUCTION
if(propose.$load != undefined) {
if(propose.$load !== undefined) {
Object.assign(propose, this.omegaExpression(propose.$load));
delete propose.$load;
}
if(propose.$dynamic_template !== undefined) {
let t = this.compileTemplate(propose.$dynamic_template);
if(t !== undefined) propose = detachObj(propose, t);
}

return {
object: Object.keys(propose).filter(e => e != "$placeholder").map(key => {
object: Object.keys(propose).filter(e => e != "$placeholder" && e != "$dynamic_template").map(key => {
if(key.startsWith("$dynamic_template.")) {
return key.split(".").pop();
}

if(key[0] == "$") {
// console.log(this.omegaExpression(key))
let exp = this.omegaExpression(key);
@@ -148,6 +155,7 @@ 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);
@@ -158,15 +166,22 @@ class Provider {
}
return this.walk(path_arr, current);
} else if(current[key] === undefined) {
key = "$placeholder";
if(current[key] === undefined && current !== LIB) {
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(current[key] === undefined && current["$placeholder"] === undefined && current !== LIB) {
for(let k of Object.keys(current)) {
if(k[0] == "$") {
key = k;
break;
}
}
}
} else if(current["$placeholder"] !== undefined) {
key = "$placeholder";
}
}
return this.walk(path_arr, current[key]);
}
@@ -201,13 +216,16 @@ class Provider {
}

setupContext(c) {
CHILDREN = c.toJSON();
if(c.parent == undefined) SIBLINGS = {};
else SIBLINGS = c.parent.toJSON();
NODE_CONTEXT = c;
PARENT_CONTEXT = c.parent;
}
contextUp() {
if(NODE_CONTEXT !== undefined) NODE_CONTEXT = NODE_CONTEXT.parent;
if(PARENT_CONTEXT !== undefined) PARENT_CONTEXT = PARENT_CONTEXT.parent;
}

compileTemplate(template) {
// console.log(template[this.dynamic(template["$key"])]);
// console.log(template["$key"], this.dynamic(template["$key"]), template[this.dynamic(template["$key"])]);
return template[this.dynamic(template["$key"])];
}

Empty file removed static/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion static/auto_completions/file_definitions.json
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
},
{
"includes": "loot_tables",
"start_state": "loot_table"
"start_state": "loot_table/main"
},
{
"includes": "trading",
7 changes: 5 additions & 2 deletions static/auto_completions/files.json
Original file line number Diff line number Diff line change
@@ -9,11 +9,14 @@
"entity/behavior",
"entity/filters",

"loot_table",
"loot_table/main",
"loot_table/general",
"loot_table/functions",
"loot_table/conditions",

"trade_table/general",
"trade_table/main",
"trade_table/v1_11",
"trade_table/general",

"spawn_rule/main",
"spawn_rule/main_v1_11",
11 changes: 3 additions & 8 deletions static/auto_completions/general.json
Original file line number Diff line number Diff line change
@@ -40,14 +40,6 @@
"filter_targets": [ "other", "parent", "player", "self", "target" ],
"filter_operators": [ "==", "!=", "<", "<=", "<>", "=", ">", ">=", "equals", "not" ]
},
"loot_table": {
"conditions": [
"random_difficulty_chance", "random_regional_difficulty_chance"
],
"functions": [
"looting_enchant", "enchant_random_gear"
]
},
"inventory_type": [
"minecart_chest", "horse", "minecart_hopper", "container"
],
@@ -73,6 +65,9 @@
"color_palette": [
"white", "light_green", "orange", "silver", "magenta", "light_blue", "yellow", "pink", "blue", "gray", "cyan", "purple", "brown", "green", "red", "black"
],
"structures": [
"buriedtreasure", "endcity", "fortress", "mansion", "mineshaft", "monument", "pillageroutpost", "ruins", "shipwreck", "stronghold", "temple", "village"
],
"particle_name": [
"mobspellambient", "villagerangry", "blockbreak", "blockdust", "bubble", "evaporation", "crit", "dragonbreath", "driplava", "dripwater", "reddust", "spell", "mobappearance", "enchantingtable", "endrod", "mobspell", "largeexplode", "hugeexplosion", "fallingdust", "fireworksspark", "waterwake", "flame", "villagerhappy", "heart", "mobspellinstantaneous", "iconcrack", "slime", "snowballpoof", "largesmoke", "lava", "mobflame", "townaura", "nautilus", "note", "explode", "portal", "rainsplash", "smoke", "watersplash", "ink", "terrain", "totem", "trackingemitter", "witchspell"
],
31 changes: 31 additions & 0 deletions static/auto_completions/loot_table/conditions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$dynamic.list.next_index": {
"condition": "$loot_table.general.conditions",

"$dynamic_template": {
"$key": "$dynamic.children.condition",

"entity_properties": {
"entity": [ "this" ],
"properties":{
"on_fire": "$general.boolean"
}
},
"random_chance":{
"chance": "$general.decimal"
},
"random_chance_with_looting":{
"chance": "$general.decimal",
"looting_multiplayer": "$general.decimal"
},
"random_difficulty_change":{
"default_chance": "$general.decimal",
"peaceful": "$general.decimal",
"hard": "$general.decimal"
},
"random_regional_difficulty_chance":{
"max_chance": "$general.decimal"
}
}
}
}
63 changes: 63 additions & 0 deletions static/auto_completions/loot_table/functions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"$dynamic.list.next_index": {
"function": "$loot_table.general.functions",
"conditions": "$loot_table.conditions",

"$dynamic_template": {
"$key": "$dynamic.children.function",

"enchant_book_for_trading": {
"base_cost": "$general.number",
"base_random_cost": "$general.number",
"per_level_cost": "$general.number",
"per_level_random_cost": "$general.number"
},
"enchant_random_gear": {
"chance": "$general.decimal"
},
"enchant_randomly": {
"treasure": "$general.boolean"
},
"enchant_with_levels": {
"treasure": "$general.boolean",
"levels": {
"min": "$general.number",
"max": "$general.number"
}
},
"exploration_map": {
"destination": "$general.structures"
},
"looting_enchant": {
"count": {
"min": "$general.number",
"max": "$general.number"
}
},
"set_banner_details": {
"type": {
"min": "$general.number",
"max": "$general.number"
}
},
"set_count": {
"count": {
"min": "$general.number",
"max": "$general.number"
}
},
"set_damage": {
"damage": {
"min": "$general.decimal",
"max": "$general.decimal"
}
},
"set_data": {
"data": {
"min": "$general.number",
"max": "$general.number"
}
}
}
}
}
8 changes: 8 additions & 0 deletions static/auto_completions/loot_table/general.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"conditions": [
"entity_properties", "killed_by_player", "killed_by_player_or_pets", "random_chance", "random_chance_with_looting", "random_difficulty_chance", "random_regional_difficulty_chance"
],
"functions": [
"enchant_book_for_trading", "enchant_random_gear", "enchant_randomly", "enchant_with_levels", "exploration_map", "furnace_smelt", "looting_enchant", "set_banner_details", "set_count", "set_damage", "set_data", "set_data_from_color_index"
]
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{
"pools": {
"$dynamic.list.next_index": {
"conditions": {
"$dynamic.list.next_index": {
"condition": "$general.loot_table.conditions"
}
},
"conditions": "$loot_table.conditions",
"tiers": {
"initial_range": "$general.number",
"bonus_rolls": "$general.number",
@@ -17,12 +13,8 @@
"type": [ "item", "loot_table" ],
"name": "$general.item_identifier and $dynamic.loot_table_files",
"weight": "$general.number",
"functions": {
"$dynamic.list.next_index": {
"function": "$general.loot_table.functions"
}
},
"pools": "$loot_table.pools"
"functions": "$loot_table.functions",
"pools": "$loot_table.main.pools"
}
}
}
9 changes: 6 additions & 3 deletions static/auto_completions/trade_table/general.json
Original file line number Diff line number Diff line change
@@ -10,7 +10,8 @@
"gives": {
"0": {
"item": "$general.item_identifier",
"quantity": "$general.number"
"quantity": "$general.number",
"functions": "$loot_table.functions"
}
}
}
@@ -20,13 +21,15 @@
"wants": {
"$dynamic.list.index_pair": {
"item": "$general.item_identifier",
"quantity": "$general.number"
"quantity": "$general.number",
"price_multiplier": "$general.decimal"
}
},
"gives": {
"0": {
"item": "$general.item_identifier",
"quantity": "$general.number"
"quantity": "$general.number",
"functions": "$loot_table.functions"
}
},
"trader_exp": "$general.number",

0 comments on commit 32cd761

Please sign in to comment.