Bläddra i källkod

Added an interface class for Surface object... like NESBank will become.

dev-tmpl
Bryan Miller 5 år sedan
förälder
incheckning
180f5753db
1 ändrade filer med 57 tillägg och 0 borttagningar
  1. +57
    -0
      app/js/ifaces/Surface.js

+ 57
- 0
app/js/ifaces/Surface.js Visa fil

@@ -0,0 +1,57 @@
import Utils from "/app/js/common/Utils.js"


export default class ISurface{
constructor(){
this.__default_pi = [
"#080808",
"#343434",
"#a2a2a2",
"#efefef",
"#666666" // Out of bounds color.
];
}

get width(){return 0;}
get height(){return 0;}
get length(){return 0;}

get coloridx(){
return new Proxy(this, {
get: function(obj, prop){
if (prop === "length")
return 0;
if (!Utils.isInt(prop))
throw new TypeError("Expected integer index.");
if (prop < 0)
throw new RangeError("Index is out of bounds.");
return obj.__default_pi[4];
}

set: function(obj, prop, value){
if (!Utils.isInt(prop))
throw new TypeError("Expected integer index.");
if (prop < 0)
throw new RangeError("Index out of bounds.");
if (!Utils.isInt(value))
throw new TypeError("Color index expected to be an integer.");
if (value < 0 || value >= 4)
throw new RangeError("Color index is out of bounds.");
return true;
}
});
}

copy(b){return this;}
clone(){return new ISurface();}

getColor(x, y){
return this.__default_pi[4];
}

setColorIndex(x, y, ci, pi){
return this;
}


}

Laddar…
Avbryt
Spara