From fe9e2c947556465f2683d6a9b1b11ead46ee2f81 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Tue, 14 Mar 2017 13:38:46 -0700 Subject: [PATCH] Moved Hint to modules --- links/main.css | 2 +- scripts/modules/module.js | 34 ++++++++++------------------------ scripts/modules/render.js | 21 ++++++++++----------- scripts/modules/terminal.js | 26 ++++++-------------------- 4 files changed, 27 insertions(+), 56 deletions(-) diff --git a/links/main.css b/links/main.css index 8fe440b..734d467 100644 --- a/links/main.css +++ b/links/main.css @@ -15,7 +15,7 @@ canvas:hover { cursor: none;} #terminal { position: fixed; bottom:0px; left:0px; background:#000; width:100vw; height: 120px;overflow: hidden;} #terminal input { display: block; position:absolute; bottom:0px; width:100vw; padding:0px 5px; font-size:10px; line-height: 20px; background:none; z-index:900; color:white;} #terminal hint { background:#000; position:absolute; bottom:0px; line-height: 20px; padding:0px 5px; width:100vw; color:#777; font-size:10px; white-space: pre;} -#terminal hint .name { font-family: "input_mono_regular"; color:#999; } +#terminal hint b { font-family: "input_mono_regular"; color:#999; } #terminal logs { display: block;position: absolute;bottom:20px;width:100vw;color:white} #terminal logs log { display: block; font-size:10px; line-height:25px; padding:0px 5px; color:#666;} #terminal logs log .rune { color:white; } diff --git a/scripts/modules/module.js b/scripts/modules/module.js index 3b2f862..174abf6 100644 --- a/scripts/modules/module.js +++ b/scripts/modules/module.js @@ -36,40 +36,26 @@ function Module(rune) } } - this.hint = function(cmd) + this.hint = function(content) { - var s = this.pad(cmd.content.join(" ")); - - s += cmd.content.join(" ").length == 0 ? ""+this.constructor.name+"" : ""; - - // Params - - var e = 0; - while(e < 10){ - if(!this.parameters[e]){ break; } - var param_name = this.parameters[e].name; - s += cmd[param_name.toLowerCase()]() ? "" : ""+param_name+""; - e += 1; + var h = ""+ronin.module.constructor.name+" "; + for(param in ronin.module.parameters){ + var name = new ronin.module.parameters[param]().constructor.name; + h += name+" "; + } + for(variable in ronin.module.variables){ + h += variable+"="+ronin.module.variables[variable]+" "; } - // Variables - if(this.variables){ - for (var key in this.variables){ - if(cmd.variable(key)){continue;} - s += ""+key+"="+this.variables[key]+" "; - } - } - - return s; + return this.pad(content)+h; } this.pad = function(input) { var s = ""; - for (i = 0; i < input.length+2; i++){ + for (i = 0; i < input.length+1; i++){ s += "_"; } - return ""+s+""; } diff --git a/scripts/modules/render.js b/scripts/modules/render.js index 21bf7c0..70dda31 100644 --- a/scripts/modules/render.js +++ b/scripts/modules/render.js @@ -30,28 +30,27 @@ function Render(rune) var name = cmd.content[0]; - if(!this.collection[name]){ console.log("unknown ",name); return; } + if(!this.collection[name]){ return; } return this.collection[name].preview(cmd); } - this.hint = function(cmd) + this.hint = function(content) { - var input = cmd.content.join(" ").trim().split(" ")[0]; - var s = this.pad(cmd.content.join(" ")); + var name = content.trim().replace(this.rune,"").trim().split(" "); - if(this.collection[input]){ - for (i = 0; i < this.collection[input].parameters.length; i++) { - s += this.collection[input].parameters[i].name+" "; + var h = ""; + if(this.collection[name]){ + for (i = 0; i < this.collection[name].parameters.length; i++) { + h += this.collection[name].parameters[i].name+" "; } } else{ for (var key in this.collection){ - s += key+" "; + h += key+" "; } - } - - return s; + } + return this.pad(content)+h; } } diff --git a/scripts/modules/terminal.js b/scripts/modules/terminal.js index 3a715dd..743b32e 100644 --- a/scripts/modules/terminal.js +++ b/scripts/modules/terminal.js @@ -121,34 +121,20 @@ function Terminal(rune) this.update_hint = function(content = this.input_element.value) { - var padding = ""; - for (var i = 0; i < this.input_element.value.length; i++) { - padding += " "; - } + ronin.terminal.input_element.setAttribute("style","color:"+ronin.brush.color.hex); if(content.indexOf(";") > -1){ - var h = padding+" "+content.split(";").length+" commands"; + this.hint_element.innerHTML = padding+" "+content.split(";").length+" commands"; } else if(ronin.module){ - var h = padding+" "+ronin.module.constructor.name+" "; - for(param in ronin.module.parameters){ - var name = new ronin.module.parameters[param]().constructor.name; - h += name+" "; - } - for(variable in ronin.module.variables){ - h += variable+"="+ronin.module.variables[variable]+" "; - } + this.hint_element.innerHTML = ronin.module.hint(content); } else{ - var h = ""; + this.hint_element.innerHTML = ""; for(module in ronin.modules){ - h += module+" "; + this.hint_element.innerHTML += ""+module+" "+ronin.modules[module].constructor.name+" "; } - } - - this.hint_element.innerHTML = h; - - ronin.terminal.input_element.setAttribute("style","color:"+ronin.brush.color.hex); + } } this.update_menu = function()