-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added basic ability to bookmark systems
the display part is still lacking. It would be nice to have a unified way to display both bookmarks and missions in the starmap
- Loading branch information
1 parent
79bbeb5
commit 5e8aede
Showing
6 changed files
with
66 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import i18n from "../i18n"; | ||
import { SystemSeed } from "../utils/systemSeed"; | ||
import { Player } from "../player/player"; | ||
import { Sounds } from "../assets/sounds"; | ||
|
||
export class StarMapBookmarkButton { | ||
readonly rootNode: HTMLElement; | ||
private readonly player: Player; | ||
|
||
private selectedSystemSeed: SystemSeed | null = null; | ||
private isSelectedSystemBookmarked = false; | ||
|
||
constructor(player: Player) { | ||
this.rootNode = document.createElement("button"); | ||
this.rootNode.classList.add("bookmarkButton"); | ||
this.rootNode.textContent = i18n.t("starMap:bookmark"); | ||
|
||
this.player = player; | ||
|
||
this.rootNode.addEventListener("click", () => { | ||
if (this.selectedSystemSeed === null) return; | ||
Sounds.MENU_SELECT_SOUND.play(); | ||
|
||
const currentSystemSeed = this.selectedSystemSeed; | ||
|
||
if (!this.isSelectedSystemBookmarked) { | ||
this.player.systemBookmarks.push(this.selectedSystemSeed); | ||
this.rootNode.classList.add("bookmarked"); | ||
this.rootNode.textContent = i18n.t("starMap:bookmarked"); | ||
} else { | ||
this.player.systemBookmarks = this.player.systemBookmarks.filter((bookmark) => !bookmark.equals(currentSystemSeed)); | ||
this.rootNode.classList.remove("bookmarked"); | ||
this.rootNode.textContent = i18n.t("starMap:bookmark"); | ||
} | ||
|
||
this.isSelectedSystemBookmarked = !this.isSelectedSystemBookmarked; | ||
}); | ||
} | ||
|
||
setSelectedSystemSeed(seed: SystemSeed) { | ||
this.selectedSystemSeed = seed; | ||
this.isSelectedSystemBookmarked = this.player.systemBookmarks.find((bookmark) => bookmark.equals(seed)) !== undefined; | ||
this.rootNode.classList.toggle("bookmarked", this.isSelectedSystemBookmarked); | ||
this.rootNode.textContent = this.isSelectedSystemBookmarked ? i18n.t("starMap:bookmarked") : i18n.t("starMap:bookmark"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters