Skip to content

Instantly share code, notes, and snippets.

@jacobrosenthal
Last active December 26, 2020 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacobrosenthal/59597417430680dffa456ce3449346f2 to your computer and use it in GitHub Desktop.
Save jacobrosenthal/59597417430680dffa456ce3449346f2 to your computer and use it in GitHub Desktop.
my unmined artifacts
/**
* 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.
* 3. plugin - To register the plugin, plus other helpful things.
*
* Let's log these to the console when you run your plugin!
*/
console.log(df, ui, plugin);
class ArtifactsFinder {
planetList;
renderPlanets = () => {
this.planetList.innerHTML = '';
const planets = Array.from(df.getMyPlanets())
.filter(p => df.isPlanetMineable(p))
.filter(p => !p.hasTriedFindingArtifact)
.sort((a, b) => parseInt(a.locationId, 16) - parseInt(b.locationId, 16));
for (const planet of planets) {
if (planet.location) {
const planetEntry = document.createElement('div');
planetEntry.addEventListener("click", () => {
ui.centerCoords({ x: planet.location.coords.x, y: planet.location.coords.y });
});
this.planetList.appendChild(planetEntry);
planetEntry.innerText =
planet.location.coords.x +
',' +
planet.location.coords.y;
}
}
};
async render(container) {
container.style.width = '100px';
console.log('rendered 1 artifacts finder');
const findArtifactsButton = document.createElement('button');
findArtifactsButton.innerText = 'find!';
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.overflowX = 'hidden';
this.planetList.style.overflowY = 'scroll';
console.log('rendered artifacts finder');
}
}
/**
* And don't forget to register it!
*/
plugin.register(new ArtifactsFinder());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment