import { LitElement, html } from "lit"; import { customElement, property, state } from "lit/decorators.js"; import { Difficulty, GameMapType, mapCategories, } from "../../../core/game/Game"; import { translateText } from "../../Utils"; import "./MapDisplay"; import randomMap from "/images/RandomMap.webp?url"; const featuredMaps: GameMapType[] = [ GameMapType.World, GameMapType.Europe, GameMapType.NorthAmerica, GameMapType.SouthAmerica, GameMapType.Asia, GameMapType.Africa, GameMapType.Japan, ]; @customElement("map-picker") export class MapPicker extends LitElement { @property({ type: String }) selectedMap: GameMapType = GameMapType.World; @property({ type: Boolean }) useRandomMap = false; @property({ type: Boolean }) showMedals = false; @property({ type: Boolean }) randomMapDivider = false; @property({ attribute: false }) mapWins: Map> = new Map(); @property({ attribute: false }) onSelectMap?: (map: GameMapType) => void; @property({ attribute: false }) onSelectRandom?: () => void; @state() private showAllMaps = false; createRenderRoot() { return this; } private handleMapSelection(mapValue: GameMapType) { this.onSelectMap?.(mapValue); } private handleSelectRandomMap = () => { this.onSelectRandom?.(); }; private preventImageDrag(event: DragEvent) { event.preventDefault(); } private getWins(mapValue: GameMapType): Set { return this.mapWins?.get(mapValue) ?? new Set(); } private renderMapCard(mapValue: GameMapType) { const mapKey = Object.entries(GameMapType).find( ([_, value]) => value === mapValue, )?.[0]; return html`
this.handleMapSelection(mapValue)} class="cursor-pointer" >
`; } private renderAllMaps() { const mapCategoryEntries = Object.entries(mapCategories); return html`
${mapCategoryEntries.map( ([categoryKey, maps]) => html`

${translateText(`map_categories.${categoryKey}`)}

${maps.map((mapValue) => this.renderMapCard(mapValue))}
`, )}
`; } private renderFeaturedMaps() { let featuredMapList = featuredMaps; if (!featuredMapList.includes(this.selectedMap)) { featuredMapList = [this.selectedMap, ...featuredMaps]; } return html`

${translateText("map_categories.featured")}

${featuredMapList.map((mapValue) => this.renderMapCard(mapValue))}
`; } render() { return html`
${this.showAllMaps ? this.renderAllMaps() : this.renderFeaturedMaps()}

${translateText("map_categories.special")}

`; } }