Skip to content
Snippets Groups Projects
Commit 6f22fa7b authored by echicken's avatar echicken
Browse files

Added method 'Frame.load_bin(contents,width,height,offset)'

Allows loading a whole or partial bin 'graphic' from a string;
decouples bin loading from file reading if desired.
Frame.load() calls Frame.load_bin() in case of a .bin file.
parent 964b7129
No related branches found
No related tags found
No related merge requests found
......@@ -786,25 +786,8 @@ Frame.prototype.load = function(filename,width,height) {
y++;
}
break;
case "BIN":
if(width == undefined || height == undefined)
throw("unknown graphic dimensions");
var offset = 0;
for(var y=0; y<height; y++) {
for(var x=0; x<width; x++) {
var c = new Char();
if(offset >= contents.length)
return(false);
c.ch = contents.substr(offset++, 1);
if(offset == contents.length)
return(false);
c.attr = ascii(contents.substr(offset++, 1));
c.id = this.id;
if(!this.__properties__.data[y])
this.__properties__.data[y]=[];
this.__properties__.data[y][x] = c;
}
}
case "BIN":
if (!this.load_bin(contents, width, height, 0)) return false;
break;
case "TXT":
var lines=contents.split(/\r\n/);
......@@ -816,6 +799,27 @@ Frame.prototype.load = function(filename,width,height) {
break;
}
}
Frame.prototype.load_bin = function(contents, width, height, offset) {
if(width == undefined || height == undefined)
throw("unknown graphic dimensions");
if(offset == undefined) offset = 0;
for(var y=0; y<height; y++) {
for(var x=0; x<width; x++) {
var c = new Char();
if(offset >= contents.length)
return(false);
c.ch = contents.substr(offset++, 1);
if(offset == contents.length)
return(false);
c.attr = ascii(contents.substr(offset++, 1));
c.id = this.id;
if(!this.__properties__.data[y])
this.__properties__.data[y]=[];
this.__properties__.data[y][x] = c;
}
}
return true;
}
Frame.prototype.scroll = function(x,y) {
var update = false;
/* default: add a new line to the data matrix */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment