forked from darkforest-eth/client
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLocate-Artifacts.ts
80 lines (68 loc) · 2.44 KB
/
Locate-Artifacts.ts
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
/**
* Remember, you have access these globals:
* 1. df - Just like the df object in your console.
* 2. ui - For interacting with the game's user interface.
*
* Let's log these to the console when you run your plugin!
*/
console.log(df, ui);
class ArtifactsFinder implements DFPlugin {
private planetList: HTMLDivElement;
renderPlanets = () => {
this.planetList.innerHTML = '';
// keep track of how many we have found
let count = 0;
const countText = document.createElement('div');
this.planetList.appendChild(countText);
for (const planet of df.getAllPlanets()) {
// @ts-ignore
if (planet.location) {
if (df.isPlanetMineable(planet)) {
// is there any other filtering you'd want to do?
// sometimes planets have artifacts deposited on them!
// somtimes a planet's artifact has already been mined.
// see if you can modify this plugin to make it do what
// you want!
const planetEntry = document.createElement('div');
this.planetList.appendChild(planetEntry);
// hint: have a hard time finding planets?
// ui.centerCoords might help...
planetEntry.innerText =
'(' +
// @ts-ignore
planet.location.coords.x +
', ' +
// @ts-ignore
planet.location.coords.y +
')';
count++;
}
}
}
if (count === 0) {
countText.innerText = 'you have not found any artifacts yet';
} else {
countText.innerText = 'you have found ' + count + ' artifacts';
}
};
async render(container: HTMLDivElement) {
console.log('rendered 1 artifacts finder');
const findArtifactsButton = document.createElement('button');
findArtifactsButton.innerText = 'find me some artifacts!';
container.appendChild(findArtifactsButton);
container.appendChild(document.createElement('br'));
container.appendChild(document.createElement('br'));
findArtifactsButton.addEventListener('click', this.renderPlanets);
this.planetList = document.createElement('div');
container.appendChild(this.planetList);
this.planetList.style.maxHeight = '300px';
this.planetList.style.width = '400px';
this.planetList.style.overflowX = 'hidden';
this.planetList.style.overflowY = 'scroll';
console.log('rendered artifacts finder');
}
}
/**
* And don't forget to export it!
*/
export default ArtifactsFinder;