diff --git a/css/activity.css b/css/activity.css index e33c18b..c8a34c6 100644 --- a/css/activity.css +++ b/css/activity.css @@ -278,3 +278,20 @@ .palette .colors tr:nth-last-child(1) button { margin-bottom: 5.5px; } +.save-load-state-button { + background-color: #4C50AF; + border: none; + color: white; + padding: 5px 5px; + text-align: center; + text-decoration: none; + display: inline-block; + font-size: 18px; + border-radius:12px; + -webkit-transition-duration: 0.4s; /* Safari */ + transition-duration: 0.4s; + +} +.save-load-state-button:hover { + background-color: #4CEF50; +} diff --git a/js/activity.js b/js/activity.js index 336f1c4..a802bb5 100644 --- a/js/activity.js +++ b/js/activity.js @@ -32,7 +32,7 @@ define([ var persistent_title_div=document.getElementById("persistent_title_div"); html=""; for(var tidx=0;tidx"+app_title[tidx]+""; } persistent_title_div.innerHTML=html; @@ -60,12 +60,13 @@ define([ runButton.onclick = function () { colormyworld.toggleRunning(); } + colormyworld.setRGBColorString('rgb(0, 0, 255)'); var colorButton = document.getElementById("color-button"); var changeColorPalette = new colorpalette.ColorPalette(colorButton); changeColorPalette.setColor(colormyworld.getRGBColorString()); // Initial color changeColorPalette.addEventListener('colorChange', function(e) { - console.log(e.detail.color); // New color selected + print(e.detail.color); // New color selected colormyworld.setRGBColorString(e.detail.color); }); /* diff --git a/lib/colormyworld.js b/lib/colormyworld.js index d2c1ec0..3e6d20e 100644 --- a/lib/colormyworld.js +++ b/lib/colormyworld.js @@ -11,6 +11,158 @@ define(["activity/ol","util","print","l10n/l10n",],function(ol,util,print,l10n){ me.mode=COLORING; me.DELAY=1500.; me.RUNNING=false; + + me.stateObj=null; + me.saveStateCB=function(){ + print("saveStateCB"); + //create a json-serializable structure which can be used to orchestrate + //reconstruction of state in loadStateCB. We'll save it in global memory + //while developing, so can wreck state in any way, then push reload-stateB + //and get back to the same thing. + var state={} + state['currents']=me.currents; + state['lang']=document.webL10n.getLanguage(); + state['mode']=me.mode; + state['cmw_bg']=me.background_color; + //Now dictionary of features with: color, candidate=t/f + //So loop over all features: + state['features']=me.loopOverAllFeatures("get",{}); + + me.stateObj=JSON.stringify(state); + print("state saved"); + } + me.loopOverAllFeatures=function(directive,stateFeatures){ + print("loopOverAllFeatures:"+directive); + print("loopOverAllFeatures:"+stateFeatures); + + var categories=me.CATEGORIES['keys']; + for(var cidx=0;cidx setTimeout(resolve, ms)); + } + + me.loadStateCB=function(){ + //in order to reload, we make use of everything we've already developed + //and then go back and apply color and candidacy, only. Saving state + //thus means modes, langs and a list of feature_name:color, candidacy pairs. + print("loadStateCB"); + var state=null; + if(me.stateObj!=null){ + state=JSON.parse(me.stateObj); + me.stateObj=null; + } + if(!state)return; + print("Loading: "+state); + me.currents=state['currents']; + for(var cidx=0;cidx{ + print("continuing"); + dummy=me.loopOverAllFeatures("set",state['features']); + me.updateTitle(); + }); + + + } + me.mkBrightRGBA=function(){ + var R_CHANNEL=parseInt(Math.random()*255); + var G_CHANNEL=parseInt(Math.random()*255); + var B_CHANNEL=parseInt(Math.random()*255); + + if(R_CHANNEL+G_CHANNEL+B_CHANNEL<300){ + var dice=parseInt(Math.random()*3); + if(dice==0)R_CHANNEL=255; + else if(dice==1)G_CHANNEL=255; + else if(dice==2)B_CHANNEL=255; + else{;} + } + + var A_CHANNEL=255; + var rval="RGBA("+R_CHANNEL+","+G_CHANNEL+","+B_CHANNEL+","+A_CHANNEL+")"; + return rval; + } + me.updateTitle=function(){ + var app_title=String.split(document.webL10n.get('appname'),''); + var persistent_title_div=document.getElementById("persistent_title_div"); + html=""; + for(var tidx=0;tidx"+app_title[tidx]+""; + } + persistent_title_div.innerHTML=html; + util.resize(); + } + me.setMode=function(val){ me.mode=val; } @@ -20,10 +172,17 @@ define(["activity/ol","util","print","l10n/l10n",],function(ol,util,print,l10n){ me.getRegion=function(){ return REGION_NAMES.indexOf(me.currents[0]); } + me.background_color='rgb(0,120,255)'; me.rgbColorString='rgb(255,255,255)'; me.setRGBColorString=function(val){me.rgbColorString=val;} me.getRGBColorString=function(){return me.rgbColorString;} - + me.set_background=function(val){//called by map.on('click') & loadStateCB + if(!val) + me.background_color=me.getRGBColorString(); + else + me.background_color=val; + document.getElementById("cmw_bg").style.backgroundColor=me.background_color; + } me.getRunning=function(){return me.RUNNING}; me.BASE_SOURCES={ 'OpenStreetMap2':new ol.source.OSM(), @@ -57,31 +216,30 @@ define(["activity/ol","util","print","l10n/l10n",],function(ol,util,print,l10n){ var keys=me.CATEGORIES['keys']; for(var kidx=0;kidx

"+util.descore(document.webL10n.get(util.enscore(target_name)))+"

"+target_layer_name+"

"; } - if(true)console.log("me.startMove:"+target_name+" "+target_layer_name); + if(true)print("me.startMove:"+target_name+" "+target_layer_name); me.showPopup(xhtml); } me.showPopup=function(xhtml){ while(me.popup.childNodes.length>0){ try{me.popup.removeChild(me.popup.childNodes[0]);} - catch(e){if(true)console.log(e);} + catch(e){if(true)print(e);} } me.popup.innerHTML=""; @@ -550,7 +591,7 @@ define(["activity/ol","util","print","l10n/l10n",],function(ol,util,print,l10n){ } me.popdown=function(e){ - if(true)console.log("popdown"); + if(true)print("popdown"); try{window.clearTimeout(me.last_timeout);} catch(e){} @@ -583,7 +624,7 @@ define(["activity/ol","util","print","l10n/l10n",],function(ol,util,print,l10n){ me.end_game=function(){ try{document.body.removeChild(me.popup);} - catch(e){if(true)console.log("me.end_game");} + catch(e){if(true)print("me.end_game");} var xhtml='

Congratulations!
You Finished!

'; if(document.webL10n.getLanguage()!='en-us'){ @@ -600,7 +641,7 @@ define(["activity/ol","util","print","l10n/l10n",],function(ol,util,print,l10n){ for(var dummy=0;dummyLANGUAGE_NAMES["keys"].length-1)languageNum=0; document.webL10n.setLanguage(LANGUAGE_NAMES["keys"][languageNum]); @@ -115,9 +115,31 @@ define(["sugar-web/graphics/palette","util"], function (palette,util) { r.insertCell(-1).appendChild(languageLabel); r.insertCell(-1).appendChild(languagebuttonnext); + +//SAVE & RELOAD + var saveStateB = document.createElement('input'); + saveStateB.setAttribute("type","button"); + saveStateB.className = 'save-load-state-button'; + saveStateB.setAttribute('id','save-state-button'); + saveStateB.setAttribute('value','Save State'); + saveStateB.onclick=function(){colormyworld.saveStateCB()}; + + var loadStateB = document.createElement('input'); + loadStateB.setAttribute("type","button"); + loadStateB.className = 'save-load-state-button'; + loadStateB.setAttribute('id','load-state-button'); + loadStateB.setAttribute('value','Load State'); + loadStateB.onclick=function(){colormyworld.loadStateCB()}; + + var saveloadTable=document.createElement("table"); + var r=saveloadTable.insertRow(-1); + r.insertCell(-1).appendChild(saveStateB); + r.insertCell(-1).appendChild(loadStateB); + modeDiv.appendChild(modeTable); modeDiv.appendChild(regionTable); modeDiv.appendChild(languageTable); + modeDiv.appendChild(saveloadTable); this.setContent([modeDiv]); // this.buttons = modeDiv.querySelectorAll('button'); diff --git a/lib/print.js b/lib/print.js index a47f632..cd27608 100644 --- a/lib/print.js +++ b/lib/print.js @@ -1,5 +1,5 @@ define(function () { return function print(msg) { - console.log(msg); + //console.log(msg); }; }); diff --git a/lib/util.js b/lib/util.js index b1727ee..38cc16d 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1,4 +1,4 @@ -define(["activity/ol"],function (ol) { +define(["activity/ol","print"],function (ol,print) { return { correct_style:new ol.style.Style({ @@ -74,34 +74,6 @@ mkRandomColor:function(){ } return rval; }, -mkBrightRGBA:function(){ - var R_CHANNEL=parseInt(Math.random()*255); - var G_CHANNEL=parseInt(Math.random()*255); - var B_CHANNEL=parseInt(Math.random()*255); - - if(R_CHANNEL+G_CHANNEL+B_CHANNEL<300){ - var dice=parseInt(Math.random()*3); - if(dice==0)R_CHANNEL=255; - else if(dice==1)G_CHANNEL=255; - else if(dice==2)B_CHANNEL=255; - else{;} - } - - var A_CHANNEL=255; - var rval="RGBA("+R_CHANNEL+","+G_CHANNEL+","+B_CHANNEL+","+A_CHANNEL+")"; - return rval; -}, -updateTitle:function(){ - var app_title=String.split(document.webL10n.get('appname'),''); - var persistent_title_div=document.getElementById("persistent_title_div"); - html=""; - for(var tidx=0;tidx"+app_title[tidx]+""; - } - persistent_title_div.innerHTML=html; - resize(); -}, computeResolution:function(bbox,is3857,W,H){ @@ -120,7 +92,7 @@ computeResolution:function(bbox,is3857,W,H){ p1=ol.proj.transform([xmin,ymin],"EPSG:4326","EPSG:3857"); } - if(true)console.log(p1+", "+p2); + if(true)print(p1+", "+p2); var dx=p2[0]-p1[0]; var dy=p2[1]-p1[1]; @@ -152,7 +124,7 @@ computeResolution:function(bbox,is3857,W,H){ res=dx/W; } } - if(true)console.log("res="+res); + if(true)print("res="+res); return res; } }});