Skip to content

Commit

Permalink
old changes left behind
Browse files Browse the repository at this point in the history
  • Loading branch information
1j01 committed Jan 26, 2015
1 parent f986f10 commit 53a0077
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 56 deletions.
87 changes: 87 additions & 0 deletions be.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@

/// Manages block types/* and block properties.*/
// #disposable
(function(){

var propertyTypes = {};
function typedef(O){
propertyTypes[O.name]=function(options){
var o = {},i;for(i in O)o[i]=O[i];
o.$prop = document.createElement("div");
o.$prop.className = "property "+O.name;
o.$ = function(q){
return o.$prop.querySelector(q);
};
o.init(options);
return o;
};
}
typedef({
name: "number",
init: function(options){
var html = "<input type='number' value='0'";
if(options.min) html += 'min="'+options.min+'"';
if(options.max) html += 'max="'+options.max+'"';
if(options.step) html += 'step="'+options.step+'"';
html += "/>";
this.$prop.innerHTML = html;
//this.$prop.innerHTML = "<input type='number' min='"+(options.min)+"' max='"+(options.max)+"' step='"+(options.step)+"'/>";
this.$input = this.$("input");
},
getValue: function(){
return this.$input.value;
},
setValue: function(value){
this.$input.value = value;
}
});
typedef({
name: "text",
init: function(options){
this.$prop.innerHTML = "<input type='text'/>";
this.$input = this.$("input");
},
getValue: function(){
return this.$input.value;
},
setValue: function(value){
this.$input.value = value;
}
});

BlockTypeEditor = function(blocktype, gui){
var be=this;
be.m = this.m || gui.M();
be.m.title("Block Type Editor").position("center left-ish? idk");
be.m.onclose=function(){
be.m=null;
return true;
};
be.update = function(){
if(!be.m)return false;
be.m.$c.innerHTML="";
/*be.m.$c.style.maxHeight="80vh";
be.m.$c.style.minHeight="200px";
be.m.$c.style.minWidth="265px";
be.m.$c.style.overflowY="auto";
be.m.$c.style.overflowX="hidden";*/
for(var i in blocktype.properties){
//var $prop=document.createElement("div");

var p=blocktype.properties[i];
if(p.type && propertyTypes[p.type]){
var P = propertyTypes[p.type](p);
be.m.$c.appendChild(P.$prop);
}else{
console.error(p.type, "not supported");
}
}
};
be.update();
be.close = function(){
be.m && be.m.close();
be.m = null;
};
};

})();
Empty file modified content/art/README.md
100755 → 100644
Empty file.
Empty file modified content/art/dawn-gods.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/art/mesa.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/art/mesa_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified content/art/platformertiles-original-palette.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified content/art/platformertiles.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified content/art/platshrooms.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified content/blocks/README.md
100755 → 100644
Empty file.
Empty file modified list-content.py
100755 → 100644
Empty file.
115 changes: 59 additions & 56 deletions pe.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,39 +162,6 @@ PixelEditor = function(gui, img, update, save){
pe.ctx.clearRect(0,0,pe.canvas.width,pe.canvas.height);
pe.ctx.drawImage(pe.ocanvas,0,0,pe.canvas.width,pe.canvas.height);

function fill(x,y, r,g,b,a, wr,wg,wb,wa, life){
if(x<0||y<0||x>=id.width||y>=id.height)return;
var i=(x%id.width+y*id.width)*4;

if(wr===undefined){
var wr=id.data[i+0],wg=id.data[i+1],wb=id.data[i+2],wa=id.data[i+3];
console.log("fill within color",wr,wg,wb);
console.log("fill with color",r,g,b);
if(r==wr&&g==wg&&b==wb&&a==wa){
console.log("Already that color.");
return false;
}
var life=650;
pe.undoable();
}

if(id.data[i+3]==wa
&& id.data[i+0]==wr
&& id.data[i+1]==wg
&& id.data[i+2]==wb){
id.data[i+0]=r;
id.data[i+1]=g;
id.data[i+2]=b;
id.data[i+3]=a;
}else return;

if(--life){
if(x<id.width)fill(x+1,y, r,g,b,a, wr,wg,wb,wa, life);
if(y<id.height)fill(x,y+1, r,g,b,a, wr,wg,wb,wa, life);
if(x>0)fill(x-1,y, r,g,b,a, wr,wg,wb,wa, life);
if(y>0)fill(x,y-1, r,g,b,a, wr,wg,wb,wa, life);
}
}
}else if(pe.tool==="Replace Color"){
var _x=pe.m.mouse.x,_y=pe.m.mouse.y;
var id=pe.octx.getImageData(0,0,pe.canvas.width,pe.canvas.height);
Expand All @@ -208,32 +175,68 @@ PixelEditor = function(gui, img, update, save){
pe.ctx.clearRect(0,0,pe.canvas.width,pe.canvas.height);
pe.ctx.drawImage(pe.ocanvas,0,0,pe.canvas.width,pe.canvas.height);

function replaceColor(x,y, r,g,b,a){
if(x<0||y<0||x>=id.width||y>=id.height)return;
var i=(x%id.width+y*id.width)*4;
var wr=id.data[i+0],wg=id.data[i+1],wb=id.data[i+2],wa=id.data[i+3];

console.log("replace all",[wr,wg,wb,wa],"with",[r,g,b,a]);
if(r==wr&&g==wg&&b==wb&&a==wa){
console.log("same color");
return;
}
pe.undoable();

for(var i=0;i<id.data.length;i+=4){
if(id.data[i+3]==wa
&& id.data[i+0]==wr
&& id.data[i+1]==wg
&& id.data[i+2]==wb){
id.data[i+0]=r;
id.data[i+1]=g;
id.data[i+2]=b;
id.data[i+3]=a;
}
}
}

}

function fill(x,y, r,g,b,a, wr,wg,wb,wa, life){
if(x<0||y<0||x>=id.width||y>=id.height)return;
var i=(x%id.width+y*id.width)*4;

if(wr===undefined){
wr=id.data[i+0];
wg=id.data[i+1];
wb=id.data[i+2];
wa=id.data[i+3];
console.log("fill within color",wr,wg,wb," with color",r,g,b);
if(r==wr&&g==wg&&b==wb&&a==wa){
console.log("Already that color.");
return false;
}
life=650;
pe.undoable();
}

if(id.data[i+3]==wa
&& id.data[i+0]==wr
&& id.data[i+1]==wg
&& id.data[i+2]==wb){
id.data[i+0]=r;
id.data[i+1]=g;
id.data[i+2]=b;
id.data[i+3]=a;
}else return;

if(--life){
if(x<id.width)fill(x+1,y, r,g,b,a, wr,wg,wb,wa, life);
if(y<id.height)fill(x,y+1, r,g,b,a, wr,wg,wb,wa, life);
if(x>0)fill(x-1,y, r,g,b,a, wr,wg,wb,wa, life);
if(y>0)fill(x,y-1, r,g,b,a, wr,wg,wb,wa, life);
}
}
function replaceColor(x,y, r,g,b,a){
if(x<0||y<0||x>=id.width||y>=id.height)return;
var i=(x%id.width+y*id.width)*4;
var wr=id.data[i+0],wg=id.data[i+1],wb=id.data[i+2],wa=id.data[i+3];

console.log("replace all",[wr,wg,wb,wa],"with",[r,g,b,a]);
if(r==wr&&g==wg&&b==wb&&a==wa){
console.log("same color");
return;
}
pe.undoable();

for(var i=0;i<id.data.length;i+=4){
if(id.data[i+3]==wa
&& id.data[i+0]==wr
&& id.data[i+1]==wg
&& id.data[i+2]==wb){
id.data[i+0]=r;
id.data[i+1]=g;
id.data[i+2]=b;
id.data[i+3]=a;
}
}
}
};
pe.mouseup = function(e){
Expand Down
Empty file modified upload.py
100755 → 100644
Empty file.

0 comments on commit 53a0077

Please sign in to comment.