diff options
Diffstat (limited to 'js/matrix.js')
| -rw-r--r-- | js/matrix.js | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/js/matrix.js b/js/matrix.js index 732820e..b1d80f6 100644 --- a/js/matrix.js +++ b/js/matrix.js @@ -6,8 +6,8 @@ function Matrix (w,h,f){ this.f = f this.initialize() } -Matrix.prototype.initialize = function(){ - var w = this.w || 1, h = this.h || 1, f = this.f +Matrix.prototype.initialize = function(f){ + var w = this.w || 1, h = this.h || 1, f = f || this.f var aa = new Array (h) for (var y = 0; y < h; y++) { aa[y] = new Array (w) @@ -23,9 +23,34 @@ Matrix.prototype.rebuild = function (){ this.append() this.bind() this.generate && this.generate() - // the focused character might disappear after resizing + // the focused character might disappear after resizing.. focused = canvas.aa[0][0] } +Matrix.prototype.clone = function () { + var base = this + var clone = new Matrix(this.w, this.h, function(x,y){ + return base.getCell(x,y).clone() + }) + clone.f = this.f + return clone +} +Matrix.prototype.assign = function (mat) { + var base = this + this.demolish() + this.w = mat.w + this.h = mat.h + this.f = function(){} + this.initialize(function(x,y){ + var el = mat.getCell(x,y).clone() + el.build() + return el + }) + this.append() + this.bind() + focused = canvas.aa[0][0] + return this +} + Matrix.prototype.bind = function () {} Matrix.prototype.demolish = function (){ this.forEach(function(lex){ @@ -94,7 +119,7 @@ Matrix.prototype.region = function(w,h,x,y) { return mat } Matrix.prototype.setCell = function(lex,x,y){ - this.aa[y] && this.aa[y][x] && this.aa[y][x].clone(lex) + this.aa[y] && this.aa[y][x] && this.aa[y][x].assign(lex) } Matrix.prototype.getCell = function(x,y){ if (this.aa[y] && this.aa[y][x]) return this.aa[y][x] |
