Browse Source

Set up system for a variety of attributes for each view

tags/v0.0.1
Fen Dweller 5 years ago
parent
commit
8ffd86c0c4
1 changed files with 24 additions and 9 deletions
  1. +24
    -9
      macrovision.js

+ 24
- 9
macrovision.js View File

@@ -159,19 +159,34 @@ function makeEntity() {
scale: 1,
views: {
body: {
baseHeight: math.unit(Math.random() * 1 + 1, "meter"),
get height() {
return math.multiply(this.parent.scale, this.baseHeight);
},
set height(value) {
this.parent.scale = math.divide(value, this.baseHeight);
attributes: {
height: {
name: "Height",
power: 1,
base: math.unit(Math.random() * 1 + 1, "meter")
}
}
}
},
init: function () {
console.log(this);
Object.entries(this.views).forEach(([key, val]) => {
val.parent = this;
Object.values(this.views).forEach(view => {
view.parent = this;

Object.entries(view.attributes).forEach(([key, val]) => {
Object.defineProperty(
view,
key,
{
get: function() {
return math.multiply(Math.pow(this.parent.scale, this.attributes[key].power), this.attributes[key].base);
},
set: function(value) {
const newScale = Math.pow(math.divide(value, this.attributes[key].base), this.attributes[key]/power);
this.parent.scale = newScale;
}
}
)
});
});
delete this.init;
return this;


Loading…
Cancel
Save