This commit is contained in:
lxsang 2020-11-29 23:31:09 +01:00
parent 8f988c4e7f
commit 00ff78aca8
8 changed files with 7 additions and 5 deletions

View File

@ -5,4 +5,5 @@ Application for serverside code testing and analytics tool.
It allows to execute lua code on the server from the browser It allows to execute lua code on the server from the browser
## Change logs ## Change logs
* 0.0.6-a: Fix ace path error
* 0.0.5-a: Fix worker path error * 0.0.5-a: Fix worker path error

View File

@ -5,4 +5,5 @@ Application for serverside code testing and analytics tool.
It allows to execute lua code on the server from the browser It allows to execute lua code on the server from the browser
## Change logs ## Change logs
* 0.0.6-a: Fix ace path error
* 0.0.5-a: Fix worker path error * 0.0.5-a: Fix worker path error

View File

@ -1,4 +1,4 @@
(function(){var e,i,n;e=class{constructor(t){this.target=t,this.el=$("<canvas>").attr("class","viewer")[0],this.offset=10,this.points=[],this.preprocess(),this.getBound(),this.prepare(),this.render()}canvasPoint(e){return new t.Point(e[0]/this.target.resolution+this.base.x,-e[1]/this.target.resolution+this.base.y)}preprocess(){return this.points=this.target.data}getBound(){var t,e,i,n,r,s,a,o;for(n={x:0,y:0},i={x:0,y:0},t=0,e=(r=this.points).length;t<e;t++)a=(s=r[t])[0]/this.target.resolution,o=s[1]/this.target.resolution,a<n.x&&(n.x=a),o<n.y&&(n.y=o),a>i.x&&(i.x=a),o>i.y&&(i.y=o);return this.bound=[n,i],this.base={x:0-this.bound[0].x+this.offset,y:this.bound[1].y+this.offset},this.width=i.x-n.x+2*this.offset,this.height=i.y-n.y+2*this.offset}drawPoint(e,i,n){return new t.Path.Circle({center:this.canvasPoint(e),radius:n,fillColor:i})}drawGrid(e,i){var n,r,s,a,o,h;for(h=this.target.resolution*e,r=Math.ceil(this.bound[0].x/e);r*e<this.bound[1].x;)a=new t.Point(r*e+this.base.x,-this.bound[0].y+this.base.y),n=new t.Point(r*e+this.base.x,-this.bound[1].y+this.base.y),(s=new t.Path).strokeColor=i,s.moveTo(a),s.lineTo(n),r++;for(r=Math.ceil(this.bound[0].y/e);r*e<this.bound[1].y;)a=new t.Point(this.bound[0].x+this.base.x,-r*e+this.base.y),n=new t.Point(this.bound[1].x+this.base.x,-r*e+this.base.y),(s=new t.Path).strokeColor=i,s.moveTo(a),s.lineTo(n),r++;return(o=new t.PointText(this.bound[0].x+this.base.x,this.base.y-this.bound[1].y+this.offset)).justification="left",o.fillColor="#494949",o.content=`Resolution: ${this.target.resolution}, grid size: ${h} mm`}drawAxis(e){var i,n,r;return(n=new t.Path).strokeColor=e,r=new t.Point(this.bound[0].x+this.base.x,this.base.y),i=new t.Point(this.bound[1].x+this.base.x,this.base.y),n.moveTo(r),n.lineTo(i),(n=new t.Path).strokeColor=e,r=new t.Point(this.base.x,-this.bound[0].y+this.base.y),i=new t.Point(this.base.x,-this.bound[1].y+this.base.y),n.moveTo(r),n.lineTo(i),this.drawPoint([0,0],e,3)}prepare(){var e;return(e=this.el.getContext("2d")).translate(this.base.x,this.base.y),e.canvas.width=this.width,e.canvas.height=this.height,t.setup(this.el)}render(){}},n=class extends e{constructor(t){super(t)}p2c(t,e){var i;return i=e*Math.PI/180,[t*Math.cos(i),t*Math.sin(i)]}preprocess(){var t,e,i,n,r,s;if("polar"!==this.target.coordinate)return this.points=this.target.data;for(this.point=[],t=0,r=[],e=0,i=(n=this.target.data).length;e<i;e++)s=n[e],this.points.push(this.p2c(s,this.target.start+t*this.target.angularResolution)),r.push(t+=1);return r}render(){var e,i,n,r,s,a,o;for(this.drawGrid(20,"#DBDBDB"),this.drawAxis("#0A84FF"),i=0,n=(s=this.points).length;i<n;i++)o=s[i],"polar"===this.target.coordinate&&((r=new t.Path).strokeColor="#c2a10e",a=this.canvasPoint([0,0]),e=this.canvasPoint(o),r.moveTo(a),r.lineTo(e)),this.drawPoint(o,"red",3);return t.view.draw()}},(i=class extends this.OS.application.BaseApplication{constructor(t){super("LuaPlayground",t)}main(){return this.datarea=this.find("editorea"),this.output=this.find("output"),ace.config.set("basePath",window.location.pathname+"/scripts/ace"),this.editor=ace.edit(this.datarea),this.editor.setOptions({enableBasicAutocompletion:!0,enableLiveAutocompletion:!0,highlightActiveLine:!0,highlightSelectedWord:!0,behavioursEnabled:!0,wrap:!0,fontSize:"11pt",showInvisibles:!0}),this.editor.getSession().setUseWrapMode(!0),this.editor.session.setMode("ace/mode/lua"),this.editor.setTheme("ace/theme/monokai"),this.on("vboxchange",()=>this.editor.resize()),this.find("log-clear").onbtclick=t=>this.log("clean"),this.find("code-run").onbtclick=t=>this.run(),this.find("code-stop").onbtclick=t=>{if(this.socket)return this.socket.close()},this.socket=null,this.bindKey("CTRL-R",()=>this.run())}menu(){return[{text:"__(Code)",nodes:[{text:"__(Run)",dataid:this.name+"-Run",shortcut:"C-R"}],onchildselect:t=>this.run()}]}log(t,e){var i;return"clean"===t?$(this.output).empty():(i=$("<p>").attr("class",t.toLowerCase())[0],$(i).html(`${t}: ${e.__()}`),$(this.output).append(i),$(this.output).scrollTop(this.output.scrollHeight))}run(){var t;if((t=this.editor.getValue().trim())&&""!==t)return this.stream().then(e=>(this.socket=e,this.socket.onopen=()=>this.socket.send(JSON.stringify({code:t})),this.socket.onmessage=t=>{var e,i;if(t.data)try{if(i=JSON.parse(t.data),!this.view(i))return this.log("INFO",t.data)}catch(i){return e=i,this.log("INFO",t.data),console.log(e)}},this.socket.onclose=()=>(this.socket=null,console.log("socket closed")))).catch(t=>this.error(__("Unable to get websocket stream")))}view(t){var e,i;return!!(t&&t.type&&this[t.type])&&(e=this[t.type](t).el,i=$("<p>").attr("class","info")[0],$(i).append(e),$(this.output).append(i),$(this.output).scrollTop(this.output.scrollHeight),!0)}pc(t){return new n(t)}cleanup(t){if(this.socket)return this.socket.close()}}).dependencies=["os://scripts/ace/ace.js"],this.OS.register("LuaPlayground",i)}).call(this); (function(){var e,i,n;e=class{constructor(t){this.target=t,this.el=$("<canvas>").attr("class","viewer")[0],this.offset=10,this.points=[],this.preprocess(),this.getBound(),this.prepare(),this.render()}canvasPoint(e){return new t.Point(e[0]/this.target.resolution+this.base.x,-e[1]/this.target.resolution+this.base.y)}preprocess(){return this.points=this.target.data}getBound(){var t,e,i,n,r,s,a,o;for(n={x:0,y:0},i={x:0,y:0},t=0,e=(r=this.points).length;t<e;t++)a=(s=r[t])[0]/this.target.resolution,o=s[1]/this.target.resolution,a<n.x&&(n.x=a),o<n.y&&(n.y=o),a>i.x&&(i.x=a),o>i.y&&(i.y=o);return this.bound=[n,i],this.base={x:0-this.bound[0].x+this.offset,y:this.bound[1].y+this.offset},this.width=i.x-n.x+2*this.offset,this.height=i.y-n.y+2*this.offset}drawPoint(e,i,n){return new t.Path.Circle({center:this.canvasPoint(e),radius:n,fillColor:i})}drawGrid(e,i){var n,r,s,a,o,h;for(h=this.target.resolution*e,r=Math.ceil(this.bound[0].x/e);r*e<this.bound[1].x;)a=new t.Point(r*e+this.base.x,-this.bound[0].y+this.base.y),n=new t.Point(r*e+this.base.x,-this.bound[1].y+this.base.y),(s=new t.Path).strokeColor=i,s.moveTo(a),s.lineTo(n),r++;for(r=Math.ceil(this.bound[0].y/e);r*e<this.bound[1].y;)a=new t.Point(this.bound[0].x+this.base.x,-r*e+this.base.y),n=new t.Point(this.bound[1].x+this.base.x,-r*e+this.base.y),(s=new t.Path).strokeColor=i,s.moveTo(a),s.lineTo(n),r++;return(o=new t.PointText(this.bound[0].x+this.base.x,this.base.y-this.bound[1].y+this.offset)).justification="left",o.fillColor="#494949",o.content=`Resolution: ${this.target.resolution}, grid size: ${h} mm`}drawAxis(e){var i,n,r;return(n=new t.Path).strokeColor=e,r=new t.Point(this.bound[0].x+this.base.x,this.base.y),i=new t.Point(this.bound[1].x+this.base.x,this.base.y),n.moveTo(r),n.lineTo(i),(n=new t.Path).strokeColor=e,r=new t.Point(this.base.x,-this.bound[0].y+this.base.y),i=new t.Point(this.base.x,-this.bound[1].y+this.base.y),n.moveTo(r),n.lineTo(i),this.drawPoint([0,0],e,3)}prepare(){var e;return(e=this.el.getContext("2d")).translate(this.base.x,this.base.y),e.canvas.width=this.width,e.canvas.height=this.height,t.setup(this.el)}render(){}},n=class extends e{constructor(t){super(t)}p2c(t,e){var i;return i=e*Math.PI/180,[t*Math.cos(i),t*Math.sin(i)]}preprocess(){var t,e,i,n,r,s;if("polar"!==this.target.coordinate)return this.points=this.target.data;for(this.point=[],t=0,r=[],e=0,i=(n=this.target.data).length;e<i;e++)s=n[e],this.points.push(this.p2c(s,this.target.start+t*this.target.angularResolution)),r.push(t+=1);return r}render(){var e,i,n,r,s,a,o;for(this.drawGrid(20,"#DBDBDB"),this.drawAxis("#0A84FF"),i=0,n=(s=this.points).length;i<n;i++)o=s[i],"polar"===this.target.coordinate&&((r=new t.Path).strokeColor="#c2a10e",a=this.canvasPoint([0,0]),e=this.canvasPoint(o),r.moveTo(a),r.lineTo(e)),this.drawPoint(o,"red",3);return t.view.draw()}},(i=class extends this.OS.application.BaseApplication{constructor(t){super("LuaPlayground",t)}main(){return this.datarea=this.find("editorea"),this.output=this.find("output"),ace.config.set("basePath","scripts/ace"),this.editor=ace.edit(this.datarea),this.editor.setOptions({enableBasicAutocompletion:!0,enableLiveAutocompletion:!0,highlightActiveLine:!0,highlightSelectedWord:!0,behavioursEnabled:!0,wrap:!0,fontSize:"11pt",showInvisibles:!0}),this.editor.getSession().setUseWrapMode(!0),this.editor.session.setMode("ace/mode/lua"),this.editor.setTheme("ace/theme/monokai"),this.on("vboxchange",()=>this.editor.resize()),this.find("log-clear").onbtclick=t=>this.log("clean"),this.find("code-run").onbtclick=t=>this.run(),this.find("code-stop").onbtclick=t=>{if(this.socket)return this.socket.close()},this.socket=null,this.bindKey("CTRL-R",()=>this.run())}menu(){return[{text:"__(Code)",nodes:[{text:"__(Run)",dataid:this.name+"-Run",shortcut:"C-R"}],onchildselect:t=>this.run()}]}log(t,e){var i;return"clean"===t?$(this.output).empty():(i=$("<p>").attr("class",t.toLowerCase())[0],$(i).html(`${t}: ${e.__()}`),$(this.output).append(i),$(this.output).scrollTop(this.output.scrollHeight))}run(){var t;if((t=this.editor.getValue().trim())&&""!==t)return this.stream().then(e=>(this.socket=e,this.socket.onopen=()=>this.socket.send(JSON.stringify({code:t})),this.socket.onmessage=t=>{var e,i;if(t.data)try{if(i=JSON.parse(t.data),!this.view(i))return this.log("INFO",t.data)}catch(i){return e=i,this.log("INFO",t.data),console.log(e)}},this.socket.onclose=()=>(this.socket=null,console.log("socket closed")))).catch(t=>this.error(__("Unable to get websocket stream")))}view(t){var e,i;return!!(t&&t.type&&this[t.type])&&(e=this[t.type](t).el,i=$("<p>").attr("class","info")[0],$(i).append(e),$(this.output).append(i),$(this.output).scrollTop(this.output.scrollHeight),!0)}pc(t){return new n(t)}cleanup(t){if(this.socket)return this.socket.close()}}).dependencies=["os://scripts/ace/ace.js"],this.OS.register("LuaPlayground",i)}).call(this);
/*! /*!
* Paper.js v0.12.0 - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js v0.12.0 - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/

View File

@ -6,7 +6,7 @@
"author": "Xuan Sang LEs", "author": "Xuan Sang LEs",
"email": "xsang.le@gmail.com" "email": "xsang.le@gmail.com"
}, },
"version":"0.0.5-a", "version":"0.0.6-a",
"category":"System", "category":"System",
"iconclass":"fa fa-adn", "iconclass":"fa fa-adn",
"mimes":["none"] "mimes":["none"]

View File

@ -149,7 +149,7 @@ class LuaPlayground extends this.OS.application.BaseApplication
main: () -> main: () ->
@datarea = @find "editorea" @datarea = @find "editorea"
@output = @find "output" @output = @find "output"
ace.config.set('basePath', "#{window.location.pathname}/scripts/ace") ace.config.set('basePath', "scripts/ace")
@.editor = ace.edit @datarea @.editor = ace.edit @datarea
@.editor.setOptions { @.editor.setOptions {
enableBasicAutocompletion: true, enableBasicAutocompletion: true,

View File

@ -6,7 +6,7 @@
"author": "Xuan Sang LEs", "author": "Xuan Sang LEs",
"email": "xsang.le@gmail.com" "email": "xsang.le@gmail.com"
}, },
"version":"0.0.5-a", "version":"0.0.6-a",
"category":"System", "category":"System",
"iconclass":"fa fa-adn", "iconclass":"fa fa-adn",
"mimes":["none"] "mimes":["none"]

View File

@ -104,7 +104,7 @@
"description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/LuaPlayground/README.md", "description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/LuaPlayground/README.md",
"category": "System", "category": "System",
"author": "Xuan Sang LEs", "author": "Xuan Sang LEs",
"version": "0.0.5-a", "version": "0.0.6-a",
"download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/LuaPlayground/build/release/LuaPlayground.zip" "download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/LuaPlayground/build/release/LuaPlayground.zip"
}, },
{ {