MCPcopy
hub / github.com/franciscop/ola / Ola

Function Ola

ola.js:69–110  ·  view source on GitHub ↗
(values, time = 300)

Source from the content-addressed store, hash-verified

67
68// The multidimensional constructor, makes a { value: init } if it's 1D
69function Ola(values, time = 300) {
70 // This is just an alias
71 if (typeof values === "number") {
72 values = { value: values };
73 }
74
75 // Loop over the first argument
76 each(values, (init, key) => {
77 const value = new Single(init, time / 1000);
78 // But we are not interested in it; instead, set it as a ghost
79 Object.defineProperty(values, "_" + key, { value }); // pos._x.to, pos._x.speed, ...
80 Object.defineProperty(values, "$" + key, { get: () => value.to }); // pos.$x
81 Object.defineProperty(values, key, {
82 get: () => value.get(new Date()), // pos.x
83 set: val => value.set(val), // pos.x = 10
84 enumerable: true
85 });
86 });
87
88 // pos.get('x')
89 Object.defineProperty(values, "get", {
90 get: () =>
91 function(name = "value", now = new Date()) {
92 return this["_" + name].get(now);
93 }
94 });
95
96 // pos.set(10)
97 // pos.set({ x: 10 })
98 // pos.set({ x: 10 }, time)
99 Object.defineProperty(values, "set", {
100 get: () =>
101 function(values, time = 0) {
102 each(values, (value, key) => {
103 this["_" + key].set(value, time / 1000);
104 });
105 }
106 });
107
108 // So that you can use the original methods
109 return values;
110}
111
112export default Ola;

Callers 2

ola.test.jsFile · 0.70
index.jsFile · 0.50

Calls 1

eachFunction · 0.70

Tested by

no test coverage detected