update code

This commit is contained in:
Xuan Sang LE
2020-06-05 17:45:07 +02:00
parent aae08d9efe
commit 676cce26c2
61 changed files with 685 additions and 264 deletions

View File

@@ -1,3 +1,4 @@
#LuaPlayground
Application for serverside code testing and analytics tool
Application for serverside code testing and analytics tool.
It allows to execute lua code on the server from the browser

View File

@@ -1,4 +1,4 @@
<afx-app-window apptitle="Lua Playground" width="500" height="400" data-id="LuaPlayground">
<afx-app-window apptitle="Lua Playground" width="500" height="400" data-id="Lua Playground">
<afx-hbox >
<div data-id="editorea" data-width="250"></div>
<afx-resizer data-width="3"></afx-resizer>

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.GUI.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").set("onbtclick",t=>this.log("clean")),this.find("code-run").set("onbtclick",t=>this.run()),this.find("code-stop").set("onbtclick",t=>{if(this.socket)return this.socket.close()}),this.socket=null,this.bindKey("CTRL-R",()=>this.run())}menu(){return[{text:"__(Code)",child:[{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.
* http://paperjs.org/

View File

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

View File

@@ -1,4 +1,4 @@
<afx-app-window apptitle="Lua Playground" width="500" height="400" data-id="LuaPlayground">
<afx-app-window apptitle="Lua Playground" width="500" height="400" data-id="Lua Playground">
<afx-hbox >
<div data-id="editorea" data-width="250"></div>
<afx-resizer data-width="3"></afx-resizer>

View File

@@ -142,7 +142,7 @@ class PointCloudViewer extends DataViewer
class LuaPlayground extends this.OS.GUI.BaseApplication
class LuaPlayground extends this.OS.application.BaseApplication
constructor: ( args ) ->
super "LuaPlayground", args
@@ -166,12 +166,12 @@ class LuaPlayground extends this.OS.GUI.BaseApplication
@editor.setTheme "ace/theme/monokai"
@on "vboxchange", () =>
@editor.resize()
(@find "log-clear").set "onbtclick", (e) =>
(@find "log-clear").onbtclick = (e) =>
@log "clean"
(@find "code-run").set "onbtclick", (e) =>
(@find "code-run").onbtclick = (e) =>
@run()
(@find "code-stop").set "onbtclick", (e) =>
(@find "code-stop").onbtclick = (e) =>
@socket.close() if @socket
@socket = null
@@ -179,7 +179,7 @@ class LuaPlayground extends this.OS.GUI.BaseApplication
menu: () ->
menu = [{
text: "__(Code)",
child: [
nodes: [
{ text: "__(Run)", dataid: "#{@name}-Run", shortcut: "C-R" }
],
onchildselect: (e) => @run()

View File

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