convert unclickable inside the react tree

This commit is contained in:
Olivier Gagnon
2021-09-25 14:00:38 -04:00
parent 125e9484f7
commit d49fea4cbc
5 changed files with 22 additions and 27 deletions

View File

@@ -0,0 +1,20 @@
import React from "react";
import { use } from "../ui/Context";
import { Exploit } from "./Exploit";
export function Unclickable(): React.ReactElement {
const player = use.Player();
function unclickable(event: React.MouseEvent<HTMLDivElement>): void {
if (!event.target || !(event.target instanceof Element)) return;
const display = window.getComputedStyle(event.target as Element).display;
const visibility = window.getComputedStyle(event.target as Element).visibility;
if (display === "none" && visibility === "hidden" && event.isTrusted) player.giveExploit(Exploit.Unclickable);
}
return (
<div id="unclickable" onClick={unclickable} style={{ display: "none", visibility: "hidden" }}>
Click on this to upgrade your Source-File -1!
</div>
);
}

View File

@@ -1,22 +0,0 @@
import { Player } from "../Player";
import { Exploit } from "./Exploit";
export function startUnclickable(): void {
function clickTheUnclickable(event: MouseEvent): void {
if (!event.target || !(event.target instanceof Element)) return;
const display = window.getComputedStyle(event.target as Element).display;
if (display === "none" && event.isTrusted) Player.giveExploit(Exploit.Unclickable);
}
function targetElement(): void {
const elem = document.getElementById("unclickable");
if (elem == null) {
console.error("Could not find the unclickable elem for the related exploit.");
return;
}
elem.addEventListener("click", clickTheUnclickable);
document.removeEventListener("DOMContentLoaded", targetElement);
}
document.addEventListener("DOMContentLoaded", targetElement);
}