xxxxxxxxxx
localforage.config({name:'RetroCraft'})
let drawing=1,drawCursor=[0,0],drawSpeed=70,rendering=0,didGenerate=0,generating=0
setup=_=>{
createCanvas(Math.min(900,windowWidth-20),Math.min(500,windowHeight-20))
hmap=createGraphics(300,300);bmap=createGraphics(1200,300)
hmap.background(0);hmap.noStroke()
bmap.background(0);bmap.noStroke()
background(255)
}
draw=_=>{
if(drawing){
background(255)
fill(0);noStroke();textAlign(CENTER,CENTER)
if(didGenerate){
textSize(15)
noStroke()
text('Save map',width/2,height-15)
}else if(generating){
textSize(30)
noStroke()
text('Generating...',width/2,height/2)
image(hmap,0,0,300,300)
}else{
textSize(30)
noStroke()
if(Math.abs(mouseX-width/2)<150&&Math.abs(mouseY-height/2)<30)stroke(0)
text('Generate new map',width/2,height/2)
noStroke()
if(Math.abs(mouseX-width/2)<50&&Math.abs(mouseY-height+15)<10)stroke(0)
textSize(15)
text('Load map',width/2,height-15)
noStroke()
text('Shift-click for config',width/2,height/2+35)
}
}else if(rendering){
background(255,0.5)
for(let i=0;i<drawSpeed;i++){
drawMap(drawCursor)
drawCursor[0]+=1
if(drawCursor[0]==300){
drawCursor[0]=0
drawCursor[1]+=1
if(drawCursor[1]==300){
rendering=0
}
}
}
}
if(rendering)drawing=0
}
mouseReleased=_=>{
if(Math.abs(mouseX-width/2)<150&&Math.abs(mouseY-height/2)<30&&!didGenerate){
if(keyIsDown(16))mapConfig=prompt('Map config')
generating=1
genMap()
}
if(Math.abs(mouseX-width/2)<50&&Math.abs(mouseY-height+15)<10&&!didGenerate){
let sname=prompt('Filename to open')
if(sname)loadMap(sname)
}
if(Math.abs(mouseX-width/2)<50&&Math.abs(mouseY-height+15)<10&&didGenerate){
let sname=prompt('Filename to save')
localforage.getItem('hmap-'+sname).then(x=>{if(x==null){saveMap(sname)}else{if(confirm('Do you really want to overwrite map "'+sname+'"?'))saveMap(sname)}})
}
}