Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/components/buttons/close-button.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isClickInsideButton, loadImages } from "@common";
import { isClickInsideButton, loadImages, Utils } from "@common";
import { MAP_BTN_IMG } from "@constants";

export default class CloseButton {
Expand Down Expand Up @@ -26,17 +26,23 @@ export default class CloseButton {
this.context = context;
this.canvas = canvas;

loadImages({ close_button_image: MAP_BTN_IMG }, (images) => {
this.close_button_image = images["close_button_image"];
this.imagesLoaded = true;
});
// don't load the image when respect mode is enabled
if (!Utils.isRespect) {
loadImages({ close_button_image: MAP_BTN_IMG }, (images) => {
this.close_button_image = images["close_button_image"];
this.imagesLoaded = true;
});
Comment on lines +29 to +34

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This block of code conditionally loads the close button image based on Utils.isRespect. It's good that the image loading is skipped when respect mode is enabled, but consider adding a comment explaining why this is done. This will help future developers understand the intent behind this conditional loading.

}

this.btnSizeAnimation = 0.19;
this.btnOriginalSize = this.btnSizeAnimation;
this.orignalPos = { x: posX, y: posY };
}

draw() {
// hide button in respect mode
if (Utils.isRespect) return;
Comment on lines +43 to +44

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This if statement checks Utils.isRespect to determine whether to hide the close button. It's a good approach to disable the button in respect mode. However, consider adding a comment that explains the purpose of the respect mode and why the button is hidden in this mode. This will improve code readability and maintainability.


if (this.imagesLoaded) {
this.context.drawImage(
this.close_button_image,
Expand All @@ -56,6 +62,9 @@ export default class CloseButton {
}

onClick(xClick: number, yClick: number): boolean {
// ignore clicks in respect mode
if (Utils.isRespect) return false;
Comment on lines +65 to +66

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This if statement prevents clicks on the close button when Utils.isRespect is true. This is a good way to disable the button's functionality in respect mode. Consider adding a comment to explain why clicks are ignored in respect mode. This will help other developers understand the purpose of this check.


const isInside = isClickInsideButton(
xClick,
yClick,
Expand Down
2 changes: 1 addition & 1 deletion src/components/popups/pause-popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class PausePopUp {
this.retryButton = new RetryButton(
this.context,
this.canvas,
this.canvas.width * 0.55,
this.canvas.width * 0.5 - (this.canvas.width * 0.19) / 2,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The calculation for the retryButton position is slightly complex. While it's correct, it could be made more readable by extracting the width calculation to a variable with a descriptive name. This would improve the code's maintainability and make it easier to understand the positioning logic.

    const buttonWidthOffset = this.canvas.width * 0.19;
    this.retryButton = new RetryButton(
      this.context,
      this.canvas,
      this.canvas.width * 0.5 - buttonWidthOffset / 2,
      this.canvas.height * 0.2 +
        this.canvas.width * 0.4 - buttonWidthOffset / 2
    );

this.canvas.height * 0.2 +
this.canvas.width * 0.4 -
(this.canvas.width * 0.19) / 2
Expand Down