@houstonp/rubiks-cube 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +82 -67
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -89,14 +89,17 @@ class RubiksCube extends HTMLElement {
89
89
  const animationQueue = new AnimationQueue();
90
90
 
91
91
  // initial camera animation
92
- new TWEEN.Tween(camera.position)
93
- .to({ x: 3, y: 3, z: 4 }, 1000)
94
- .easing(TWEEN.Easing.Cubic.InOut)
95
- .start();
92
+ const cameraAnimationGroup = new TWEEN.Group();
93
+ cameraAnimationGroup.add(
94
+ new TWEEN.Tween(camera.position)
95
+ .to({ x: 3, y: 3, z: 4 }, 1000)
96
+ .easing(TWEEN.Easing.Cubic.InOut)
97
+ .start()
98
+ );
96
99
 
97
100
  // animation loop
98
101
  function animate() {
99
- TWEEN.update();
102
+ cameraAnimationGroup.update();
100
103
  controls.update();
101
104
  animationQueue.update();
102
105
  const animationGroup = animationQueue.getAnimationGroup();
@@ -120,73 +123,85 @@ class RubiksCube extends HTMLElement {
120
123
  });
121
124
  this.addEventListener("camera", (e) => {
122
125
  console.log(cube.getStickerState());
123
- new TWEEN.Tween(camera.position);
126
+
124
127
  if (e.detail.action === "peek-toggle-horizontal") {
125
- new TWEEN.Tween(camera.position)
126
- .to(
127
- {
128
- x: camera.position.x > 0 ? -2.5 : 2.5,
129
- y: camera.position.y > 0 ? 2.5 : -2.5,
130
- z: 4,
131
- },
132
- 200
133
- )
134
- .start();
128
+ cameraAnimationGroup.add(
129
+ new TWEEN.Tween(camera.position)
130
+ .to(
131
+ {
132
+ x: camera.position.x > 0 ? -2.5 : 2.5,
133
+ y: camera.position.y > 0 ? 2.5 : -2.5,
134
+ z: 4,
135
+ },
136
+ 200
137
+ )
138
+ .start()
139
+ );
135
140
  } else if (e.detail.action === "peek-toggle-vertical") {
136
- new TWEEN.Tween(camera.position)
137
- .to(
138
- {
139
- x: camera.position.x > 0 ? 2.5 : -2.5,
140
- y: camera.position.y > 0 ? -2.5 : 2.5,
141
- z: 4,
142
- },
143
- 200
144
- )
145
- .start();
146
- } else if (e.detail.action === "peek-right") {
147
- new TWEEN.Tween(camera.position)
148
- .to(
149
- {
150
- x: 2.5,
151
- y: camera.position.y > 0 ? 2.5 : -2.5,
152
- z: 4,
153
- },
154
- 200
155
- )
156
- .start();
141
+ cameraAnimationGroup.add(
142
+ new TWEEN.Tween(camera.position)
143
+ .to(
144
+ {
145
+ x: camera.position.x > 0 ? 2.5 : -2.5,
146
+ y: camera.position.y > 0 ? -2.5 : 2.5,
147
+ z: 4,
148
+ },
149
+ 200
150
+ )
151
+ .start()
152
+ );
153
+ } else if (e.etail.action === "peek-right") {
154
+ cameraAnimationGroup.add(
155
+ new TWEEN.Tween(camera.position)
156
+ .to(
157
+ {
158
+ x: 2.5,
159
+ y: camera.position.y > 0 ? 2.5 : -2.5,
160
+ z: 4,
161
+ },
162
+ 200
163
+ )
164
+ .start()
165
+ );
157
166
  } else if (e.detail.action === "peek-left") {
158
- new TWEEN.Tween(camera.position)
159
- .to(
160
- {
161
- x: -2.5,
162
- y: camera.position.y > 0 ? 2.5 : -2.5,
163
- z: 4,
164
- },
165
- 200
166
- )
167
- .start();
167
+ cameraAnimationGroup.add(
168
+ new TWEEN.Tween(camera.position)
169
+ .to(
170
+ {
171
+ x: -2.5,
172
+ y: camera.position.y > 0 ? 2.5 : -2.5,
173
+ z: 4,
174
+ },
175
+ 200
176
+ )
177
+ .start()
178
+ );
168
179
  } else if (e.detail.action === "peek-up") {
169
- new TWEEN.Tween(camera.position)
170
- .to(
171
- {
172
- x: camera.position.x > 0 ? 2.5 : -2.5,
173
- y: 2.5,
174
- z: 4,
175
- },
176
- 200
177
- )
178
- .start();
180
+ cameraAnimationGroup.add(
181
+ new TWEEN.Tween(camera.position)
182
+ .to(
183
+ {
184
+ x: camera.position.x > 0 ? 2.5 : -2.5,
185
+ y: 2.5,
186
+ z: 4,
187
+ },
188
+ 200
189
+ )
190
+ .start()
191
+ );
179
192
  } else if (e.detail.action === "peek-down") {
180
- new TWEEN.Tween(camera.position)
181
- .to(
182
- {
183
- x: camera.position.x > 0 ? 2.5 : -2.5,
184
- y: -2.5,
185
- z: 4,
186
- },
187
- 200
188
- )
189
- .start();
193
+ cameraAnimationGroup.add(
194
+ new TWEEN.Tween(camera.position)
195
+ .to(
196
+ {
197
+ x: camera.position.x > 0 ? 2.5 : -2.5,
198
+ y: -2.5,
199
+ z: 4,
200
+ },
201
+ 200
202
+ )
203
+ .start()
204
+ );
190
205
  }
191
206
  });
192
207
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@houstonp/rubiks-cube",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Rubiks Cube Web Component built with threejs",
5
5
  "main": "index.js",
6
6
  "author": "Houston Pearse",