-
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.
Map data to be pushed to teiserver for the need of multiplayer games and matchmaking.
- Loading branch information
Showing
4 changed files
with
111 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
$schema: https://json-schema.org/draft/2020-12/schema | ||
$id: https://maps-metadata.beyondallreason.dev/latest/schemas/teiserver_maps.json | ||
description: Map information for https://github.com/beyond-all-reason/teiserver | ||
type: object | ||
title: TeiserverMaps | ||
properties: | ||
maps: | ||
type: array | ||
items: | ||
$ref: "#/$defs/teiserverMapInfo" | ||
required: | ||
- maps | ||
$defs: | ||
teiserverMapInfo: | ||
title: TeiserverMapInfo | ||
type: object | ||
properties: | ||
springName: | ||
type: string | ||
modoptions: | ||
$ref: "map_modoptions.json#/$defs/mapModoptions" | ||
default: {} | ||
matchmakingQueues: | ||
type: array | ||
items: | ||
type: string | ||
# Values from https://github.com/beyond-all-reason/teiserver/blob/778450852dd63e087174a62853aae563b6723479/lib/teiserver/matchmaking/queue_supervisor.ex#L9 | ||
# will need to figure out how to evolve it over time | ||
enum: | ||
- 1v1 | ||
- 2v2 | ||
uniqueItems: true | ||
default: [] | ||
startboxesSet: | ||
type: array | ||
items: | ||
$ref: "map_list.json#/$defs/startboxesInfo" | ||
required: | ||
- springName | ||
- startboxesSet |
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,52 @@ | ||
import { readMapList } from "./maps_metadata.js"; | ||
import fs from "node:fs/promises"; | ||
import { program } from "@commander-js/extra-typings"; | ||
import stringify from "json-stable-stringify"; | ||
import type { | ||
TeiserverMapInfo, | ||
TeiserverMaps, | ||
} from "../../../gen/types/teiserver_maps.js"; | ||
import { MapModoptions } from '../../../gen/types/map_modoptions.js'; | ||
|
||
async function readMapModoptions(): Promise<{[springName: string]: MapModoptions['modoptions']}> { | ||
const contents = await fs.readFile('gen/map_modoptions.validated.json', { 'encoding': 'utf8' }); | ||
const mapModoptions = JSON.parse(contents) as MapModoptions[]; | ||
return Object.fromEntries(mapModoptions.map((m) => [m.springName, m.modoptions])); | ||
} | ||
|
||
async function genTeiserverMaps(): Promise<string> { | ||
const maps = await readMapList(); | ||
const mapModoptions = await readMapModoptions(); | ||
|
||
const tMaps: TeiserverMapInfo[] = []; | ||
for (const [_rowyId, map] of Object.entries(maps)) { | ||
if (!map.inPool) { | ||
continue; | ||
} | ||
|
||
// TODO: Do some better mapping, maybe add dedicated clear map lists | ||
// in Rowy for exactly this purpose. Atm just reusing the one that | ||
// exists for competitive 1v1. | ||
const matchmakingQueues: TeiserverMapInfo["matchmakingQueues"] = []; | ||
if (map.mapLists?.includes("competitive2p")) { | ||
matchmakingQueues.push("1v1"); | ||
} | ||
|
||
tMaps.push({ | ||
springName: map.springName, | ||
startboxesSet: Object.values(map.startboxesSet || {}), | ||
matchmakingQueues, | ||
modoptions: mapModoptions[map.springName] | ||
}); | ||
} | ||
|
||
tMaps.sort((a, b) => a.springName.localeCompare(b.springName)); | ||
const teiserverMaps: TeiserverMaps = { maps: tMaps }; | ||
return stringify(teiserverMaps); | ||
} | ||
|
||
const prog = program | ||
.argument("<teiserverMaps>", "Lobby maps output path.") | ||
.parse(); | ||
const [teiserverMapsPath] = prog.processedArgs; | ||
await fs.writeFile(teiserverMapsPath, await genTeiserverMaps()); |