Allow killing sheep

This commit is contained in:
Dustin Brett
2024-07-17 20:39:53 -07:00
parent 9d4214c888
commit dd174ebc6c
5 changed files with 22 additions and 8 deletions

View File

@@ -921,7 +921,9 @@ const useCommandInterpreter = (
}
case "sheep":
case "esheep": {
const { default: spawnSheep } = await import("utils/spawnSheep");
const { countSheep, killSheep, spawnSheep } = await import(
"utils/spawnSheep"
);
let [count = 1, duration = 0] = commandArgs;
if (!Number.isNaN(count) && !Number.isNaN(duration)) {
@@ -936,10 +938,12 @@ const useCommandInterpreter = (
const maxDuration =
(duration || (count > 1 ? 1 : 0)) * MILLISECONDS_IN_SECOND;
Array.from({ length: count })
Array.from({ length: count === 0 ? countSheep() : count })
.fill(0)
.map(() => Math.floor(Math.random() * maxDuration))
.forEach((delay) => setTimeout(spawnSheep, delay));
.forEach((delay) =>
setTimeout(count === 0 ? killSheep : spawnSheep, delay)
);
}
break;
}

View File

@@ -23,7 +23,7 @@ import {
} from "utils/constants";
import { getExtension, haltEvent } from "utils/functions";
import { getIpfsFileName, getIpfsResource } from "utils/ipfs";
import spawnSheep from "utils/spawnSheep";
import { spawnSheep } from "utils/spawnSheep";
import Icon from "styles/common/Icon";
const OPEN_ID = "open";

View File

@@ -50,7 +50,7 @@ const easterEggOnClick: React.MouseEventHandler<HTMLElement> = async ({
triggerEasterEggCountdown -= 1;
if (triggerEasterEggCountdown === 0) {
const { default: spawnSheep } = await import("utils/spawnSheep");
const { spawnSheep } = await import("utils/spawnSheep");
spawnSheep();

View File

@@ -78,7 +78,7 @@ const StartButton: FC<StartButtonProps> = ({
toggleStartMenu();
if (ctrlKey && shiftKey) {
const { default: spawnSheep } = await import("utils/spawnSheep");
const { spawnSheep } = await import("utils/spawnSheep");
spawnSheep();
}

View File

@@ -41,7 +41,7 @@ const pickRandomPet = (): string => {
return petPath;
};
const spawnSheep = (): Promise<void> =>
export const spawnSheep = (): Promise<void> =>
loadFiles(["/Program Files/eSheep/eSheep.js"]).then(() => {
if (window.Sheep) {
const sheep = new window.Sheep({
@@ -59,4 +59,14 @@ const spawnSheep = (): Promise<void> =>
}
});
export default spawnSheep;
const sheepSelector =
"main > div[style*='z-index: 2000'] > img[src^='data:image']";
export const killSheep = (): void => {
const firstSheep = document.querySelector(sheepSelector) as HTMLElement;
firstSheep?.parentElement?.remove();
};
export const countSheep = (): number =>
document.querySelectorAll(sheepSelector).length;