-
-
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.
make mission container to separate component
- Loading branch information
1 parent
b1acc1b
commit fdabb89
Showing
3 changed files
with
71 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Mission } from "../../missions/mission"; | ||
import { Player } from "../../player/player"; | ||
import { Sounds } from "../../assets/sounds"; | ||
|
||
export class AcceptMissionButton { | ||
readonly rootNode: HTMLElement; | ||
|
||
constructor(mission: Mission, player: Player) { | ||
this.rootNode = document.createElement("button"); | ||
this.rootNode.className = "missionButton"; | ||
this.rootNode.innerText = "Accept"; | ||
|
||
if(player.currentMissions.find((m) => m.equals(mission))) { | ||
this.rootNode.classList.add("accepted"); | ||
this.rootNode.innerText = "Accepted"; | ||
} | ||
|
||
this.rootNode.addEventListener("click", () => { | ||
Sounds.MENU_SELECT_SOUND.play(); | ||
if(player.currentMissions.find((m) => m.equals(mission))) { | ||
this.rootNode.classList.remove("accepted"); | ||
this.rootNode.innerText = "Accept"; | ||
player.currentMissions = player.currentMissions.filter((m) => !m.equals(mission)); | ||
return; | ||
} | ||
|
||
this.rootNode.classList.add("accepted"); | ||
this.rootNode.innerText = "Accepted"; | ||
player.currentMissions.push(mission); | ||
}); | ||
} | ||
} |
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,36 @@ | ||
import { Mission } from "../../missions/mission"; | ||
import { Player } from "../../player/player"; | ||
import { Settings } from "../../settings"; | ||
import { AcceptMissionButton } from "./acceptMissionButton"; | ||
|
||
export class MissionContainer { | ||
readonly rootNode: HTMLElement; | ||
|
||
constructor(mission: Mission, player: Player) { | ||
this.rootNode = document.createElement("div"); | ||
this.rootNode.className = "missionItem"; | ||
|
||
const descriptionContainer = document.createElement("div"); | ||
descriptionContainer.className = "missionDescription"; | ||
this.rootNode.appendChild(descriptionContainer); | ||
|
||
const missionH4 = document.createElement("h4"); | ||
missionH4.innerText = mission.getTypeString(); | ||
descriptionContainer.appendChild(missionH4); | ||
|
||
const missionP = document.createElement("p"); | ||
missionP.innerText = mission.describe(); | ||
descriptionContainer.appendChild(missionP); | ||
|
||
const rewardP = document.createElement("p"); | ||
rewardP.innerText = `Reward: ${Settings.CREDIT_SYMBOL}${mission.getReward().toLocaleString()}`; | ||
descriptionContainer.appendChild(rewardP); | ||
|
||
const buttonContainer = document.createElement("div"); | ||
buttonContainer.className = "missionButtonContainer"; | ||
this.rootNode.appendChild(buttonContainer); | ||
|
||
const acceptButton = new AcceptMissionButton(mission, player); | ||
buttonContainer.appendChild(acceptButton.rootNode); | ||
} | ||
} |
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