From 21c7253b764c30d982f5dd24cd8006e8c70be50d Mon Sep 17 00:00:00 2001 From: Gnieark Date: Thu, 2 Feb 2017 17:54:49 +0100 Subject: [PATCH 1/3] oups --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b9494b0..5198e2e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,7 +24,7 @@ RUN cp /var/www/src/config.php.empty /var/www/src/config.php && \ chmod +x /populate_mysql.sh && \ chown -R www-data:www-data /var/www -EXPOSE 80 3306 +EXPOSE 80 ADD install.sql /install.sql RUN rm /run.sh From 78d565f11bad13e0fd98ad8bd13a4b89dc348ec5 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 8 Feb 2017 18:41:26 +0100 Subject: [PATCH 2/3] fix README.md --- README.md | 6 ++-- html/testBotScripts/tron.html | 68 +++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d6c08f6..8dd0bff 100755 --- a/README.md +++ b/README.md @@ -18,9 +18,9 @@ See dockerFile and associated scripts to understand what is needed. To test an image of bots arena with docker: - make - docker build . - docker run --name hey -p 127.0.0.1:8080:80 DockerImageId + make + docker build . + docker run --name hey -p 127.0.0.1:8080:80 DockerImageId For nginx Rewrite rules in server directive are: diff --git a/html/testBotScripts/tron.html b/html/testBotScripts/tron.html index 23308d2..52d3a66 100755 --- a/html/testBotScripts/tron.html +++ b/html/testBotScripts/tron.html @@ -42,6 +42,17 @@ function createElem(type,attributes){ {elem.setAttribute(i,attributes[i]);} return elem; } + +function makeid(){ + var text = ""; + var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + + for( var i=0; i < 5; i++ ) + text += possible.charAt(Math.floor(Math.random() * possible.length)); + + return text; +} + function changeRandom(index,newValue){ if (newValue == "random" ){ document.getElementById("posX" + index).className = "hidden"; @@ -52,11 +63,68 @@ function changeRandom(index,newValue){ } } + function changeTypePlayer(index,newValue){ if (newValue == "Human") document.getElementById("botUrl" + index).className = "hidden"; else document.getElementById("botUrl" + index).className = ""; } + +function createElemWithLabel(type,attributes,labelTxt, id =''){ + /* + * return an em element containing label and data like this: + * + * + * + * + */ + + if( id == ''){ + var em = createElem ('em',{}); + }else{ + var em = createElem ('em',{'id':id}); + } + + if (typeof attributes['id'] !== 'undefined') { + var forId = attributes['id']; + }else{ + var forId = makeid(); + } + var label = createElem('label',{'for' : forId}); + em.appendChild(label); + var elem = createElem(type,attributes); + if (typeof attributes['id'] !== 'undefined') { + em.setAttribute('id',forId); + } + em.appendChild(elem); + return em; + +} +function createLineSelect(labelTxt,arrayOptions,attributes){ + //attributes are the select 's attributes, not his container + var em = createElem('em',{}); + if (typeof attributes['id'] !== 'undefined') { + var forId = attributes['id']; + }else{ + var forId = makeid(); + } + var label = createElem('label',{'for':forId}); + label.innerHTML = labelTxt; + em.appendChild(label); + + var select = createElem('select',attributes); + if (typeof attributes['id'] !== 'undefined') { + select.setAttribute('id',forId); + } + + for(var i=0; i < arrayOptions.length; i++){ + var option = createElem('option',{'value':arrayOptions[i]['value']}); + + + } + + return em; +} function createPlayerForm(index){ var container = document.getElementById("playersSettings"); var divForm = createElem("div", {"id": "containerPlayer" + index,"class":"playerBox" } ); From aabde97ec523abb951f58ee84945028693a190c6 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 8 Feb 2017 19:43:07 +0100 Subject: [PATCH 3/3] factorise JS WIP --- html/testBotScripts/tron.html | 99 ++++++++++++++++++++--------------- 1 file changed, 56 insertions(+), 43 deletions(-) diff --git a/html/testBotScripts/tron.html b/html/testBotScripts/tron.html index 52d3a66..c5d0f2d 100755 --- a/html/testBotScripts/tron.html +++ b/html/testBotScripts/tron.html @@ -25,7 +25,9 @@ section{margin: 0 auto; width: 90%;} article{float: right; width:70%;} aside{float:left;width:29%;} .playerBox{} -.playerBox input, .playerBox select {width:100%;} +.playerBox em {width: 100%;} +.playerBox em label { width: 40%; text-align: right;} +.playerBox em input,.playerBox em input, .playerBox em select {width:59%; float:right;} @@ -91,6 +93,7 @@ function createElemWithLabel(type,attributes,labelTxt, id =''){ var forId = makeid(); } var label = createElem('label',{'for' : forId}); + label.innerHTML = labelTxt; em.appendChild(label); var elem = createElem(type,attributes); if (typeof attributes['id'] !== 'undefined') { @@ -119,54 +122,64 @@ function createLineSelect(labelTxt,arrayOptions,attributes){ for(var i=0; i < arrayOptions.length; i++){ var option = createElem('option',{'value':arrayOptions[i]['value']}); - - + option.innerHTML = arrayOptions[i]['text']; + select.appendChild(option); } - + em.appendChild(select); return em; } function createPlayerForm(index){ var container = document.getElementById("playersSettings"); var divForm = createElem("div", {"id": "containerPlayer" + index,"class":"playerBox" } ); - - //Type of player - var select = createElem("select",{"id":"playerType" + index,"onchange":"changeTypePlayer('" + index + "', this.value);"}); - var optionHuman = createElem("option",{"value":"Human"}); - optionHuman.innerHTML = "Human"; - var optionBot = createElem("option",{"value":"Bot"}); - optionBot.innerHTML = "Bot"; - - select.appendChild(optionBot); - select.appendChild(optionHuman); - divForm.appendChild(select); - - //url - var inputUrl = createElem("input", {"id":"botUrl" + index, "type": "text", "value":"", "placeholder":"http://Bot.url" }); - divForm.appendChild(inputUrl); - - - - //Starting cell - var selectRandomStartCell = createElem("select",{ - "id": "randomOrNot" + index, - "onchange":"changeRandom('" + index + "', this.value);" - }); - - var optionRandom = createElem("option",{"value":"random","selected":"selected"}); - optionRandom.innerHTML = "random"; - - var optionDefined = createElem("option",{"value":"defined"}); - optionDefined.innerHTML = "Let me define it"; - selectRandomStartCell.appendChild(optionRandom); - selectRandomStartCell.appendChild(optionDefined); - - divForm.appendChild(selectRandomStartCell); - - var inputX = createElem("input",{"type":"text","value": "0","id":"posX" + index,"class":"hidden"}); - var inputY = createElem("input",{"type":"text","value": "0","id":"posY" + index,"class":"hidden"}); - - divForm.appendChild(inputX); - divForm.appendChild(inputY); + + divForm.appendChild( + createLineSelect('Type:', + [ {'value':'bot','text' : 'bot'}, + {'value':'human','text' : 'human'} + ], + + {"id":"playerType" + index, + "onchange":"changeTypePlayer('" + index + "', this.value);" + } + ) + ); + divForm.appendChild( + createElemWithLabel( + 'input', + { + "id":"botUrl" + index, "type": "text", "value":"", + "placeholder":"http://Bot.url" + }, + 'URL du Bot' + ) + + ); + divForm.appendChild( + createLineSelect('Starting cell:', + [ {'value':'random','text' : 'random'}, + {'value':'defined','text' : 'Let me define it'} + ], + + { + "id": "randomOrNot" + index, + "onchange":"changeRandom('" + index + "', this.value);" + } + ) + ); + divForm.appendChild( + createElemWithLabel( + 'input', + {"type":"text","value": "0","id":"posX" + index}, + 'X coord:' + ) + ); + divForm.appendChild( + createElemWithLabel( + 'input', + {"type":"text","value": "0","id":"posY" + index}, + 'Y coord:' + ) + ); container.appendChild(divForm);