-
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.
Automatically update nextmap mapLists.conf (#128)
Adds functionality wanted in #118
- Loading branch information
Showing
4 changed files
with
151 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
# Generates maplists for https://github.com/beyond-all-reason/spads_config_bar/blob/main/etc/mapLists.conf . This controls the !nextmap command in spads. | ||
|
||
import json | ||
import math | ||
|
||
teamsizes = ['2v2','3v3','4v4','5v5','6v6','7v7','8v8','ffa3','ffa4','ffa5','ffa6','ffa7','ffa8','ffa9','ffa10','ffa11','ffa12','ffa13','ffa14','ffa15','ffa16','2v2v2','2v2v2v2','2v2v2v2v2','2v2v2v2v2v2','2v2v2v2v2v2v2','2v2v2v2v2v2v2v2','3v3v3','3v3v3v3','3v3v3v3v3','4v4v4','4v4v4v4','5v5v5'] | ||
|
||
def get_data(input_file): | ||
with open(input_file) as f: | ||
contents = json.load(f) | ||
|
||
teamsize_dict = {} | ||
certified_maps = [] | ||
uncertified_maps = [] | ||
maps_1v1 = [] | ||
|
||
for i in teamsizes: | ||
teamsize_dict[i] = [] | ||
|
||
for map in contents.values(): | ||
if not map["inPool"]: | ||
continue | ||
is_team = False | ||
mapname = '' | ||
player_count = 0 | ||
|
||
|
||
mapname = map["springName"] | ||
is_team = "team" in map["gameType"] | ||
|
||
if "playerCount" in map: | ||
player_count = map["playerCount"] | ||
#32 player ffa or other such sillyness not supported in !nextmap | ||
if player_count > 16: | ||
player_count = 16 | ||
if player_count < 2: | ||
player_count = 2 | ||
|
||
if "startboxesSet" in map: | ||
for startboxes_info in map["startboxesSet"].values(): | ||
if "maxPlayersPerStartbox" in startboxes_info: | ||
team_count = len(startboxes_info["startboxes"]) | ||
max_players_per_startbox = startboxes_info["maxPlayersPerStartbox"] | ||
|
||
# add non-ffa maps to teamsize_dict | ||
if team_count*max_players_per_startbox <= 16: | ||
for x in range(2,max_players_per_startbox+1): | ||
if x >= math.floor(max_players_per_startbox/2): | ||
teamsize_dict['v'.join([str(x)] * team_count)].append(mapname) | ||
|
||
# if a map didn't have "maxPlayersPerStartbox" set for its startboxes, but it's a teamgame map with startboxes for 2 teams, we'll use playerCount instead: | ||
if not "maxPlayersPerStartbox" in startboxes_info and player_count and is_team: | ||
team_count = len(startboxes_info["startboxes"]) | ||
if team_count == 2 and player_count >=4: | ||
for x in range(2,math.floor(player_count/2)+1): | ||
if x >= math.floor(player_count/4): | ||
teamsize_dict['v'.join([str(x)] * team_count)].append(mapname) | ||
|
||
# add ffa maps to teamsize_dict | ||
if "ffa" in map["gameType"]: | ||
for x in range(3,17): | ||
if x <= player_count and x >= math.floor(player_count/2): | ||
teamsize_dict['ffa' + str(x)].append(mapname) | ||
|
||
# add maps to certified and uncertified lists | ||
if map["certified"]: | ||
certified_maps.append(mapname) | ||
else: | ||
uncertified_maps.append(mapname) | ||
|
||
# add maps to 1v1 list | ||
if "1v1" in map["gameType"]: | ||
maps_1v1.append(mapname) | ||
|
||
# make the lists more human-readable | ||
for maplist in teamsize_dict.values(): | ||
maplist.sort() | ||
|
||
certified_maps.sort() | ||
uncertified_maps.sort() | ||
maps_1v1.sort() | ||
|
||
# if combined_dict has empty lists then add ".*" (meaning all maps) to that list | ||
for i in teamsize_dict: | ||
if len(teamsize_dict[i]) == 0: | ||
teamsize_dict[i].append('.*') | ||
|
||
return teamsize_dict, certified_maps, uncertified_maps, maps_1v1 | ||
|
||
def get_output_string(teamsize_dict, certified_maps, uncertified_maps, maps_1v1): | ||
nl = '\n' | ||
output_string = f"""# This file was automatically generated by https://github.com/beyond-all-reason/maps-metadata/tree/main/scripts/py/gen_nextmap_maplists.py using data from rowy. | ||
# Next update from rowy will overwrite this file so do not manually edit this file. | ||
# If you want to make updates to this see https://github.com/beyond-all-reason/maps-metadata/wiki/Adding-a-created-map-to-the-game. | ||
# A map needs properly configured playercount, startboxes and maxPlayersPerStartbox in https://rowy.beyondallreason.dev/table/maps to appear here. | ||
# For example a 2v2v2v2 map needs a startbox configuration with 4 startboxes and maxPlayersPerStartbox >= 2. | ||
[all] | ||
.* | ||
[certified] | ||
{nl.join(certified_maps)} | ||
[uncertified] | ||
{nl.join(uncertified_maps)} | ||
[small] | ||
.* | ||
[medium] | ||
.* | ||
[large] | ||
.* | ||
[extraLarge] | ||
.* | ||
[misc] | ||
.* | ||
[1v1] | ||
{nl.join(maps_1v1)} | ||
""" | ||
|
||
for i in teamsize_dict: | ||
output_string = output_string + '[' + i + ']\n' | ||
output_string += '\n'.join(teamsize_dict[i]) | ||
output_string = output_string + '\n\n' | ||
|
||
return output_string | ||
|
||
def process(input_file,output_file): | ||
teamsize_dict, certified_maps, uncertified_maps, maps_1v1 = get_data(input_file) | ||
output = get_output_string(teamsize_dict, certified_maps, uncertified_maps, maps_1v1) | ||
with open(output_file, "w") as f: | ||
f.write(output) | ||
|
||
if __name__ == '__main__': | ||
input_file = './gen/map_list.validated.json' | ||
output_file = './gen/mapLists.conf' | ||
process(input_file, output_file) |