-
Notifications
You must be signed in to change notification settings - Fork 209
/
drop-manager.js
85 lines (79 loc) · 2.03 KB
/
drop-manager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import * as THREE from 'three';
import metaversefile from 'metaversefile';
import generateStats from './procgen/stats.js';
const r = () => -1 + Math.random() * 2;
class DropManager extends EventTarget {
constructor() {
super();
this.claims = [];
}
createDropApp({
start_url,
components = [],
type = 'minor', // 'minor', 'major', 'key'
position,
quaternion,
scale,
velocity = new THREE.Vector3(r(), 1 + Math.random(), r())
.normalize()
.multiplyScalar(5),
angularVelocity = new THREE.Vector3(0, 0.001, 0),
voucher = 'fakeVoucher', // XXX should really throw if no voucher
}) {
// const r = () => (-0.5+Math.random())*2;
const dropComponent = {
key: 'drop',
value: {
type,
voucher,
velocity: velocity.toArray(),
angularVelocity: angularVelocity.toArray(),
},
};
components.push(dropComponent);
const trackedApp = metaversefile.addTrackedApp(
start_url,
position,
quaternion,
scale,
components
);
return trackedApp;
}
addClaim(name, contentId, voucher) {
const result = generateStats(contentId);
const {/*art, */stats} = result;
const {level} = stats;
const start_url = contentId;
const claim = {
name,
start_url,
level,
voucher,
};
this.claims.push(claim);
this.dispatchEvent(new MessageEvent('claimschange', {
data: {
claims: this.claims,
},
}));
}
pickupApp(app) {
this.addClaim(app.name, app.contentId, app.getComponent('voucher'));
}
dropToken(contractAddress, tokenId, voucher) {
// XXX engine implements this
}
claimVoucher(contractAddress, tokenId, voucher) {
// ui handles this
this.dispatchEvent(new MessageEvent('claimvoucher', {
data: {
contractAddress,
tokenId,
voucher,
},
}));
}
}
const dropManager = new DropManager();
export default dropManager;