Fixing mouse detection

This commit is contained in:
2023-08-27 18:14:24 +02:00
parent 3cd115c488
commit 2b37a025be
3 changed files with 14 additions and 10 deletions

View File

@ -127,6 +127,11 @@ export class UserAPI {
// Mouse functions // Mouse functions
// ============================================================= // =============================================================
onmousemove = (e: MouseEvent) => {
this.app._mouseX = e.clientX;
this.app._mouseY = e.clientY;
}
public mouseX = (): number => { public mouseX = (): number => {
/** /**
* @returns The current x position of the mouse * @returns The current x position of the mouse

View File

@ -6,7 +6,6 @@ const key_shortcut = (shortcut: string): string => {
const samples_to_markdown = (application: Editor) => { const samples_to_markdown = (application: Editor) => {
let samples = application.api._all_samples(); let samples = application.api._all_samples();
console.log(samples)
let markdownList = ""; let markdownList = "";
let keys = Object.keys(samples); let keys = Object.keys(samples);
let i = -1; let i = -1;

View File

@ -628,7 +628,7 @@ export class Editor {
if (universeParam !== null) { if (universeParam !== null) {
new_universe = JSON.parse(atob(universeParam)); new_universe = JSON.parse(atob(universeParam));
const randomName: string = uniqueNamesGenerator({ const randomName: string = uniqueNamesGenerator({
length: 2, separator: '', length: 2, separator: '_',
dictionaries: [colors, animals], dictionaries: [colors, animals],
}); });
this.loadUniverse(randomName, new_universe["universe"]); this.loadUniverse(randomName, new_universe["universe"]);
@ -970,15 +970,7 @@ export class Editor {
// Creating the application // Creating the application
const app = new Editor(); const app = new Editor();
/**
* @param event The mouse event
*/
function reportMouseCoordinates(event: MouseEvent) {
app._mouseX = event.clientX;
app._mouseY = event.clientY;
}
window.addEventListener("mousemove", reportMouseCoordinates);
// When the user leaves the page, all the universes should be saved in the localStorage // When the user leaves the page, all the universes should be saved in the localStorage
window.addEventListener("beforeunload", () => { window.addEventListener("beforeunload", () => {
@ -991,3 +983,11 @@ window.addEventListener("beforeunload", () => {
app.clock.stop(); app.clock.stop();
return null; return null;
}); });
// function reportMouseCoordinates(event: MouseEvent) {
// app._mouseX = event.clientX;
// app._mouseY = event.clientY;
// }
onmousemove = function(e){console.log("mouse location:", e.clientX, e.clientY)}