Unnamed Fossil Project

Check-in [ff55e2623b]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:fixed stuff with the file functions.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:ff55e2623b34f88506f17129793255b9c506ff33
User & Date: Derek 2013-02-27 21:31:48
Context
2013-02-27
21:36
added resetting playmode to reset function check-in: e97605d164 user: Derek tags: trunk
21:31
fixed stuff with the file functions. check-in: ff55e2623b user: Derek tags: trunk
17:53
an additional test of b64 and e64 check-in: aa02d9cc8b user: Derek tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to maze.html.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
..
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
..
85
86
87
88
89
90
91

92
93
94
95
96
97
98
99
100
101















102
103
104
105
106
107
108
...
111
112
113
114
115
116
117

118
119
120
121
122
123
124
125
126
127
128
129
130
131
...
183
184
185
186
187
188
189


190
191
192
193
194
195
196
197
198
199
200
201
202







203
204
205
206
207
208
209
210
211
212
213
.bigtxt{font-size:125%;}
.menubutton:hover{border-color:#fff;}
.menubutton:active{border-style:solid;background-color:#888;border-color:#000}
</style><script>//<!--

//globals
var canvas,ctx,mazecanvas,menudiv,
arr=[],width=30,height=30,pxsize=2,maxpxdimsum=800,
x,y,goalx,goaly,startx,starty,
dx=0,dy=0,
screenblocks=33,//controls zoom
dt=30,speed=12,turbofactor=1.75,pcolor="#2b2",
keys=[],mousedown=null,mouseloc=null,mousejoystickradius=80;edit=false,testonly=false,brush=1,victory=false,
savetime=10000,
helpmsg="Help Message goes here.";
................................................................................
for(j=0;j<a.length;++j){
k=a[j][0];r[i++]=k-lastk;r[i++]=a[j][1];lastk=k;}
lastk=lastk-l;k=0;
for(j=0;j<b.length;++j){
k=b[j][0];r[i++]=k-lastk;r[i++]=b[j][1];lastk=k;}
return r;}

//alert()
setTimeout(function(){
//alert(e64([1,2,3,4,5,992,38092932309,17,999,12345,1]));
alert(d64(e64([1,2,3,4,5,992,38092932309,17,999,12345,1])).join(','));
//var q=encodelines({w:width,h:height,start:[startx,starty],end:[goalx,goaly],arr:arr});
//alert(q.join(','));
//alert(JSON.stringify(decodelines(q)));
}, 1000);

function decodelines(r){
var w,h,s=[],e=[],arr=[],i=0,j,c,lines=[];
w=r[i++];h=r[i++];l=w*h;for(j=0;j<l;++j)arr[j]=0;
c=r[i++];for(j=0;j<c;++j)s.push(r[i++]);//start
c=r[i++];for(j=0;j<c;++j)e.push(r[i++]);//end
c=r[i++];i+=c;//ignore destinations
while(i<r.length)lines.push(r[i++]);
................................................................................
(function(){for(var i=0;i<ch64.length;++i){ch64rev[ch64[i]]=i;}})();

//lower half of charset has built in delimiter
function e64(arr){
var i,j,s="",x,a=[];
for(i=0;i<arr.length;++i){
x=arr[i];a.length=0;while(x>0){a.push(x%32);x=Math.floor(x/32);}

for(j=a.length-1;j>0;--j)s+=ch64[a[j]+32];
s+=ch64[a[0]];}
return s;}

function d64(str){
var i,x,y=0,a=[],arr=[];
for(i=0;i<str.length;++i){
x=ch64rev[str[i]];y=32*y+x-32;
if(x<32){y+=32;arr.push(y);y=0;}}
return arr;}
















function save(){
localStorage.saved=false;
localStorage.mazestate=JSON.stringify(
{x:x,y:y,w:width,h:height,startx:startx,starty:starty,goalx:goalx,goaly:goaly,arr:arr});
localStorage.saved=true;}

................................................................................
var o=JSON.parse(localStorage.mazestate);
x=o.x;y=o.y;width=o.w;height=o.h;arr=o.arr;startx=o.startx;starty=o.starty;goalx=o.goalx;goaly=o.goaly;dx=0;dy=0;
pxsize=Math.max(Math.floor(maxpxdimsum/(width+height)),1);
return 1;}

function reset(w,h){
if(w&&h)width=w,height=h;

w=width,h=height;
pxsize=Math.max(Math.floor(maxpxdimsum/(w+h)),1);
goalx=w-1,goaly=h-1,startx=0,starty=0,
arr=new Array(w*h);
for(var i=0;i<w*h;++i)arr[i]=0;
x=0.5,y=0.5,dx=0,dy=0;
drawmaze();}

function drawmaze(){//mazecanvas
var w=width,h=height,l=w*h,pxs=pxsize;
if(!mazecanvas)return;mazecanvas.width=pxs*w*2;mazecanvas.height=pxs*h*2;
var mctx=mazecanvas.getContext("2d");
mctx.fillStyle="#fff";mctx.fillRect(0,0,pxs*w,pxs*h);mctx.fillStyle="#000";
for(var _y=0;_y<h;++_y){for(var _x=0;_x<w;++_x){
................................................................................
if(parnt) parnt.appendChild(e);
if(csscls) e.className=csscls;
if(id) e.id=id;
return e;}

function getElem(id){return document.getElementById(id);}



// make user menus
function makemenu(){
menudiv=crElem("div",document.body,"menudiv");

function addbutton(txt,c,f){
var b=crElem("input",menudiv,"menubutton");
b.type="button";b.value=txt;b.onclick=f;
if(c)b.style.backgroundColor=c;
crElem("br",menudiv);return b;}

var eb,zi,zo;//undo;//editbutton,zoomin,zoomout
function playmode(){edit=false,eb.value="Edit";eb.style.backgroundColor="#fb6";pcolor=testonly?"#fe4":"#2b2";}
function editmode(){edit=true,eb.value="Test";eb.style.backgroundColor="#fea";pcolor="#f82";victory=false;}








var _=addbutton;
_("Start","#cfc",function(){x=startx+0.5,y=starty+0.5;victory=false;testonly=false;playmode();});
_("File","#cbf",function(){});
eb=_("Edit","#fb6",function(){edit?playmode():(editmode(),testonly=true);});
_("Reset","#faa",function(){testonly=false;playmode();reset(5,5);});
_("Help","#acf",function(){alert(helpmsg);});
zi=_("+",0,function(){screenblocks*=0.8;});
zo=_("-",0,function(){screenblocks/=0.8;});
//undo=_("<",0,function(){alert('undo stuff goes here.');}
zi.className+=" bigtxt";zo.className+=" bigtxt";//undo.className+=" bigtxt";







|







 







<
<
<
<
<
<
<
<
<







 







>







|


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>






|







 







>
>











|
|
>
>
>
>
>
>
>



|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
..
52
53
54
55
56
57
58









59
60
61
62
63
64
65
..
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
...
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
...
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
.bigtxt{font-size:125%;}
.menubutton:hover{border-color:#fff;}
.menubutton:active{border-style:solid;background-color:#888;border-color:#000}
</style><script>//<!--

//globals
var canvas,ctx,mazecanvas,menudiv,
arr=[],width=30,height=30,pxsize=2,maxpxdimsum=800,maxdimsum=800,
x,y,goalx,goaly,startx,starty,
dx=0,dy=0,
screenblocks=33,//controls zoom
dt=30,speed=12,turbofactor=1.75,pcolor="#2b2",
keys=[],mousedown=null,mouseloc=null,mousejoystickradius=80;edit=false,testonly=false,brush=1,victory=false,
savetime=10000,
helpmsg="Help Message goes here.";
................................................................................
for(j=0;j<a.length;++j){
k=a[j][0];r[i++]=k-lastk;r[i++]=a[j][1];lastk=k;}
lastk=lastk-l;k=0;
for(j=0;j<b.length;++j){
k=b[j][0];r[i++]=k-lastk;r[i++]=b[j][1];lastk=k;}
return r;}










function decodelines(r){
var w,h,s=[],e=[],arr=[],i=0,j,c,lines=[];
w=r[i++];h=r[i++];l=w*h;for(j=0;j<l;++j)arr[j]=0;
c=r[i++];for(j=0;j<c;++j)s.push(r[i++]);//start
c=r[i++];for(j=0;j<c;++j)e.push(r[i++]);//end
c=r[i++];i+=c;//ignore destinations
while(i<r.length)lines.push(r[i++]);
................................................................................
(function(){for(var i=0;i<ch64.length;++i){ch64rev[ch64[i]]=i;}})();

//lower half of charset has built in delimiter
function e64(arr){
var i,j,s="",x,a=[];
for(i=0;i<arr.length;++i){
x=arr[i];a.length=0;while(x>0){a.push(x%32);x=Math.floor(x/32);}
if(!a.length)a.push(0);
for(j=a.length-1;j>0;--j)s+=ch64[a[j]+32];
s+=ch64[a[0]];}
return s;}

function d64(str){
var i,x,y=0,a=[],arr=[];
for(i=0;i<str.length;++i){
x=ch64rev[str[i]];if(x===undefined)break;y=32*y+x-32;
if(x<32){y+=32;arr.push(y);y=0;}}
return arr;}

function _import(str){
if(!str||!str.length)return 0;
var o=decodelines(d64(str));if(!o)return 0;
width=o.w;height=o.h;arr=o.arr;startx=o.start[0];starty=o.start[1];
goalx=o.end[0];goaly=o.end[1];dx=0;dy=0;x=startx+0.5;y=starty+0.5;
pxsize=Math.max(Math.floor(maxpxdimsum/(width+height)),1);
testonly=false;if(playmode)playmode();
drawmaze();draw();
return 1;}

function _export(){
var o={w:width,h:height,start:[startx,starty],end:[goalx,goaly],arr:arr};
return e64(encodelines(o));}


function save(){
localStorage.saved=false;
localStorage.mazestate=JSON.stringify(
{x:x,y:y,w:width,h:height,startx:startx,starty:starty,goalx:goalx,goaly:goaly,arr:arr});
localStorage.saved=true;}

................................................................................
var o=JSON.parse(localStorage.mazestate);
x=o.x;y=o.y;width=o.w;height=o.h;arr=o.arr;startx=o.startx;starty=o.starty;goalx=o.goalx;goaly=o.goaly;dx=0;dy=0;
pxsize=Math.max(Math.floor(maxpxdimsum/(width+height)),1);
return 1;}

function reset(w,h){
if(w&&h)width=w,height=h;
if(w+h>maxdimsum)return 0;
w=width,h=height;
pxsize=Math.max(Math.floor(maxpxdimsum/(w+h)),1);
goalx=w-1,goaly=h-1,startx=0,starty=0,
arr=new Array(w*h);
for(var i=0;i<w*h;++i)arr[i]=0;
x=0.5,y=0.5,dx=0,dy=0;
drawmaze();draw();return 1;}

function drawmaze(){//mazecanvas
var w=width,h=height,l=w*h,pxs=pxsize;
if(!mazecanvas)return;mazecanvas.width=pxs*w*2;mazecanvas.height=pxs*h*2;
var mctx=mazecanvas.getContext("2d");
mctx.fillStyle="#fff";mctx.fillRect(0,0,pxs*w,pxs*h);mctx.fillStyle="#000";
for(var _y=0;_y<h;++_y){for(var _x=0;_x<w;++_x){
................................................................................
if(parnt) parnt.appendChild(e);
if(csscls) e.className=csscls;
if(id) e.id=id;
return e;}

function getElem(id){return document.getElementById(id);}

var playmode,editmode;

// make user menus
function makemenu(){
menudiv=crElem("div",document.body,"menudiv");

function addbutton(txt,c,f){
var b=crElem("input",menudiv,"menubutton");
b.type="button";b.value=txt;b.onclick=f;
if(c)b.style.backgroundColor=c;
crElem("br",menudiv);return b;}

var eb,zi,zo;//undo;//editbutton,zoomin,zoomout
playmode=function(){edit=false,eb.value="Edit";eb.style.backgroundColor="#fb6";pcolor=testonly?"#fe4":"#2b2";}
editmode=function(){edit=true,eb.value="Test";eb.style.backgroundColor="#fea";pcolor="#f82";victory=false;}

function file(){
if(confirm("\nExport maze?\n"))prompt("\nMaze Data\nCopy this:\n",_export());
else if(confirm("\nImport maze?\n"))_import(prompt("\nPaste Maze Data here:\n"));
else if(confirm("\nReset maze?\n")){
var dim=/([0-9]*)[^0-9]*([0-9]*)/.exec(prompt("\nEnter new dimensions\n(Current maze will be cleared):\n"));
reset(dim[1],dim[2]);}}

var _=addbutton;
_("Start","#cfc",function(){x=startx+0.5,y=starty+0.5;victory=false;testonly=false;playmode();});
_("File","#cbf",file);
eb=_("Edit","#fb6",function(){edit?playmode():(editmode(),testonly=true);});
_("Reset","#faa",function(){testonly=false;playmode();reset(5,5);});
_("Help","#acf",function(){alert(helpmsg);});
zi=_("+",0,function(){screenblocks*=0.8;});
zo=_("-",0,function(){screenblocks/=0.8;});
//undo=_("<",0,function(){alert('undo stuff goes here.');}
zi.className+=" bigtxt";zo.className+=" bigtxt";//undo.className+=" bigtxt";